CircleCI

RDStation Ruby Client

RDstation ruby wrapper to interact with RDStation API.

Upgrading? Check the migration guide before bumping to a new major version.

Table of Contents

  1. Installation
  2. Usage
    1. Authentication
    2. Contacts
    3. Events
    4. Fields
    5. Webhooks
    6. Errors
  3. Changelog
  4. Migration guide
    1. Upgrading from 1.2.x to 2.0.0
  5. Contributing
  6. Maintainers
  7. Reference

Installation

Add this line to your application's Gemfile:

gem 'rdstation-ruby-client'

And then execute:

$ bundle

Or install it yourself as:

$ gem install rdstation-ruby-client

Usage

Authentication

For more details, check the developers portal.

Getting authentication URL

rdstation_authentication = RDStation::Authentication.new('client_id', 'client_secret')

redirect_url = 'https://yourapp.org/auth/callback'
rdstation_authentication.auth_url(redirect_url)

Getting access_token

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.

rdstation_authentication = RDStation::Authentication.new('client_id', 'client_secret')
rdstation_authentication.authenticate(code_returned_from_rdstation)

Updating access_token

rdstation_authentication = RDStation::Authentication.new('client_id', 'client_secret')
rdstation_authentication.update_access_token('refresh_token')

Revoking an access_token

RDStation::Authentication.revoke(access_token: "your token")

Note: this will completely remove your credentials from RD Station (update_access_token won't work anymore).

Contacts

Getting a Contact by UUID

Returns data about a specific Contact

client = RDStation::Client.new(access_token: 'access_token')
client.contacts.by_uuid('uuid')

More info: https://developers.rdstation.com/pt-BR/reference/contacts#methodGetDetailsuuid

Getting a Contact by Email

Returns data about a specific Contact

client = RDStation::Client.new(access_token: 'access_token')
client.contacts.by_email('email')

More info: https://developers.rdstation.com/pt-BR/reference/contacts#methodGetDetailsemail

Update a Contact by UUID

Updates the properties of a Contact.

contact_info = {
  name: "Joe Foo"
}

client = RDStation::Client.new(access_token: 'access_token')
client.contacts.update('uuid', contact_info)

Contact Default Parameters

  • email
  • name
  • job_title
  • linkedin
  • facebook
  • twitter
  • personal_phone
  • mobile_phone
  • website
  • tags

More info: https://developers.rdstation.com/pt-BR/reference/contacts#methodPatchDetails

Upsert a Contact by identifier and value

With an UPSERT like behavior, this method is capable of both updating the properties of a Contact or creating a new Contact. Whatever is used as an identifier cannot appear in the request payload as a field. This will result in a BAD_REQUEST error.

contact_info = {
  name: "Joe Foo"
}

identifier = "email"
identifier_value = "[email protected]"

client = RDStation::Client.new(access_token: 'access_token')
client.contacts.upsert(identifier, identifier_value, contact_info)

More info: https://developers.rdstation.com/pt-BR/reference/contacts#methodPatchUpsertDetails

Events

Sending a new event

The events endpoint are responsible for receiving different event types in which RD Station Contacts take part in.

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.

Check the developers portal to learn about the required payload structure and which events are available.

This creates a new event on RDSM:

payload = {} # hash representing the payload
client = RDStation::Client.new(access_token: 'access_token')
client.events.create(payload)

Fields

Endpoints to manage Contact Fields information in your RD Station account.

List all fields

client = RDStation::Client.new(access_token: 'access_token')
client.fields.all

Webhooks

Webhooks provide the ability to receive real-time data updates about your contact activity.

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.

List all webhooks

client = RDStation::Client.new(access_token: 'access_token')
client.webhooks.all

Getting a webhook by UUID

client = RDStation::Client.new(access_token: 'access_token')
client.webhooks.by_uuid('WEBHOOK_UUID')

Creating a webhook

payload = {} # payload representing a webhook
client = RDStation::Client.new(access_token: 'access_token')
client.webhooks.create(payload)

The required strucutre of the payload is described here.

Updating a webhook

payload = {} # payload representing a webhook
client = RDStation::Client.new(access_token: 'access_token')
client.webhooks.create('WEBHOOK_UUID', payload)

The required strucutre of the payload is described here.

Deleting a webhook

client = RDStation::Client.new(access_token: 'access_token')
client.webhooks.delete('WEBHOOK_UUID')

Errors

Each endpoint may raise errors accoording to the HTTP response code from RDStation:

  • RDStation::Error::BadRequest (400)
  • RDStation::Error::Unauthorized (401)
  • RDStation::Error::Forbidden (403)
  • RDStation::Error::NotFound (404)
  • RDStation::Error::MethodNotAllowed (405)
  • RDStation::Error::NotAcceptable (406)
  • RDStation::Error::Conflict (409)
  • RDStation::Error::UnsupportedMediaType (415)
  • RDStation::Error::UnprocessableEntity (422)
  • RDStation::Error::InternalServerError (500)
  • RDStation::Error::NotImplemented (501)
  • RDStation::Error::BadGateway (502)
  • RDStation::Error::ServiceUnavailable (503)
  • RDStation::Error::ServerError (which is returned for 5xx errors different than 500, 501, 502 or 503)

In case of a Bad Request (400), the following specific errors may be raised (those are subclasses of RDStation::Error::BadRequest):

  • RDStation::Error::ConflictingField
  • RDStation::Error::InvalidEventType

In cause of Unauthorized (401), the following specific errors may be raised (those are subclasses of RDStation::Error::Unauthorized):

  • RDStation::Error::ExpiredAccessToken
  • RDStation::Error::ExpiredCodeGrant
  • RDStation::Error::InvalidCredentials

Changelog

See CHANGELOG.md

Migration guide

Upgrading from 1.2.x to 2.0.0

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 first. Also take a look at the release notes, as they explain the changes in greater detail.

So, here is a step-by-step guide on how to upgrade your app:

  • Ensure you're using ruby >= 2.0.0.
  • Remove every direct instantiation of RDStation::Contacts, RDStation::Events, RDStation::Fields and RDStation::Webhooks and use RDStation::Client to get them instead.
  • 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.
  • Review your error handling, as more options are available now.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Maintainers

Reference

You can check out RDstation's integration documentation at our developers portal.