opinionated_http 0.0.5 → 0.0.6
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 +4 -4
- data/lib/opinionated_http/client.rb +3 -3
- data/lib/opinionated_http/version.rb +1 -1
- data/test/client_test.rb +33 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5c63d8fd6c65797a7afcef26ff0ef72507dcf75f8dbbd4bc93e768cf0ddffc9a
|
4
|
+
data.tar.gz: 0a56d817ad5a0a988886faf17b034df697712c3958719cbcd72558ebb1bd8ee1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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}"
|
data/test/client_test.rb
CHANGED
@@ -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.
|
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-
|
11
|
+
date: 2020-06-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: persistent_http
|