Sha256: 9a9bc32a717f5233744ea2f1842ada3df76f000ab9dc5d9ef63bc53c6c4f5299

Contents?: true

Size: 1.06 KB

Versions: 1

Compression:

Stored size: 1.06 KB

Contents

module Outreach
  module Service
    class Prospect
      def initialize(client)
        @request = client.request
      end

      def find(id)
        response = @request.get("#{api_url}/#{id}")
        collection_class.new(response['data'])
      end

      def find_all(attrs={})
        response = @request.get(api_url, attribute_mapping(attrs))
        response['data'].map {|attrs| collection_class.new(attrs)}
      end

      protected

      def api_url
        "https://api.outreach.io/1.0/prospects"
      end

      def collection_class
        Outreach::Prospect
      end

      def attribute_mapping(attrs)
        if attrs[:first_name]
          attrs["filter[personal/name/first]"] = attrs.delete(:first_name)
        end
        if attrs[:last_name]
          attrs["filter[personal/name/last]"] = attrs.delete(:last_name)
        end
        attrs["filter[contact/email]"] = attrs.delete(:email) if attrs[:email]
        if attrs[:company_name]
          attrs["filter[company/name]"] = attrs.delete(company_name)
        end
        attrs
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
outreach-0.1.0 lib/outreach/service/prospect.rb