rdstation-ruby-client 1.2.0 → 2.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/ISSUE_TEMPLATE/rdsm-ruby-client-issue-template.md +49 -0
- data/.rspec +2 -0
- data/CHANGELOG.md +163 -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 -70
- data/lib/rdstation/contacts.rb +21 -16
- data/lib/rdstation/error.rb +22 -15
- data/lib/rdstation/error/format.rb +21 -3
- data/lib/rdstation/error/formatter.rb +53 -7
- data/lib/rdstation/error_handler.rb +29 -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 +153 -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 +40 -13
- data/Gemfile.lock +0 -59
- 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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
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
|
@@ -0,0 +1,49 @@
|
|
1
|
+
---
|
2
|
+
name: RDSM Ruby Client Issue Template
|
3
|
+
about: Template for new Issues for the RD Station Ruby Client Project
|
4
|
+
title: ''
|
5
|
+
labels: ''
|
6
|
+
assignees: ''
|
7
|
+
|
8
|
+
---
|
9
|
+
|
10
|
+
# Prerequisites
|
11
|
+
|
12
|
+
Please answer the following questions for yourself before submitting an issue. **YOU MAY DELETE THE PREREQUISITES SECTION.**
|
13
|
+
|
14
|
+
- [ ] I am running the latest version
|
15
|
+
- [ ] I checked the documentation and found no answer
|
16
|
+
- [ ] I checked to make sure that this issue has not already been filed
|
17
|
+
- [ ] I'm reporting the issue to the correct repository
|
18
|
+
|
19
|
+
# Expected Behavior
|
20
|
+
|
21
|
+
Please describe the behavior you are expecting
|
22
|
+
|
23
|
+
# Current Behavior
|
24
|
+
|
25
|
+
What is the current behavior?
|
26
|
+
|
27
|
+
# Failure Information (for bugs)
|
28
|
+
|
29
|
+
Please help to provide information about the failure if this is a bug. If it is not a bug, please remove the rest of this template.
|
30
|
+
|
31
|
+
## Steps to Reproduce
|
32
|
+
|
33
|
+
Please provide detailed steps for reproducing the issue.
|
34
|
+
|
35
|
+
1. step 1
|
36
|
+
2. step 2
|
37
|
+
3. you get it...
|
38
|
+
|
39
|
+
## Context
|
40
|
+
|
41
|
+
Please provide any relevant information about your setup. This is important in case the issue is not reproducible except for under certain conditions.
|
42
|
+
|
43
|
+
* Operating System:
|
44
|
+
* Ruby Version:
|
45
|
+
* Rails Version:
|
46
|
+
|
47
|
+
## Failure Logs
|
48
|
+
|
49
|
+
Please include any relevant log snippets or files here.
|
data/.rspec
ADDED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,163 @@
|
|
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
|
+
|
52
|
+
## 2.2.0
|
53
|
+
|
54
|
+
### Additions
|
55
|
+
|
56
|
+
#### Configuration
|
57
|
+
|
58
|
+
Now it is possible to configure global params like client_id and client_secret only once, so you don't need to provide them to `RDStation::Authentication` every time.
|
59
|
+
|
60
|
+
This can be done in the following way:
|
61
|
+
|
62
|
+
```ruby
|
63
|
+
RDStation.configure do |config|
|
64
|
+
config.client_id = YOUR_CLIENT_ID
|
65
|
+
config.client_secret = YOUR_CLIENT_SECRET
|
66
|
+
end
|
67
|
+
```
|
68
|
+
|
69
|
+
If you're using Rails, this can be done in `config/initializers`.
|
70
|
+
|
71
|
+
#### Automatic refresh of access_tokens
|
72
|
+
|
73
|
+
When an access_token expires, a new one will be obtained automatically and the request will be made again.
|
74
|
+
|
75
|
+
For this to work, you have to use `RDStation.configure` as described above, and provide the refresh token when instantiating `RDStation::Client` (ex: RDStation::Client.new(access_token: MY_ACCESS_TOKEN, refresh_token: MY_REFRESH_TOKEN).
|
76
|
+
|
77
|
+
You can keep track of access_token changes, by providing a callback block inconfiguration. This block will be called with an `RDStation::Authorization` object, which contains the updated `access_token` and `refresh_token`. For example:
|
78
|
+
|
79
|
+
```ruby
|
80
|
+
RDStation.configure do |config|
|
81
|
+
config.on_access_token_refresh do |authorization|
|
82
|
+
MyStoredAuth.where(refresh_token: authorization.refresh_token).update_all(access_token: authorization.access_token)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
```
|
86
|
+
|
87
|
+
### Deprecations
|
88
|
+
|
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.
|
90
|
+
|
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.
|
92
|
+
|
93
|
+
## 2.1.1
|
94
|
+
|
95
|
+
- Fixed a bug in error handling (issue [#47](https://github.com/ResultadosDigitais/rdstation-ruby-client/issues/47))
|
96
|
+
|
97
|
+
## 2.1.0
|
98
|
+
|
99
|
+
### Additions
|
100
|
+
|
101
|
+
`RDStation::Authentication.revoke` added. This method revokes an access_token at RD Station.
|
102
|
+
|
103
|
+
## 2.0.0
|
104
|
+
|
105
|
+
### Removals
|
106
|
+
|
107
|
+
All API methods that were called directly on `RDStation::Client` (ex: `RDStation::Client.new('rdstation_token', 'auth_token').create_lead(lead_info)`) have been removed. See the [migration guide](README.md#Upgrading-from-1.2.x-to-2.0.0) for a comprehensive guide on how to upgrade from version 1.2.x.
|
108
|
+
|
109
|
+
### Notable changes
|
110
|
+
|
111
|
+
#### RDStation::Client
|
112
|
+
|
113
|
+
Now `RDStation::Client` is facade to all available endpoints in the 2.0 API. It needs to be instantiated with an access_token and has accessors to those endpoints. Usage examples:
|
114
|
+
|
115
|
+
```ruby
|
116
|
+
client = RDStation::Client.new((access_token: 'my_token')
|
117
|
+
client.contacts.by_uuid('CONTACT_UUID')
|
118
|
+
client.webhooks.all
|
119
|
+
client.events.create(my_json_payload)
|
120
|
+
client.fields.all
|
121
|
+
```
|
122
|
+
|
123
|
+
`RDStation::Contacts`, `RDStation::Events`, `RDStation::Fields` and `RDStation::Webhooks` are not suposed to be instantiated directly anymore. Use `RDStation::Client` to get them instead.
|
124
|
+
|
125
|
+
#### Error handling
|
126
|
+
|
127
|
+
Now specific errors are raised for each HTTP status:
|
128
|
+
|
129
|
+
- `RDStation::Error::BadRequest` (400)
|
130
|
+
- `RDStation::Error::Unauthorized` (401)
|
131
|
+
- `RDStation::Error::Forbidden` (403)
|
132
|
+
- `RDStation::Error::NotFound` (404)
|
133
|
+
- `RDStation::Error::MethodNotAllowed` (405)
|
134
|
+
- `RDStation::Error::NotAcceptable` (406)
|
135
|
+
- `RDStation::Error::Conflict` (409)
|
136
|
+
- `RDStation::Error::UnsupportedMediaType` (415)
|
137
|
+
- `RDStation::Error::UnprocessableEntity` (422)
|
138
|
+
- `RDStation::Error::InternalServerError` (500)
|
139
|
+
- `RDStation::Error::NotImplemented` (501)
|
140
|
+
- `RDStation::Error::BadGateway` (502)
|
141
|
+
- `RDStation::Error::ServiceUnavailable` (503)
|
142
|
+
- `RDStation::Error::ServerError` (which is returned for 5xx errors different than 500, 501, 502 or 503)
|
143
|
+
|
144
|
+
In case of a Bad Request (400), the following specific errors may be raised (those are subclasses of `RDStation::Error::BadRequest`):
|
145
|
+
- `RDStation::Error::ConflictingField`
|
146
|
+
- `RDStation::Error::InvalidEventType`
|
147
|
+
|
148
|
+
In cause of Unauthorized (401), the following specific errors may be raised (those are subclasses of `RDStation::Error::Unauthorized`):
|
149
|
+
- `RDStation::Error::ExpiredAccessToken`
|
150
|
+
- `RDStation::Error::ExpiredCodeGrant`
|
151
|
+
- `RDStation::Error::InvalidCredentials`
|
152
|
+
|
153
|
+
The specific message and the http code are now returned by the `details` method.
|
154
|
+
|
155
|
+
### Dependencies
|
156
|
+
|
157
|
+
`rdstation-ruby-client` now requires `ruby >= 2.0.0`.
|
158
|
+
|
159
|
+
## 1.2.1
|
160
|
+
|
161
|
+
### Deprecations
|
162
|
+
|
163
|
+
All API methods that were called directly on `RDStation::Client` (ex: `RDStation::Client.new('rdstation_token', 'auth_token').create_lead(lead_info)`) are now deprecated. Those methods call RDSM's 1.3 API and will be removed in the next release.
|
data/README.md
CHANGED
@@ -4,6 +4,26 @@
|
|
4
4
|
|
5
5
|
RDstation ruby wrapper to interact with RDStation API.
|
6
6
|
|
7
|
+
Upgrading? Check the [migration guide](#Migration-guide) before bumping to a new major version.
|
8
|
+
|
9
|
+
## Table of Contents
|
10
|
+
|
11
|
+
1. [Installation](#Installation)
|
12
|
+
2. [Usage](#Usage)
|
13
|
+
1. [Configuration](#Configuration)
|
14
|
+
2. [Authentication](#Authentication)
|
15
|
+
3. [Contacts](#Contacts)
|
16
|
+
4. [Events](#Events)
|
17
|
+
5. [Fields](#Fields)
|
18
|
+
6. [Webhooks](#Webhooks)
|
19
|
+
7. [Errors](#Errors)
|
20
|
+
3. [Changelog](#Changelog)
|
21
|
+
4. [Migration guide](#Migration-guide)
|
22
|
+
1. [Upgrading from 1.2.x to 2.0.0](#Upgrading-from-1.2.x-to-2.0.0)
|
23
|
+
5. [Contributing](#Contributing)
|
24
|
+
6. [Maintainers](#Maintainers)
|
25
|
+
7. [Reference](#Reference)
|
26
|
+
|
7
27
|
## Installation
|
8
28
|
|
9
29
|
Add this line to your application's Gemfile:
|
@@ -20,41 +40,27 @@ Or install it yourself as:
|
|
20
40
|
|
21
41
|
## Usage
|
22
42
|
|
23
|
-
###
|
24
|
-
|
25
|
-
```ruby
|
26
|
-
lead_info = {
|
27
|
-
email: 'joe@foo.bar',
|
28
|
-
name: 'Joe foo',
|
29
|
-
empresa: 'A random Company',
|
30
|
-
cargo: 'Developer',
|
31
|
-
identificador: 'nome_da_conversao'
|
32
|
-
}
|
33
|
-
|
34
|
-
rdstation_client = RDStation::Client.new('rdstation_token', 'auth_token')
|
35
|
-
rdstation_client.create_lead(lead_info)
|
36
|
-
```
|
43
|
+
### Configuration
|
37
44
|
|
38
|
-
|
45
|
+
Before getting youre credentials, you need to configure client_id and client_secret as following:
|
39
46
|
|
40
47
|
```ruby
|
41
|
-
|
42
|
-
|
48
|
+
RDStation.configure do |config|
|
49
|
+
config.client_id = YOUR_CLIENT_ID
|
50
|
+
config.client_secret = YOUR_CLIENT_SECRET
|
51
|
+
end
|
43
52
|
```
|
44
53
|
|
45
|
-
|
46
|
-
|
47
|
-
```ruby
|
48
|
-
rdstation_client = RDStation::Client.new('rdstation_token', 'auth_token')
|
49
|
-
rdstation_client.change_lead_status(email: 'joe@foo.bar', status: 'won', value: 999)
|
50
|
-
```
|
54
|
+
For details on what `client_id` and `client_secret` are, check the [developers portal](https://developers.rdstation.com/en/authentication).
|
51
55
|
|
52
56
|
### Authentication
|
53
57
|
|
58
|
+
For more details, check the [developers portal](https://developers.rdstation.com/en/authentication).
|
59
|
+
|
54
60
|
#### Getting authentication URL
|
55
61
|
|
56
62
|
```ruby
|
57
|
-
rdstation_authentication = RDStation::Authentication.new
|
63
|
+
rdstation_authentication = RDStation::Authentication.new
|
58
64
|
|
59
65
|
redirect_url = 'https://yourapp.org/auth/callback'
|
60
66
|
rdstation_authentication.auth_url(redirect_url)
|
@@ -65,17 +71,43 @@ rdstation_authentication.auth_url(redirect_url)
|
|
65
71
|
You will need the code param that is returned from RD Station to your application after the user confirms the access at the authorization dialog.
|
66
72
|
|
67
73
|
```ruby
|
68
|
-
rdstation_authentication = RDStation::Authentication.new
|
74
|
+
rdstation_authentication = RDStation::Authentication.new
|
69
75
|
rdstation_authentication.authenticate(code_returned_from_rdstation)
|
76
|
+
# => { 'access_token' => '54321', 'expires_in' => 86_400, 'refresh_token' => 'refresh' }
|
70
77
|
```
|
71
78
|
|
72
|
-
#### Updating access_token
|
79
|
+
#### Updating an expired access_token
|
73
80
|
|
74
81
|
```ruby
|
75
|
-
rdstation_authentication = RDStation::Authentication.new
|
82
|
+
rdstation_authentication = RDStation::Authentication.new
|
76
83
|
rdstation_authentication.update_access_token('refresh_token')
|
77
84
|
```
|
78
85
|
|
86
|
+
**NOTE**: This is done automatically when a request fails due to access_token expiration. To keep track of the new token, you have to provide a callback block in configuration. For example:
|
87
|
+
|
88
|
+
```ruby
|
89
|
+
RDStation.configure do |config|
|
90
|
+
config.client_id = YOUR_CLIENT_ID
|
91
|
+
config.client_secret = YOUR_CLIENT_SECRET
|
92
|
+
config.on_access_token_refresh do |authorization|
|
93
|
+
# authorization.access_token_expires_in is the time (in seconds for with the token is valid)
|
94
|
+
# authorization.access_token is the new token
|
95
|
+
# authorization.refresh_token is the existing refresh_token
|
96
|
+
#
|
97
|
+
# If you are using ActiveRecord, you may want to update the stored access_token, like in the following code:
|
98
|
+
MyStoredAuth.where(refresh_token: authorization.refresh_token).update_all(access_token: authorization.access_token)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
```
|
102
|
+
|
103
|
+
#### Revoking an access_token
|
104
|
+
|
105
|
+
```ruby
|
106
|
+
RDStation::Authentication.revoke(access_token: "your token")
|
107
|
+
```
|
108
|
+
|
109
|
+
Note: this will completely remove your credentials from RD Station (`update_access_token` won't work anymore).
|
110
|
+
|
79
111
|
### Contacts
|
80
112
|
|
81
113
|
#### Getting a Contact by UUID
|
@@ -83,8 +115,8 @@ rdstation_authentication.update_access_token('refresh_token')
|
|
83
115
|
Returns data about a specific Contact
|
84
116
|
|
85
117
|
```ruby
|
86
|
-
|
87
|
-
|
118
|
+
client = RDStation::Client.new(access_token: 'access_token', refresh_token: 'refresh_token')
|
119
|
+
client.contacts.by_uuid('uuid')
|
88
120
|
```
|
89
121
|
|
90
122
|
More info: https://developers.rdstation.com/pt-BR/reference/contacts#methodGetDetailsuuid
|
@@ -94,8 +126,8 @@ More info: https://developers.rdstation.com/pt-BR/reference/contacts#methodGetDe
|
|
94
126
|
Returns data about a specific Contact
|
95
127
|
|
96
128
|
```ruby
|
97
|
-
|
98
|
-
|
129
|
+
client = RDStation::Client.new(access_token: 'access_token', refresh_token: 'refresh_token')
|
130
|
+
client.contacts.by_email('email')
|
99
131
|
```
|
100
132
|
|
101
133
|
More info: https://developers.rdstation.com/pt-BR/reference/contacts#methodGetDetailsemail
|
@@ -109,8 +141,8 @@ contact_info = {
|
|
109
141
|
name: "Joe Foo"
|
110
142
|
}
|
111
143
|
|
112
|
-
|
113
|
-
|
144
|
+
client = RDStation::Client.new(access_token: 'access_token', refresh_token: 'refresh_token')
|
145
|
+
client.contacts.update('uuid', contact_info)
|
114
146
|
```
|
115
147
|
Contact Default Parameters
|
116
148
|
- email
|
@@ -139,12 +171,183 @@ contact_info = {
|
|
139
171
|
identifier = "email"
|
140
172
|
identifier_value = "joe@foo.bar"
|
141
173
|
|
142
|
-
|
143
|
-
|
174
|
+
client = RDStation::Client.new(access_token: 'access_token', refresh_token: 'refresh_token')
|
175
|
+
client.contacts.upsert(identifier, identifier_value, contact_info)
|
144
176
|
```
|
145
177
|
|
146
178
|
More info: https://developers.rdstation.com/pt-BR/reference/contacts#methodPatchUpsertDetails
|
147
179
|
|
180
|
+
### Events
|
181
|
+
|
182
|
+
#### Sending a new event
|
183
|
+
|
184
|
+
The events endpoint are responsible for receiving different event types in which RD Station Contacts take part in.
|
185
|
+
|
186
|
+
It is possible to send default events to RD Station such as conversion events, lifecycle events and won and lost events. Also, RD Station supports the possibility of receiving different event types, for instance, chat events, ecommerce ones and others.
|
187
|
+
|
188
|
+
Check the [developers portal](https://developers.rdstation.com/en/reference/events) to learn about the required payload structure and which events are available.
|
189
|
+
|
190
|
+
This creates a new event on RDSM:
|
191
|
+
|
192
|
+
```ruby
|
193
|
+
payload = {} # hash representing the payload
|
194
|
+
client = RDStation::Client.new(access_token: 'access_token', refresh_token: 'refresh_token')
|
195
|
+
client.events.create(payload)
|
196
|
+
```
|
197
|
+
|
198
|
+
### Fields
|
199
|
+
|
200
|
+
Endpoints to [manage Contact Fields](https://developers.rdstation.com/en/reference/fields) information in your RD Station account.
|
201
|
+
|
202
|
+
#### List all fields
|
203
|
+
|
204
|
+
```ruby
|
205
|
+
client = RDStation::Client.new(access_token: 'access_token', refresh_token: 'refresh_token')
|
206
|
+
client.fields.all
|
207
|
+
```
|
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
|
+
|
258
|
+
### Webhooks
|
259
|
+
|
260
|
+
Webhooks provide the ability to receive real-time data updates about your contact activity.
|
261
|
+
|
262
|
+
Choose to receive data based on certain actions, re-cast or marked as an opportunity, and have all applicable data sent to a URL of your choice. You can then use your own custom application to read, save, and do actions with that data. This is a powerful option that allows you to keep all your data in sync and opens the possibility for all types of integration.
|
263
|
+
|
264
|
+
#### List all webhooks
|
265
|
+
|
266
|
+
```ruby
|
267
|
+
client = RDStation::Client.new(access_token: 'access_token', refresh_token: 'refresh_token')
|
268
|
+
client.webhooks.all
|
269
|
+
```
|
270
|
+
|
271
|
+
#### Getting a webhook by UUID
|
272
|
+
|
273
|
+
```ruby
|
274
|
+
client = RDStation::Client.new(access_token: 'access_token', refresh_token: 'refresh_token')
|
275
|
+
client.webhooks.by_uuid('WEBHOOK_UUID')
|
276
|
+
```
|
277
|
+
|
278
|
+
#### Creating a webhook
|
279
|
+
|
280
|
+
```ruby
|
281
|
+
payload = {} # payload representing a webhook
|
282
|
+
client = RDStation::Client.new(access_token: 'access_token', refresh_token: 'refresh_token')
|
283
|
+
client.webhooks.create(payload)
|
284
|
+
```
|
285
|
+
|
286
|
+
The required strucutre of the payload is [described here](https://developers.rdstation.com/en/reference/webhooks#methodPostDetails).
|
287
|
+
|
288
|
+
#### Updating a webhook
|
289
|
+
|
290
|
+
```ruby
|
291
|
+
payload = {} # payload representing a webhook
|
292
|
+
client = RDStation::Client.new(access_token: 'access_token', refresh_token: 'refresh_token')
|
293
|
+
client.webhooks.create('WEBHOOK_UUID', payload)
|
294
|
+
```
|
295
|
+
|
296
|
+
The required strucutre of the payload is [described here](https://developers.rdstation.com/en/reference/webhooks#methodPutDetails).
|
297
|
+
|
298
|
+
#### Deleting a webhook
|
299
|
+
|
300
|
+
```ruby
|
301
|
+
client = RDStation::Client.new(access_token: 'access_token', refresh_token: 'refresh_token')
|
302
|
+
client.webhooks.delete('WEBHOOK_UUID')
|
303
|
+
```
|
304
|
+
|
305
|
+
### Errors
|
306
|
+
|
307
|
+
Each endpoint may raise errors accoording to the HTTP response code from RDStation:
|
308
|
+
|
309
|
+
- `RDStation::Error::BadRequest` (400)
|
310
|
+
- `RDStation::Error::Unauthorized` (401)
|
311
|
+
- `RDStation::Error::Forbidden` (403)
|
312
|
+
- `RDStation::Error::NotFound` (404)
|
313
|
+
- `RDStation::Error::MethodNotAllowed` (405)
|
314
|
+
- `RDStation::Error::NotAcceptable` (406)
|
315
|
+
- `RDStation::Error::Conflict` (409)
|
316
|
+
- `RDStation::Error::UnsupportedMediaType` (415)
|
317
|
+
- `RDStation::Error::UnprocessableEntity` (422)
|
318
|
+
- `RDStation::Error::InternalServerError` (500)
|
319
|
+
- `RDStation::Error::NotImplemented` (501)
|
320
|
+
- `RDStation::Error::BadGateway` (502)
|
321
|
+
- `RDStation::Error::ServiceUnavailable` (503)
|
322
|
+
- `RDStation::Error::ServerError` (which is returned for 5xx errors different than 500, 501, 502 or 503)
|
323
|
+
|
324
|
+
In case of a Bad Request (400), the following specific errors may be raised (those are subclasses of `RDStation::Error::BadRequest`):
|
325
|
+
- `RDStation::Error::ConflictingField`
|
326
|
+
- `RDStation::Error::InvalidEventType`
|
327
|
+
|
328
|
+
In cause of Unauthorized (401), the following specific errors may be raised (those are subclasses of `RDStation::Error::Unauthorized`):
|
329
|
+
- `RDStation::Error::ExpiredAccessToken`
|
330
|
+
- `RDStation::Error::ExpiredCodeGrant`
|
331
|
+
- `RDStation::Error::InvalidCredentials`
|
332
|
+
|
333
|
+
Any error class has a `details` method which returns the specific error message and the http_status.
|
334
|
+
|
335
|
+
## Changelog
|
336
|
+
|
337
|
+
See [CHANGELOG.md](CHANGELOG.md)
|
338
|
+
|
339
|
+
## Migration guide
|
340
|
+
|
341
|
+
### Upgrading from 1.2.x to 2.0.0
|
342
|
+
|
343
|
+
v2.0.0 main change is that it drops support for RDSM's old 1.x API. If you're not familiar with the 2.0 API yet, [check it out](https://developers.rdstation.com) first. Also take a look at [the release notes](CHANGELOG.md#2.0.0), as they explain the changes in greater detail.
|
344
|
+
|
345
|
+
So, here is a step-by-step guide on how to upgrade your app:
|
346
|
+
- Ensure you're using `ruby >= 2.0.0`.
|
347
|
+
- Remove every direct instantiation of `RDStation::Contacts`, `RDStation::Events`, `RDStation::Fields` and `RDStation::Webhooks` and use `RDStation::Client` to get them instead.
|
348
|
+
- Replace any call of `RDStation::Client#create_lead`, `RDStation::Client#change_lead` or `RDStation::Client#change_lead_status` with the equivalent method in the [Contacts API](#Contacts).
|
349
|
+
- Review your error handling, as [more options](CHANGELOG.md#Error-handling) are available now. `http_status` method will always return nil. To get the status now use `error.details[:http_status]` or check the type of the class.
|
350
|
+
|
148
351
|
## Contributing
|
149
352
|
|
150
353
|
1. Fork it
|
@@ -153,14 +356,11 @@ More info: https://developers.rdstation.com/pt-BR/reference/contacts#methodPatch
|
|
153
356
|
4. Push to the branch (`git push origin my-new-feature`)
|
154
357
|
5. Create new Pull Request
|
155
358
|
|
156
|
-
##
|
157
|
-
[Nando Sousa](mailto:fernando.sousa@resultadosdigitais.com.br)
|
359
|
+
## Maintainers
|
158
360
|
|
159
|
-
|
361
|
+
- [Filipe Nascimento](mailto:filipe.nascimento@resultadosdigitais.com.br)
|
362
|
+
- [João Hornburg](mailto:joao@rdstation.com)
|
160
363
|
|
161
|
-
|
364
|
+
## Reference
|
162
365
|
|
163
|
-
|
164
|
-
- [Wordpress & Contact Form 7](https://gist.github.com/pedrobachiega/3277536);
|
165
|
-
- [PHP](https://gist.github.com/pedrobachiega/3248293);
|
166
|
-
- [HTML+Ajax with jQuery](https://gist.github.com/pedrobachiega/3248013);
|
366
|
+
You can check out RDstation's integration documentation at our [developers portal](https://developers.rdstation.com).
|