Sha256: 042f2df7bc81e6842deb1514f26d7024366af9ff255897b4a28646d79ea743cd

Contents?: true

Size: 1.68 KB

Versions: 2

Compression:

Stored size: 1.68 KB

Contents

# encoding: utf-8
module RDStation
  # More info: https://developers.rdstation.com/pt-BR/reference/contacts
  class Contacts
    include HTTParty

    def initialize(auth_token)
      @auth_token = auth_token
    end

    #
    # param uuid:
    #   The unique uuid associated to each RD Station Contact.
    #
    def by_uuid(uuid)
      response = self.class.get(base_url(uuid), headers: required_headers)
      ApiResponse.build(response)
    end

    def by_email(email)
      response = self.class.get(base_url("email:#{email}"), headers: required_headers)
      ApiResponse.build(response)
    end

    # The Contact hash may contain the following parameters:
    # :email
    # :name
    # :job_title
    # :linkedin
    # :facebook
    # :twitter
    # :personal_phone
    # :mobile_phone
    # :website
    # :tags
    def update(uuid, contact_hash)
      response = self.class.patch(base_url(uuid), :body => contact_hash.to_json, :headers => required_headers)
      ApiResponse.build(response)
    end

    #
    # param identifier:
    #   Field that will be used to identify the contact.
    # param identifier_value:
    #   Value to the identifier given.
    # param contact_hash:
    #   Contact data
    #
    def upsert(identifier, identifier_value, contact_hash)
      path = "#{identifier}:#{identifier_value}"
      response = self.class.patch(base_url(path), body: contact_hash.to_json, headers: required_headers)
      ApiResponse.build(response)
    end

    private

    def base_url(path = "")
      "https://api.rd.services/platform/contacts/#{path}"
    end

    def required_headers
      { "Authorization" => "Bearer #{@auth_token}", "Content-Type" => "application/json" }
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rdstation-ruby-client-1.2.1 lib/rdstation/contacts.rb
rdstation-ruby-client-1.2.0 lib/rdstation/contacts.rb