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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ba82a8adc41f610974a1e5f0fee1616d04e4d465
4
- data.tar.gz: 4eaf91d77ceebe086c1bdeab2f068d9e143a5c68
3
+ metadata.gz: 324339036e6fd309bcbc293699a5a95c7d409144
4
+ data.tar.gz: c9a3f3e36193f7290be939b904239dda6aefafc4
5
5
  SHA512:
6
- metadata.gz: ba82e06bd569ae40504b93c0d4327c0f53d76d06bb198d4100209e3501101de59dfa957b66ec61009b5350b1817eaa43f7c4ceb32824bade269e5bed8738736f
7
- data.tar.gz: 234196702252c07ae88ba1bcd57d41b130751c8230a06056429d18171ccbe239903c8ea4db22c9dd88cb7a75ea79f1f0667bf564979426493b32e291359f2c3e
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.1
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
- script: bundle exec rspec
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.1)
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.7.1)
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.0)
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
- # Maremma
2
-
1
+ [![Identifier](https://img.shields.io/badge/doi-10.5438%2Fqeg0--3gm3-fca709.svg)](https://doi.org/10.5438/qeg0-3gm3)
3
2
  [![Gem Version](https://badge.fury.io/rb/maremma.svg)](https://badge.fury.io/rb/maremma)
4
3
  [![Build Status](https://travis-ci.org/datacite/maremma.svg?branch=master)](https://travis-ci.org/datacite/maremma)
5
- [![Test Coverage](https://codeclimate.com/github/datacite/maremma/badges/coverage.svg)](https://codeclimate.com/github/datacite/maremma/coverage)
6
4
  [![Code Climate](https://codeclimate.com/github/datacite/maremma/badges/gpa.svg)](https://codeclimate.com/github/datacite/maremma)
5
+ [![Test Coverage](https://codeclimate.com/github/datacite/maremma/badges/coverage.svg)](https://codeclimate.com/github/datacite/maremma/coverage)
6
+
7
+ # Maremma: a Ruby library for simplified network calls
7
8
 
8
- Utility library for network calls. 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
+ 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
- conn = faraday_conn(options)
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
- is_valid_url?(url)
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
- is_valid_url?(url)
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
- response = conn.delete url, {}, options[:headers]
36
+ def self.get(url, options={})
37
+ self.method(url, options.merge(method: "get"))
38
+ end
81
39
 
82
- OpenStruct.new(body: parse_success_response(response.body, options),
83
- headers: response.headers,
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.get(url, options={})
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 = conn.get url, {}, options[:headers]
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
- options[:headers] ||= {}
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
- options[:headers]['User-Agent'] = ENV['HOSTNAME'].present? ? "Maremma - http://#{ENV['HOSTNAME']}" : "Maremma - https://github.com/datacite/maremma"
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
- if options[:content_type].present?
181
- content_type_headers = { "html" => 'text/html; charset=UTF-8',
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
- accept_headers = { "html" => 'text/html; charset=UTF-8',
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
- options[:headers]['Accept'] ||= "text/html,application/json,application/xml;q=0.9, text/plain;q=0.8,image/png,*/*;q=0.5"
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
- options[:headers]['Authorization'] = "Bearer #{options[:bearer]}"
129
+ headers['Authorization'] = "Bearer #{options[:bearer]}"
199
130
  elsif options[:token].present?
200
- options[:headers]["Authorization"] = "Token token=#{options[:token]}"
131
+ headers["Authorization"] = "Token token=#{options[:token]}"
201
132
  elsif options[:username].present?
202
- basic = Base64.encode64("#{options[:username]}:#{options[:password].to_s}").rstrip
203
- options[:headers]["Authorization"] = "Basic #{basic}"
133
+ basic = Base64.encode64("#{options[:username]}:#{options[:password]}").rstrip
134
+ headers["Authorization"] = "Basic #{basic}"
204
135
  end
205
136
 
206
- options[:headers]
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?
@@ -1,3 +1,3 @@
1
1
  module Maremma
2
- VERSION = "3.5.1"
2
+ VERSION = "3.5.2"
3
3
  end
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 = "Simplifies network calls, including json/xml parsing and error handling. Based on Faraday."
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(:body => data.to_s, :status => 200, :headers => { "Content-Type" => "text/html" })
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.1
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-02-21 00:00:00.000000000 Z
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: Simplifies network calls, including json/xml parsing and error handling.
290
- Based on Faraday.
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