rdstation-ruby-client 1.2.1 → 2.0.0

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.
@@ -1,12 +1,14 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  RSpec.describe RDStation::Fields do
4
- let(:valid_auth_token) { 'valid_auth_token' }
5
- let(:rdstation_fields_with_valid_token) { described_class.new(valid_auth_token) }
4
+ let(:valid_access_token) { 'valid_access_token' }
5
+ let(:rdstation_fields_with_valid_token) do
6
+ described_class.new(authorization_header: RDStation::AuthorizationHeader.new(access_token: valid_access_token))
7
+ end
6
8
 
7
9
  let(:valid_headers) do
8
10
  {
9
- 'Authorization' => "Bearer #{valid_auth_token}",
11
+ 'Authorization' => "Bearer #{valid_access_token}",
10
12
  'Content-Type' => 'application/json'
11
13
  }
12
14
  end
@@ -1,18 +1,21 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  RSpec.describe RDStation::Webhooks do
4
- let(:webhooks_client) { described_class.new('auth_token') }
4
+ let(:webhooks_client) do
5
+ described_class.new(authorization_header: RDStation::AuthorizationHeader.new(access_token: 'access_token'))
6
+ end
7
+
5
8
  let(:webhooks_endpoint) { 'https://api.rd.services/integrations/webhooks/' }
6
9
 
7
10
  let(:headers) do
8
11
  {
9
- 'Authorization' => 'Bearer auth_token',
12
+ 'Authorization' => 'Bearer access_token',
10
13
  'Content-Type' => 'application/json'
11
14
  }
12
15
  end
13
16
 
14
17
  let(:error_handler) do
15
- instance_double(RDStation::ErrorHandler, raise_errors: 'mock raised errors')
18
+ instance_double(RDStation::ErrorHandler, raise_error: 'mock raised errors')
16
19
  end
17
20
 
18
21
  before do
@@ -63,9 +66,9 @@ RSpec.describe RDStation::Webhooks do
63
66
  .to_return(status: 400, body: { 'errors' => ['all errors'] }.to_json)
64
67
  end
65
68
 
66
- it 'calls raise_errors on error handler' do
69
+ it 'calls raise_error on error handler' do
67
70
  webhooks_client.all
68
- expect(error_handler).to have_received(:raise_errors)
71
+ expect(error_handler).to have_received(:raise_error)
69
72
  end
70
73
  end
71
74
  end
@@ -105,9 +108,9 @@ RSpec.describe RDStation::Webhooks do
105
108
  .to_return(status: 400, body: { 'errors' => ['all errors'] }.to_json)
106
109
  end
107
110
 
108
- it 'calls raise_errors on error handler' do
111
+ it 'calls raise_error on error handler' do
109
112
  webhooks_client.by_uuid(uuid)
110
- expect(error_handler).to have_received(:raise_errors)
113
+ expect(error_handler).to have_received(:raise_error)
111
114
  end
112
115
  end
113
116
  end
@@ -154,9 +157,9 @@ RSpec.describe RDStation::Webhooks do
154
157
  .to_return(status: 400, body: { 'errors' => ['all errors'] }.to_json)
155
158
  end
156
159
 
157
- it 'calls raise_errors on error handler' do
160
+ it 'calls raise_error on error handler' do
158
161
  webhooks_client.create(payload)
159
- expect(error_handler).to have_received(:raise_errors)
162
+ expect(error_handler).to have_received(:raise_error)
160
163
  end
161
164
  end
162
165
  end
@@ -205,9 +208,9 @@ RSpec.describe RDStation::Webhooks do
205
208
  .to_return(status: 400, body: { 'errors' => ['all errors'] }.to_json)
206
209
  end
207
210
 
208
- it 'calls raise_errors on error handler' do
211
+ it 'calls raise_error on error handler' do
209
212
  webhooks_client.update(uuid, new_payload)
210
- expect(error_handler).to have_received(:raise_errors)
213
+ expect(error_handler).to have_received(:raise_error)
211
214
  end
212
215
  end
213
216
  end
@@ -234,9 +237,9 @@ RSpec.describe RDStation::Webhooks do
234
237
  .to_return(status: 400, body: { 'errors' => ['all errors'] }.to_json)
235
238
  end
236
239
 
237
- it 'calls raise_errors on error handler' do
240
+ it 'calls raise_error on error handler' do
238
241
  webhooks_client.delete(uuid)
239
- expect(error_handler).to have_received(:raise_errors)
242
+ expect(error_handler).to have_received(:raise_error)
240
243
  end
241
244
  end
242
245
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rdstation-ruby-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paulo L F Casaretto
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-04-05 00:00:00.000000000 Z
11
+ date: 2019-04-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -116,7 +116,10 @@ extensions: []
116
116
  extra_rdoc_files: []
117
117
  files:
118
118
  - ".circleci/config.yml"
119
+ - ".github/ISSUE_TEMPLATE/rdsm-ruby-client-issue-template.md"
119
120
  - ".gitignore"
121
+ - ".rspec"
122
+ - CHANGELOG.md
120
123
  - Gemfile
121
124
  - LICENSE
122
125
  - README.md
@@ -124,19 +127,19 @@ files:
124
127
  - lib/rdstation-ruby-client.rb
125
128
  - lib/rdstation/api_response.rb
126
129
  - lib/rdstation/authentication.rb
130
+ - lib/rdstation/authorization_header.rb
127
131
  - lib/rdstation/client.rb
128
132
  - lib/rdstation/contacts.rb
129
133
  - lib/rdstation/error.rb
130
134
  - lib/rdstation/error/format.rb
131
135
  - lib/rdstation/error/formatter.rb
132
136
  - lib/rdstation/error_handler.rb
137
+ - lib/rdstation/error_handler/bad_request.rb
133
138
  - lib/rdstation/error_handler/conflicting_field.rb
134
- - lib/rdstation/error_handler/default.rb
135
139
  - lib/rdstation/error_handler/expired_access_token.rb
136
140
  - lib/rdstation/error_handler/expired_code_grant.rb
137
141
  - lib/rdstation/error_handler/invalid_credentials.rb
138
142
  - lib/rdstation/error_handler/invalid_event_type.rb
139
- - lib/rdstation/error_handler/resource_not_found.rb
140
143
  - lib/rdstation/error_handler/unauthorized.rb
141
144
  - lib/rdstation/events.rb
142
145
  - lib/rdstation/fields.rb
@@ -145,16 +148,16 @@ files:
145
148
  - rdstation-ruby-client.gemspec
146
149
  - spec/lib/rdstation-ruby-client_spec.rb
147
150
  - spec/lib/rdstation/authentication_spec.rb
151
+ - spec/lib/rdstation/authorization_header_spec.rb
152
+ - spec/lib/rdstation/client_spec.rb
148
153
  - spec/lib/rdstation/contacts_spec.rb
149
154
  - spec/lib/rdstation/error/format_spec.rb
150
155
  - spec/lib/rdstation/error/formatter_spec.rb
151
156
  - spec/lib/rdstation/error_handler/conflicting_field_spec.rb
152
- - spec/lib/rdstation/error_handler/default_spec.rb
153
157
  - spec/lib/rdstation/error_handler/expired_access_token_spec.rb
154
158
  - spec/lib/rdstation/error_handler/expired_code_grant_spec.rb
155
159
  - spec/lib/rdstation/error_handler/invalid_credentials_spec.rb
156
160
  - spec/lib/rdstation/error_handler/invalid_event_type_spec.rb
157
- - spec/lib/rdstation/error_handler/resource_not_found_spec.rb
158
161
  - spec/lib/rdstation/error_handler/unauthorized_spec.rb
159
162
  - spec/lib/rdstation/error_handler_spec.rb
160
163
  - spec/lib/rdstation/error_spec.rb
@@ -174,7 +177,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
174
177
  requirements:
175
178
  - - ">="
176
179
  - !ruby/object:Gem::Version
177
- version: '0'
180
+ version: 2.0.0
178
181
  required_rubygems_version: !ruby/object:Gem::Requirement
179
182
  requirements:
180
183
  - - ">="
@@ -188,16 +191,16 @@ summary: Ruby API wrapper for RD Station
188
191
  test_files:
189
192
  - spec/lib/rdstation-ruby-client_spec.rb
190
193
  - spec/lib/rdstation/authentication_spec.rb
194
+ - spec/lib/rdstation/authorization_header_spec.rb
195
+ - spec/lib/rdstation/client_spec.rb
191
196
  - spec/lib/rdstation/contacts_spec.rb
192
197
  - spec/lib/rdstation/error/format_spec.rb
193
198
  - spec/lib/rdstation/error/formatter_spec.rb
194
199
  - spec/lib/rdstation/error_handler/conflicting_field_spec.rb
195
- - spec/lib/rdstation/error_handler/default_spec.rb
196
200
  - spec/lib/rdstation/error_handler/expired_access_token_spec.rb
197
201
  - spec/lib/rdstation/error_handler/expired_code_grant_spec.rb
198
202
  - spec/lib/rdstation/error_handler/invalid_credentials_spec.rb
199
203
  - spec/lib/rdstation/error_handler/invalid_event_type_spec.rb
200
- - spec/lib/rdstation/error_handler/resource_not_found_spec.rb
201
204
  - spec/lib/rdstation/error_handler/unauthorized_spec.rb
202
205
  - spec/lib/rdstation/error_handler_spec.rb
203
206
  - spec/lib/rdstation/error_spec.rb
@@ -1,15 +0,0 @@
1
- module RDStation
2
- class ErrorHandler
3
- class Default
4
- attr_reader :errors
5
-
6
- def initialize(errors)
7
- @errors = errors
8
- end
9
-
10
- def raise_error
11
- raise RDStation::Error::Default, errors.first
12
- end
13
- end
14
- end
15
- end
@@ -1,24 +0,0 @@
1
- module RDStation
2
- class ErrorHandler
3
- class ResourceNotFound
4
- attr_reader :errors
5
-
6
- ERROR_CODE = 'RESOURCE_NOT_FOUND'.freeze
7
-
8
- def initialize(errors)
9
- @errors = errors
10
- end
11
-
12
- def raise_error
13
- return if resource_not_found_errors.empty?
14
- raise RDStation::Error::ResourceNotFound, resource_not_found_errors.first
15
- end
16
-
17
- private
18
-
19
- def resource_not_found_errors
20
- errors.select { |error| error['error_type'] == ERROR_CODE }
21
- end
22
- end
23
- end
24
- end
@@ -1,14 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe RDStation::ErrorHandler::Default do
4
- describe '#raise_error' do
5
- let(:errors) { [{ 'error_message' => 'Error Message' }] }
6
- let(:default_error) { described_class.new(errors) }
7
-
8
- it 'raises the received error' do
9
- expect do
10
- default_error.raise_error
11
- end.to raise_error(RDStation::Error::Default, errors.first['error_message'])
12
- end
13
- end
14
- end
@@ -1,54 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe RDStation::ErrorHandler::ResourceNotFound do
4
- describe '#raise_error' do
5
-
6
- subject(:resource_not_found_error) { described_class.new(errors) }
7
-
8
- context 'when there is a resource not found error' do
9
- let(:errors) do
10
- [
11
- {
12
- 'error_message' => 'Error Message',
13
- 'error_type' => 'RESOURCE_NOT_FOUND'
14
- }
15
- ]
16
- end
17
-
18
- it 'raises an ResourceNotFound error' do
19
- expect do
20
- resource_not_found_error.raise_error
21
- end.to raise_error(RDStation::Error::ResourceNotFound, 'Error Message')
22
- end
23
- end
24
-
25
- context 'when none of the errors are resource not found errors' do
26
- let(:errors) do
27
- [
28
- {
29
- 'error_message' => 'Error Message',
30
- 'error_type' => 'RANDOM_ERROR_TYPE'
31
- },
32
- {
33
- 'error_message' => 'Another Error Message',
34
- 'error_type' => 'ANOTHER_RANDOM_ERROR_TYPE'
35
- }
36
- ]
37
- end
38
-
39
- it 'does not raise an ResourceNotFound error' do
40
- result = resource_not_found_error.raise_error
41
- expect(result).to be_nil
42
- end
43
- end
44
-
45
- context 'when there are no errors' do
46
- let(:errors) { [] }
47
-
48
- it 'does not raise an ResourceNotFound error' do
49
- result = resource_not_found_error.raise_error
50
- expect(result).to be_nil
51
- end
52
- end
53
- end
54
- end