Class: DocFox::Document::DownloadService
- Inherits:
-
BaseService
- Object
- BaseService
- DocFox::Document::DownloadService
- 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
-
#content_type ⇒ Object
readonly
Returns the value of attribute content_type.
-
#document_id ⇒ Object
readonly
Returns the value of attribute document_id.
-
#document_token_id ⇒ Object
readonly
Returns the value of attribute document_token_id.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
-
#call ⇒ Object
Download a document file.
-
#initialize(document_id: nil, document_token_id: nil, content_type: nil) ⇒ DownloadService
constructor
A new instance of DownloadService.
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_type ⇒ Object (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_id ⇒ Object (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_id ⇒ Object (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 |
#url ⇒ Object (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
#call ⇒ Object
Download a document file.
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 |