Sha256: 2105f8eea92a1a0ff644d6995bc3a7c4087370520dd44c03cf08a91e963295cc

Contents?: true

Size: 1.66 KB

Versions: 13

Compression:

Stored size: 1.66 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_OWNER_PATH    = '/owners/v2/owners/:owner_id' # GET
    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(id, include_inactive=false)
        path     = GET_OWNER_PATH
        response = Hubspot::Connection.get_json(path, owner_id: id,
          include_inactive: include_inactive)
        new(response)
      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

13 entries across 13 versions & 1 rubygems

Version Path
hubspot-api-ruby-0.18.0 lib/hubspot/owner.rb
hubspot-api-ruby-0.17.1 lib/hubspot/owner.rb
hubspot-api-ruby-0.17.0 lib/hubspot/owner.rb
hubspot-api-ruby-0.16.0 lib/hubspot/owner.rb
hubspot-api-ruby-0.15.0 lib/hubspot/owner.rb
hubspot-api-ruby-0.14.0 lib/hubspot/owner.rb
hubspot-api-ruby-0.13.0 lib/hubspot/owner.rb
hubspot-api-ruby-0.12.0 lib/hubspot/owner.rb
hubspot-api-ruby-0.11.0 lib/hubspot/owner.rb
hubspot-api-ruby-0.10.0 lib/hubspot/owner.rb
hubspot-api-ruby-0.9.0 lib/hubspot/owner.rb
hubspot-api-ruby-0.8.1 lib/hubspot/owner.rb
hubspot-api-ruby-0.8.0 lib/hubspot/owner.rb