rdstation-ruby-client 2.2.0 → 2.3.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +53 -2
- data/README.md +49 -0
- data/lib/rdstation-ruby-client.rb +3 -0
- data/lib/rdstation/builder/field.rb +70 -0
- data/lib/rdstation/error/format.rb +21 -3
- data/lib/rdstation/error/formatter.rb +53 -7
- data/lib/rdstation/events.rb +1 -9
- data/lib/rdstation/fields.rb +28 -2
- data/lib/rdstation/version.rb +1 -1
- data/spec/lib/rdstation/builder/field_spec.rb +69 -0
- data/spec/lib/rdstation/error/format_spec.rb +46 -0
- data/spec/lib/rdstation/error/formatter_spec.rb +83 -0
- metadata +7 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 93cdc7036300cb21cf4609bb92042f47e280a864f84cfaba3b5a9e6181274aad
|
4
|
+
data.tar.gz: 349d48fb5a969953c3e637b0cf73aef037328aafff3aeb779c7f217c0ac1e537
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8cfa5e1cd4d75f9a30536b99055075e92a7bdb3630ed8b71cfc66f4032983677079d78663d9eaadc4fcfb88875665281e271b270c6a584e93a81b5065bd7f005
|
7
|
+
data.tar.gz: 7e64c0b2983ce2d081d4236c42d432a7c994f2927f17e766020067b512a2ed47b1988acdc5c1a8d81edaf3cd0acc43f96209e1a0192abb11d0f52074758a1989
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,54 @@
|
|
1
|
+
## 2.3.0
|
2
|
+
|
3
|
+
### Additions
|
4
|
+
|
5
|
+
#### 1. New Field methods
|
6
|
+
|
7
|
+
The following methods were added to "Fields" client:
|
8
|
+
|
9
|
+
- create
|
10
|
+
- update
|
11
|
+
- delete
|
12
|
+
|
13
|
+
Besides reading, this client is now capable of create, update or delete a field.
|
14
|
+
|
15
|
+
Usage example:
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
client = RDStation::Client.new(access_token: 'ACCESS_TOKEN', refresh_token: 'REFRESH_TOKEN')
|
19
|
+
client.fields.delete('FIELD_UUID')
|
20
|
+
```
|
21
|
+
|
22
|
+
#### 2. New format of errors supported
|
23
|
+
|
24
|
+
Two new formats of errors are now supported by the error handler:
|
25
|
+
|
26
|
+
##### `HASH_OF_HASHES`
|
27
|
+
|
28
|
+
When the error message is a hash containing other hashes as values, for example:
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
{
|
32
|
+
'error' => {
|
33
|
+
'field1' => {...},
|
34
|
+
'field2' => {...}
|
35
|
+
}
|
36
|
+
}
|
37
|
+
```
|
38
|
+
|
39
|
+
##### `HASH_OF_MULTIPLE_TYPES`
|
40
|
+
|
41
|
+
When the error message is a hash that could contain multiple data types as values, for example:
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
{
|
45
|
+
'error' => {
|
46
|
+
'field1' => [...] # Array,
|
47
|
+
'field2' => {...} # Hash
|
48
|
+
}
|
49
|
+
}
|
50
|
+
```
|
51
|
+
|
1
52
|
## 2.2.0
|
2
53
|
|
3
54
|
### Additions
|
@@ -37,7 +88,7 @@ end
|
|
37
88
|
|
38
89
|
Providing `client_id` and `client_secret` directly to `RDStation::Authentication.new` is deprecated and will be removed in future versions. Use `RDStation.configure` instead.
|
39
90
|
|
40
|
-
Specifying refresh_token in `RDStation::Client.new(access_token: 'at', refresh_token: 'rt')` is optional right now, but will be mandatory in future versions.
|
91
|
+
Specifying refresh_token in `RDStation::Client.new(access_token: 'at', refresh_token: 'rt')` is optional right now, but will be mandatory in future versions.
|
41
92
|
|
42
93
|
## 2.1.1
|
43
94
|
|
@@ -94,7 +145,7 @@ In case of a Bad Request (400), the following specific errors may be raised (tho
|
|
94
145
|
- `RDStation::Error::ConflictingField`
|
95
146
|
- `RDStation::Error::InvalidEventType`
|
96
147
|
|
97
|
-
In cause of
|
148
|
+
In cause of Unauthorized (401), the following specific errors may be raised (those are subclasses of `RDStation::Error::Unauthorized`):
|
98
149
|
- `RDStation::Error::ExpiredAccessToken`
|
99
150
|
- `RDStation::Error::ExpiredCodeGrant`
|
100
151
|
- `RDStation::Error::InvalidCredentials`
|
data/README.md
CHANGED
@@ -206,6 +206,55 @@ client = RDStation::Client.new(access_token: 'access_token', refresh_token: 'ref
|
|
206
206
|
client.fields.all
|
207
207
|
```
|
208
208
|
|
209
|
+
#### Create a field
|
210
|
+
|
211
|
+
```ruby
|
212
|
+
payload = {} # hash representing the payload
|
213
|
+
client = RDStation::Client.new(access_token: 'access_token', refresh_token: 'refresh_token')
|
214
|
+
client.fields.create payload
|
215
|
+
```
|
216
|
+
Or you can use the new `RDStation::Builder::Field`
|
217
|
+
|
218
|
+
```ruby
|
219
|
+
payload = {} # hash representing the payload
|
220
|
+
builder = RDStation::Builder::Field.new payload['api_identifier']
|
221
|
+
builder.data_type(payload['data_type'])
|
222
|
+
builder.presentation_type(payload['presentation_type'])
|
223
|
+
builder.name('pt-BR', payload['name'])
|
224
|
+
builder.label('pt-BR', payload['label'])
|
225
|
+
|
226
|
+
client = RDStation::Client.new(access_token: 'access_token', refresh_token: 'refresh_token')
|
227
|
+
client.fields.create builder.build
|
228
|
+
```
|
229
|
+
|
230
|
+
#### Update a field
|
231
|
+
|
232
|
+
```ruby
|
233
|
+
payload = {} # hash representing the payload
|
234
|
+
client = RDStation::Client.new(access_token: 'access_token', refresh_token: 'refresh_token')
|
235
|
+
client.fields.update('FIELD_UUID', payload)
|
236
|
+
```
|
237
|
+
Or you can use the new `RDStation::Builder::Field`
|
238
|
+
|
239
|
+
```ruby
|
240
|
+
payload = {} # hash representing the payload
|
241
|
+
builder = RDStation::Builder::Field.new payload['api_identifier']
|
242
|
+
builder.data_type(payload['data_type'])
|
243
|
+
builder.presentation_type(payload['presentation_type'])
|
244
|
+
builder.name('pt-BR', payload['name'])
|
245
|
+
builder.label('pt-BR', payload['label'])
|
246
|
+
|
247
|
+
client = RDStation::Client.new(access_token: 'access_token', refresh_token: 'refresh_token')
|
248
|
+
client.fields.update('FIELD_UUID', builder.build)
|
249
|
+
```
|
250
|
+
#### Deleting a field
|
251
|
+
|
252
|
+
```ruby
|
253
|
+
client = RDStation::Client.new(access_token: 'access_token', refresh_token: 'refresh_token')
|
254
|
+
client.fields.delete('FIELD_UUID')
|
255
|
+
```
|
256
|
+
|
257
|
+
|
209
258
|
### Webhooks
|
210
259
|
|
211
260
|
Webhooks provide the ability to receive real-time data updates about your contact activity.
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RDStation
|
4
|
+
class Builder
|
5
|
+
# More info: https://developers.rdstation.com/pt-BR/reference/fields#methodPostDetails
|
6
|
+
class Field
|
7
|
+
DATA_TYPES = %w(STRING INTEGER BOOLEAN STRING[]).freeze
|
8
|
+
PRESENTATION_TYPES = %w[TEXT_INPUT TEXT_AREA URL_INPUT PHONE_INPUT
|
9
|
+
EMAIL_INPUT CHECK_BOX NUMBER_INPUT COMBO_BOX
|
10
|
+
RADIO_BUTTON MULTIPLE_CHOICE].freeze
|
11
|
+
|
12
|
+
REQUIRED_FIELDS = %w[api_identifier data_type presentation_type label name].freeze
|
13
|
+
|
14
|
+
def initialize(api_identifier)
|
15
|
+
raise 'api_identifier required' unless api_identifier
|
16
|
+
unless valid_identifier(api_identifier)
|
17
|
+
raise 'api_identifier is not in a valid format, need start with "cf_"'
|
18
|
+
end
|
19
|
+
|
20
|
+
@values = {}
|
21
|
+
@values['api_identifier'] = api_identifier
|
22
|
+
end
|
23
|
+
|
24
|
+
def data_type(data_type)
|
25
|
+
raise "Not valid data_type - #{DATA_TYPES}" unless DATA_TYPES.include? data_type
|
26
|
+
|
27
|
+
@values['data_type'] = data_type
|
28
|
+
end
|
29
|
+
|
30
|
+
def presentation_type(presentation_type)
|
31
|
+
unless PRESENTATION_TYPES.include? presentation_type
|
32
|
+
raise "Not valid presentation_type - #{PRESENTATION_TYPES}"
|
33
|
+
end
|
34
|
+
|
35
|
+
@values['presentation_type'] = presentation_type
|
36
|
+
end
|
37
|
+
|
38
|
+
def label(language, label)
|
39
|
+
@values['label'] = { language.to_s => label }
|
40
|
+
end
|
41
|
+
|
42
|
+
def name(language, name)
|
43
|
+
@values['name'] = { language.to_s => name }
|
44
|
+
end
|
45
|
+
|
46
|
+
def validation_rules(validation_rules)
|
47
|
+
@values['validation_rules'] = validation_rules
|
48
|
+
end
|
49
|
+
|
50
|
+
def valid_options(valid_options)
|
51
|
+
@values['valid_options'] = valid_options
|
52
|
+
end
|
53
|
+
|
54
|
+
def build
|
55
|
+
empty_fields = REQUIRED_FIELDS.select { |field| @values[field].nil? }
|
56
|
+
unless empty_fields.empty?
|
57
|
+
raise "Required fields are missing - #{empty_fields}"
|
58
|
+
end
|
59
|
+
|
60
|
+
@values
|
61
|
+
end
|
62
|
+
|
63
|
+
private
|
64
|
+
|
65
|
+
def valid_identifier(api_identifier)
|
66
|
+
api_identifier.start_with? 'cf_'
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -1,9 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module RDStation
|
2
4
|
class Error
|
3
5
|
class Format
|
4
|
-
FLAT_HASH = 'FLAT_HASH'
|
5
|
-
HASH_OF_ARRAYS = 'HASH_OF_ARRAYS'
|
6
|
-
ARRAY_OF_HASHES = 'ARRAY_OF_HASHES'
|
6
|
+
FLAT_HASH = 'FLAT_HASH'
|
7
|
+
HASH_OF_ARRAYS = 'HASH_OF_ARRAYS'
|
8
|
+
ARRAY_OF_HASHES = 'ARRAY_OF_HASHES'
|
9
|
+
HASH_OF_MULTIPLE_TYPES = 'HASH_OF_MULTIPLE_TYPES'
|
10
|
+
HASH_OF_HASHES = 'HASH_OF_HASHES'
|
7
11
|
|
8
12
|
def initialize(errors)
|
9
13
|
@errors = errors
|
@@ -12,6 +16,9 @@ module RDStation
|
|
12
16
|
def format
|
13
17
|
return FLAT_HASH if flat_hash?
|
14
18
|
return HASH_OF_ARRAYS if hash_of_arrays?
|
19
|
+
return HASH_OF_HASHES if hash_of_hashes?
|
20
|
+
return HASH_OF_MULTIPLE_TYPES if hash_of_multiple_types?
|
21
|
+
|
15
22
|
ARRAY_OF_HASHES
|
16
23
|
end
|
17
24
|
|
@@ -19,12 +26,23 @@ module RDStation
|
|
19
26
|
|
20
27
|
def flat_hash?
|
21
28
|
return unless @errors.is_a?(Hash)
|
29
|
+
|
22
30
|
@errors.key?('error_type')
|
23
31
|
end
|
24
32
|
|
25
33
|
def hash_of_arrays?
|
26
34
|
@errors.is_a?(Hash) && @errors.values.all? { |error| error.is_a? Array }
|
27
35
|
end
|
36
|
+
|
37
|
+
def hash_of_hashes?
|
38
|
+
@errors.is_a?(Hash) && @errors.values.all? { |error| error.is_a? Hash }
|
39
|
+
end
|
40
|
+
|
41
|
+
def hash_of_multiple_types?
|
42
|
+
@errors.is_a?(Hash) &&
|
43
|
+
@errors.values.any? { |error| error.is_a? Hash } &&
|
44
|
+
@errors.values.any? { |error| error.is_a? Array }
|
45
|
+
end
|
28
46
|
end
|
29
47
|
end
|
30
48
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative './format'
|
2
4
|
|
3
5
|
module RDStation
|
@@ -15,6 +17,10 @@ module RDStation
|
|
15
17
|
return from_flat_hash
|
16
18
|
when RDStation::Error::Format::HASH_OF_ARRAYS
|
17
19
|
return from_hash_of_arrays
|
20
|
+
when RDStation::Error::Format::HASH_OF_HASHES
|
21
|
+
return from_hash_of_hashes
|
22
|
+
when RDStation::Error::Format::HASH_OF_MULTIPLE_TYPES
|
23
|
+
return from_hash_of_multiple_types
|
18
24
|
end
|
19
25
|
|
20
26
|
errors
|
@@ -24,14 +30,29 @@ module RDStation
|
|
24
30
|
[errors]
|
25
31
|
end
|
26
32
|
|
27
|
-
def
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
33
|
+
def from_hash_of_multiple_types
|
34
|
+
array_of_errors = []
|
35
|
+
errors.each do |attribute_name, errors|
|
36
|
+
if errors.is_a? Array
|
37
|
+
result = build_error_from_array(attribute_name, errors)
|
38
|
+
end
|
39
|
+
if errors.is_a? Hash
|
40
|
+
result = build_error_from_multilingual_hash(attribute_name, errors)
|
41
|
+
end
|
42
|
+
array_of_errors.push(*result)
|
34
43
|
end
|
44
|
+
|
45
|
+
array_of_errors
|
46
|
+
end
|
47
|
+
|
48
|
+
def from_hash_of_hashes
|
49
|
+
array_of_errors = []
|
50
|
+
errors.each do |attribute_name, errors|
|
51
|
+
result = build_error_from_multilingual_hash(attribute_name, errors)
|
52
|
+
array_of_errors.push(*result)
|
53
|
+
end
|
54
|
+
|
55
|
+
array_of_errors
|
35
56
|
end
|
36
57
|
|
37
58
|
def error_format
|
@@ -41,6 +62,31 @@ module RDStation
|
|
41
62
|
def errors
|
42
63
|
@errors ||= @error_response['errors']
|
43
64
|
end
|
65
|
+
|
66
|
+
private
|
67
|
+
|
68
|
+
def build_error_from_array(attribute_name, attribute_errors)
|
69
|
+
path = { 'path' => "body.#{attribute_name}" }
|
70
|
+
attribute_errors.map { |error| error.merge(path) }
|
71
|
+
end
|
72
|
+
|
73
|
+
def build_error_from_multilingual_hash(attribute_name, errors_by_language)
|
74
|
+
array_of_errors = []
|
75
|
+
errors_by_language.each do |language, errors|
|
76
|
+
result = build_error_from_array("#{attribute_name}.#{language}", errors)
|
77
|
+
array_of_errors.push(*result)
|
78
|
+
end
|
79
|
+
array_of_errors
|
80
|
+
end
|
81
|
+
|
82
|
+
def from_hash_of_arrays
|
83
|
+
errors.each_with_object([]) do |errors, array_of_errors|
|
84
|
+
attribute_name = errors.first
|
85
|
+
attribute_errors = errors.last
|
86
|
+
errors = build_error_from_array(attribute_name, attribute_errors)
|
87
|
+
array_of_errors.push(*errors)
|
88
|
+
end
|
89
|
+
end
|
44
90
|
end
|
45
91
|
end
|
46
92
|
end
|
data/lib/rdstation/events.rb
CHANGED
@@ -12,16 +12,8 @@ module RDStation
|
|
12
12
|
def create(payload)
|
13
13
|
retryable_request(@authorization) do |authorization|
|
14
14
|
response = self.class.post(EVENTS_ENDPOINT, headers: authorization.headers, body: payload.to_json)
|
15
|
-
|
16
|
-
return response_body unless errors?(response_body)
|
17
|
-
RDStation::ErrorHandler.new(response).raise_error
|
15
|
+
ApiResponse.build(response)
|
18
16
|
end
|
19
17
|
end
|
20
|
-
|
21
|
-
private
|
22
|
-
|
23
|
-
def errors?(response_body)
|
24
|
-
response_body.is_a?(Array) || response_body['errors']
|
25
|
-
end
|
26
18
|
end
|
27
19
|
end
|
data/lib/rdstation/fields.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
module RDStation
|
3
|
-
# More info: https://developers.rdstation.com/pt-BR/reference/
|
3
|
+
# More info: https://developers.rdstation.com/pt-BR/reference/fields
|
4
4
|
class Fields
|
5
5
|
include HTTParty
|
6
6
|
include ::RDStation::RetryableRequest
|
7
7
|
|
8
8
|
BASE_URL = 'https://api.rd.services/platform/contacts/fields'.freeze
|
9
|
-
|
9
|
+
|
10
10
|
def initialize(authorization:)
|
11
11
|
@authorization = authorization
|
12
12
|
end
|
@@ -18,5 +18,31 @@ module RDStation
|
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
+
def create(payload)
|
22
|
+
retryable_request(@authorization) do |authorization|
|
23
|
+
response = self.class.post(BASE_URL, headers: authorization.headers, body: payload.to_json)
|
24
|
+
ApiResponse.build(response)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def update(uuid, payload)
|
29
|
+
retryable_request(@authorization) do |authorization|
|
30
|
+
response = self.class.patch(base_url(uuid), headers: authorization.headers, body: payload.to_json)
|
31
|
+
ApiResponse.build(response)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def delete(uuid)
|
36
|
+
retryable_request(@authorization) do |authorization|
|
37
|
+
response = self.class.delete(base_url(uuid), headers: authorization.headers)
|
38
|
+
ApiResponse.build(response)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def base_url(path = '')
|
45
|
+
"#{BASE_URL}/#{path}"
|
46
|
+
end
|
21
47
|
end
|
22
48
|
end
|
data/lib/rdstation/version.rb
CHANGED
@@ -0,0 +1,69 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe RDStation::Builder::Field do
|
6
|
+
def valid_builder
|
7
|
+
described_class.new('cf_identifier')
|
8
|
+
end
|
9
|
+
|
10
|
+
describe 'when create a builder' do
|
11
|
+
context 'valid' do
|
12
|
+
let(:initial_parameters) do
|
13
|
+
'cf_api_identifier'
|
14
|
+
end
|
15
|
+
|
16
|
+
let(:builder) { described_class.new(initial_parameters) }
|
17
|
+
|
18
|
+
let(:expected_result) do
|
19
|
+
{
|
20
|
+
'api_identifier' => 'cf_api_identifier',
|
21
|
+
'data_type' => 'STRING',
|
22
|
+
'presentation_type' => 'TEXT_INPUT',
|
23
|
+
'label' => { 'pt-BR' => 'My label' },
|
24
|
+
'name' => { 'pt-BR' => 'My name' }
|
25
|
+
}
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'returns an hash of required values' do
|
29
|
+
builder.label 'pt-BR', 'My label'
|
30
|
+
builder.name 'pt-BR', 'My name'
|
31
|
+
builder.data_type 'STRING'
|
32
|
+
builder.presentation_type 'TEXT_INPUT'
|
33
|
+
|
34
|
+
result = builder.build
|
35
|
+
expect(result).to eq(expected_result)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context 'invalid' do
|
40
|
+
it 'using invalid api_identifier ' do
|
41
|
+
expect { described_class.new('invald_identifier') }.to raise_error(
|
42
|
+
'api_identifier is not in a valid format, need start with "cf_"'
|
43
|
+
)
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'using invalid data_type ' do
|
47
|
+
expect { valid_builder.data_type('invalid_data_type') }.to raise_error(
|
48
|
+
'Not valid data_type - ["STRING", "INTEGER", "BOOLEAN", "STRING[]"]'
|
49
|
+
)
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'using invalid presentation_type ' do
|
53
|
+
expect { valid_builder.presentation_type('invalid presentation_type') }.to raise_error(
|
54
|
+
'Not valid presentation_type - ["TEXT_INPUT", "TEXT_AREA", "URL_INPUT", "PHONE_INPUT", "EMAIL_INPUT", "CHECK_BOX", "NUMBER_INPUT", "COMBO_BOX", "RADIO_BUTTON", "MULTIPLE_CHOICE"]'
|
55
|
+
)
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'without api_identifier' do
|
59
|
+
expect { described_class.new(nil) }.to raise_error('api_identifier required')
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'without required fields' do
|
63
|
+
expect { valid_builder.build }.to raise_error(
|
64
|
+
'Required fields are missing - ["data_type", "presentation_type", "label", "name"]'
|
65
|
+
)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -52,5 +52,51 @@ RSpec.describe RDStation::Error::Format do
|
|
52
52
|
expect(result).to eq(RDStation::Error::Format::ARRAY_OF_HASHES)
|
53
53
|
end
|
54
54
|
end
|
55
|
+
|
56
|
+
context 'when receives a mixed type of errors' do
|
57
|
+
let(:errors) do
|
58
|
+
{
|
59
|
+
'label': {
|
60
|
+
'pt-BR': [
|
61
|
+
{
|
62
|
+
'error_type': 'CANNOT_BE_BLANK',
|
63
|
+
'error_message': 'cannot be blank'
|
64
|
+
}
|
65
|
+
]
|
66
|
+
},
|
67
|
+
'api_identifier': [
|
68
|
+
{
|
69
|
+
'error_type': 'CANNOT_BE_BLANK',
|
70
|
+
'error_message': 'cannot be blank'
|
71
|
+
}
|
72
|
+
]
|
73
|
+
}
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'returns the HASH_OF_MULTIPLE_TYPES format' do
|
77
|
+
result = error_format.format
|
78
|
+
expect(result).to eq(RDStation::Error::Format::HASH_OF_MULTIPLE_TYPES)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
context 'when receives a hash of hashes errors' do
|
83
|
+
let(:errors) do
|
84
|
+
{
|
85
|
+
label: {
|
86
|
+
'pt-BR': [
|
87
|
+
{
|
88
|
+
'error_type': 'CANNOT_BE_BLANK',
|
89
|
+
'error_message': 'cannot be blank'
|
90
|
+
}
|
91
|
+
]
|
92
|
+
}
|
93
|
+
}
|
94
|
+
end
|
95
|
+
|
96
|
+
it 'returns the HASH_OF_MULTILINGUAL format' do
|
97
|
+
result = error_format.format
|
98
|
+
expect(result).to eq(RDStation::Error::Format::HASH_OF_HASHES)
|
99
|
+
end
|
100
|
+
end
|
55
101
|
end
|
56
102
|
end
|
@@ -132,5 +132,88 @@ RSpec.describe RDStation::Error::Formatter do
|
|
132
132
|
expect(result).to eq(expected_result)
|
133
133
|
end
|
134
134
|
end
|
135
|
+
|
136
|
+
context 'when receives a hash of multiple type errors' do
|
137
|
+
let(:error_format) { instance_double(RDStation::Error::Format, format: RDStation::Error::Format::HASH_OF_MULTIPLE_TYPES) }
|
138
|
+
|
139
|
+
let(:error_response) do
|
140
|
+
{
|
141
|
+
'errors' => {
|
142
|
+
'label' => {
|
143
|
+
'pt-BR' => [
|
144
|
+
{
|
145
|
+
'error_type' => 'CANNOT_BE_BLANK',
|
146
|
+
'error_message' => 'cannot be blank'
|
147
|
+
}
|
148
|
+
]
|
149
|
+
},
|
150
|
+
'api_identifier' => [
|
151
|
+
{
|
152
|
+
'error_type' => 'CANNOT_BE_BLANK',
|
153
|
+
'error_message' => 'cannot be blank'
|
154
|
+
}
|
155
|
+
]
|
156
|
+
}
|
157
|
+
}
|
158
|
+
end
|
159
|
+
|
160
|
+
let(:error_formatter) { described_class.new(error_response) }
|
161
|
+
|
162
|
+
let(:expected_result) do
|
163
|
+
[
|
164
|
+
{
|
165
|
+
'error_type' => 'CANNOT_BE_BLANK',
|
166
|
+
'error_message' => 'cannot be blank',
|
167
|
+
'path' => 'body.label.pt-BR'
|
168
|
+
},
|
169
|
+
{
|
170
|
+
'error_type' => 'CANNOT_BE_BLANK',
|
171
|
+
'error_message' => 'cannot be blank',
|
172
|
+
'path' => 'body.api_identifier'
|
173
|
+
}
|
174
|
+
]
|
175
|
+
end
|
176
|
+
|
177
|
+
it 'returns an array of errors' do
|
178
|
+
result = error_formatter.to_array
|
179
|
+
expect(result).to eq(expected_result)
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
context 'when receives a hash of hashes type errors' do
|
184
|
+
let(:error_format) { instance_double(RDStation::Error::Format, format: RDStation::Error::Format::HASH_OF_HASHES) }
|
185
|
+
|
186
|
+
let(:error_response) do
|
187
|
+
{
|
188
|
+
'errors' => {
|
189
|
+
'label' => {
|
190
|
+
'pt-BR' => [
|
191
|
+
{
|
192
|
+
'error_type' => 'CANNOT_BE_BLANK',
|
193
|
+
'error_message' => 'cannot be blank'
|
194
|
+
}
|
195
|
+
]
|
196
|
+
}
|
197
|
+
}
|
198
|
+
}
|
199
|
+
end
|
200
|
+
|
201
|
+
let(:error_formatter) { described_class.new(error_response) }
|
202
|
+
|
203
|
+
let(:expected_result) do
|
204
|
+
[
|
205
|
+
{
|
206
|
+
'error_type' => 'CANNOT_BE_BLANK',
|
207
|
+
'error_message' => 'cannot be blank',
|
208
|
+
'path' => 'body.label.pt-BR'
|
209
|
+
}
|
210
|
+
]
|
211
|
+
end
|
212
|
+
|
213
|
+
it 'returns an array of errors' do
|
214
|
+
result = error_formatter.to_array
|
215
|
+
expect(result).to eq(expected_result)
|
216
|
+
end
|
217
|
+
end
|
135
218
|
end
|
136
219
|
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: 2.
|
4
|
+
version: 2.3.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:
|
11
|
+
date: 2020-08-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -143,6 +143,7 @@ files:
|
|
143
143
|
- lib/rdstation/api_response.rb
|
144
144
|
- lib/rdstation/authentication.rb
|
145
145
|
- lib/rdstation/authorization.rb
|
146
|
+
- lib/rdstation/builder/field.rb
|
146
147
|
- lib/rdstation/client.rb
|
147
148
|
- lib/rdstation/contacts.rb
|
148
149
|
- lib/rdstation/error.rb
|
@@ -166,6 +167,7 @@ files:
|
|
166
167
|
- spec/lib/rdstation/api_response_spec.rb
|
167
168
|
- spec/lib/rdstation/authentication_spec.rb
|
168
169
|
- spec/lib/rdstation/authorization_spec.rb
|
170
|
+
- spec/lib/rdstation/builder/field_spec.rb
|
169
171
|
- spec/lib/rdstation/client_spec.rb
|
170
172
|
- spec/lib/rdstation/contacts_spec.rb
|
171
173
|
- spec/lib/rdstation/error/format_spec.rb
|
@@ -203,7 +205,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
203
205
|
- !ruby/object:Gem::Version
|
204
206
|
version: '0'
|
205
207
|
requirements: []
|
206
|
-
|
208
|
+
rubyforge_project:
|
209
|
+
rubygems_version: 2.7.6.2
|
207
210
|
signing_key:
|
208
211
|
specification_version: 4
|
209
212
|
summary: Ruby API wrapper for RD Station
|
@@ -212,6 +215,7 @@ test_files:
|
|
212
215
|
- spec/lib/rdstation/api_response_spec.rb
|
213
216
|
- spec/lib/rdstation/authentication_spec.rb
|
214
217
|
- spec/lib/rdstation/authorization_spec.rb
|
218
|
+
- spec/lib/rdstation/builder/field_spec.rb
|
215
219
|
- spec/lib/rdstation/client_spec.rb
|
216
220
|
- spec/lib/rdstation/contacts_spec.rb
|
217
221
|
- spec/lib/rdstation/error/format_spec.rb
|