class Toptranslation::Resource::ReferenceDocument

Attributes

comment[R]
created_at[R]
filename[R]
filesize[R]
identifier[R]
mime_type[R]

Public Class Methods

new(connection, options = {}) click to toggle source
# File lib/toptranslation/resource/reference_document.rb, line 5
def initialize(connection, options = {})
  @connection = connection
  @options = options
  update_from_response(options)
end

Public Instance Methods

download(options = {}) click to toggle source
# File lib/toptranslation/resource/reference_document.rb, line 11
def download(options = {})
  download_path = if options[:path]
                    options[:path]
                  else
                    tempfile = Tempfile.new
                    temp_path = tempfile.path
                    tempfile.close
                    temp_path
                  end
  @connection.download(download_url, download_path)
end
download_url() click to toggle source
# File lib/toptranslation/resource/reference_document.rb, line 23
def download_url
  @download_url ||= @connection.get("/reference_documents/#{identifier}/download", version: 2)['download_url']
end

Private Instance Methods

update_from_response(response) click to toggle source
# File lib/toptranslation/resource/reference_document.rb, line 29
def update_from_response(response)
  @identifier = response['identifier'] if response['identifier']
  @filename = response['filename'] if response['filename']
  @filesize = response['filesize'] if response['filesize']
  @mime_type = response['mime_type'] if response['mime_type']
  @comment = response['comment'] if response['comment']
  @created_at = Time.parse(response['created_at']) if response['created_at']
end