class PipeRocket::DealService

Constants

HOST

Public Instance Methods

deal_files(deal_id) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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