maremma 1.0.1 → 1.0.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: 2afaf83b4f0e5b91eb5b2a74e56a7292919b84d4
4
- data.tar.gz: c01ce052e14830d112fdc43e4f6f7cd2da6cfd1f
3
+ metadata.gz: 49610599e5a78ccf1f77a901315904dccd78bca7
4
+ data.tar.gz: 7bbb1504d73a9e7c3d448240ca42f440c3f5f14d
5
5
  SHA512:
6
- metadata.gz: 57c2cc958450f2afd128563bfe44226c9a8455cb006d40b3f413349d681347092a4128366f1248618f1211a8306e1fd945adb7cefbda57cc270e86cd89398df1
7
- data.tar.gz: ea99d5bfd797b0823f1b6fc4ee8297a69aff7f403056fa83130c0d06da007421350008cb5dd5f1c4ae93684c7b89f4307779568f9c9a3a537fc9c6bc0d61fd37
6
+ metadata.gz: 5efeb18cad885f699ac5dce945f3681f4b0b185d1935c8b0b130d62082bd6ab4c4b786a4c540b38ef880289c95b89090221f5aa181b2273fe0edfec43d4bf422
7
+ data.tar.gz: 8ef207e5e8195dc9dc992267373b13f95d9ee68aaef61c7e86275126eb6dcba953d8662cf2e51ae52ddfd908d312f292723d1e2443da5d6022ec0503b5867ed7
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- maremma (1.0.0)
4
+ maremma (1.0.1)
5
5
  activesupport (~> 4.2, >= 4.2.5)
6
6
  builder (~> 3.2, >= 3.2.2)
7
7
  excon (~> 0.45.0)
@@ -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
- if options[:data]
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)
@@ -1,3 +1,3 @@
1
1
  module Maremma
2
- VERSION = "1.0.1"
2
+ VERSION = "1.0.2"
3
3
  end
@@ -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.get(url, content_type: 'xml', data: post_data.to_xml) { |response| expect(Hash.from_xml(response.to_s)["hash"]).to eq(data) }
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.get(url, content_type: 'xml', data: post_data.to_xml) { |response| expect(response).to be_nil }
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.get(url, content_type: 'xml', data: post_data.to_xml) { |response| expect(Hash.from_xml(response.to_s)["hash"]).to eq(error) }
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.get(url, content_type: 'xml', data: post_data.to_xml) { |response| expect(response).to be_nil }
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.get(url, content_type: 'xml', data: post_data.to_xml) { |response| expect(response).to be_nil }
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: maremma
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Fenner