Class: PipeRocket::FileService

Inherits:
Service
  • Object
show all
Defined in:
lib/pipe_rocket/file_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) ⇒ FileService

Returns a new instance of FileService.



5
6
7
# File 'lib/pipe_rocket/file_service.rb', line 5

def initialize(resource_name)
  @resource_name = resource_name
end

Instance Method Details

#file_url(id) ⇒ Object

Download a file by id



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/pipe_rocket/file_service.rb', line 10

def file_url(id)
  uri = build_uri({}, id, 'download')
  response = HTTP.get(uri)

  case response.code
  when 302
    response.headers['Location']
  else
    raise PipeRocket::Error.new(response.code)
  end
rescue HTTP::ConnectionError
  raise PipeRocket::Error.new(408)
end