rest_api_builder 0.1.0 → 0.1.1
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/LICENSE +0 -0
- data/README.md +4 -4
- data/lib/rest_api_builder.rb +0 -0
- data/lib/rest_api_builder/request_options.rb +0 -0
- data/lib/rest_api_builder/response_handler.rb +0 -0
- data/lib/rest_api_builder/url_helper.rb +0 -0
- data/lib/rest_api_builder/webmock_request_expectations.rb +17 -1
- data/rest_api_builder.gemspec +1 -1
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dd44f147795470f5d2665d31c027f845fccf9430e925fbae1a2e070037637f8a
|
4
|
+
data.tar.gz: 8f9a34b3768349a1e8ec837cd2739b6c997766adee3910a6d7518084eed6e13d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 23e78a1b9a9e16c120515e389857366b3093ba776b2c329610fa3ef684d302dce82ca5018476ca3381b4edd5fc4cf9c31532e715fa34f347ae30822170f0ea60
|
7
|
+
data.tar.gz: fde6a4d5c6fb9fcbb3caeba61720b68f0867492052d566370488f706ec199eef0759937e3ae10e4efa9074a497ee666c85c1c365f49c37732bcfe2e342639f06
|
data/LICENSE
CHANGED
File without changes
|
data/README.md
CHANGED
@@ -132,9 +132,9 @@ Expectations.expect_execute(
|
|
132
132
|
base_url: "test.com",
|
133
133
|
method: :post,
|
134
134
|
response: { body: 'hello' },
|
135
|
-
request: { body:
|
135
|
+
request: { body: { foo: "bar" } } # body will be matched partially using hash_including matcher
|
136
136
|
)
|
137
|
-
response = my_request.json_execute(base_url: "test.com", method: :post, body: {foo: "bar"})
|
137
|
+
response = my_request.json_execute(base_url: "test.com", method: :post, body: { foo: "bar", bar: "baz" })
|
138
138
|
response[:success] #=> true
|
139
139
|
response[:body] #=> 'hello'
|
140
140
|
|
@@ -184,13 +184,13 @@ Returns ruby hash with `:success` and `:raw_response` keys.
|
|
184
184
|
|
185
185
|
## WebMockRequestExpectations API
|
186
186
|
### RestAPIBuilder::WebMockRequestExpectations.expect_execute(options)
|
187
|
-
Defines a request expectation using WebMock's `stub_request`. Returns an instance of `WebMock::RequestStub` on which methods such as `with`, `to_return`, `to_timeout` can be called
|
187
|
+
Defines a request expectation using WebMock's `stub_request`. Returns an instance of `WebMock::RequestStub` on which methods such as `with`, `to_return`, `to_timeout` can be called.
|
188
188
|
|
189
189
|
#### Options:
|
190
190
|
* **base_url**: Base URL of the request. Required.
|
191
191
|
* **method**: HTTP method of the request(e.g :get, :post, :patch). Required.
|
192
192
|
* **path**: Path to be appended to the :base_url. Optional.
|
193
|
-
* **request**: request details which will be passed to `WebMock::RequestStub#with` if provided. Optional
|
193
|
+
* **request**: request details which will be passed to `WebMock::RequestStub#with` if provided. If `query` or `body` keys are present and are hashes, they will be converted into WebMock's `hash_including` matcher. Optional
|
194
194
|
* **response**: response details which will be passed to `WebMock::RequestStub#to_return` if provided. Optional
|
195
195
|
|
196
196
|
### RestAPIBuilder::WebMockRequestExpectations.expect_json_execute(options)
|
data/lib/rest_api_builder.rb
CHANGED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -17,11 +17,27 @@ module RestAPIBuilder
|
|
17
17
|
def expect_execute(base_url:, method:, path: nil, request: nil, response: nil)
|
18
18
|
expectation = stub_request(method, full_url(base_url, path))
|
19
19
|
|
20
|
-
|
20
|
+
if !request.nil? && request.any?
|
21
|
+
add_request_expectations(expectation, request)
|
22
|
+
end
|
23
|
+
|
21
24
|
expectation.to_return(response) if response
|
22
25
|
|
23
26
|
expectation
|
24
27
|
end
|
28
|
+
|
29
|
+
def add_request_expectations(expectation, request)
|
30
|
+
if request[:body].is_a?(Hash)
|
31
|
+
request = request.merge(body: hash_including(request[:body]))
|
32
|
+
end
|
33
|
+
|
34
|
+
if request[:query].is_a?(Hash)
|
35
|
+
query = request[:query].transform_values(&:to_s)
|
36
|
+
request = request.merge(query: hash_including(query))
|
37
|
+
end
|
38
|
+
|
39
|
+
expectation.with(request)
|
40
|
+
end
|
25
41
|
end
|
26
42
|
|
27
43
|
WebMockRequestExpectations = WebMockRequestExpectationsSingleton.new
|
data/rest_api_builder.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'rest_api_builder'
|
3
|
-
s.version = '0.1.
|
3
|
+
s.version = '0.1.1'
|
4
4
|
s.summary = "A simple wrapper for rest-client"
|
5
5
|
s.description = "A simple wrapper for rest-client aiming to make creation and testing of API clients easier."
|
6
6
|
s.authors = ["Alexey D"]
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rest_api_builder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexey D
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-09-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubocop
|
@@ -86,8 +86,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
86
86
|
- !ruby/object:Gem::Version
|
87
87
|
version: '0'
|
88
88
|
requirements: []
|
89
|
-
|
90
|
-
rubygems_version: 2.7.8
|
89
|
+
rubygems_version: 3.1.2
|
91
90
|
signing_key:
|
92
91
|
specification_version: 4
|
93
92
|
summary: A simple wrapper for rest-client
|