figshare_api_v2 0.9.6 → 0.9.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1a7584ac8d8eb3bd0c1750eccfd3568eef74781b1bb3c5d3c3cce12fe17affab
4
- data.tar.gz: 3d10aed08ec5bbb2b4f9534510e478d70c4ec3f20b2674e073c33249d9e6b56e
3
+ metadata.gz: 5a59303e131674b6b915f07bf0e0aa317a3d5d594c8e87586fe273d8ed83697d
4
+ data.tar.gz: b8bdb004509e69e295b110f60f98ac6da83ea2ea3c5d2bf72e9d46ec041d274a
5
5
  SHA512:
6
- metadata.gz: 141ffdc6d2487e5febd08fd547f2836efadd0b3d55907ba9e025f61846efed48c6e8382c52c0729b85093c5916a5c9569f5fa1adcc08d8650ef132f450ddc46f
7
- data.tar.gz: cf73c9713e16b66e782ef79246a8f7422166d8ae8f06318d34f9fff2bd8bd517af9b1116050604c4ce4e58841b62590f87f4706384578f0f0b808726bc7d3373
6
+ metadata.gz: ebdcee71baa8b80d0c434c9c041255a8843c897574c00725c60c288670854c0d3bce3e404805f03201951b981148ea8bfc49acf465b686af75cabd2bd47655f9
7
+ data.tar.gz: 5cdd11942289e5cb75e4e09afd730ebd12209b161fc68221aa5dadc347a90fc04370d9af464c419b69ed7cb794097254d796cd318ffc9957402cd3736728328b
data/History.txt CHANGED
@@ -1,3 +1,57 @@
1
+ robertburrowes Tue May 10 10:42:27 2022 +1200
2
+ Comment
3
+ robertburrowes Tue May 10 10:40:02 2022 +1200
4
+ Left out the pagination args
5
+ robertburrowes Tue May 10 10:27:57 2022 +1200
6
+ API changes
7
+ robertburrowes Tue May 10 10:21:39 2022 +1200
8
+ API changes
9
+ robertburrowes Tue May 10 10:11:50 2022 +1200
10
+ API changes Added missed &block
11
+ robertburrowes Tue May 10 09:27:50 2022 +1200
12
+ Api changes
13
+ robertburrowes Tue May 10 09:27:27 2022 +1200
14
+ Missed adding _paginate
15
+ robertburrowes Tue May 10 09:26:58 2022 +1200
16
+ Use offset for paginatioon, if only the offset is passed in.
17
+ robertburrowes Mon May 9 17:06:07 2022 +1200
18
+ Add an HTML PATCH wrapper
19
+ robertburrowes Mon May 9 16:57:06 2022 +1200
20
+ Readme update
21
+ robertburrowes Mon May 9 16:54:56 2022 +1200
22
+ Bump version for new Figshare APIs.
23
+ robertburrowes Mon May 9 16:53:27 2022 +1200
24
+ API changes Fixed URL collection article
25
+ robertburrowes Mon May 9 16:52:47 2022 +1200
26
+ fixed param type
27
+ robertburrowes Mon May 9 16:17:56 2022 +1200
28
+ API changes
29
+ robertburrowes Mon May 9 14:55:40 2022 +1200
30
+ Ignore test script
31
+ robertburrowes Mon May 9 14:54:41 2022 +1200
32
+ +x
33
+ robertburrowes Mon May 9 14:54:11 2022 +1200
34
+ Include tags pushing to github
35
+ robertburrowes Mon May 9 14:52:11 2022 +1200
36
+ API updates
37
+ robertburrowes Mon May 9 14:39:15 2022 +1200
38
+ API additions/response changes. Added page/page_size Fixed some string quotes Fixed URL mistypings
39
+ robertburrowes Mon May 9 12:36:08 2022 +1200
40
+ Added setting pagination params from the args
41
+ robertburrowes Mon May 9 11:46:21 2022 +1200
42
+ Search has pagination
43
+ robertburrowes Thu Dec 23 12:20:05 2021 +1300
44
+ Fixed Institutions::hr_upload
45
+ robertburrowes Tue Nov 2 14:49:47 2021 +1300
46
+ hr upload is post, not put
47
+ robertburrowes Tue Nov 2 13:12:30 2021 +1300
48
+ Saner initialization option :)
49
+ robertburrowes Tue Sep 21 13:03:44 2021 +1200
50
+ Experimenting with fetching user accounts. Finding a 9000 limit on the total responses, resulting in odd differences in the numbers between fetching everyone, just active, and just inactive accounts. None of which match using the figshare admin web pages
51
+ robertburrowes Tue Sep 21 13:01:16 2021 +1200
52
+ Rubocop'd
53
+ robertburrowes Tue Sep 21 13:00:57 2021 +1200
54
+ Rubocop'd Added chdir, so Atom starts in the right dir
1
55
  robertburrowes Mon Sep 20 12:31:26 2021 +1200
2
56
  Test for listing all institutional accounts, and getting individual account quota.
3
57
  robertburrowes Mon Sep 20 12:30:34 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
@@ -13,12 +13,19 @@ module Figshare
13
13
  # Opens a connection to the LDAP server, setting @ldap for other methods to use.
14
14
  #
15
15
  # @param figshare_user [String] figshare user, in the figshare_keys.json
16
- # @param conf_dir [String] directory for figshare_keys.json and figshare_site_params.json
17
- def initialize(figshare_user:, conf_dir:)
18
- figshare_token = load_json_file("#{conf_dir}/figshare_keys.json")
16
+ # @param conf_dir [String|nil] directory for figshare_keys.json and figshare_site_params.json
17
+ # @param key_file [String|nil] conf_dir/figshare_keys.json if nil
18
+ # @param conf_file [String|nil] conf_dir/figshare_site_params.json if nil
19
+ def initialize(figshare_user:, conf_dir: nil, key_file: nil, conf_file: nil)
20
+ raise 'Figshare_api_v2.initialize: Need to specify the conf_dir if key_file or conf_file are nil' if conf_dir.nil? && (key_file.nil? || conf_file.nil?)
21
+
22
+ conf_file ||= "#{conf_dir}/figshare_site_params.json"
23
+ key_file ||= "#{conf_dir}/figshare_keys.json"
24
+
25
+ figshare_token = load_json_file(key_file)
19
26
  @auth_token = figshare_token[figshare_user]
20
27
 
21
- figshare_site_params = load_json_file("#{conf_dir}/figshare_site_params.json")
28
+ figshare_site_params = load_json_file(conf_file)
22
29
 
23
30
  @hostname = figshare_site_params['host']
24
31
  @api_url = figshare_site_params['api_url']
@@ -70,10 +77,19 @@ module Figshare
70
77
  raise 'get_paginate(): Expecting args to be a Hash'
71
78
  end
72
79
 
73
- offset = 0
74
- page = 1
75
- limit = page_size = 100
80
+ # Loop variables, if we are using pages
81
+ page = args['page'].nil? ? 1 : args['page']
82
+ page_size = args['page_size'].nil? ? 100 : args['page_size']
83
+
84
+ # Loop variables, if we are using offsets
85
+ offset = args['offset'].nil? ? 0 : args['offset']
86
+ limit = args['limit'].nil? ? 100 : args['limit']
87
+
88
+ by_offset = true if args['page'].nil? && ! args['offset'].nil?
89
+
90
+ # How many results so far.
76
91
  result_count = 0
92
+
77
93
  loop do
78
94
  content_type = response = nil
79
95
  form_args = by_offset ? { 'limit' => limit, 'offset' => offset } : { 'page_size' => page_size, 'page' => page }
@@ -141,11 +157,19 @@ module Figshare
141
157
  # @yield [String] if given a block, iterates through the result from figshare
142
158
  # @return [Integer] number of results.
143
159
  private def post_paginate(api_query:, args: {}, debug: false, by_offset: false, &block)
144
- page = 1
145
- offset = 0
146
- limit = page_size = 100
160
+ # Loop variables, if we are using pages
161
+ page = args['page'].nil? ? 1 : args['page']
162
+ page_size = args['page_size'].nil? ? 100 : args['page_size']
163
+
164
+ # Loop variables, if we are using offsets
165
+ offset = args['offset'].nil? ? 0 : args['offset']
166
+ limit = args['limit'].nil? ? 100 : args['limit']
167
+
168
+ # How many results so far.
147
169
  result_count = 0
148
170
 
171
+ by_offset = true if args['page'].nil? && ! args['offset'].nil?
172
+
149
173
  args = {} if args.nil?
150
174
  if ! args.is_a?(Hash)
151
175
  raise 'post_paginate(): Expecting args to be a Hash'
@@ -207,6 +231,41 @@ module Figshare
207
231
  return iterate_json_response(response: response, content_type: content_type, debug: debug, &block)
208
232
  end
209
233
 
234
+ # Patch iterates through the API response, yielding each value to the passed block
235
+ # When Figshare API usually has no paging option.
236
+ # If there is no block, then the results are printed (useful for debugging)
237
+ #
238
+ # @param api_query [String] base figshare api call, to which we add parameters defined in args
239
+ # @param args [Hash] Key, value pairs which get converted to ?key=arg&key=arg...
240
+ # @param debug [Boolean] print result to stdout
241
+ # @param content_type [String] Assuming Json, but might need binary ('application/octet-stream')
242
+ # @yield [String] if given a block, iterates through the result from figshare
243
+ # @return [Integer] number of results
244
+ private def patch(api_query:, args: {}, data: nil, debug: false, content_type: 'application/json; charset=UTF-8', &block)
245
+ body = nil
246
+ body = if data.is_a?(Hash)
247
+ # Convert hash to json, and merge in additional args
248
+ data.merge(args).to_j
249
+ elsif data.nil? && ! args.empty?
250
+ # No data, but args, so just use the args
251
+ args.to_j
252
+ else
253
+ # Data isn't a Hash, so just pass it through (might be nil)
254
+ data
255
+ end
256
+
257
+ response = nil
258
+ WIKK::WebBrowser.https_session( host: @hostname, verify_cert: false ) do |ws|
259
+ response = ws.patch_req( query: "#{@api_url}#{api_query}",
260
+ content_type: content_type,
261
+ authorization: "token #{@auth_token}",
262
+ data: body
263
+ )
264
+ content_type = ws.header_value(key: 'Content-Type')
265
+ end
266
+ return iterate_json_response(response: response, content_type: content_type, debug: debug, &block)
267
+ end
268
+
210
269
  # delete sends an HTML DELETE request.
211
270
  # We don't expect to get a response to this call.
212
271
  #
@@ -1,7 +1,7 @@
1
1
  module Figshare # :nodoc:
2
2
  # Figshare module initialization
3
3
  #
4
- VERSION = '0.9.6'
4
+ VERSION = '0.9.9'
5
5
 
6
6
  require 'wikk_webbrowser'
7
7
  require 'wikk_json'
@@ -33,94 +33,98 @@ module Figshare # :nodoc:
33
33
  # Intitialize the Init class, so it can dynamically initialize the Figshare subclasses
34
34
  #
35
35
  # @param figshare_user [String] figshare user, in the figshare_keys.json
36
- # @param conf_dir [String] directory for figshare_keys.json and figshare_site_params.json
37
- def initialize(figshare_user:, conf_dir:)
36
+ # @param conf_dir [String|nil] directory for figshare_keys.json and figshare_site_params.json
37
+ # @param key_file [String|nil] conf_dir/figshare_keys.json if nil
38
+ # @param conf_file [String|nil] conf_dir/figshare_site_params.json if nil
39
+ def initialize(figshare_user:, conf_dir: nil, key_file: nil, conf_file: nil)
38
40
  @figshare_user = figshare_user
39
41
  @conf_dir = conf_dir
42
+ @key_file = key_file
43
+ @conf_file = conf_file
40
44
  end
41
45
 
42
46
  # Create Figshare::Authors, if it doesn't exist. Initialized with @figshare_user and @conf_dir
43
47
  #
44
48
  # @return [Figshare::Authors]
45
49
  def authors
46
- @authors ||= Authors.new(figshare_user: @figshare_user, conf_dir: @conf_dir)
50
+ @authors ||= Authors.new(figshare_user: @figshare_user, conf_dir: @conf_dir, key_file: @key_file, conf_file: @conf_file)
47
51
  end
48
52
 
49
53
  # Create Figshare::Institutions, if it doesn't exist. Initialized with @figshare_user and @conf_dir
50
54
  #
51
55
  # @return [Figshare::Institutions]
52
56
  def institutions
53
- @institutions ||= Institutions.new(figshare_user: @figshare_user, conf_dir: @conf_dir)
57
+ @institutions ||= Institutions.new(figshare_user: @figshare_user, conf_dir: @conf_dir, key_file: @key_file, conf_file: @conf_file)
54
58
  end
55
59
 
56
60
  # Create Figshare::Other, if it doesn't exist. Initialized with @figshare_user and @conf_dir
57
61
  #
58
62
  # @return [Figshare::Other]
59
63
  def other
60
- @other ||= Other.new(figshare_user: @figshare_user, conf_dir: @conf_dir)
64
+ @other ||= Other.new(figshare_user: @figshare_user, conf_dir: @conf_dir, key_file: @key_file, conf_file: @conf_file)
61
65
  end
62
66
 
63
67
  # Create Figshare::PrivateArticles, if it doesn't exist. Initialized with @figshare_user and @conf_dir
64
68
  #
65
69
  # @return [Figshare::PrivateArticles]
66
70
  def private_articles
67
- @private_articles ||= PrivateArticles.new(figshare_user: @figshare_user, conf_dir: @conf_dir)
71
+ @private_articles ||= PrivateArticles.new(figshare_user: @figshare_user, conf_dir: @conf_dir, key_file: @key_file, conf_file: @conf_file)
68
72
  end
69
73
 
70
74
  # Create Figshare::PrivateCollections, if it doesn't exist. Initialized with @figshare_user and @conf_dir
71
75
  #
72
76
  # @return [Figshare::PrivateCollections]
73
77
  def private_collections
74
- @private_collections ||= PrivateCollections.new(figshare_user: @figshare_user, conf_dir: @conf_dir)
78
+ @private_collections ||= PrivateCollections.new(figshare_user: @figshare_user, conf_dir: @conf_dir, key_file: @key_file, conf_file: @conf_file)
75
79
  end
76
80
 
77
81
  # Create Figshare::PrivateProjects, if it doesn't exist. Initialized with @figshare_user and @conf_dir
78
82
  #
79
83
  # @return [Figshare::PrivateProjects]
80
84
  def private_projects
81
- @private_projects ||= PrivateProjects.new(figshare_user: @figshare_user, conf_dir: @conf_dir)
85
+ @private_projects ||= PrivateProjects.new(figshare_user: @figshare_user, conf_dir: @conf_dir, key_file: @key_file, conf_file: @conf_file)
82
86
  end
83
87
 
84
88
  # Create Figshare::PublicArticles, if it doesn't exist. Initialized with @figshare_user and @conf_dir
85
89
  #
86
90
  # @return [Figshare::PublicArticles]
87
91
  def public_articles
88
- @public_articles ||= PublicArticles.new(figshare_user: @figshare_user, conf_dir: @conf_dir)
92
+ @public_articles ||= PublicArticles.new(figshare_user: @figshare_user, conf_dir: @conf_dir, key_file: @key_file, conf_file: @conf_file)
89
93
  end
90
94
 
91
95
  # Create Figshare::PublicCollections, if it doesn't exist. Initialized with @figshare_user and @conf_dir
92
96
  #
93
97
  # @return [Figshare::PublicCollections]
94
98
  def public_collections
95
- @public_collections ||= PublicCollections.new(figshare_user: @figshare_user, conf_dir: @conf_dir)
99
+ @public_collections ||= PublicCollections.new(figshare_user: @figshare_user, conf_dir: @conf_dir, key_file: @key_file, conf_file: @conf_file)
96
100
  end
97
101
 
98
102
  # Create Figshare::PublicProjects, if it doesn't exist. Initialized with @figshare_user and @conf_dir
99
103
  #
100
104
  # @return [Figshare::PublicProjects]
101
105
  def public_projects
102
- @public_projects ||= PublicProjects.new(figshare_user: @figshare_user, conf_dir: @conf_dir)
106
+ @public_projects ||= PublicProjects.new(figshare_user: @figshare_user, conf_dir: @conf_dir, key_file: @key_file, conf_file: @conf_file)
103
107
  end
104
108
 
105
109
  # Create Figshare::Upload, if it doesn't exist. Initialized with @figshare_user and @conf_dir
106
110
  #
107
111
  # @return [Figshare::Upload]
108
112
  def upload
109
- @upload ||= Upload.new(figshare_user: @figshare_user, conf_dir: @conf_dir)
113
+ @upload ||= Upload.new(figshare_user: @figshare_user, conf_dir: @conf_dir, key_file: @key_file, conf_file: @conf_file)
110
114
  end
111
115
 
112
116
  # Create Figshare::Stats, if it doesn't exist. Initialized with @figshare_user and @conf_dir
113
117
  #
114
118
  # @return [Figshare::Stats]
115
119
  def stats
116
- @stats ||= Stats.new(figshare_user: @figshare_user, conf_dir: @conf_dir)
120
+ @stats ||= Stats.new(figshare_user: @figshare_user, conf_dir: @conf_dir, key_file: @key_file, conf_file: @conf_file)
117
121
  end
118
122
 
119
123
  # Create Figshare::OAI_PMH, if it doesn't exist. Initialized with @figshare_user and @conf_dir
120
124
  #
121
125
  # @return [Figshare::OAI_PMH]
122
126
  def oai_pmh
123
- @oai_pmh ||= OAI_PMH.new(figshare_user: @figshare_user, conf_dir: @conf_dir)
127
+ @oai_pmh ||= OAI_PMH.new(figshare_user: @figshare_user, conf_dir: @conf_dir, key_file: @key_file, conf_file: @conf_file)
124
128
  end
125
129
  end
126
130
  end