Class: DocFox::Document::DownloadService

Inherits:
BaseService
  • Object
show all
Defined in:
lib/doc_fox/document/download_service.rb

Constant Summary collapse

CONTENT_TYPES =
['image/jpeg', 'image/png', 'application/pdf'].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(document_id: nil, document_token_id: nil, content_type: nil) ⇒ DownloadService

Returns a new instance of DownloadService.



26
27
28
29
30
# File 'lib/doc_fox/document/download_service.rb', line 26

def initialize(document_id: nil, document_token_id: nil, content_type: nil)
  @document_id       = document_id
  @document_token_id = document_token_id
  @content_type      = content_type
end

Instance Attribute Details

#content_typeObject (readonly)

Returns the value of attribute content_type.



6
7
8
# File 'lib/doc_fox/document/download_service.rb', line 6

def content_type
  @content_type
end

#document_idObject (readonly)

Returns the value of attribute document_id.



6
7
8
# File 'lib/doc_fox/document/download_service.rb', line 6

def document_id
  @document_id
end

#document_token_idObject (readonly)

Returns the value of attribute document_token_id.



6
7
8
# File 'lib/doc_fox/document/download_service.rb', line 6

def document_token_id
  @document_token_id
end

#urlObject (readonly)

Returns the value of attribute url.



6
7
8
# File 'lib/doc_fox/document/download_service.rb', line 6

def url
  @url
end

Instance Method Details

#callObject

Download a document file.

https://www.docfoxapp.com/api/v2/documentation#tag/Download-Documents/paths/~1api~1v2~1document_file_downloads~1%7Bdocument_token_id%7D/get

Examples

service = DocFox::Document::DownloadService.call(document_token_id: '', content_type: 'image/png')

service.success? # => true
service.errors # => #<ActiveModel::Errors []>

service.response # => #<Faraday::Response ...>
service.response.status # => 200
service.response.body # => "\xFF\xD8\xFF\xDB\x00\x84\x00\x04\x05\x..."

Possible values for content_type.

- `image/jpeg`
- `image/png`
- `application/pdf`

You can also provide just the document_id and the service will automatically request the document_token_id and content_type for you.

service = DocFox::Document::DownloadService.call(document_id: '')

GET /api/v2/document_file_downloads/:document_token_id



58
59
60
# File 'lib/doc_fox/document/download_service.rb', line 58

def call
  connection.get("document_file_downloads/#{document_token_id}", nil, { 'Accept' => content_type })
end