@@ -12,11 +12,14 @@ class Dataverse(object):
1212 def __init__ (self , connection , collection ):
1313 self .connection = connection
1414 self .collection = collection
15+
16+ self ._collection_info = None
1517 self ._contents_json = None
1618
1719 @property
1820 def is_published (self ):
1921
22+ # Always check latest version
2023 collection_info = requests .get (
2124 self .collection .get ('href' ),
2225 auth = self .connection .auth ,
@@ -61,6 +64,16 @@ def get_contents(self, refresh=False):
6164 self ._contents_json = resp .json ()['data' ]
6265 return self ._contents_json
6366
67+ def get_collection_info (self , refresh = False ):
68+ if not refresh and self ._collection_info :
69+ return self ._collection_info
70+
71+ self ._collection_info = requests .get (
72+ self .collection .get ('href' ),
73+ auth = self .connection .auth ,
74+ ).content
75+ return self ._collection_info
76+
6477 def publish (self ):
6578 edit_uri = 'https://{0}/dvn/api/data-deposit/v1.1/swordv2/edit/dataverse/{1}' .format (
6679 self .connection .host , self .alias
@@ -94,6 +107,7 @@ def add_dataset(self, dataset):
94107
95108 dataset .dataverse = self
96109 dataset ._refresh (receipt = resp .content )
110+ self .get_collection_info (refresh = True )
97111
98112 def delete_dataset (self , dataset ):
99113 if dataset ._state == 'DELETED' or dataset ._state == 'DEACCESSIONED' :
@@ -111,22 +125,18 @@ def delete_dataset(self, dataset):
111125 )
112126
113127 dataset ._state = 'DEACCESSIONED'
128+ self .get_collection_info (refresh = True )
114129
115- def get_datasets (self ):
116-
117- collection_info = requests .get (
118- self .collection .get ('href' ),
119- auth = self .connection .auth ,
120- ).content
121-
130+ def get_datasets (self , refresh = False ):
131+ collection_info = self .get_collection_info (refresh )
122132 entries = get_elements (collection_info , tag = 'entry' )
123133 return [Dataset .from_dataverse (entry , self ) for entry in entries ]
124134
125- def get_dataset_by_doi (self , doi ):
126- return next ((s for s in self .get_datasets () if s .doi == doi ), None )
135+ def get_dataset_by_doi (self , doi , refresh = False ):
136+ return next ((s for s in self .get_datasets (refresh ) if s .doi == doi ), None )
127137
128- def get_dataset_by_title (self , title ):
129- return next ((s for s in self .get_datasets () if s .title == title ), None )
138+ def get_dataset_by_title (self , title , refresh = False ):
139+ return next ((s for s in self .get_datasets (refresh ) if s .title == title ), None )
130140
131- def get_dataset_by_string_in_entry (self , string ):
132- return next ((s for s in self .get_datasets () if string in s .get_entry ()), None )
141+ def get_dataset_by_string_in_entry (self , string , refresh = False ):
142+ return next ((s for s in self .get_datasets (refresh ) if string in s .get_entry ()), None )
0 commit comments