figshare_api_v2 0.9.7 → 0.9.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a86e2853e1c2c18bf91ac4c3bd5052969bdf6924ea5fb3c7e89c47e6b3269c17
4
- data.tar.gz: 4a27f7e8c20b0e9bbdc6227b7f0a0d85ab68f66e8ff8870c9d62754976dddc12
3
+ metadata.gz: 1b02d428dc8877f75c9bf9ba05d54b1465944745ec2ff1ca0c962bc6803cdc0a
4
+ data.tar.gz: 6095dffd50dbd105b0ccadeffd3f9243c0434f44cb79bcec32872008add97fab
5
5
  SHA512:
6
- metadata.gz: dc319835c9ce246e14d9b221bff575af8aa05b70e782b12d674b17f858ff2cfd309f1535ca0e371dea3f5ce23b33d26d64721dd786eb2085cde995aa213d370d
7
- data.tar.gz: '01970e2696c5a5f969463d38446a7a658e12f0e8cabad2704fc5fb00202058891ef7748d5993540e7da24da6ebea4081f8322917493141bd491329608c98800a'
6
+ metadata.gz: 59456d19b2df1624bd7f276c6672326ce888fa967f51ff8aace4b8317ac67990e579aaa85affcd098f4b390b46073353df479d50cd9a65b1b690e04d2a96fcc1
7
+ data.tar.gz: c06980357bed4295c410ae9f08a04de00108620647268445990c8d7c5a82221d4d824c0a32e1baa08918f9be9c628057afce07dca3c5da2b0013258f1258e485
data/History.txt CHANGED
@@ -1,3 +1,69 @@
1
+ robertburrowes Fri May 13 08:40:05 2022 +1200
2
+ Bumped minor version
3
+ robertburrowes Thu May 12 17:25:07 2022 +1200
4
+ Moved the accounts_wrapper() into institution.accounts(), less the debugging stuff
5
+ robertburrowes Thu May 12 17:06:48 2022 +1200
6
+ Comment
7
+ robertburrowes Thu May 12 16:52:57 2022 +1200
8
+ Check returned account IDs are in order (they do seem to be)
9
+ robertburrowes Thu May 12 16:32:58 2022 +1200
10
+ Incorporate the new id_gte into institute.accounts, as page/page_size pagination has a 9000 record limit.
11
+ robertburrowes Thu May 12 16:22:48 2022 +1200
12
+ return earlier, in _paginate, to not set 'page'
13
+ robertburrowes Thu May 12 15:56:44 2022 +1200
14
+ Added 'once_only' to the post and get _pagination calls, so we don't automatically move onto the next page.
15
+ robertburrowes Thu May 12 11:18:45 2022 +1200
16
+ Refactored _pagination response code to see if it helped fix the duplicate record issue. It didn't.
17
+ robertburrowes Thu May 12 09:43:45 2022 +1200
18
+ Added debug output of updated Figshare API.
19
+ robertburrowes Wed May 11 09:07:42 2022 +1200
20
+ update comments
21
+ robertburrowes Tue May 10 10:42:27 2022 +1200
22
+ Comment
23
+ robertburrowes Tue May 10 10:40:02 2022 +1200
24
+ Left out the pagination args
25
+ robertburrowes Tue May 10 10:27:57 2022 +1200
26
+ API changes
27
+ robertburrowes Tue May 10 10:21:39 2022 +1200
28
+ API changes
29
+ robertburrowes Tue May 10 10:11:50 2022 +1200
30
+ API changes Added missed &block
31
+ robertburrowes Tue May 10 09:27:50 2022 +1200
32
+ Api changes
33
+ robertburrowes Tue May 10 09:27:27 2022 +1200
34
+ Missed adding _paginate
35
+ robertburrowes Tue May 10 09:26:58 2022 +1200
36
+ Use offset for paginatioon, if only the offset is passed in.
37
+ robertburrowes Mon May 9 17:06:07 2022 +1200
38
+ Add an HTML PATCH wrapper
39
+ robertburrowes Mon May 9 16:57:06 2022 +1200
40
+ Readme update
41
+ robertburrowes Mon May 9 16:54:56 2022 +1200
42
+ Bump version for new Figshare APIs.
43
+ robertburrowes Mon May 9 16:53:27 2022 +1200
44
+ API changes Fixed URL collection article
45
+ robertburrowes Mon May 9 16:52:47 2022 +1200
46
+ fixed param type
47
+ robertburrowes Mon May 9 16:17:56 2022 +1200
48
+ API changes
49
+ robertburrowes Mon May 9 14:55:40 2022 +1200
50
+ Ignore test script
51
+ robertburrowes Mon May 9 14:54:41 2022 +1200
52
+ +x
53
+ robertburrowes Mon May 9 14:54:11 2022 +1200
54
+ Include tags pushing to github
55
+ robertburrowes Mon May 9 14:52:11 2022 +1200
56
+ API updates
57
+ robertburrowes Mon May 9 14:39:15 2022 +1200
58
+ API additions/response changes. Added page/page_size Fixed some string quotes Fixed URL mistypings
59
+ robertburrowes Mon May 9 12:36:08 2022 +1200
60
+ Added setting pagination params from the args
61
+ robertburrowes Mon May 9 11:46:21 2022 +1200
62
+ Search has pagination
63
+ robertburrowes Thu Dec 23 12:20:05 2021 +1300
64
+ Fixed Institutions::hr_upload
65
+ robertburrowes Tue Nov 2 14:49:47 2021 +1300
66
+ hr upload is post, not put
1
67
  robertburrowes Tue Nov 2 13:12:30 2021 +1300
2
68
  Saner initialization option :)
3
69
  robertburrowes Tue Sep 21 13:03:44 2021 +1200
data/README.md CHANGED
@@ -7,7 +7,9 @@
7
7
 
8
8
  ## DESCRIPTION:
9
9
 
10
- Figshare version 2 API.
10
+ Figshare version 2 API.
11
+
12
+ Actually the second version of the version 2 APIs. Lots of changes have been made by Figshare, mostly expanding what is returned from the API calls, but they also added some fields. Looks mostly backwards compatible.
11
13
 
12
14
  ## FEATURES/PROBLEMS:
13
15
 
@@ -71,4 +73,3 @@ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
71
73
  CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
72
74
  TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
73
75
  SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
74
-
data/lib/authors.rb CHANGED
@@ -4,13 +4,17 @@ module Figshare
4
4
  class Authors < Base
5
5
  # Search authors
6
6
  #
7
- # @param institution [Boolean] Just our institution
8
- # @param group_id [Integer] Only return this group's collections
7
+ # @param institution [Boolean] Just our institution. We have already stored the institute_id.
9
8
  # @param orcid [String] Matches this orcid
9
+ # @param group_id [Integer] Only return this group's collections
10
10
  # @param is_active [Boolean]
11
11
  # @param is_public [Boolean]
12
12
  # @param order [String] "published_date" Default, "modified_date", "views", "cites", "shares"
13
13
  # @param order_direction [String] "desc" Default, "asc"
14
+ # @param page [Numeric] Pages start at 1. Page and Page size go together
15
+ # @param page_size [Numeric]
16
+ # @param offset [Numeric] offset is 0 based. Offset and Limit go together
17
+ # @param limit [Numeric]
14
18
  # @yield [Hash] {id, first_name, last_name, full_name, url_name, is_active, is_public, orcid_id, institution_id, group_id, job_title}
15
19
  def search( search_for:,
16
20
  institute: false,
@@ -20,6 +24,10 @@ module Figshare
20
24
  is_public: true,
21
25
  order: 'published_date',
22
26
  order_direction: 'desc',
27
+ page: nil,
28
+ page_size: nil,
29
+ offset: nil,
30
+ limit: nil,
23
31
  &block
24
32
  )
25
33
  args = { 'search_for' => search_for }
@@ -30,7 +38,11 @@ module Figshare
30
38
  args['orcid'] = orcid unless orcid.nil?
31
39
  args['order'] = order unless order.nil?
32
40
  args['order_direction'] = order_direction unless order_direction.nil?
33
- post(api_query: 'account/authors/search', args: args, &block)
41
+ args['page'] = page unless page.nil?
42
+ args['page_size'] = page_size unless page_size.nil?
43
+ args['offset'] = offset unless offset.nil?
44
+ args['limit'] = limit unless limit.nil?
45
+ post_paginate(api_query: 'account/authors/search', args: args, &block)
34
46
  end
35
47
 
36
48
  # Get an authors details
@@ -38,7 +50,7 @@ module Figshare
38
50
  # @param author_id [Integer] Figshare Author ID
39
51
  # @yield [Hash] {id, first_name, last_name, full_name, url_name, is_active, is_public, orcid_id, institution_id, group_id, job_title}
40
52
  def detail(author_id:, &block)
41
- get(api_query: "account/authors/#{author_id}", &block)
53
+ get(api_query: "account/authors/#{author_id}", &block)
42
54
  end
43
55
  end
44
56
  end
data/lib/base.rb CHANGED
@@ -71,32 +71,53 @@ module Figshare
71
71
  # @param by_offset [Boolean] use offset/limit rather than page/page_size in API calls
72
72
  # @yield [String] if given a block, iterates through the result from figshare
73
73
  # @return [Integer] number of results.
74
- private def get_paginate(api_query:, args: {}, debug: false, by_offset: false, &block)
74
+ private def get_paginate(api_query:, args: {}, debug: false, by_offset: false, once_only: false, &block)
75
75
  args = {} if args.nil?
76
- if ! args.is_a?(Hash)
77
- raise 'get_paginate(): Expecting args to be a Hash'
76
+ raise 'get_paginate(): Expecting args to be a Hash' unless args.is_a?(Hash)
77
+
78
+ by_offset = true if args['page'].nil? && ! args['offset'].nil?
79
+ if by_offset
80
+ # Loop variables, if we are using offsets
81
+ offset = args['offset'].nil? ? 0 : args['offset']
82
+ limit = args['limit'].nil? ? 100 : args['limit']
83
+ args['offset'] = offset
84
+ args['limit'] = limit
85
+ else
86
+ page = args['page'].nil? ? 1 : args['page']
87
+ page_size = args['page_size'].nil? ? 100 : args['page_size']
88
+ args['page'] = page
89
+ args['page_size'] = page_size
78
90
  end
79
91
 
80
- offset = 0
81
- page = 1
82
- limit = page_size = 100
92
+ # How many results so far.
83
93
  result_count = 0
94
+
84
95
  loop do
85
96
  content_type = response = nil
86
- form_args = by_offset ? { 'limit' => limit, 'offset' => offset } : { 'page_size' => page_size, 'page' => page }
87
97
  WIKK::WebBrowser.https_session( host: @hostname, verify_cert: false ) do |ws|
88
98
  response = ws.get_page( query: "#{@api_url}#{api_query}",
89
99
  authorization: "token #{@auth_token}",
90
- form_values: form_args.merge(args)
100
+ form_values: args
91
101
  )
92
102
  content_type = ws.header_value(key: 'Content-Type')
93
103
  end
104
+ # File.write("/tmp/debug_#{args['id_gte']}_#{page}.json", response)
94
105
  page_count = iterate_json_response(response: response, content_type: content_type, debug: debug, &block)
95
106
  result_count += page_count
96
- break if page_count < page_size # Got less results than we asked for, so it was the last page
97
107
 
98
- page += 1 # Ready to fetch next page
99
- offset += limit # if we use offset, then mor
108
+ return result_count if once_only
109
+
110
+ if by_offset
111
+ break if page_count < limit # Got less results than we asked for, so it was the last page
112
+
113
+ offset += limit # if we use offset
114
+ args['offset'] = offset
115
+ else
116
+ break if page_count < page_size # Got less results than we asked for, so it was the last page
117
+
118
+ page += 1 # Ready to fetch next page
119
+ args['page'] = page
120
+ end
100
121
  end
101
122
 
102
123
  return result_count
@@ -147,34 +168,54 @@ module Figshare
147
168
  # @param by_offset [Boolean] use offset/limit rather than page/page_size in API calls
148
169
  # @yield [String] if given a block, iterates through the result from figshare
149
170
  # @return [Integer] number of results.
150
- private def post_paginate(api_query:, args: {}, debug: false, by_offset: false, &block)
151
- page = 1
152
- offset = 0
153
- limit = page_size = 100
154
- result_count = 0
155
-
171
+ private def post_paginate(api_query:, args: {}, debug: false, by_offset: false, once_only: false, &block)
172
+ # Loop variables, if we are using pages
156
173
  args = {} if args.nil?
157
- if ! args.is_a?(Hash)
158
- raise 'post_paginate(): Expecting args to be a Hash'
174
+ raise 'post_paginate(): Expecting args to be a Hash' unless args.is_a?(Hash)
175
+
176
+ by_offset = true if args['page'].nil? && ! args['offset'].nil?
177
+ if by_offset
178
+ # Loop variables, if we are using offsets
179
+ offset = args['offset'].nil? ? 0 : args['offset']
180
+ limit = args['limit'].nil? ? 100 : args['limit']
181
+ args['offset'] = offset
182
+ args['limit'] = limit
183
+ else
184
+ page = args['page'].nil? ? 1 : args['page']
185
+ page_size = args['page_size'].nil? ? 100 : args['page_size']
186
+ args['page'] = page
187
+ args['page_size'] = page_size
159
188
  end
160
189
 
190
+ # How many results so far.
191
+ result_count = 0
192
+
161
193
  loop do
162
194
  content_type = response = nil
163
- form_args = by_offset ? { 'limit' => limit, 'offset' => offset } : { 'page_size' => page_size, 'page' => page }
164
195
  WIKK::WebBrowser.https_session( host: @hostname, verify_cert: false ) do |ws|
165
196
  response = ws.post_page( query: "#{@api_url}#{api_query}",
166
197
  content_type: 'application/json; charset=UTF-8',
167
198
  authorization: "token #{@auth_token}",
168
- data: args.merge(form_args).to_j
199
+ data: args.to_j
169
200
  )
170
201
  content_type = ws.header_value(key: 'Content-Type')
171
202
  end
172
203
  page_count = iterate_json_response(response: response, content_type: content_type, debug: debug, &block)
173
204
  result_count += page_count
174
- break if page_count < page_size # Got less results than we asked for, so it was the last page
175
205
 
176
- page += 1 # Ready to fetch next page
177
- offset += limit # if we use offset
206
+ return result_count if once_only
207
+
208
+ if by_offset
209
+ break if page_count < limit # Got less results than we asked for, so it was the last page
210
+
211
+ offset += limit # if we use offset
212
+ args['offset'] = offset
213
+ else
214
+ break if page_count < page_size # Got less results than we asked for, so it was the last page
215
+
216
+ page += 1 # Ready to fetch next page
217
+ args['page'] = page
218
+ end
178
219
  end
179
220
  return result_count
180
221
  end
@@ -214,6 +255,41 @@ module Figshare
214
255
  return iterate_json_response(response: response, content_type: content_type, debug: debug, &block)
215
256
  end
216
257
 
258
+ # Patch iterates through the API response, yielding each value to the passed block
259
+ # When Figshare API usually has no paging option.
260
+ # If there is no block, then the results are printed (useful for debugging)
261
+ #
262
+ # @param api_query [String] base figshare api call, to which we add parameters defined in args
263
+ # @param args [Hash] Key, value pairs which get converted to ?key=arg&key=arg...
264
+ # @param debug [Boolean] print result to stdout
265
+ # @param content_type [String] Assuming Json, but might need binary ('application/octet-stream')
266
+ # @yield [String] if given a block, iterates through the result from figshare
267
+ # @return [Integer] number of results
268
+ private def patch(api_query:, args: {}, data: nil, debug: false, content_type: 'application/json; charset=UTF-8', &block)
269
+ body = nil
270
+ body = if data.is_a?(Hash)
271
+ # Convert hash to json, and merge in additional args
272
+ data.merge(args).to_j
273
+ elsif data.nil? && ! args.empty?
274
+ # No data, but args, so just use the args
275
+ args.to_j
276
+ else
277
+ # Data isn't a Hash, so just pass it through (might be nil)
278
+ data
279
+ end
280
+
281
+ response = nil
282
+ WIKK::WebBrowser.https_session( host: @hostname, verify_cert: false ) do |ws|
283
+ response = ws.patch_req( query: "#{@api_url}#{api_query}",
284
+ content_type: content_type,
285
+ authorization: "token #{@auth_token}",
286
+ data: body
287
+ )
288
+ content_type = ws.header_value(key: 'Content-Type')
289
+ end
290
+ return iterate_json_response(response: response, content_type: content_type, debug: debug, &block)
291
+ end
292
+
217
293
  # delete sends an HTML DELETE request.
218
294
  # We don't expect to get a response to this call.
219
295
  #
@@ -1,7 +1,7 @@
1
1
  module Figshare # :nodoc:
2
2
  # Figshare module initialization
3
3
  #
4
- VERSION = '0.9.7'
4
+ VERSION = '0.9.10'
5
5
 
6
6
  require 'wikk_webbrowser'
7
7
  require 'wikk_json'