api_client_builder 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/Jenkinsfile +13 -0
- data/README.md +18 -0
- data/api_client_builder.gemspec +2 -2
- data/lib/api_client_builder.rb +1 -0
- data/lib/api_client_builder/api_client.rb +17 -0
- data/lib/api_client_builder/delete_request.rb +19 -0
- data/lib/api_client_builder/version.rb +1 -1
- data/spec/lib/api_client_builder/api_client_spec.rb +10 -0
- data/spec/lib/api_client_builder/delete_request_spec.rb +29 -0
- data/spec/lib/api_client_builder/test_client/client.rb +1 -0
- data/spec/lib/api_client_builder/test_client/response_handler.rb +4 -0
- metadata +20 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 2accab064d29f0ff8f30fe57c72e1d6d4e8443e638fc118c0c3491072f4f9893
|
4
|
+
data.tar.gz: 36eca023a1104ab85da81b13422b2ab0125601c0d008a398e91310697cd1b99c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 811764f10bf9810621e0148944e040123433690f7fce45e7512c9e5537e894b62b5dfb2fa96f2c45df7221c5942121879728cc488181495223bb9bb6d57162bb
|
7
|
+
data.tar.gz: 39a5f07153ddaef6f2e5dbb2acb971c8f033f3d97421b915fb9b0b43a5fcc02159321c1d807c930ff934115c21ecedca74ed97c18734371694eefa71739bd1c1
|
data/Jenkinsfile
ADDED
data/README.md
CHANGED
@@ -186,6 +186,10 @@ class HTTPClientHandler
|
|
186
186
|
client.post(route, params, headers)
|
187
187
|
end
|
188
188
|
|
189
|
+
def delete(route, params = nil, headers = {})
|
190
|
+
client.delete(route, params, headers)
|
191
|
+
end
|
192
|
+
|
189
193
|
# Define a client to use here. The HTTPClient gem is a good option
|
190
194
|
|
191
195
|
# Build up headers and authentication handling here as well
|
@@ -296,6 +300,20 @@ def post_request
|
|
296
300
|
end
|
297
301
|
```
|
298
302
|
|
303
|
+
#### For deletes
|
304
|
+
|
305
|
+
The builder will call `#delete_request` when handling delete routes.
|
306
|
+
|
307
|
+
```ruby
|
308
|
+
def delete_request
|
309
|
+
# Build the URL -- this could be to add pagination params to the route, or
|
310
|
+
# add whatever else is necessary to the route.
|
311
|
+
# Also send the body if that's how the client handler is configured.
|
312
|
+
http_response = @http_client.delete("a URL")
|
313
|
+
build_response(http_response)
|
314
|
+
end
|
315
|
+
```
|
316
|
+
|
299
317
|
#### Handling retry-able requests
|
300
318
|
|
301
319
|
If requests defined need to be retry-able, extend the response handler by providing
|
data/api_client_builder.gemspec
CHANGED
@@ -4,8 +4,8 @@ Gem::Specification.new do |gem|
|
|
4
4
|
gem.name = 'api_client_builder'
|
5
5
|
gem.summary = 'API Client Builder provides an easy to use interface for creating HTTP api clients'
|
6
6
|
gem.description = 'API Client Builder provides an easy to use interface for creating HTTP api clients'
|
7
|
-
gem.authors = ['Jayce Higgins'
|
8
|
-
gem.email = ['jhiggins@instructure.com', '
|
7
|
+
gem.authors = ['Jayce Higgins']
|
8
|
+
gem.email = ['jhiggins@instructure.com', 'eng@instructure.com']
|
9
9
|
gem.homepage = 'https://github.com/instructure/api-client-builder'
|
10
10
|
|
11
11
|
gem.version = APIClientBuilder::VERSION
|
data/lib/api_client_builder.rb
CHANGED
@@ -8,6 +8,7 @@ require_relative 'api_client_builder/get_collection_request'
|
|
8
8
|
require_relative 'api_client_builder/get_item_request'
|
9
9
|
require_relative 'api_client_builder/post_request'
|
10
10
|
require_relative 'api_client_builder/put_request'
|
11
|
+
require_relative 'api_client_builder/delete_request'
|
11
12
|
require_relative 'api_client_builder/url_generator'
|
12
13
|
|
13
14
|
require_relative 'api_client_builder/api_client'
|
@@ -75,5 +75,22 @@ module APIClientBuilder
|
|
75
75
|
)
|
76
76
|
end
|
77
77
|
end
|
78
|
+
|
79
|
+
# Used to define a DELETE api route on the base class. Will
|
80
|
+
# yield a method that takes the shape of 'delete_type' that will
|
81
|
+
# return a DeleteRequest.
|
82
|
+
#
|
83
|
+
# @param type [Symbol] defines the route model
|
84
|
+
# @param route [String] defines the routes endpoint
|
85
|
+
#
|
86
|
+
# @return [DeleteRequest] the request object that handles puts
|
87
|
+
def self.delete(type, route)
|
88
|
+
define_method("delete_#{type}") do |**params|
|
89
|
+
DeleteRequest.new(
|
90
|
+
type,
|
91
|
+
response_handler_build(http_client, @url_generator.build_route(route, **params), type)
|
92
|
+
)
|
93
|
+
end
|
94
|
+
end
|
78
95
|
end
|
79
96
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module APIClientBuilder
|
2
|
+
class DeleteRequest < Request
|
3
|
+
# Yields the response body if the response was successful. Will call
|
4
|
+
# the response handlers if there was not a successful response.
|
5
|
+
#
|
6
|
+
# @return [JSON] the http response body
|
7
|
+
def response
|
8
|
+
response = response_handler.delete_request
|
9
|
+
|
10
|
+
if response.success?
|
11
|
+
response
|
12
|
+
else
|
13
|
+
error_handlers.each do |handler|
|
14
|
+
handler.call(response, self)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -41,5 +41,15 @@ module APIClientBuilder
|
|
41
41
|
expect(client.put_some_object({})).to be_a(APIClientBuilder::PutRequest)
|
42
42
|
end
|
43
43
|
end
|
44
|
+
|
45
|
+
describe '.delete' do
|
46
|
+
it 'defines a delete method on the client' do
|
47
|
+
expect(client).to respond_to(:delete_some_object)
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'returns a DeleteRequest object' do
|
51
|
+
expect(client.delete_some_object({})).to be_a(APIClientBuilder::DeleteRequest)
|
52
|
+
end
|
53
|
+
end
|
44
54
|
end
|
45
55
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require_relative 'test_client/client'
|
3
|
+
|
4
|
+
module APIClientBuilder
|
5
|
+
describe DeleteRequest do
|
6
|
+
describe '#response' do
|
7
|
+
context 'request was successful' do
|
8
|
+
it 'returns a response object' do
|
9
|
+
client = TestClient::Client.new(domain: 'https://www.domain.com/api/endpoints/')
|
10
|
+
|
11
|
+
some_object = client.delete_some_object({}).response
|
12
|
+
expect(some_object.body).to eq('good delete request')
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
context 'request was unsuccessful' do
|
17
|
+
it 'calls the error handlers' do
|
18
|
+
client = TestClient::Client.new(domain: 'https://www.domain.com/api/endpoints/')
|
19
|
+
|
20
|
+
bad_response = APIClientBuilder::Response.new('bad request', 400, [200])
|
21
|
+
allow_any_instance_of(TestClient::ResponseHandler).to receive(:delete_request).and_return(bad_response)
|
22
|
+
expect { client.delete_some_object({}).response }.to raise_error(
|
23
|
+
APIClientBuilder::DefaultPageError, /Error Code: 400/
|
24
|
+
)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -18,6 +18,10 @@ module TestClient
|
|
18
18
|
APIClientBuilder::Response.new([4, 5, 6], SUCCESS_STATUS, SUCCESS_RANGE)
|
19
19
|
end
|
20
20
|
|
21
|
+
def delete_request
|
22
|
+
APIClientBuilder::Response.new('good delete request', SUCCESS_STATUS, SUCCESS_RANGE)
|
23
|
+
end
|
24
|
+
|
21
25
|
def put_request(_body)
|
22
26
|
APIClientBuilder::Response.new('good request', SUCCESS_STATUS, SUCCESS_RANGE)
|
23
27
|
end
|
metadata
CHANGED
@@ -1,92 +1,92 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: api_client_builder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jayce Higgins
|
8
|
-
- Bryan Petty
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2020-03-27 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: pry
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
16
|
requirements:
|
18
|
-
- -
|
17
|
+
- - ">="
|
19
18
|
- !ruby/object:Gem::Version
|
20
19
|
version: '0'
|
21
20
|
type: :development
|
22
21
|
prerelease: false
|
23
22
|
version_requirements: !ruby/object:Gem::Requirement
|
24
23
|
requirements:
|
25
|
-
- -
|
24
|
+
- - ">="
|
26
25
|
- !ruby/object:Gem::Version
|
27
26
|
version: '0'
|
28
27
|
- !ruby/object:Gem::Dependency
|
29
28
|
name: rspec
|
30
29
|
requirement: !ruby/object:Gem::Requirement
|
31
30
|
requirements:
|
32
|
-
- - ~>
|
31
|
+
- - "~>"
|
33
32
|
- !ruby/object:Gem::Version
|
34
33
|
version: '3.7'
|
35
34
|
type: :development
|
36
35
|
prerelease: false
|
37
36
|
version_requirements: !ruby/object:Gem::Requirement
|
38
37
|
requirements:
|
39
|
-
- - ~>
|
38
|
+
- - "~>"
|
40
39
|
- !ruby/object:Gem::Version
|
41
40
|
version: '3.7'
|
42
41
|
- !ruby/object:Gem::Dependency
|
43
42
|
name: rubocop
|
44
43
|
requirement: !ruby/object:Gem::Requirement
|
45
44
|
requirements:
|
46
|
-
- - ~>
|
45
|
+
- - "~>"
|
47
46
|
- !ruby/object:Gem::Version
|
48
47
|
version: 0.57.2
|
49
48
|
type: :development
|
50
49
|
prerelease: false
|
51
50
|
version_requirements: !ruby/object:Gem::Requirement
|
52
51
|
requirements:
|
53
|
-
- - ~>
|
52
|
+
- - "~>"
|
54
53
|
- !ruby/object:Gem::Version
|
55
54
|
version: 0.57.2
|
56
55
|
- !ruby/object:Gem::Dependency
|
57
56
|
name: simplecov
|
58
57
|
requirement: !ruby/object:Gem::Requirement
|
59
58
|
requirements:
|
60
|
-
- - ~>
|
59
|
+
- - "~>"
|
61
60
|
- !ruby/object:Gem::Version
|
62
61
|
version: '0'
|
63
62
|
type: :development
|
64
63
|
prerelease: false
|
65
64
|
version_requirements: !ruby/object:Gem::Requirement
|
66
65
|
requirements:
|
67
|
-
- - ~>
|
66
|
+
- - "~>"
|
68
67
|
- !ruby/object:Gem::Version
|
69
68
|
version: '0'
|
70
69
|
description: API Client Builder provides an easy to use interface for creating HTTP
|
71
70
|
api clients
|
72
71
|
email:
|
73
72
|
- jhiggins@instructure.com
|
74
|
-
- bpetty@instructure.com
|
75
73
|
- eng@instructure.com
|
76
74
|
executables: []
|
77
75
|
extensions: []
|
78
76
|
extra_rdoc_files: []
|
79
77
|
files:
|
80
|
-
- .gitignore
|
81
|
-
- .rubocop.yml
|
82
|
-
- .travis.yml
|
78
|
+
- ".gitignore"
|
79
|
+
- ".rubocop.yml"
|
80
|
+
- ".travis.yml"
|
83
81
|
- Gemfile
|
82
|
+
- Jenkinsfile
|
84
83
|
- LICENSE.txt
|
85
84
|
- README.md
|
86
85
|
- api_client_builder.gemspec
|
87
86
|
- build.sh
|
88
87
|
- lib/api_client_builder.rb
|
89
88
|
- lib/api_client_builder/api_client.rb
|
89
|
+
- lib/api_client_builder/delete_request.rb
|
90
90
|
- lib/api_client_builder/get_collection_request.rb
|
91
91
|
- lib/api_client_builder/get_item_request.rb
|
92
92
|
- lib/api_client_builder/post_request.rb
|
@@ -96,6 +96,7 @@ files:
|
|
96
96
|
- lib/api_client_builder/url_generator.rb
|
97
97
|
- lib/api_client_builder/version.rb
|
98
98
|
- spec/lib/api_client_builder/api_client_spec.rb
|
99
|
+
- spec/lib/api_client_builder/delete_request_spec.rb
|
99
100
|
- spec/lib/api_client_builder/get_collection_request_spec.rb
|
100
101
|
- spec/lib/api_client_builder/get_item_request_spec.rb
|
101
102
|
- spec/lib/api_client_builder/post_request_spec.rb
|
@@ -117,23 +118,23 @@ require_paths:
|
|
117
118
|
- lib
|
118
119
|
required_ruby_version: !ruby/object:Gem::Requirement
|
119
120
|
requirements:
|
120
|
-
- -
|
121
|
+
- - ">="
|
121
122
|
- !ruby/object:Gem::Version
|
122
123
|
version: '2.3'
|
123
124
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
124
125
|
requirements:
|
125
|
-
- -
|
126
|
+
- - ">="
|
126
127
|
- !ruby/object:Gem::Version
|
127
128
|
version: '0'
|
128
129
|
requirements: []
|
129
|
-
|
130
|
-
rubygems_version: 2.0.14
|
130
|
+
rubygems_version: 3.0.6
|
131
131
|
signing_key:
|
132
132
|
specification_version: 4
|
133
133
|
summary: API Client Builder provides an easy to use interface for creating HTTP api
|
134
134
|
clients
|
135
135
|
test_files:
|
136
136
|
- spec/lib/api_client_builder/api_client_spec.rb
|
137
|
+
- spec/lib/api_client_builder/delete_request_spec.rb
|
137
138
|
- spec/lib/api_client_builder/get_collection_request_spec.rb
|
138
139
|
- spec/lib/api_client_builder/get_item_request_spec.rb
|
139
140
|
- spec/lib/api_client_builder/post_request_spec.rb
|