opinionated_http 0.0.5 → 0.0.6

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
  SHA256:
3
- metadata.gz: e42aeb5b1a1b2647f48288e3b34b54064b327f72b0cce291ea75a1c0a563eb79
4
- data.tar.gz: 533c7d1bf33a594ebb5b910e25a4ebf0b8420d9e5a24d0aac5f99e83e779fbe4
3
+ metadata.gz: 5c63d8fd6c65797a7afcef26ff0ef72507dcf75f8dbbd4bc93e768cf0ddffc9a
4
+ data.tar.gz: 0a56d817ad5a0a988886faf17b034df697712c3958719cbcd72558ebb1bd8ee1
5
5
  SHA512:
6
- metadata.gz: e2555937900d00a7b139a1bee2b76de642065b8b0469aeebb7783934c588bd032dc9b72b211e7ba5b04f06d01f55ece6f7a45d44439f14303c051e71cb4207bc
7
- data.tar.gz: c78cfe4681bfe65cba9d570878dcf78328059d5835e9de0cbff7d416d7ee5954cc4d4fd831f459373027bff9cf37f096ad12f5108ae40fd32db5502fd02ebd12
6
+ metadata.gz: f38a9f47681824038a271244c560639b119ff9ff138210c93eeb2e9d2e0955b05198f0956d5fba2f1b60b965bf4084e8f3aca0b89af759d6ecf78419d9f05903
7
+ data.tar.gz: 4b882e2ec2025a9d626c1a3e6d52edff1a20db6fb6dc48bc10203f14117bb1856764f373c4a0ca0bd81f97fc75a4798a68a57b2cdeafd1c3ad7d6b36ef93a14d
@@ -86,14 +86,14 @@ module OpinionatedHTTP
86
86
  def get(action:, path: "/#{action}", **args)
87
87
  request = build_request(path: path, verb: "Get", **args)
88
88
  response = request(action: action, request: request)
89
- extract_body(response)
89
+ extract_body(response, 'GET', action)
90
90
  end
91
91
 
92
92
  def post(action:, path: "/#{action}", **args)
93
93
  request = build_request(path: path, verb: "Post", **args)
94
94
 
95
95
  response = request(action: action, request: request)
96
- extract_body(response)
96
+ extract_body(response, 'POST', action)
97
97
  end
98
98
 
99
99
  def build_request(verb:, path:, headers: nil, body: nil, form_data: nil, username: nil, password: nil, parameters: nil)
@@ -164,7 +164,7 @@ module OpinionatedHTTP
164
164
  response
165
165
  end
166
166
 
167
- def extract_body(response)
167
+ def extract_body(response, http_method, action)
168
168
  return response.body if response.is_a?(Net::HTTPSuccess)
169
169
 
170
170
  message = "HTTP #{http_method}: #{action} Failure: (#{response.code}) #{response.message}"
@@ -1,3 +1,3 @@
1
1
  module OpinionatedHTTP
2
- VERSION = "0.0.5".freeze
2
+ VERSION = "0.0.6".freeze
3
3
  end
@@ -27,6 +27,16 @@ module OpinionatedHTTP
27
27
  end
28
28
  assert_equal body, response
29
29
  end
30
+
31
+ it "fails" do
32
+ message = "HTTP GET: lookup Failure: (403) Forbidden"
33
+ error = assert_raises ServiceError do
34
+ stub_request(Net::HTTPForbidden, 403, "Forbidden", "") do
35
+ http.get(action: "lookup", parameters: {zip: "12345"})
36
+ end
37
+ end
38
+ assert_equal message, error.message
39
+ end
30
40
  end
31
41
 
32
42
  describe "post" do
@@ -47,6 +57,29 @@ module OpinionatedHTTP
47
57
  end
48
58
  assert_equal body, response
49
59
  end
60
+
61
+ it "fails with body" do
62
+ message = "HTTP POST: lookup Failure: (403) Forbidden"
63
+ output = {zip: "12345", population: 54_321}
64
+ body = output.to_json
65
+ error = assert_raises ServiceError do
66
+ stub_request(Net::HTTPForbidden, 403, "Forbidden", "") do
67
+ http.post(action: "lookup", body: body)
68
+ end
69
+ end
70
+ assert_equal message, error.message
71
+ end
72
+
73
+ it "fails with form data" do
74
+ output = {zip: "12345", population: 54_321}
75
+ message = "HTTP POST: lookup Failure: (403) Forbidden"
76
+ error = assert_raises ServiceError do
77
+ stub_request(Net::HTTPForbidden, 403, "Forbidden", "") do
78
+ http.post(action: "lookup", form_data: output)
79
+ end
80
+ end
81
+ assert_equal message, error.message
82
+ end
50
83
  end
51
84
 
52
85
  describe "build_request" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opinionated_http
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Reid Morrison
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-29 00:00:00.000000000 Z
11
+ date: 2020-06-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: persistent_http