Sha256: 1a3715679a1f25c27996a389749dd2d79ca628dab5319e71b9a2e85688508fa9

Contents?: true

Size: 1.56 KB

Versions: 2

Compression:

Stored size: 1.56 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 get_contact(uuid)
      self.class.get(base_url(uuid), :headers => required_headers)
    end

    def get_contact_by_email(email)
      self.class.get(base_url("email:#{email}"), :headers => required_headers)
    end

    # The Contact hash may contain the following parameters:
    # :email
    # :name
    # :job_title
    # :linkedin
    # :facebook
    # :twitter
    # :personal_phone
    # :mobile_phone
    # :website
    # :tags
    def update_contact(uuid, contact_hash)
      self.class.patch(base_url(uuid), :body => contact_hash.to_json, :headers => required_headers)
    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_contact(identifier, identifier_value, contact_hash)
      path = "#{identifier}:#{identifier_value}"
      self.class.patch(base_url(path), :body => contact_hash.to_json, :headers => required_headers)
    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-0.1.1 lib/rdstation/contacts.rb
rdstation-ruby-client-0.1 lib/rdstation/contacts.rb