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

#get_all(status) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/pipe_rocket/deal_service.rb', line 37

def get_all(status)
  uri = build_uri({start: 0, limit: 500, status: status})
  response = HTTP.get(uri)

  case response.code
  when 200
    cur = ::JSON.parse(response)['data']
    res = cur
    return [] unless cur

    offset = 500

    while cur
      uri = build_uri({start: offset, limit: 500, status: status})
      response = HTTP.get(uri)

      cur = ::JSON.parse(response)['data']
      res += cur if cur
      offset += 500
    end

    res.map{|raw|build_entity(raw)}
  else
    raise PipeRocket::Error.new(response.code)
  end
rescue HTTP::ConnectionError
  raise PipeRocket::Error.new(408)
end