Class: SmartlingApi::File
- Inherits:
-
Object
- Object
- SmartlingApi::File
- Defined in:
- lib/smartling_api/file.rb
Overview
Access to Smartling Files API
Instance Method Summary collapse
-
#delete(file_uri:) ⇒ Hash
Access to Smartling files api to delete a file.
-
#download_locale(locale_id:, file_uri:, **options) ⇒ String
Access to Smartling files api to download a file for a given locale id.
-
#get_translations(file_path:, file_uri:, locale_id:, **options) ⇒ Hash
Temporarily uploads a file, then returns a translated version for requested locales.
-
#initialize(smartling: smartling_client, token: access_token, project_id: current_project_id) ⇒ File
constructor
A new instance of File.
-
#list_files(**options) ⇒ Array
Access to Smartling files api to retrieve list of files for a given project.
-
#upload(file_path:, file_uri:, file_type:, **options) ⇒ Hash
Access to Smartling files api to upload a file.
Constructor Details
#initialize(smartling: smartling_client, token: access_token, project_id: current_project_id) ⇒ File
Returns a new instance of File.
8 9 10 11 12 |
# File 'lib/smartling_api/file.rb', line 8 def initialize(smartling: smartling_client, token: access_token, project_id: current_project_id) @token = token @project_id = project_id @smartling = smartling end |
Instance Method Details
#delete(file_uri:) ⇒ Hash
Access to Smartling files api to delete a file
76 77 78 |
# File 'lib/smartling_api/file.rb', line 76 def delete(file_uri:) smartling.post(url: "/files-api/v2/projects/#{project_id}/file/delete", token: token, body: { fileUri: file_uri }) end |
#download_locale(locale_id:, file_uri:, **options) ⇒ String
Access to Smartling files api to download a file for a given locale id
39 40 41 42 43 |
# File 'lib/smartling_api/file.rb', line 39 def download_locale(locale_id:, file_uri:, **) params = { fileUri: file_uri }.merge() smartling.download(url: "/files-api/v2/projects/#{project_id}/locales/#{locale_id}/file", token: token, params: params) end |
#get_translations(file_path:, file_uri:, locale_id:, **options) ⇒ Hash
Temporarily uploads a file, then returns a translated version for requested locales.
92 93 94 95 96 97 98 99 |
# File 'lib/smartling_api/file.rb', line 92 def get_translations(file_path:, file_uri:, locale_id:, **) body = { file: Faraday::UploadIO.new(file_path, 'text/plain'), fileUri: file_uri, }.merge() smartling.upload(url: "/files-api/v2/projects/#{project_id}/locales/#{locale_id}/file/get-translations", token: token, body: body) end |
#list_files(**options) ⇒ Array
Access to Smartling files api to retrieve list of files for a given project
23 24 25 26 |
# File 'lib/smartling_api/file.rb', line 23 def list_files(**) files = smartling.get(url: "/files-api/v2/projects/#{project_id}/files/list", token: token, params: ) files.fetch("items") end |
#upload(file_path:, file_uri:, file_type:, **options) ⇒ Hash
Access to Smartling files api to upload a file
57 58 59 60 61 62 63 64 65 |
# File 'lib/smartling_api/file.rb', line 57 def upload(file_path:, file_uri:, file_type:, **) body = { file: Faraday::UploadIO.new(file_path, 'text/plain'), fileUri: file_uri, fileType: file_type }.merge() smartling.upload(url: "/files-api/v2/projects/#{project_id}/file", token: token, body: body) end |