Class: Translator::Smartling::API::DownloadFile

Inherits:
Object
  • Object
show all
Includes:
Base
Defined in:
lib/nexmo_developer/app/services/translator/smartling/api/download_file.rb

Instance Method Summary collapse

Methods included from Base

#call, #cleanup, #error, included, #make_request!, #response_body

Constructor Details

#initialize(project_id:, locale_id:, file_uri:, token:) ⇒ DownloadFile

Returns a new instance of DownloadFile.



7
8
9
10
11
12
# File 'lib/nexmo_developer/app/services/translator/smartling/api/download_file.rb', line 7

def initialize(project_id:, locale_id:, file_uri:, token:)
  @project_id   = project_id
  @locale_id    = locale_id
  @file_uri     = file_uri
  @token        = token
end

Instance Method Details

#build_requestObject



14
15
16
# File 'lib/nexmo_developer/app/services/translator/smartling/api/download_file.rb', line 14

def build_request
  Net::HTTP::Get.new(uri, headers)
end

#headersObject



31
32
33
# File 'lib/nexmo_developer/app/services/translator/smartling/api/download_file.rb', line 31

def headers
  { 'Authorization' => "Bearer #{@token}", 'Content-Type' => 'application/json' }
end

#return_valueObject



39
40
41
# File 'lib/nexmo_developer/app/services/translator/smartling/api/download_file.rb', line 39

def return_value
  @return_value ||= @response.body
end

#success?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/nexmo_developer/app/services/translator/smartling/api/download_file.rb', line 35

def success?
  @response.code == '200'
end

#to_sObject



43
44
45
# File 'lib/nexmo_developer/app/services/translator/smartling/api/download_file.rb', line 43

def to_s
  "#{@file_uri} => #{@locale_id}"
end

#uriObject



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/nexmo_developer/app/services/translator/smartling/api/download_file.rb', line 18

def uri
  @uri ||= begin
    uri = URI("https://api.smartling.com/files-api/v2/projects/#{@project_id}/locales/#{@locale_id}/file")
    uri.query = URI.encode_www_form(
      {
        'fileUri' => @file_uri,
        'retrievalType' => 'published',
      }
    )
    uri
  end
end