maremma 3.5.1 → 3.5.2
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/.travis.yml +12 -2
- data/Gemfile.lock +3 -4
- data/README.md +5 -4
- data/codemeta.json +36 -0
- data/lib/maremma.rb +38 -105
- data/lib/maremma/version.rb +1 -1
- data/maremma.gemspec +1 -1
- data/spec/maremma_spec.rb +1 -1
- metadata +7 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 324339036e6fd309bcbc293699a5a95c7d409144
|
4
|
+
data.tar.gz: c9a3f3e36193f7290be939b904239dda6aefafc4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2f6152f610737e07bbd72aad5ef3b7f3ccd329dca72beeb26402ea6dc58cdfeb3bf25d6e39fa9181c9b82d72390f35d907083df6f983fc79a698fefba1a7a3ee
|
7
|
+
data.tar.gz: c16cc48c7b0c97317eb358ef7ae047b83cc3a7d57732b2d5171d8a481053f5f00e70c56ec3f5aaf430a4d9e2c94579841f08ef1d1a9cf38df67f9bb9ad9e4f47
|
data/.travis.yml
CHANGED
@@ -1,9 +1,18 @@
|
|
1
1
|
language: ruby
|
2
2
|
rvm:
|
3
|
-
- 2.3.
|
3
|
+
- 2.3.3
|
4
|
+
|
5
|
+
addons:
|
6
|
+
code_climate:
|
7
|
+
repo_token: $CODECLIMATE_REPO_TOKEN
|
8
|
+
|
4
9
|
install:
|
5
10
|
- travis_retry bundle install
|
6
|
-
|
11
|
+
|
12
|
+
script:
|
13
|
+
- bundle exec rspec
|
14
|
+
- bundle exec codeclimate-test-reporter
|
15
|
+
|
7
16
|
deploy:
|
8
17
|
provider: rubygems
|
9
18
|
api_key:
|
@@ -14,4 +23,5 @@ deploy:
|
|
14
23
|
repo: datacite/maremma
|
15
24
|
|
16
25
|
notifications:
|
26
|
+
email: false
|
17
27
|
slack: datacite:Wt8En0ALoTA6Kjc5EOKNDWxN
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
maremma (3.5.
|
4
|
+
maremma (3.5.2)
|
5
5
|
activesupport (~> 4.2, >= 4.2.5)
|
6
6
|
addressable (>= 2.3.6)
|
7
7
|
builder (~> 3.2, >= 3.2.2)
|
@@ -16,9 +16,8 @@ PATH
|
|
16
16
|
GEM
|
17
17
|
remote: https://rubygems.org/
|
18
18
|
specs:
|
19
|
-
activesupport (4.2.
|
19
|
+
activesupport (4.2.8)
|
20
20
|
i18n (~> 0.7)
|
21
|
-
json (~> 1.7, >= 1.7.7)
|
22
21
|
minitest (~> 5.1)
|
23
22
|
thread_safe (~> 0.3, >= 0.3.4)
|
24
23
|
tzinfo (~> 1.1)
|
@@ -39,7 +38,7 @@ GEM
|
|
39
38
|
faraday_middleware (0.10.1)
|
40
39
|
faraday (>= 0.7.4, < 1.0)
|
41
40
|
hashdiff (0.3.2)
|
42
|
-
i18n (0.8.
|
41
|
+
i18n (0.8.1)
|
43
42
|
json (1.8.6)
|
44
43
|
mini_portile2 (2.1.0)
|
45
44
|
minitest (5.10.1)
|
data/README.md
CHANGED
@@ -1,11 +1,12 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
[](https://doi.org/10.5438/qeg0-3gm3)
|
3
2
|
[](https://badge.fury.io/rb/maremma)
|
4
3
|
[](https://travis-ci.org/datacite/maremma)
|
5
|
-
[](https://codeclimate.com/github/datacite/maremma/coverage)
|
6
4
|
[](https://codeclimate.com/github/datacite/maremma)
|
5
|
+
[](https://codeclimate.com/github/datacite/maremma/coverage)
|
6
|
+
|
7
|
+
# Maremma: a Ruby library for simplified network calls
|
7
8
|
|
8
|
-
|
9
|
+
Ruby utility library for network requests. Based on [Faraday](https://github.com/lostisland/faraday) and [Excon](https://github.com/excon/excon), provides a wrapper for XML/JSON parsing and error handling. All successful responses are returned as hash with key `data`, all errors in a JSONAPI-friendly hash with key `errors`.
|
9
10
|
|
10
11
|
## Installation
|
11
12
|
|
data/codemeta.json
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
{
|
2
|
+
"@context": "https://raw.githubusercontent.com/codemeta/codemeta/master/codemeta.jsonld",
|
3
|
+
"@type": "SoftwareSourceCode",
|
4
|
+
"@id": "https://doi.org/10.5438/QEG0-3GM3",
|
5
|
+
"agents": {
|
6
|
+
"@id": "http://orcid.org/0000-0003-0077-4738",
|
7
|
+
"@type": "person",
|
8
|
+
"name": "Martin Fenner",
|
9
|
+
"affiliation": "DataCite",
|
10
|
+
"mustBeCited": true,
|
11
|
+
"isMaintainer": true,
|
12
|
+
"isRightsHolder": true
|
13
|
+
},
|
14
|
+
"identifier": "https://doi.org/10.5438/QEG0-3GM3",
|
15
|
+
"codeRepository": "https://github.com/datacite/maremma",
|
16
|
+
"controlledTem": "software",
|
17
|
+
"dateCreated": "2015-11-28",
|
18
|
+
"datePublished": "2017-02-24",
|
19
|
+
"dateModified": "2017-02-24",
|
20
|
+
"description": "Ruby utility library for network requests. Based on Faraday and Excon, provides a wrapper for XML/JSON parsing and error handling. All successful responses are returned as hash with key data, all errors in a JSONAPI-friendly hash with key errors.",
|
21
|
+
"isAutomatedBuild": true,
|
22
|
+
"licenseId": "MIT",
|
23
|
+
"publisher": "DataCite",
|
24
|
+
"tags": [
|
25
|
+
"faraday",
|
26
|
+
"excon",
|
27
|
+
"net/http"
|
28
|
+
],
|
29
|
+
"title": "Maremma: a Ruby library for simplified network calls",
|
30
|
+
"programmingLanguage": {
|
31
|
+
"name": "Ruby",
|
32
|
+
"version": "≥ 2.3.3",
|
33
|
+
"URL": "https://www.ruby-lang.org"
|
34
|
+
},
|
35
|
+
"readme": "https://github.com/datacite/maremma/blob/master/README.md"
|
36
|
+
}
|
data/lib/maremma.rb
CHANGED
@@ -20,85 +20,44 @@ module Maremma
|
|
20
20
|
ArgumentError,
|
21
21
|
NoMethodError,
|
22
22
|
TypeError]
|
23
|
-
|
24
|
-
def self.post(url, options={})
|
25
|
-
is_valid_url?(url)
|
26
|
-
|
27
|
-
options[:data] ||= {}
|
28
|
-
options[:headers] = set_request_headers(url, options)
|
29
23
|
|
30
|
-
|
31
|
-
|
32
|
-
conn.options[:timeout] = options[:timeout] || DEFAULT_TIMEOUT
|
33
|
-
|
34
|
-
response = conn.post url, {}, options[:headers] do |request|
|
35
|
-
request.body = options[:data]
|
36
|
-
end
|
37
|
-
OpenStruct.new(body: parse_success_response(response.body, options),
|
38
|
-
headers: response.headers,
|
39
|
-
status: response.status,
|
40
|
-
url: response.env[:url].to_s)
|
41
|
-
rescue *NETWORKABLE_EXCEPTIONS => error
|
42
|
-
error_response = rescue_faraday_error(error)
|
43
|
-
OpenStruct.new(body: error_response,
|
44
|
-
status: error_response.fetch("errors", {}).first.fetch("status", 400))
|
24
|
+
def self.post(url, options={})
|
25
|
+
self.method(url, options.merge(method: "post"))
|
45
26
|
end
|
46
27
|
|
47
28
|
def self.put(url, options={})
|
48
|
-
|
49
|
-
|
50
|
-
options[:data] ||= {}
|
51
|
-
options[:headers] = set_request_headers(url, options)
|
52
|
-
|
53
|
-
conn = faraday_conn(options)
|
54
|
-
|
55
|
-
conn.options[:timeout] = options[:timeout] || DEFAULT_TIMEOUT
|
56
|
-
|
57
|
-
response = conn.put url, {}, options[:headers] do |request|
|
58
|
-
request.body = options[:data]
|
59
|
-
end
|
60
|
-
OpenStruct.new(body: parse_success_response(response.body, options),
|
61
|
-
headers: response.headers,
|
62
|
-
status: response.status,
|
63
|
-
url: response.env[:url].to_s)
|
64
|
-
rescue *NETWORKABLE_EXCEPTIONS => error
|
65
|
-
error_response = rescue_faraday_error(error)
|
66
|
-
OpenStruct.new(body: error_response,
|
67
|
-
status: error_response.fetch("errors", {}).first.fetch("status", 400))
|
29
|
+
self.method(url, options.merge(method: "put"))
|
68
30
|
end
|
69
31
|
|
70
32
|
def self.delete(url, options={})
|
71
|
-
|
72
|
-
|
73
|
-
options[:data] ||= {}
|
74
|
-
options[:headers] = set_request_headers(url, options)
|
75
|
-
|
76
|
-
conn = faraday_conn(options)
|
77
|
-
|
78
|
-
conn.options[:timeout] = options[:timeout] || DEFAULT_TIMEOUT
|
33
|
+
self.method(url, options.merge(method: "delete"))
|
34
|
+
end
|
79
35
|
|
80
|
-
|
36
|
+
def self.get(url, options={})
|
37
|
+
self.method(url, options.merge(method: "get"))
|
38
|
+
end
|
81
39
|
|
82
|
-
|
83
|
-
|
84
|
-
status: response.status,
|
85
|
-
url: response.env[:url].to_s)
|
86
|
-
rescue *NETWORKABLE_EXCEPTIONS => error
|
87
|
-
error_response = rescue_faraday_error(error)
|
88
|
-
OpenStruct.new(body: error_response,
|
89
|
-
status: error_response.fetch("errors", {}).first.fetch("status", 400))
|
40
|
+
def self.head(url, options={})
|
41
|
+
self.method(url, options.merge(method: "head"))
|
90
42
|
end
|
91
43
|
|
92
|
-
def self.
|
44
|
+
def self.method(url, options={})
|
93
45
|
is_valid_url?(url)
|
94
46
|
|
47
|
+
options[:data] ||= {}
|
95
48
|
options[:headers] = set_request_headers(url, options)
|
96
49
|
|
97
50
|
conn = faraday_conn(options)
|
98
51
|
|
99
52
|
conn.options[:timeout] = options[:timeout] || DEFAULT_TIMEOUT
|
100
53
|
|
101
|
-
response =
|
54
|
+
response = case options[:method]
|
55
|
+
when "get" then conn.get url, {}, options[:headers]
|
56
|
+
when "post" then conn.post url, {}, options[:headers] { |request| request.body = options[:data] }
|
57
|
+
when "put" then conn.put url, {}, options[:headers] { |request| request.body = options[:data] }
|
58
|
+
when "delete" then conn.delete url, {}, options[:headers]
|
59
|
+
when "head" then conn.head url, {}, options[:headers]
|
60
|
+
end
|
102
61
|
|
103
62
|
# return error if we are close to the rate limit, if supported in headers
|
104
63
|
if get_rate_limit_remaining(response.headers) < 10
|
@@ -106,6 +65,7 @@ module Maremma
|
|
106
65
|
headers: response.headers,
|
107
66
|
status: response.status)
|
108
67
|
end
|
68
|
+
|
109
69
|
OpenStruct.new(body: parse_success_response(response.body, options),
|
110
70
|
headers: response.headers,
|
111
71
|
status: response.status,
|
@@ -116,30 +76,6 @@ module Maremma
|
|
116
76
|
status: error_response.fetch("errors", {}).first.fetch("status", 400))
|
117
77
|
end
|
118
78
|
|
119
|
-
def self.head(url, options={})
|
120
|
-
options[:headers] = set_request_headers(url, options)
|
121
|
-
|
122
|
-
conn = faraday_conn(options)
|
123
|
-
|
124
|
-
conn.options[:timeout] = options[:timeout] || DEFAULT_TIMEOUT
|
125
|
-
|
126
|
-
response = conn.head url, {}, options[:headers]
|
127
|
-
|
128
|
-
# return error if we are close to the rate limit, if supported in headers
|
129
|
-
if get_rate_limit_remaining(response.headers) < 10
|
130
|
-
return OpenStruct.new(body: { "errors" => [{ 'status' => 429, 'title' => "Too many requests" }] },
|
131
|
-
headers: response.headers,
|
132
|
-
status: response.status)
|
133
|
-
end
|
134
|
-
OpenStruct.new(headers: response.headers,
|
135
|
-
status: response.status,
|
136
|
-
url: response.env[:url].to_s)
|
137
|
-
rescue *NETWORKABLE_EXCEPTIONS => error
|
138
|
-
error_response = rescue_faraday_error(error)
|
139
|
-
OpenStruct.new(body: error_response,
|
140
|
-
status: error_response.fetch("errors", {}).first.fetch("status", 400))
|
141
|
-
end
|
142
|
-
|
143
79
|
def self.faraday_conn(options = {})
|
144
80
|
# make sure we have headers
|
145
81
|
options[:headers] ||= {}
|
@@ -167,43 +103,38 @@ module Maremma
|
|
167
103
|
end
|
168
104
|
|
169
105
|
def self.set_request_headers(url, options={})
|
170
|
-
|
106
|
+
header_options = { "html" => 'text/html; charset=UTF-8',
|
107
|
+
"xml" => 'application/xml',
|
108
|
+
"json" => 'application/json' }
|
109
|
+
|
110
|
+
headers = options[:headers] ||= {}
|
171
111
|
|
172
112
|
# set useragent
|
173
|
-
|
113
|
+
headers['User-Agent'] = ENV['HOSTNAME'].present? ? "Maremma - http://#{ENV['HOSTNAME']}" : "Maremma - https://github.com/datacite/maremma"
|
174
114
|
|
175
115
|
# set host, needed for some services behind proxy
|
176
|
-
if options[:host]
|
177
|
-
options[:headers]['Host'] = URI.parse(url).host
|
178
|
-
end
|
116
|
+
headers['Host'] = URI.parse(url).host if options[:host]
|
179
117
|
|
180
|
-
|
181
|
-
|
182
|
-
"xml" => 'application/xml',
|
183
|
-
"json" => 'application/json' }
|
184
|
-
options[:headers]['Content-type'] = content_type_headers.fetch(options[:content_type], options[:content_type])
|
185
|
-
end
|
118
|
+
# set Content-Type
|
119
|
+
headers['Content-type'] = header_options.fetch(options[:content_type], options[:content_type]) if options[:content_type].present?
|
186
120
|
|
187
121
|
if options[:accept].present?
|
188
|
-
|
189
|
-
"xml" => 'application/xml',
|
190
|
-
"json" => 'application/json' }
|
191
|
-
options[:headers]['Accept'] = accept_headers.fetch(options[:accept], options[:accept])
|
122
|
+
headers['Accept'] = header_options.fetch(options[:accept], options[:accept])
|
192
123
|
else
|
193
124
|
# accept all content
|
194
|
-
|
125
|
+
headers['Accept'] ||= "text/html,application/json,application/xml;q=0.9, text/plain;q=0.8,image/png,*/*;q=0.5"
|
195
126
|
end
|
196
127
|
|
197
128
|
if options[:bearer].present?
|
198
|
-
|
129
|
+
headers['Authorization'] = "Bearer #{options[:bearer]}"
|
199
130
|
elsif options[:token].present?
|
200
|
-
|
131
|
+
headers["Authorization"] = "Token token=#{options[:token]}"
|
201
132
|
elsif options[:username].present?
|
202
|
-
basic = Base64.encode64("#{options[:username]}:#{options[:password]
|
203
|
-
|
133
|
+
basic = Base64.encode64("#{options[:username]}:#{options[:password]}").rstrip
|
134
|
+
headers["Authorization"] = "Basic #{basic}"
|
204
135
|
end
|
205
136
|
|
206
|
-
|
137
|
+
headers
|
207
138
|
end
|
208
139
|
|
209
140
|
def self.rescue_faraday_error(error)
|
@@ -219,6 +150,8 @@ module Maremma
|
|
219
150
|
end
|
220
151
|
|
221
152
|
def self.parse_success_response(string, options={})
|
153
|
+
return nil if options[:method] == "head"
|
154
|
+
|
222
155
|
string = parse_response(string, options)
|
223
156
|
|
224
157
|
if string.blank?
|
data/lib/maremma/version.rb
CHANGED
data/maremma.gemspec
CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |s|
|
|
8
8
|
s.homepage = "https://github.com/datacite/maremma"
|
9
9
|
s.summary = "Simplified network calls"
|
10
10
|
s.date = Date.today
|
11
|
-
s.description = "
|
11
|
+
s.description = "Ruby utility library for network requests. Based on Faraday and Excon, provides a wrapper for XML/JSON parsing and error handling. All successful responses are returned as hash with key data, all errors in a JSONAPI-friendly hash with key errors."
|
12
12
|
s.require_paths = ["lib"]
|
13
13
|
s.version = Maremma::VERSION
|
14
14
|
s.extra_rdoc_files = ["README.md"]
|
data/spec/maremma_spec.rb
CHANGED
@@ -70,7 +70,7 @@ describe Maremma do
|
|
70
70
|
|
71
71
|
context "head" do
|
72
72
|
it "head html" do
|
73
|
-
stub = stub_request(:head, url).to_return(:
|
73
|
+
stub = stub_request(:head, url).to_return(:status => 200, :headers => { "Content-Type" => "text/html" })
|
74
74
|
response = subject.head(url, accept: 'html')
|
75
75
|
expect(response.body).to be_nil
|
76
76
|
expect(response.headers).to eq("Content-Type"=>"text/html")
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: maremma
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.5.
|
4
|
+
version: 3.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Martin Fenner
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-04-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -286,8 +286,10 @@ dependencies:
|
|
286
286
|
- - ">="
|
287
287
|
- !ruby/object:Gem::Version
|
288
288
|
version: '0'
|
289
|
-
description:
|
290
|
-
|
289
|
+
description: Ruby utility library for network requests. Based on Faraday and Excon,
|
290
|
+
provides a wrapper for XML/JSON parsing and error handling. All successful responses
|
291
|
+
are returned as hash with key data, all errors in a JSONAPI-friendly hash with key
|
292
|
+
errors.
|
291
293
|
email: mfenner@datacite.org
|
292
294
|
executables: []
|
293
295
|
extensions: []
|
@@ -302,6 +304,7 @@ files:
|
|
302
304
|
- LICENSE.md
|
303
305
|
- README.md
|
304
306
|
- Rakefile
|
307
|
+
- codemeta.json
|
305
308
|
- lib/maremma.rb
|
306
309
|
- lib/maremma/version.rb
|
307
310
|
- lib/maremma/xml_converter.rb
|