serrano 0.6.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'faraday'
4
- require 'multi_json'
3
+ require "faraday"
4
+ require "multi_json"
5
5
 
6
6
  # @private
7
7
  module FaradayMiddleware
@@ -15,13 +15,13 @@ module FaradayMiddleware
15
15
  when 404
16
16
  raise Serrano::NotFound, error_message_400(response)
17
17
  when 500
18
- raise Serrano::InternalServerError, error_message_500(response, 'Something is technically wrong.')
18
+ raise Serrano::InternalServerError, error_message_500(response, "Something is technically wrong.")
19
19
  when 502
20
- raise Serrano::BadGateway, error_message_500(response, 'The server returned an invalid or incomplete response.')
20
+ raise Serrano::BadGateway, error_message_500(response, "The server returned an invalid or incomplete response.")
21
21
  when 503
22
- raise Serrano::ServiceUnavailable, error_message_500(response, 'Crossref is rate limiting your requests.')
22
+ raise Serrano::ServiceUnavailable, error_message_500(response, "Crossref is rate limiting your requests.")
23
23
  when 504
24
- raise Serrano::GatewayTimeout, error_message_500(response, '504 Gateway Time-out')
24
+ raise Serrano::GatewayTimeout, error_message_500(response, "504 Gateway Time-out")
25
25
  end
26
26
  end
27
27
  end
@@ -41,12 +41,12 @@ module FaradayMiddleware
41
41
  if !body.nil? && !body.empty? && body.is_a?(String)
42
42
  if json?(body)
43
43
  body = ::MultiJson.load(body)
44
- if body['message'].nil?
44
+ if body["message"].nil?
45
45
  body = nil
46
- elseif body['message'].length == 1
47
- body = body['message']
46
+ elseif body["message"].length == 1
47
+ body = body["message"]
48
48
  else
49
- body = body['message'].collect { |x| x['message'] }.join('; ')
49
+ body = body["message"].collect { |x| x["message"] }.join("; ")
50
50
  end
51
51
  end
52
52
  end
@@ -59,7 +59,7 @@ module FaradayMiddleware
59
59
  end
60
60
 
61
61
  def error_message_500(response, body = nil)
62
- "#{response[:method].to_s.upcase} #{response[:url]}: #{[response[:status].to_s + ':', body].compact.join(' ')}"
62
+ "#{response[:method].to_s.upcase} #{response[:url]}: #{[response[:status].to_s + ":", body].compact.join(" ")}"
63
63
  end
64
64
 
65
65
  def json?(string)
@@ -4,41 +4,41 @@
4
4
  module Helpers
5
5
  def filter_handler(x = nil)
6
6
  others = %w[license_url license_version license_delay full_text_version full_text_type
7
- award_number award_funder]
7
+ award_number award_funder]
8
8
  if x.nil?
9
9
  nil
10
10
  else
11
11
  x = stringify(x)
12
12
  nn = x.keys.collect(&:to_s)
13
13
  if nn.collect { |w| others.include? w }.any?
14
- nn = nn.collect do |b|
14
+ nn = nn.collect { |b|
15
15
  if others.include? b
16
16
  case b
17
- when 'license_url'
18
- 'license.url'
19
- when 'license_version'
20
- 'license.version'
21
- when 'license_delay'
22
- 'license.delay'
23
- when 'full_text_version'
24
- 'full-text.version'
25
- when 'full_text_type'
26
- 'full-text.type'
27
- when 'award_number'
28
- 'award.number'
29
- when 'award_funder'
30
- 'award.funder'
17
+ when "license_url"
18
+ "license.url"
19
+ when "license_version"
20
+ "license.version"
21
+ when "license_delay"
22
+ "license.delay"
23
+ when "full_text_version"
24
+ "full-text.version"
25
+ when "full_text_type"
26
+ "full-text.type"
27
+ when "award_number"
28
+ "award.number"
29
+ when "award_funder"
30
+ "award.funder"
31
31
  end
32
32
  else
33
33
  b
34
34
  end
35
- end
35
+ }
36
36
  end
37
37
 
38
- newnn = nn.collect { |m| m.tr('_', '-') }
38
+ newnn = nn.collect { |m| m.tr("_", "-") }
39
39
  x = rename_keys(x, newnn)
40
- x = x.collect { |k, v| [k, v].join(':') }.join(',')
41
- x
40
+ x.collect { |k, v| [k, v].join(":") }.join(",")
41
+
42
42
  end
43
43
  end
44
44
 
@@ -28,73 +28,73 @@ module Serrano
28
28
  end
29
29
 
30
30
  FILTER_DETAILS = {
31
- 'has_funder' => { 'possible_values' => nil, 'description' => 'metadata which includes one or more funder entry' },
32
- 'funder' => { 'possible_values' => '{funder_id}', 'description' => 'metadata which include the {funder_id} in FundRef data' },
33
- 'location' => { 'possible_values' => '{country_name}', 'description' => 'funder records where location = {country name}. Only works on /funders route' },
34
- 'prefix' => { 'possible_values' => '{owner_prefix}', 'description' => "metadata belonging to a DOI owner prefix {owner_prefix} (e.g. '10.1016' )" },
35
- 'member' => { 'possible_values' => '{member_id}', 'description' => 'metadata belonging to a CrossRef member' },
36
- 'from_index_date' => { 'possible_values' => '{date}', 'description' => 'metadata indexed since (inclusive) {date}' },
37
- 'until_index_date' => { 'possible_values' => '{date}', 'description' => 'metadata indexed before (inclusive) {date}' },
38
- 'from_deposit_date' => { 'possible_values' => '{date}', 'description' => 'metadata last (re)deposited since (inclusive) {date}' },
39
- 'until_deposit_date' => { 'possible_values' => '{date}', 'description' => 'metadata last (re)deposited before (inclusive) {date}' },
40
- 'from_update_date' => { 'possible_values' => '{date}', 'description' => "Metadata updated since (inclusive) {date} Currently the same as 'from_deposit_date'" },
41
- 'until_update_date' => { 'possible_values' => '{date}', 'description' => "Metadata updated before (inclusive) {date} Currently the same as 'until_deposit_date'" },
42
- 'from_created_date' => { 'possible_values' => '{date}', 'description' => 'metadata first deposited since (inclusive) {date}' },
43
- 'until_created_date' => { 'possible_values' => '{date}', 'description' => 'metadata first deposited before (inclusive) {date}' },
44
- 'from_pub_date' => { 'possible_values' => '{date}', 'description' => 'metadata where published date is since (inclusive) {date}' },
45
- 'until_pub_date' => { 'possible_values' => '{date}', 'description' => 'metadata where published date is before (inclusive) {date}' },
46
- 'from_online_pub_date' => { 'possible_values' => '{date}', 'description' => 'metadata where online published date is since (inclusive) {date}' },
47
- 'until_online_pub_date' => { 'possible_values' => '{date}', 'description' => 'metadata where online published date is before (inclusive) {date}' },
48
- 'from_print_pub_date' => { 'possible_values' => '{date}', 'description' => 'metadata where print published date is since (inclusive) {date}' },
49
- 'until_print_pub_date' => { 'possible_values' => '{date}', 'description' => 'metadata where print published date is before (inclusive) {date}' },
50
- 'from_posted_date' => { 'possible_values' => '{date}', 'description' => 'metadata where posted date is since (inclusive) {date}' },
51
- 'until_posted_date' => { 'possible_values' => '{date}', 'description' => 'metadata where posted date is before (inclusive) {date}' },
52
- 'from_accepted_date' => { 'possible_values' => '{date}', 'description' => 'metadata where accepted date is since (inclusive) {date}' },
53
- 'until_accepted_date' => { 'possible_values' => '{date}', 'description' => 'metadata where accepted date is before (inclusive) {date}' },
54
- 'has_license' => { 'possible_values' => nil, 'description' => "metadata that includes any '<license_ref>' elements" },
55
- 'license_url' => { 'possible_values' => '{url}', 'description' => "metadata where '<license_ref>' value equals {url}" },
56
- 'license_version' => { 'possible_values' => '{string}', 'description' => "metadata where the '<license_ref>''s 'applies_to' attribute is '{string}'" },
57
- 'license_delay' => { 'possible_values' => '{integer}', 'description' => "metadata where difference between publication date and the '<license_ref>''s 'start_date' attribute is <= '{integer}' (in days" },
58
- 'has_full_text' => { 'possible_values' => nil, 'description' => "metadata that includes any full text '<resource>' elements_" },
59
- 'full_text_version' => { 'possible_values' => '{string}', 'description' => "metadata where '<resource>' element's 'content_version' attribute is '{string}'" },
60
- 'full_text_type' => { 'possible_values' => '{mime_type}', 'description' => "metadata where '<resource>' element's 'content_type' attribute is '{mime_type}' (e.g. 'application/pdf')" },
61
- 'full_text_application' => { 'possible_values' => '{string}', 'description' => 'metadata where <resource> link has one of the following intended applications: text-mining, similarity-checking or unspecified' },
62
- 'has_references' => { 'possible_values' => nil, 'description' => 'metadata for works that have a list of references' },
63
- 'has_archive' => { 'possible_values' => nil, 'description' => 'metadata which include name of archive partner' },
64
- 'archive' => { 'possible_values' => '{string}', 'description' => "metadata which where value of archive partner is '{string}'" },
65
- 'has_orcid' => { 'possible_values' => nil, 'description' => 'metadata which includes one or more ORCIDs' },
66
- 'has_authenticated_orcid' => { 'possible_values' => nil, 'description' => 'metadata which includes one or more ORCIDs where the depositing publisher claims to have witness the ORCID owner authenticate with ORCID' },
67
- 'orcid' => { 'possible_values' => '{orcid}', 'description' => "metadata where '<orcid>' element's value = '{orcid}'" },
68
- 'issn' => { 'possible_values' => '{issn}', 'description' => "metadata where record has an ISSN = '{issn}' Format is 'xxxx_xxxx'." },
69
- 'directory' => { 'possible_values' => '{directory}', 'description' => "metadata records whose article or serial are mentioned in the given '{directory}'. Currently the only supported value is 'doaj'" },
70
- 'doi' => { 'possible_values' => '{doi}', 'description' => "metadata describing the DOI '{doi}'" },
71
- 'updates' => { 'possible_values' => '{doi}', 'description' => "metadata for records that represent editorial updates to the DOI '{doi}'" },
72
- 'is_update' => { 'possible_values' => nil, 'description' => 'metadata for records that represent editorial updates' },
73
- 'has_update_policy' => { 'possible_values' => nil, 'description' => 'metadata for records that include a link to an editorial update policy' },
74
- 'container_title' => { 'possible_values' => nil, 'description' => 'metadata for records with a publication title exactly with an exact match' },
75
- 'category_name' => { 'possible_values' => nil, 'description' => 'metadata for records with an exact matching category label' },
76
- 'type' => { 'possible_values' => '{type}', 'description' => "metadata records whose type = '{type}' Type must be an ID value from the list of types returned by the '/types' resource" },
77
- 'type_name' => { 'possible_values' => nil, 'description' => 'metadata for records with an exacty matching type label' },
78
- 'award_number' => { 'possible_values' => '{award_number}', 'description' => "metadata for records with a matching award nunber_ Optionally combine with 'award_funder'" },
79
- 'award_funder' => { 'possible_values' => '{funder doi or id}', 'description' => "metadata for records with an award with matching funder. Optionally combine with 'award_number'" },
80
- 'has_assertion' => { 'possible_values' => nil, 'description' => 'metadata for records with any assertions' },
81
- 'assertion_group' => { 'possible_values' => nil, 'description' => 'metadata for records with an assertion in a particular group' },
82
- 'assertion' => { 'possible_values' => nil, 'description' => 'metadata for records with a particular named assertion' },
83
- 'has_affiliation' => { 'possible_values' => nil, 'description' => 'metadata for records that have any affiliation information' },
84
- 'alternative_id' => { 'possible_values' => nil, 'description' => 'metadata for records with the given alternative ID, which may be a publisher_specific ID, or any other identifier a publisher may have provided' },
85
- 'article_number' => { 'possible_values' => nil, 'description' => 'metadata for records with a given article number' },
86
- 'has_abstract' => { 'possible_values' => nil, 'description' => 'metadata for records which include an abstract' },
87
- 'has_clinical_trial_number' => { 'possible_values' => nil, 'description' => 'metadata for records which include a clinical trial number' },
88
- 'content_domain' => { 'possible_values' => nil, 'description' => 'metadata where the publisher records a particular domain name as the location Crossmark content will appear' },
89
- 'has_content_domain' => { 'possible_values' => nil, 'description' => 'metadata where the publisher records a domain name location for Crossmark content' },
90
- 'has_crossmark_restriction' => { 'possible_values' => nil, 'description' => 'metadata where the publisher restricts Crossmark usage to content domains' },
91
- 'has_relation' => { 'possible_values' => nil, 'description' => 'metadata for records that either assert or are the object of a relation' },
92
- 'relation_type' => { 'possible_values' => nil, 'description' => 'One of the relation types from the Crossref relations schema (e.g. is-referenced-by, is-parent-of, is-preprint-of)' },
93
- 'relation_object' => { 'possible_values' => nil, 'description' => 'Relations where the object identifier matches the identifier provided' },
94
- 'relation_object_type' => { 'possible_values' => nil, 'description' => 'One of the identifier types from the Crossref relations schema (e.g. doi, issn)' },
95
- 'public_references' => { 'possible_values' => nil, 'description' => 'metadata where publishers allow references to be distributed publically' },
96
- 'publisher_name' => { 'possible_values' => nil, 'description' => 'metadata for records with an exact matching publisher name' },
97
- 'affiliation' => { 'possible_values' => nil, 'description' => 'metadata for records with at least one contributor with the given affiliation' }
31
+ "has_funder" => {"possible_values" => nil, "description" => "metadata which includes one or more funder entry"},
32
+ "funder" => {"possible_values" => "{funder_id}", "description" => "metadata which include the {funder_id} in FundRef data"},
33
+ "location" => {"possible_values" => "{country_name}", "description" => "funder records where location = {country name}. Only works on /funders route"},
34
+ "prefix" => {"possible_values" => "{owner_prefix}", "description" => "metadata belonging to a DOI owner prefix {owner_prefix} (e.g. '10.1016' )"},
35
+ "member" => {"possible_values" => "{member_id}", "description" => "metadata belonging to a CrossRef member"},
36
+ "from_index_date" => {"possible_values" => "{date}", "description" => "metadata indexed since (inclusive) {date}"},
37
+ "until_index_date" => {"possible_values" => "{date}", "description" => "metadata indexed before (inclusive) {date}"},
38
+ "from_deposit_date" => {"possible_values" => "{date}", "description" => "metadata last (re)deposited since (inclusive) {date}"},
39
+ "until_deposit_date" => {"possible_values" => "{date}", "description" => "metadata last (re)deposited before (inclusive) {date}"},
40
+ "from_update_date" => {"possible_values" => "{date}", "description" => "Metadata updated since (inclusive) {date} Currently the same as 'from_deposit_date'"},
41
+ "until_update_date" => {"possible_values" => "{date}", "description" => "Metadata updated before (inclusive) {date} Currently the same as 'until_deposit_date'"},
42
+ "from_created_date" => {"possible_values" => "{date}", "description" => "metadata first deposited since (inclusive) {date}"},
43
+ "until_created_date" => {"possible_values" => "{date}", "description" => "metadata first deposited before (inclusive) {date}"},
44
+ "from_pub_date" => {"possible_values" => "{date}", "description" => "metadata where published date is since (inclusive) {date}"},
45
+ "until_pub_date" => {"possible_values" => "{date}", "description" => "metadata where published date is before (inclusive) {date}"},
46
+ "from_online_pub_date" => {"possible_values" => "{date}", "description" => "metadata where online published date is since (inclusive) {date}"},
47
+ "until_online_pub_date" => {"possible_values" => "{date}", "description" => "metadata where online published date is before (inclusive) {date}"},
48
+ "from_print_pub_date" => {"possible_values" => "{date}", "description" => "metadata where print published date is since (inclusive) {date}"},
49
+ "until_print_pub_date" => {"possible_values" => "{date}", "description" => "metadata where print published date is before (inclusive) {date}"},
50
+ "from_posted_date" => {"possible_values" => "{date}", "description" => "metadata where posted date is since (inclusive) {date}"},
51
+ "until_posted_date" => {"possible_values" => "{date}", "description" => "metadata where posted date is before (inclusive) {date}"},
52
+ "from_accepted_date" => {"possible_values" => "{date}", "description" => "metadata where accepted date is since (inclusive) {date}"},
53
+ "until_accepted_date" => {"possible_values" => "{date}", "description" => "metadata where accepted date is before (inclusive) {date}"},
54
+ "has_license" => {"possible_values" => nil, "description" => "metadata that includes any '<license_ref>' elements"},
55
+ "license_url" => {"possible_values" => "{url}", "description" => "metadata where '<license_ref>' value equals {url}"},
56
+ "license_version" => {"possible_values" => "{string}", "description" => "metadata where the '<license_ref>''s 'applies_to' attribute is '{string}'"},
57
+ "license_delay" => {"possible_values" => "{integer}", "description" => "metadata where difference between publication date and the '<license_ref>''s 'start_date' attribute is <= '{integer}' (in days"},
58
+ "has_full_text" => {"possible_values" => nil, "description" => "metadata that includes any full text '<resource>' elements_"},
59
+ "full_text_version" => {"possible_values" => "{string}", "description" => "metadata where '<resource>' element's 'content_version' attribute is '{string}'"},
60
+ "full_text_type" => {"possible_values" => "{mime_type}", "description" => "metadata where '<resource>' element's 'content_type' attribute is '{mime_type}' (e.g. 'application/pdf')"},
61
+ "full_text_application" => {"possible_values" => "{string}", "description" => "metadata where <resource> link has one of the following intended applications: text-mining, similarity-checking or unspecified"},
62
+ "has_references" => {"possible_values" => nil, "description" => "metadata for works that have a list of references"},
63
+ "has_archive" => {"possible_values" => nil, "description" => "metadata which include name of archive partner"},
64
+ "archive" => {"possible_values" => "{string}", "description" => "metadata which where value of archive partner is '{string}'"},
65
+ "has_orcid" => {"possible_values" => nil, "description" => "metadata which includes one or more ORCIDs"},
66
+ "has_authenticated_orcid" => {"possible_values" => nil, "description" => "metadata which includes one or more ORCIDs where the depositing publisher claims to have witness the ORCID owner authenticate with ORCID"},
67
+ "orcid" => {"possible_values" => "{orcid}", "description" => "metadata where '<orcid>' element's value = '{orcid}'"},
68
+ "issn" => {"possible_values" => "{issn}", "description" => "metadata where record has an ISSN = '{issn}' Format is 'xxxx_xxxx'."},
69
+ "directory" => {"possible_values" => "{directory}", "description" => "metadata records whose article or serial are mentioned in the given '{directory}'. Currently the only supported value is 'doaj'"},
70
+ "doi" => {"possible_values" => "{doi}", "description" => "metadata describing the DOI '{doi}'"},
71
+ "updates" => {"possible_values" => "{doi}", "description" => "metadata for records that represent editorial updates to the DOI '{doi}'"},
72
+ "is_update" => {"possible_values" => nil, "description" => "metadata for records that represent editorial updates"},
73
+ "has_update_policy" => {"possible_values" => nil, "description" => "metadata for records that include a link to an editorial update policy"},
74
+ "container_title" => {"possible_values" => nil, "description" => "metadata for records with a publication title exactly with an exact match"},
75
+ "category_name" => {"possible_values" => nil, "description" => "metadata for records with an exact matching category label"},
76
+ "type" => {"possible_values" => "{type}", "description" => "metadata records whose type = '{type}' Type must be an ID value from the list of types returned by the '/types' resource"},
77
+ "type_name" => {"possible_values" => nil, "description" => "metadata for records with an exacty matching type label"},
78
+ "award_number" => {"possible_values" => "{award_number}", "description" => "metadata for records with a matching award nunber_ Optionally combine with 'award_funder'"},
79
+ "award_funder" => {"possible_values" => "{funder doi or id}", "description" => "metadata for records with an award with matching funder. Optionally combine with 'award_number'"},
80
+ "has_assertion" => {"possible_values" => nil, "description" => "metadata for records with any assertions"},
81
+ "assertion_group" => {"possible_values" => nil, "description" => "metadata for records with an assertion in a particular group"},
82
+ "assertion" => {"possible_values" => nil, "description" => "metadata for records with a particular named assertion"},
83
+ "has_affiliation" => {"possible_values" => nil, "description" => "metadata for records that have any affiliation information"},
84
+ "alternative_id" => {"possible_values" => nil, "description" => "metadata for records with the given alternative ID, which may be a publisher_specific ID, or any other identifier a publisher may have provided"},
85
+ "article_number" => {"possible_values" => nil, "description" => "metadata for records with a given article number"},
86
+ "has_abstract" => {"possible_values" => nil, "description" => "metadata for records which include an abstract"},
87
+ "has_clinical_trial_number" => {"possible_values" => nil, "description" => "metadata for records which include a clinical trial number"},
88
+ "content_domain" => {"possible_values" => nil, "description" => "metadata where the publisher records a particular domain name as the location Crossmark content will appear"},
89
+ "has_content_domain" => {"possible_values" => nil, "description" => "metadata where the publisher records a domain name location for Crossmark content"},
90
+ "has_crossmark_restriction" => {"possible_values" => nil, "description" => "metadata where the publisher restricts Crossmark usage to content domains"},
91
+ "has_relation" => {"possible_values" => nil, "description" => "metadata for records that either assert or are the object of a relation"},
92
+ "relation_type" => {"possible_values" => nil, "description" => "One of the relation types from the Crossref relations schema (e.g. is-referenced-by, is-parent-of, is-preprint-of)"},
93
+ "relation_object" => {"possible_values" => nil, "description" => "Relations where the object identifier matches the identifier provided"},
94
+ "relation_object_type" => {"possible_values" => nil, "description" => "One of the identifier types from the Crossref relations schema (e.g. doi, issn)"},
95
+ "public_references" => {"possible_values" => nil, "description" => "metadata where publishers allow references to be distributed publically"},
96
+ "publisher_name" => {"possible_values" => nil, "description" => "metadata for records with an exact matching publisher name"},
97
+ "affiliation" => {"possible_values" => nil, "description" => "metadata for records with at least one contributor with the given affiliation"}
98
98
  }.freeze
99
99
  end
100
100
  end
@@ -1,11 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'erb'
4
- require 'faraday'
5
- require 'multi_json'
6
- require 'serrano/error'
7
- require 'serrano/utils'
8
- require 'serrano/helpers/configuration'
3
+ require "erb"
4
+ require "faraday"
5
+ require "multi_json"
6
+ require "serrano/error"
7
+ require "serrano/utils"
8
+ require "serrano/helpers/configuration"
9
9
 
10
10
  ##
11
11
  # Serrano::Request
@@ -30,8 +30,8 @@ module Serrano
30
30
  attr_accessor :verbose
31
31
 
32
32
  def initialize(endpt, id, query, filter, offset,
33
- limit, sample, sort, order, facet, select,
34
- works, agency, options, verbose)
33
+ limit, sample, sort, order, facet, select,
34
+ works, agency, options, verbose)
35
35
 
36
36
  self.endpt = endpt
37
37
  self.id = id
@@ -53,29 +53,29 @@ module Serrano
53
53
  def perform
54
54
  filt = filter_handler(filter)
55
55
 
56
- self.select = select.join(',') if select && select.class == Array
56
+ self.select = select.join(",") if select && select.class == Array
57
57
 
58
- args = { query: query, filter: filt, offset: offset,
59
- rows: limit, sample: sample, sort: sort,
60
- order: order, facet: facet,
61
- select: select }
58
+ args = {query: query, filter: filt, offset: offset,
59
+ rows: limit, sample: sample, sort: sort,
60
+ order: order, facet: facet,
61
+ select: select}
62
62
  opts = args.delete_if { |_k, v| v.nil? }
63
63
 
64
64
  conn = if verbose
65
- Faraday.new(url: Serrano.base_url, request: options || []) do |f|
66
- f.response :logger
67
- f.use FaradayMiddleware::RaiseHttpException
68
- f.adapter Faraday.default_adapter
69
- end
70
- else
71
- Faraday.new(url: Serrano.base_url, request: options || []) do |f|
72
- f.use FaradayMiddleware::RaiseHttpException
73
- f.adapter Faraday.default_adapter
74
- end
75
- end
65
+ Faraday.new(url: Serrano.base_url, request: options || []) do |f|
66
+ f.response :logger
67
+ f.use FaradayMiddleware::RaiseHttpException
68
+ f.adapter Faraday.default_adapter
69
+ end
70
+ else
71
+ Faraday.new(url: Serrano.base_url, request: options || []) do |f|
72
+ f.use FaradayMiddleware::RaiseHttpException
73
+ f.adapter Faraday.default_adapter
74
+ end
75
+ end
76
76
 
77
77
  conn.headers[:user_agent] = make_ua
78
- conn.headers['X-USER-AGENT'] = make_ua
78
+ conn.headers["X-USER-AGENT"] = make_ua
79
79
 
80
80
  if id.nil?
81
81
  res = conn.get endpt, opts
@@ -87,12 +87,12 @@ module Serrano
87
87
  coll = []
88
88
  id.each do |x|
89
89
  endpt = if works
90
- self.endpt + '/' + x.to_s + '/works'
91
- elsif agency
92
- self.endpt + '/' + x.to_s + '/agency'
93
- else
94
- self.endpt + '/' + x.to_s
95
- end
90
+ self.endpt + "/" + x.to_s + "/works"
91
+ elsif agency
92
+ self.endpt + "/" + x.to_s + "/agency"
93
+ else
94
+ self.endpt + "/" + x.to_s
95
+ end
96
96
 
97
97
  res = conn.get endpt, opts
98
98
  coll << MultiJson.load(res.body)
@@ -1,15 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'erb'
4
- require 'faraday'
5
- require 'faraday_middleware'
6
- require 'multi_json'
7
- require 'serrano/error'
8
- require 'serrano/helpers/configuration'
9
- require 'serrano/filterhandler'
10
- require 'serrano/error'
11
- require 'serrano/faraday'
12
- require 'serrano/utils'
3
+ require "erb"
4
+ require "faraday"
5
+ require "faraday_middleware"
6
+ require "multi_json"
7
+ require "serrano/error"
8
+ require "serrano/helpers/configuration"
9
+ require "serrano/filterhandler"
10
+ require "serrano/error"
11
+ require "serrano/faraday"
12
+ require "serrano/utils"
13
13
 
14
14
  ##
15
15
  # Serrano::RequestCursor
@@ -37,9 +37,9 @@ module Serrano
37
37
  attr_accessor :args
38
38
 
39
39
  def initialize(endpt, id, query, filter, offset,
40
- limit, sample, sort, order, facet, select,
41
- works, agency, options, verbose, cursor,
42
- cursor_max, args)
40
+ limit, sample, sort, order, facet, select,
41
+ works, agency, options, verbose, cursor,
42
+ cursor_max, args)
43
43
 
44
44
  self.endpt = endpt
45
45
  self.id = id
@@ -64,42 +64,42 @@ module Serrano
64
64
  def perform
65
65
  filt = filter_handler(filter)
66
66
  fieldqueries = field_query_handler(args)
67
- self.select = select.join(',') if select && select.class == Array
67
+ self.select = select.join(",") if select && select.class == Array
68
68
 
69
69
  unless cursor_max.class.nil?
70
- raise 'cursor_max must be of class int' unless cursor_max.is_a?(Integer)
70
+ raise "cursor_max must be of class int" unless cursor_max.is_a?(Integer)
71
71
  end
72
72
 
73
- arguments = { query: query, filter: filt, offset: offset,
74
- rows: limit, sample: sample, sort: sort,
75
- order: order, facet: facet, select: select,
76
- cursor: cursor }.tostrings
73
+ arguments = {query: query, filter: filt, offset: offset,
74
+ rows: limit, sample: sample, sort: sort,
75
+ order: order, facet: facet, select: select,
76
+ cursor: cursor}.tostrings
77
77
  arguments = arguments.merge(fieldqueries)
78
78
  opts = arguments.delete_if { |_k, v| v.nil? }
79
79
 
80
80
  conn = if verbose
81
- Faraday.new(url: Serrano.base_url, request: options || []) do |f|
82
- f.response :logger
83
- f.use FaradayMiddleware::RaiseHttpException
84
- f.adapter Faraday.default_adapter
85
- end
86
- else
87
- Faraday.new(url: Serrano.base_url, request: options || []) do |f|
88
- f.use FaradayMiddleware::RaiseHttpException
89
- f.adapter Faraday.default_adapter
90
- end
91
- end
81
+ Faraday.new(url: Serrano.base_url, request: options || []) do |f|
82
+ f.response :logger
83
+ f.use FaradayMiddleware::RaiseHttpException
84
+ f.adapter Faraday.default_adapter
85
+ end
86
+ else
87
+ Faraday.new(url: Serrano.base_url, request: options || []) do |f|
88
+ f.use FaradayMiddleware::RaiseHttpException
89
+ f.adapter Faraday.default_adapter
90
+ end
91
+ end
92
92
 
93
93
  conn.headers[:user_agent] = make_ua
94
- conn.headers['X-USER-AGENT'] = make_ua
94
+ conn.headers["X-USER-AGENT"] = make_ua
95
95
 
96
96
  if id.nil?
97
97
  endpt2 = endpt
98
98
  js = _req(conn, endpt, opts)
99
- cu = js['message']['next-cursor']
100
- max_avail = js['message']['total-results']
101
- res = _redo_req(conn, js, opts, cu, max_avail)
102
- res
99
+ cu = js["message"]["next-cursor"]
100
+ max_avail = js["message"]["total-results"]
101
+ _redo_req(conn, js, opts, cu, max_avail)
102
+
103
103
  else
104
104
  self.id = Array(id)
105
105
  # url encoding
@@ -107,18 +107,18 @@ module Serrano
107
107
  coll = []
108
108
  id.each do |x|
109
109
  endpt2 = if works
110
- endpt + '/' + x.to_s + '/works'
111
- else
112
- endpt2 = if agency
113
- endpt + '/' + x.to_s + '/agency'
114
- else
115
- endpt + '/' + x.to_s
116
- end
117
- end
110
+ endpt + "/" + x.to_s + "/works"
111
+ else
112
+ endpt2 = if agency
113
+ endpt + "/" + x.to_s + "/agency"
114
+ else
115
+ endpt + "/" + x.to_s
116
+ end
117
+ end
118
118
 
119
119
  js = _req(conn, endpt2, opts)
120
- cu = js['message']['next-cursor']
121
- max_avail = js['message']['total-results']
120
+ cu = js["message"]["next-cursor"]
121
+ max_avail = js["message"]["total-results"]
122
122
  coll << _redo_req(conn, js, opts, cu, max_avail)
123
123
  end
124
124
  coll
@@ -126,15 +126,15 @@ module Serrano
126
126
  end
127
127
 
128
128
  def _redo_req(conn, js, opts, cu, max_avail)
129
- if !cu.nil? && (cursor_max > js['message']['items'].length)
129
+ if !cu.nil? && (cursor_max > js["message"]["items"].length)
130
130
  res = [js]
131
- total = js['message']['items'].length
131
+ total = js["message"]["items"].length
132
132
  while !cu.nil? && (cursor_max > total) && (total < max_avail)
133
133
  opts[:cursor] = cu
134
134
  out = _req(conn, endpt2, opts)
135
- cu = out['message']['next-cursor']
135
+ cu = out["message"]["next-cursor"]
136
136
  res << out
137
- total = res.collect { |x| x['message']['items'].length }.reduce(0, :+)
137
+ total = res.collect { |x| x["message"]["items"].length }.sum
138
138
  end
139
139
  res
140
140
  else