rdstation-ruby-client 1.2.1 → 2.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/ISSUE_TEMPLATE/rdsm-ruby-client-issue-template.md +49 -0
- data/.rspec +2 -0
- data/CHANGELOG.md +167 -0
- data/README.md +243 -43
- data/lib/rdstation-ruby-client.rb +6 -0
- data/lib/rdstation.rb +19 -0
- data/lib/rdstation/api_response.rb +3 -3
- data/lib/rdstation/authentication.rb +32 -3
- data/lib/rdstation/authorization.rb +24 -0
- data/lib/rdstation/builder/field.rb +70 -0
- data/lib/rdstation/client.rb +17 -74
- data/lib/rdstation/contacts.rb +21 -16
- data/lib/rdstation/error.rb +23 -15
- data/lib/rdstation/error/format.rb +21 -3
- data/lib/rdstation/error/formatter.rb +53 -7
- data/lib/rdstation/error_handler.rb +31 -26
- data/lib/rdstation/error_handler/bad_request.rb +30 -0
- data/lib/rdstation/error_handler/unauthorized.rb +17 -9
- data/lib/rdstation/events.rb +7 -19
- data/lib/rdstation/fields.rb +31 -7
- data/lib/rdstation/retryable_request.rb +35 -0
- data/lib/rdstation/version.rb +1 -1
- data/lib/rdstation/webhooks.rb +25 -17
- data/rdstation-ruby-client.gemspec +4 -1
- data/spec/lib/rdstation-ruby-client_spec.rb +1 -1
- data/spec/lib/rdstation/api_response_spec.rb +34 -0
- data/spec/lib/rdstation/authentication_spec.rb +164 -0
- data/spec/lib/rdstation/authorization_spec.rb +24 -0
- data/spec/lib/rdstation/builder/field_spec.rb +69 -0
- data/spec/lib/rdstation/client_spec.rb +37 -0
- data/spec/lib/rdstation/contacts_spec.rb +54 -41
- data/spec/lib/rdstation/error/format_spec.rb +46 -0
- data/spec/lib/rdstation/error/formatter_spec.rb +83 -0
- data/spec/lib/rdstation/error_handler/unauthorized_spec.rb +0 -29
- data/spec/lib/rdstation/error_handler_spec.rb +162 -26
- data/spec/lib/rdstation/events_spec.rb +20 -9
- data/spec/lib/rdstation/fields_spec.rb +10 -3
- data/spec/lib/rdstation/retryable_request_spec.rb +142 -0
- data/spec/lib/rdstation/webhooks_spec.rb +41 -13
- data/spec/lib/rdstation_spec.rb +18 -0
- metadata +41 -12
- data/lib/rdstation/error_handler/default.rb +0 -15
- data/lib/rdstation/error_handler/resource_not_found.rb +0 -24
- data/spec/lib/rdstation/error_handler/default_spec.rb +0 -14
- data/spec/lib/rdstation/error_handler/resource_not_found_spec.rb +0 -54
@@ -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
|