Sha256: 750b7a7051a7e94d897e6ce1092fdedfe6636e7d324aaa97acfa3217caf9c5be

Contents?: true

Size: 1.38 KB

Versions: 8

Compression:

Stored size: 1.38 KB

Contents

module Hubspot
  #
  # HubSpot Owners API
  #
  # {http://developers.hubspot.com/docs/methods/owners/get_owners}
  #
  # TODO: Create an Owner
  # TODO: Update an Owner
  # TODO: Delete an Owner
  class Owner
    GET_OWNERS_PATH   = '/owners/v2/owners' # GET
    CREATE_OWNER_PATH = '/owners/v2/owners' # POST
    UPDATE_OWNER_PATH = '/owners/v2/owners/:owner_id' # PUT
    DELETE_OWNER_PATH = '/owners/v2/owners/:owner_id' # DELETE


    attr_reader :properties, :owner_id, :email

    def initialize(property_hash)
      @properties = property_hash
      @owner_id   = @properties['ownerId']
      @email      = @properties['email']
    end

    def [](property)
      @properties[property]
    end

    class << self
      def all(include_inactive=false)
        path     = GET_OWNERS_PATH
        params   = { includeInactive: include_inactive }
        response = Hubspot::Connection.get_json(path, params)
        response.map { |r| new(r) }
      end

      def find_by_email(email, include_inactive=false)
        path     = GET_OWNERS_PATH
        params   = { email: email, includeInactive: include_inactive }
        response = Hubspot::Connection.get_json(path, params)
        response.blank? ? nil : new(response.first)
      end

      def find_by_emails(emails, include_inactive=false)
        emails.map { |email| find_by_email(email, include_inactive) }.reject(&:blank?)
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
hubspot-ruby-0.7.0 lib/hubspot/owner.rb
hubspot-ruby-0.6.1 lib/hubspot/owner.rb
hubspot-ruby-0.6.0 lib/hubspot/owner.rb
hubspot-ruby-0.5.0 lib/hubspot/owner.rb
hubspot-ruby-0.4.0 lib/hubspot/owner.rb
hubspot-ruby-0.3.0 lib/hubspot/owner.rb
hubspot-ruby-0.2.1 lib/hubspot/owner.rb
hubspot-ruby-0.2.0 lib/hubspot/owner.rb