Class: PipedriveJetrockets::PersonService

Inherits:
Service
  • Object
show all
Defined in:
lib/pipedrive_jetrockets/person_service.rb

Constant Summary collapse

HOST =
'https://api.pipedrive.com/v1'

Constants inherited from Service

Service::RESOURCES_WITH_CUSTOM_FIELDS

Instance Method Summary collapse

Methods inherited from Service

#all, #build_entity, #build_uri, #create, #find, #first, #update

Constructor Details

#initialize(resource_name) ⇒ PersonService

Returns a new instance of PersonService.



5
6
7
# File 'lib/pipedrive_jetrockets/person_service.rb', line 5

def initialize(resource_name)
  @resource_name = resource_name
end

Instance Method Details

#find_by_email(email) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/pipedrive_jetrockets/person_service.rb', line 9

def find_by_email(email)
  uri = build_uri({term: email, search_by_email: true }, 'find')
  response = HTTP.get(uri)

  case response.code
  when 200
    json_array = ::JSON.parse(response)['data']
    return [] unless json_array
    json_array.map{|raw|build_entity(raw)}
  else
    raise PipedriveJetrockets::Error.new(response.code)
  end
rescue HTTP::ConnectionError
  raise PipedriveJetrockets::Error.new(408)
end