colrapi 0.1.0 → 0.1.1

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: 45d0b45d7d61f0ef91fda1d02f2f90eef26296a0f9dde8621637a03d3616469e
4
- data.tar.gz: ba27842e25d7727443e69481e03b75af7649dd53d917136cbd1b6883a4b8cd4f
3
+ metadata.gz: 6d185adfc2ce8f6fb4fbcfe4147e3eba4534e94a2934af0a068480bb681a1364
4
+ data.tar.gz: d05ecc9a9c656f13b64ea4993809208da7b623a8702d37571090066d16625477
5
5
  SHA512:
6
- metadata.gz: 24197d4e95bb99ed80189ce7263781ec212c04b733cb98f188b496a78f1ec42ca3cdf14e3cd73e64acdd520e89047c9502785beaf5f53582b2cbed7740af0747
7
- data.tar.gz: c80b544c93a171ba2f768468a262175dcae973df961e88e0d28639596d876c3237e714af3e1b8b530c009a3932b7c8f5698991009ecb2dde93e794cae29acbab
6
+ metadata.gz: 1ead5baa09b3af575ac5608621e8c409620de0fc1e8c780823824517fba02bbb95ccf6d82cfdcac4796fc69c4fc2f9809823b811d1db38bb60a008ca3472ae74
7
+ data.tar.gz: a654921132c8e78be7db02c29fd69df842178e286098eafb9a6128ae26b7030eabcdd47a294b752f904b326802f3c91ab03583cb3a5135cb8b8005dd6d0fedcf
data/.gitignore CHANGED
@@ -8,3 +8,4 @@
8
8
  /pkg/
9
9
  /spec/reports/
10
10
  /tmp/
11
+ *.gem
data/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.1.1] - 2023-04-17
4
+ - Updated Faraday version
5
+
3
6
  ## [0.1.0] - 2022-01-20
4
7
 
5
8
  - Initial release
data/Gemfile.lock CHANGED
@@ -1,9 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- colrapi (0.1.0)
5
- faraday (~> 1.0)
6
- faraday_middleware (~> 1.2)
4
+ colrapi (0.1.1)
5
+ faraday (~> 2.2)
6
+ faraday-follow_redirects (>= 0.1, < 0.4)
7
7
  multi_json (~> 1.15)
8
8
 
9
9
  GEM
@@ -14,35 +14,15 @@ GEM
14
14
  byebug (11.1.3)
15
15
  crack (0.4.5)
16
16
  rexml
17
- faraday (1.9.3)
18
- faraday-em_http (~> 1.0)
19
- faraday-em_synchrony (~> 1.0)
20
- faraday-excon (~> 1.1)
21
- faraday-httpclient (~> 1.0)
22
- faraday-multipart (~> 1.0)
23
- faraday-net_http (~> 1.0)
24
- faraday-net_http_persistent (~> 1.0)
25
- faraday-patron (~> 1.0)
26
- faraday-rack (~> 1.0)
27
- faraday-retry (~> 1.0)
17
+ faraday (2.7.4)
18
+ faraday-net_http (>= 2.0, < 3.1)
28
19
  ruby2_keywords (>= 0.0.4)
29
- faraday-em_http (1.0.0)
30
- faraday-em_synchrony (1.0.0)
31
- faraday-excon (1.1.0)
32
- faraday-httpclient (1.0.1)
33
- faraday-multipart (1.0.3)
34
- multipart-post (>= 1.2, < 3)
35
- faraday-net_http (1.0.1)
36
- faraday-net_http_persistent (1.2.0)
37
- faraday-patron (1.0.0)
38
- faraday-rack (1.0.0)
39
- faraday-retry (1.0.3)
40
- faraday_middleware (1.2.0)
41
- faraday (~> 1.0)
20
+ faraday-follow_redirects (0.3.0)
21
+ faraday (>= 1, < 3)
22
+ faraday-net_http (3.0.2)
42
23
  hashdiff (1.0.1)
43
24
  minitest (5.15.0)
44
25
  multi_json (1.15.0)
45
- multipart-post (2.1.1)
46
26
  power_assert (2.0.1)
47
27
  public_suffix (5.0.1)
48
28
  rake (13.0.6)
data/colrapi.gemspec CHANGED
@@ -42,8 +42,8 @@ Gem::Specification.new do |s|
42
42
  s.add_development_dependency "vcr", "~> 6.0"
43
43
  s.add_development_dependency "webmock", "~> 3.18"
44
44
 
45
- s.add_runtime_dependency "faraday", "~> 1.0"
46
- s.add_runtime_dependency "faraday_middleware", "~> 1.2" # requires 1.0
45
+ s.add_runtime_dependency "faraday", "~> 2.2"
46
+ s.add_runtime_dependency "faraday-follow_redirects", ">= 0.1", "< 0.4"
47
47
  s.add_runtime_dependency "multi_json", "~> 1.15"
48
48
 
49
49
  # TODO: comment out
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Colrapi
4
+ # Custom error class for rescuing from all Colrapi errors
5
+ class Error < StandardError; end
6
+
7
+ # Raised when ChecklistBank returns the HTTP status code 400
8
+ class BadRequest < Error; end
9
+
10
+ # Raised when ChecklistBank returns the HTTP status code 404
11
+ class NotFound < Error; end
12
+
13
+ # Raised when ChecklistBank returns the HTTP status code 500
14
+ class InternalServerError < Error; end
15
+
16
+ # Raised when ChecklistBank returns the HTTP status code 502
17
+ class BadGateway < Error; end
18
+
19
+ # Raised when ChecklistBank returns the HTTP status code 503
20
+ class ServiceUnavailable < Error; end
21
+
22
+ # Raised when ChecklistBank returns the HTTP status code 504
23
+ class GatewayTimeout < Error; end
24
+ end
@@ -1,73 +1,72 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "faraday"
4
- require "faraday_middleware"
5
4
  require "multi_json"
6
5
 
7
6
  # @private
8
- module FaradayMiddleware
9
- # @private
10
- class RaiseHttpException < Faraday::Middleware
11
- def call(env)
12
- @app.call(env).on_complete do |response|
13
- case response[:status].to_i
14
- when 400
15
- raise Colrapi::BadRequest, error_message_400(response)
16
- when 404
17
- raise Colrapi::NotFound, error_message_400(response)
18
- when 500
19
- raise Colrapi::InternalServerError, error_message_500(response, "Something is technically wrong.")
20
- when 502
21
- raise Colrapi::BadGateway, error_message_500(response, "The server returned an invalid or incomplete response.")
22
- when 503
23
- raise Colrapi::ServiceUnavailable, error_message_500(response, "Crossref is rate limiting your requests.")
24
- when 504
25
- raise Colrapi::GatewayTimeout, error_message_500(response, "504 Gateway Time-out")
7
+ module Faraday
8
+ module ColrapiErrors
9
+ # @private
10
+ class Middleware < Faraday::Middleware
11
+ def call(env)
12
+ @app.call(env).on_complete do |response|
13
+ case response[:status].to_i
14
+ when 400
15
+ raise Colrapi::BadRequest, error_message_400(response)
16
+ when 404
17
+ raise Colrapi::NotFound, error_message_400(response)
18
+ when 500
19
+ raise Colrapi::InternalServerError, error_message_500(response, "Something is technically wrong.")
20
+ when 502
21
+ raise Colrapi::BadGateway, error_message_500(response, "The server returned an invalid or incomplete response.")
22
+ when 503
23
+ raise Colrapi::ServiceUnavailable, error_message_500(response, "Crossref is rate limiting your requests.")
24
+ when 504
25
+ raise Colrapi::GatewayTimeout, error_message_500(response, "504 Gateway Time-out")
26
+ end
26
27
  end
27
28
  end
28
- end
29
29
 
30
- def initialize(app)
31
- super app
32
- @parser = nil
33
- end
30
+ def initialize(app)
31
+ super app
32
+ @parser = nil
33
+ end
34
34
 
35
- private
35
+ private
36
36
 
37
- def error_message_400(response)
38
- "\n #{response[:method].to_s.upcase} #{response[:url]}\n Status #{response[:status]}#{error_body(response[:body])}"
39
- end
37
+ def error_message_400(response)
38
+ "\n #{response[:method].to_s.upcase} #{response[:url]}\n Status #{response[:status]}#{error_body(response[:body])}"
39
+ end
40
40
 
41
- def error_body(body)
42
- if !body.nil? && !body.empty? && body.is_a?(String)
43
- if json?(body)
44
- body = ::MultiJson.load(body)
45
- if body["message"].nil?
46
- body = nil
47
- elseif body["message"].length == 1
48
- body = body["message"]
49
- else
50
- body = body["message"].collect { |x| x["message"] }.join("; ")
41
+ def error_body(body)
42
+ if !body.nil? && !body.empty? && body.is_a?(String)
43
+ if json?(body)
44
+ body = ::MultiJson.load(body)
45
+ if body["message"].nil?
46
+ body = nil
47
+ else
48
+ body = body["message"]
49
+ end
51
50
  end
52
51
  end
53
- end
54
52
 
55
- if body.nil?
56
- nil
57
- else
58
- ": #{body}"
53
+ if body.nil?
54
+ nil
55
+ else
56
+ ": #{body}"
57
+ end
59
58
  end
60
- end
61
59
 
62
- def error_message_500(response, body = nil)
63
- "#{response[:method].to_s.upcase} #{response[:url]}: #{[response[:status].to_s + ":", body].compact.join(" ")}"
64
- end
60
+ def error_message_500(response, body = nil)
61
+ "#{response[:method].to_s.upcase} #{response[:url]}: #{[response[:status].to_s + ":", body].compact.join(" ")}"
62
+ end
65
63
 
66
- def json?(string)
67
- MultiJson.load(string)
68
- true
69
- rescue MultiJson::ParseError
70
- false
64
+ def json?(string)
65
+ MultiJson.load(string)
66
+ true
67
+ rescue MultiJson::ParseError
68
+ false
69
+ end
71
70
  end
72
71
  end
73
72
  end
@@ -1,6 +1,7 @@
1
1
  require_relative "faraday" # !! Potential ruby 3.0 difference in module loading? relative differs from Serrano
2
- require "faraday_middleware"
2
+ require "faraday/follow_redirects"
3
3
  require_relative "utils"
4
+ require "colrapi/error"
4
5
 
5
6
  module Colrapi
6
7
  class Request
@@ -137,7 +138,7 @@ module Colrapi
137
138
  f.request(:basic_auth, @user, @password)
138
139
  end
139
140
  f.response :logger
140
- f.use FaradayMiddleware::RaiseHttpException
141
+ f.use Faraday::ColrapiErrors::Middleware
141
142
  f.adapter Faraday.default_adapter
142
143
  end
143
144
  else
@@ -145,7 +146,7 @@ module Colrapi
145
146
  if !@user.nil? and !@password.nil?
146
147
  f.request(:basic_auth, @user, @password)
147
148
  end
148
- f.use FaradayMiddleware::RaiseHttpException
149
+ f.use Faraday::ColrapiErrors::Middleware
149
150
  f.adapter Faraday.default_adapter
150
151
  end
151
152
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Colrapi
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
data/lib/colrapi.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "erb"
4
+ require_relative "colrapi/error"
4
5
  require_relative "colrapi/version"
5
6
  require_relative "colrapi/request"
6
7
  require "colrapi/helpers/configuration"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: colrapi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Yoder, Geoff Ower
@@ -104,28 +104,34 @@ dependencies:
104
104
  requirements:
105
105
  - - "~>"
106
106
  - !ruby/object:Gem::Version
107
- version: '1.0'
107
+ version: '2.2'
108
108
  type: :runtime
109
109
  prerelease: false
110
110
  version_requirements: !ruby/object:Gem::Requirement
111
111
  requirements:
112
112
  - - "~>"
113
113
  - !ruby/object:Gem::Version
114
- version: '1.0'
114
+ version: '2.2'
115
115
  - !ruby/object:Gem::Dependency
116
- name: faraday_middleware
116
+ name: faraday-follow_redirects
117
117
  requirement: !ruby/object:Gem::Requirement
118
118
  requirements:
119
- - - "~>"
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0.1'
122
+ - - "<"
120
123
  - !ruby/object:Gem::Version
121
- version: '1.2'
124
+ version: '0.4'
122
125
  type: :runtime
123
126
  prerelease: false
124
127
  version_requirements: !ruby/object:Gem::Requirement
125
128
  requirements:
126
- - - "~>"
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0.1'
132
+ - - "<"
127
133
  - !ruby/object:Gem::Version
128
- version: '1.2'
134
+ version: '0.4'
129
135
  - !ruby/object:Gem::Dependency
130
136
  name: multi_json
131
137
  requirement: !ruby/object:Gem::Requirement
@@ -175,6 +181,7 @@ files:
175
181
  - bin/setup
176
182
  - colrapi.gemspec
177
183
  - lib/colrapi.rb
184
+ - lib/colrapi/error.rb
178
185
  - lib/colrapi/faraday.rb
179
186
  - lib/colrapi/helpers/configuration.rb
180
187
  - lib/colrapi/request.rb
@@ -186,7 +193,7 @@ licenses:
186
193
  metadata:
187
194
  homepage_uri: https://github.com/SpeciesFileGroup/colrapi
188
195
  source_code_uri: https://github.com/SpeciesFileGroup/colrapi
189
- changelog_uri: https://github.com/SpeciesFileGroup/colrapi/releases/tag/v0.1.0
196
+ changelog_uri: https://github.com/SpeciesFileGroup/colrapi/releases/tag/v0.1.1
190
197
  post_install_message:
191
198
  rdoc_options: []
192
199
  require_paths:
@@ -202,7 +209,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
202
209
  - !ruby/object:Gem::Version
203
210
  version: '0'
204
211
  requirements: []
205
- rubygems_version: 3.3.7
212
+ rubygems_version: 3.4.10
206
213
  signing_key:
207
214
  specification_version: 4
208
215
  summary: Catalog of Life Client