Class: PipeRocket::DealService

Inherits:
Service
  • Object
show all
Defined in:
lib/pipe_rocket/deal_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, #initialize, #update

Constructor Details

This class inherits a constructor from PipeRocket::Service

Instance Method Details

#deal_files(deal_id) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/pipe_rocket/deal_service.rb', line 5

def deal_files(deal_id)
  uri = build_uri({}, deal_id, 'files')
  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, 'file')}
  else
    raise PipeRocket::Error.new(response.code)
  end
rescue HTTP::ConnectionError
  raise PipeRocket::Error.new(408)
end

#deal_mail_messages(deal_id) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/pipe_rocket/deal_service.rb', line 21

def deal_mail_messages(deal_id)
  uri = build_uri({}, deal_id, 'mailMessages')
  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['data'], 'mailMessage')}
  else
    raise PipeRocket::Error.new(response.code)
  end
rescue HTTP::ConnectionError
  raise PipeRocket::Error.new(408)
end