maremma 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/maremma.rb +18 -7
- data/lib/maremma/version.rb +1 -1
- data/spec/maremma_spec.rb +5 -5
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 49610599e5a78ccf1f77a901315904dccd78bca7
|
4
|
+
data.tar.gz: 7bbb1504d73a9e7c3d448240ca42f440c3f5f14d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5efeb18cad885f699ac5dce945f3681f4b0b185d1935c8b0b130d62082bd6ab4c4b786a4c540b38ef880289c95b89090221f5aa181b2273fe0edfec43d4bf422
|
7
|
+
data.tar.gz: 8ef207e5e8195dc9dc992267373b13f95d9ee68aaef61c7e86275126eb6dcba953d8662cf2e51ae52ddfd908d312f292723d1e2443da5d6022ec0503b5867ed7
|
data/Gemfile.lock
CHANGED
data/lib/maremma.rb
CHANGED
@@ -19,6 +19,23 @@ NETWORKABLE_EXCEPTIONS = [Faraday::ClientError,
|
|
19
19
|
TypeError]
|
20
20
|
|
21
21
|
module Maremma
|
22
|
+
def self.post(url, content_type: 'json', data: {}, headers: {}, **options)
|
23
|
+
conn = faraday_conn(content_type, options)
|
24
|
+
conn = auth_conn(conn, options)
|
25
|
+
|
26
|
+
conn.options[:timeout] = options[:timeout] || DEFAULT_TIMEOUT
|
27
|
+
|
28
|
+
# make sure we use a 'Host' header
|
29
|
+
headers['Host'] = URI.parse(url).host
|
30
|
+
|
31
|
+
response = conn.post url, {}, headers do |request|
|
32
|
+
request.body = data
|
33
|
+
end
|
34
|
+
parse_response(response.body)
|
35
|
+
rescue *NETWORKABLE_EXCEPTIONS => error
|
36
|
+
rescue_faraday_error(error)
|
37
|
+
end
|
38
|
+
|
22
39
|
def self.get(url, content_type: 'json', headers: {}, **options)
|
23
40
|
conn = faraday_conn(content_type, options)
|
24
41
|
conn = auth_conn(conn, options)
|
@@ -28,13 +45,7 @@ module Maremma
|
|
28
45
|
# make sure we use a 'Host' header
|
29
46
|
headers['Host'] = URI.parse(url).host
|
30
47
|
|
31
|
-
|
32
|
-
response = conn.post url, {}, headers do |request|
|
33
|
-
request.body = options[:data]
|
34
|
-
end
|
35
|
-
else
|
36
|
-
response = conn.get url, {}, headers
|
37
|
-
end
|
48
|
+
response = conn.get url, {}, headers
|
38
49
|
parse_response(response.body)
|
39
50
|
rescue *NETWORKABLE_EXCEPTIONS => error
|
40
51
|
rescue_faraday_error(error)
|
data/lib/maremma/version.rb
CHANGED
data/spec/maremma_spec.rb
CHANGED
@@ -30,7 +30,7 @@ describe Maremma do
|
|
30
30
|
|
31
31
|
it "post xml" do
|
32
32
|
stub = stub_request(:post, url).with(:body => post_data.to_xml).to_return(:body => data.to_xml, :status => 200, :headers => { "Content-Type" => "text/html" })
|
33
|
-
subject.
|
33
|
+
subject.post(url, content_type: 'xml', data: post_data.to_xml) { |response| expect(Hash.from_xml(response.to_s)["hash"]).to eq(data) }
|
34
34
|
expect(stub).to have_been_requested
|
35
35
|
end
|
36
36
|
end
|
@@ -59,7 +59,7 @@ describe Maremma do
|
|
59
59
|
|
60
60
|
it "post xml" do
|
61
61
|
stub = stub_request(:post, url).with(:body => post_data.to_xml).to_return(:body => nil, :status => 200, :headers => { "Content-Type" => "application/xml" })
|
62
|
-
subject.
|
62
|
+
subject.post(url, content_type: 'xml', data: post_data.to_xml) { |response| expect(response).to be_nil }
|
63
63
|
expect(stub).to have_been_requested
|
64
64
|
end
|
65
65
|
end
|
@@ -87,7 +87,7 @@ describe Maremma do
|
|
87
87
|
|
88
88
|
it "post xml" do
|
89
89
|
stub = stub_request(:post, url).with(:body => post_data.to_xml).to_return(:body => error.to_xml, :status => [404], :headers => { "Content-Type" => "application/xml" })
|
90
|
-
subject.
|
90
|
+
subject.post(url, content_type: 'xml', data: post_data.to_xml) { |response| expect(Hash.from_xml(response.to_s)["hash"]).to eq(error) }
|
91
91
|
expect(stub).to have_been_requested
|
92
92
|
end
|
93
93
|
end
|
@@ -116,7 +116,7 @@ describe Maremma do
|
|
116
116
|
|
117
117
|
it "post xml" do
|
118
118
|
stub = stub_request(:post, url).with(:body => post_data.to_xml).to_return(:status => [408])
|
119
|
-
subject.
|
119
|
+
subject.post(url, content_type: 'xml', data: post_data.to_xml) { |response| expect(response).to be_nil }
|
120
120
|
expect(stub).to have_been_requested
|
121
121
|
end
|
122
122
|
end
|
@@ -145,7 +145,7 @@ describe Maremma do
|
|
145
145
|
|
146
146
|
it "post xml" do
|
147
147
|
stub = stub_request(:post, url).with(:body => post_data.to_xml).to_timeout
|
148
|
-
subject.
|
148
|
+
subject.post(url, content_type: 'xml', data: post_data.to_xml) { |response| expect(response).to be_nil }
|
149
149
|
expect(stub).to have_been_requested
|
150
150
|
end
|
151
151
|
end
|