colrapi 0.1.0 → 0.1.1
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 +4 -4
- data/.gitignore +1 -0
- data/CHANGELOG.md +3 -0
- data/Gemfile.lock +8 -28
- data/colrapi.gemspec +2 -2
- data/lib/colrapi/error.rb +24 -0
- data/lib/colrapi/faraday.rb +51 -52
- data/lib/colrapi/request.rb +4 -3
- data/lib/colrapi/version.rb +1 -1
- data/lib/colrapi.rb +1 -0
- metadata +17 -10
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6d185adfc2ce8f6fb4fbcfe4147e3eba4534e94a2934af0a068480bb681a1364
|
|
4
|
+
data.tar.gz: d05ecc9a9c656f13b64ea4993809208da7b623a8702d37571090066d16625477
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1ead5baa09b3af575ac5608621e8c409620de0fc1e8c780823824517fba02bbb95ccf6d82cfdcac4796fc69c4fc2f9809823b811d1db38bb60a008ca3472ae74
|
|
7
|
+
data.tar.gz: a654921132c8e78be7db02c29fd69df842178e286098eafb9a6128ae26b7030eabcdd47a294b752f904b326802f3c91ab03583cb3a5135cb8b8005dd6d0fedcf
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
colrapi (0.1.
|
|
5
|
-
faraday (~>
|
|
6
|
-
|
|
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 (
|
|
18
|
-
faraday-
|
|
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-
|
|
30
|
-
|
|
31
|
-
faraday-
|
|
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", "~>
|
|
46
|
-
s.add_runtime_dependency "
|
|
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
|
data/lib/colrapi/faraday.rb
CHANGED
|
@@ -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
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
def initialize(app)
|
|
31
|
+
super app
|
|
32
|
+
@parser = nil
|
|
33
|
+
end
|
|
34
34
|
|
|
35
|
-
|
|
35
|
+
private
|
|
36
36
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
53
|
+
if body.nil?
|
|
54
|
+
nil
|
|
55
|
+
else
|
|
56
|
+
": #{body}"
|
|
57
|
+
end
|
|
59
58
|
end
|
|
60
|
-
end
|
|
61
59
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
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
|
data/lib/colrapi/request.rb
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
require_relative "faraday" # !! Potential ruby 3.0 difference in module loading? relative differs from Serrano
|
|
2
|
-
require "
|
|
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
|
|
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
|
|
149
|
+
f.use Faraday::ColrapiErrors::Middleware
|
|
149
150
|
f.adapter Faraday.default_adapter
|
|
150
151
|
end
|
|
151
152
|
end
|
data/lib/colrapi/version.rb
CHANGED
data/lib/colrapi.rb
CHANGED
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.
|
|
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: '
|
|
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: '
|
|
114
|
+
version: '2.2'
|
|
115
115
|
- !ruby/object:Gem::Dependency
|
|
116
|
-
name:
|
|
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: '
|
|
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: '
|
|
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.
|
|
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.
|
|
212
|
+
rubygems_version: 3.4.10
|
|
206
213
|
signing_key:
|
|
207
214
|
specification_version: 4
|
|
208
215
|
summary: Catalog of Life Client
|