maremma 3.1.1 → 3.1.2

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
  SHA1:
3
- metadata.gz: ab2e7075facc4988175f758e582800b7479f3554
4
- data.tar.gz: 99b3bf7a5d806867588e8e3384a003c2233ded50
3
+ metadata.gz: 53bc14a971c53267ff46eb19933dac01c69b4a0b
4
+ data.tar.gz: 07bd47197a25322f7e661b655caae1478692cac9
5
5
  SHA512:
6
- metadata.gz: b98eb05622984eab0c819f0650341127f93b1b58b83ccadaf121af8535227a54b6924a364e8e36d52bd1dce726d5d4307c2481644c8ac06f9ad2f9dcc697665a
7
- data.tar.gz: 130bdf89a39c65dec55c9c3b48fd5ed8b8f9f10ac8ca63662b9ae44e72d152aaca3e7a6a7f54ba95afea47cc5ae03f6c8caa5a4e5ed7c0a6bd1599962cbca3a2
6
+ metadata.gz: 2483a2aa0dd96578dd01cb96c12133b835e6419b6de8e97329123f597cb1cc282c425c7589bdd177af931cb3687018b0e78d10403ae1f6d78ce9328ef9ce71eb
7
+ data.tar.gz: 95ec7ee526586c93b775242b01fedb6f95c89af4f8af88c97c07b288057708d66210378ae5b1c4688bdda408652851d94422bb19f71bc44dbdba2ad27b2e636a
@@ -1,3 +1,9 @@
1
+ ## v.3.1.2 (January 29, 2017)
2
+
3
+ [maremma 3.1.2](https://github.com/datacite/maremma/releases/tag/v.3.1.2) was released on January 29, 2017:
4
+
5
+ * raise error if invalid URL is provided
6
+
1
7
  ## v.3.1.1 (January 2, 2017)
2
8
 
3
9
  [maremma 3.1.1](https://github.com/datacite/maremma/releases/tag/v.3.1.1) was released on January 2, 2017:
@@ -1,8 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- maremma (3.1.1)
4
+ maremma (3.1.2)
5
5
  activesupport (~> 4.2, >= 4.2.5)
6
+ addressable (~> 2.5)
6
7
  builder (~> 3.2, >= 3.2.2)
7
8
  excon (~> 0.45.0)
8
9
  faraday (~> 0.9.2)
@@ -23,12 +24,12 @@ GEM
23
24
  tzinfo (~> 1.1)
24
25
  addressable (2.5.0)
25
26
  public_suffix (~> 2.0, >= 2.0.2)
26
- builder (3.2.2)
27
- codeclimate-test-reporter (1.0.3)
27
+ builder (3.2.3)
28
+ codeclimate-test-reporter (1.0.5)
28
29
  simplecov
29
30
  crack (0.4.3)
30
31
  safe_yaml (~> 1.0.0)
31
- diff-lcs (1.2.5)
32
+ diff-lcs (1.3)
32
33
  docile (1.1.5)
33
34
  excon (0.45.4)
34
35
  faraday (0.9.2)
@@ -37,9 +38,9 @@ GEM
37
38
  faraday
38
39
  faraday_middleware (0.10.1)
39
40
  faraday (>= 0.7.4, < 1.0)
40
- hashdiff (0.3.1)
41
+ hashdiff (0.3.2)
41
42
  i18n (0.7.0)
42
- json (1.8.3)
43
+ json (1.8.6)
43
44
  mini_portile2 (2.1.0)
44
45
  minitest (5.10.1)
45
46
  multi_json (1.11.3)
@@ -47,7 +48,7 @@ GEM
47
48
  nokogiri (1.6.8.1)
48
49
  mini_portile2 (~> 2.1.0)
49
50
  oj (2.13.1)
50
- public_suffix (2.0.4)
51
+ public_suffix (2.0.5)
51
52
  rack (2.0.1)
52
53
  rack-test (0.6.3)
53
54
  rack (>= 1.0)
@@ -66,7 +67,7 @@ GEM
66
67
  rspec-support (~> 3.5.0)
67
68
  rspec-support (3.5.0)
68
69
  safe_yaml (1.0.4)
69
- simplecov (0.12.0)
70
+ simplecov (0.13.0)
70
71
  docile (~> 1.1.0)
71
72
  json (>= 1.8, < 3)
72
73
  simplecov-html (~> 0.10.0)
@@ -6,6 +6,7 @@ require 'faraday_middleware'
6
6
  require 'faraday/encoding'
7
7
  require 'excon'
8
8
  require 'uri'
9
+ require 'addressable/uri'
9
10
 
10
11
  DEFAULT_TIMEOUT = 60
11
12
  NETWORKABLE_EXCEPTIONS = [Faraday::ClientError,
@@ -20,6 +21,8 @@ NETWORKABLE_EXCEPTIONS = [Faraday::ClientError,
20
21
 
21
22
  module Maremma
22
23
  def self.post(url, options={})
24
+ is_valid_url?(url)
25
+
23
26
  options[:data] ||= {}
24
27
  options[:headers] = set_request_headers(url, options)
25
28
 
@@ -40,6 +43,8 @@ module Maremma
40
43
  end
41
44
 
42
45
  def self.put(url, options={})
46
+ is_valid_url?(url)
47
+
43
48
  options[:data] ||= {}
44
49
  options[:headers] = set_request_headers(url, options)
45
50
 
@@ -60,6 +65,8 @@ module Maremma
60
65
  end
61
66
 
62
67
  def self.delete(url, options={})
68
+ is_valid_url?(url)
69
+
63
70
  options[:data] ||= {}
64
71
  options[:headers] = set_request_headers(url, options)
65
72
 
@@ -79,6 +86,8 @@ module Maremma
79
86
  end
80
87
 
81
88
  def self.get(url, options={})
89
+ is_valid_url?(url)
90
+
82
91
  options[:headers] = set_request_headers(url, options)
83
92
 
84
93
  conn = faraday_conn(options)
@@ -146,6 +155,11 @@ module Maremma
146
155
  end
147
156
  end
148
157
 
158
+ def self.is_valid_url?(url)
159
+ parsed = Addressable::URI.parse(url)
160
+ raise TypeError, "Invalid URL: #{url}" unless %w(http https).include?(parsed.scheme)
161
+ end
162
+
149
163
  def self.set_request_headers(url, options={})
150
164
  options[:headers] ||= {}
151
165
 
@@ -1,3 +1,3 @@
1
1
  module Maremma
2
- VERSION = "3.1.1"
2
+ VERSION = "3.1.2"
3
3
  end
@@ -28,6 +28,7 @@ Gem::Specification.new do |s|
28
28
  s.add_dependency 'multi_json', '~> 1.11.2'
29
29
  s.add_dependency 'oj', '~> 2.13.1'
30
30
  s.add_dependency 'activesupport', '~> 4.2', '>= 4.2.5'
31
+ s.add_dependency 'addressable', '~> 2.5'
31
32
  s.add_development_dependency 'bundler', '~> 1.0'
32
33
  s.add_development_dependency 'rspec', '~> 3.4'
33
34
  s.add_development_dependency 'rake'
@@ -32,26 +32,6 @@ describe Maremma do
32
32
  expect(stub).to have_been_requested
33
33
  end
34
34
 
35
- it "head html" do
36
- stub = stub_request(:head, url).to_return(:body => data.to_s, :status => 200, :headers => { "Content-Type" => "text/html" })
37
- response = subject.head(url, accept: 'html')
38
- expect(response.body).to be_nil
39
- expect(response.headers).to eq("Content-Type"=>"text/html")
40
- expect(stub).to have_been_requested
41
- end
42
-
43
- it "post xml" do
44
- stub = stub_request(:post, url).with(:body => post_data.to_xml).to_return(:body => data.to_xml, :status => 200, :headers => { "Content-Type" => "text/html" })
45
- subject.post(url, accept: 'xml', data: post_data.to_xml) { |response| expect(Hash.from_xml(response.body.to_s)["hash"]).to eq(data) }
46
- expect(stub).to have_been_requested
47
- end
48
-
49
- it "put xml" do
50
- stub = stub_request(:put, url).with(:body => post_data.to_xml).to_return(:body => data.to_xml, :status => 200, :headers => { "Content-Type" => "text/html" })
51
- subject.put(url, accept: 'xml', data: post_data.to_xml) { |response| expect(Hash.from_xml(response.body.to_s)["hash"]).to eq(data) }
52
- expect(stub).to have_been_requested
53
- end
54
-
55
35
  it "get json with params", vcr: true do
56
36
  params = { q: "*:*",
57
37
  fl: "doi,title,description,publisher,publicationYear,resourceType,resourceTypeGeneral,rightsURI,datacentre_symbol,xml,minted,updated",
@@ -88,6 +68,44 @@ describe Maremma do
88
68
  end
89
69
  end
90
70
 
71
+ context "head" do
72
+ it "head html" do
73
+ stub = stub_request(:head, url).to_return(:body => data.to_s, :status => 200, :headers => { "Content-Type" => "text/html" })
74
+ response = subject.head(url, accept: 'html')
75
+ expect(response.body).to be_nil
76
+ expect(response.headers).to eq("Content-Type"=>"text/html")
77
+ expect(stub).to have_been_requested
78
+ end
79
+ end
80
+
81
+ context "post" do
82
+ it "post json" do
83
+ stub = stub_request(:post, url).with(:body => post_data.to_json).to_return(:body => data.to_json, :status => 200, :headers => { "Content-Type" => "application/json" })
84
+ subject.post(url, content_type: 'json', data: post_data.to_json) { |response| expect(response.body).to eq(2) }
85
+ expect(stub).to have_been_requested
86
+ end
87
+
88
+ it "post xml" do
89
+ stub = stub_request(:post, url).with(:body => post_data.to_xml).to_return(:body => data.to_xml, :status => 200, :headers => { "Content-Type" => "text/html" })
90
+ subject.post(url, content_type: 'xml', data: post_data.to_xml) { |response| expect(Hash.from_xml(response.body.to_s)["hash"]).to eq(data) }
91
+ expect(stub).to have_been_requested
92
+ end
93
+ end
94
+
95
+ context "put" do
96
+ it "put json" do
97
+ stub = stub_request(:put, url).with(:body => post_data.to_json).to_return(:body => data.to_json, :status => 200, :headers => { "Content-Type" => "application/json" })
98
+ subject.put(url, content_type: 'json', data: post_data.to_json) { |response| expect(JSON.parse(response.body.to_s)).to eq(data) }
99
+ expect(stub).to have_been_requested
100
+ end
101
+
102
+ it "put xml" do
103
+ stub = stub_request(:put, url).with(:body => post_data.to_xml).to_return(:body => data.to_xml, :status => 200, :headers => { "Content-Type" => "text/html" })
104
+ subject.put(url, content_type: 'xml', data: post_data.to_xml) { |response| expect(Hash.from_xml(response.body.to_s)["hash"]).to eq(data) }
105
+ expect(stub).to have_been_requested
106
+ end
107
+ end
108
+
91
109
  context "empty response" do
92
110
  it "get json" do
93
111
  stub = stub_request(:get, url).to_return(:body => nil, :status => 200, :headers => { "Content-Type" => "application/json" })
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.1.1
4
+ version: 3.1.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-01-02 00:00:00.000000000 Z
11
+ date: 2017-01-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -148,6 +148,20 @@ dependencies:
148
148
  - - ">="
149
149
  - !ruby/object:Gem::Version
150
150
  version: 4.2.5
151
+ - !ruby/object:Gem::Dependency
152
+ name: addressable
153
+ requirement: !ruby/object:Gem::Requirement
154
+ requirements:
155
+ - - "~>"
156
+ - !ruby/object:Gem::Version
157
+ version: '2.5'
158
+ type: :runtime
159
+ prerelease: false
160
+ version_requirements: !ruby/object:Gem::Requirement
161
+ requirements:
162
+ - - "~>"
163
+ - !ruby/object:Gem::Version
164
+ version: '2.5'
151
165
  - !ruby/object:Gem::Dependency
152
166
  name: bundler
153
167
  requirement: !ruby/object:Gem::Requirement