class SmartlingApi::File
Access to Smartling Files API
Attributes
Public Class Methods
# 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
Public Instance Methods
Access to Smartling files api to delete a file
@see docs.smartling.com/pages/API/v2/FileAPI/Delete/
@example List Files
SmartlingApi::File.new.delete(file_uri: '/translations/website') #=> { "code" => "SUCCESS" }
@param file_uri [String] File
path within Smartling to delete @return [Hash] Details for file deletion
# 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
Access to Smartling files api to download a file for a given locale id
@see docs.smartling.com/pages/API/v2/FileAPI/Download-File/Single-Locale/
@example Download file
SmartlingApi::File.new.download_locale(locale_id: 'fr-Fr', file_uri: '/translation/website') #=> "translations"
@param locale_id [String] Locale id for the given file @param file_uri [String] File
path within smartling @param options [Hash] Additional options for the given request. @return [String] Contents of the specified file
# File lib/smartling_api/file.rb, line 39 def download_locale(locale_id:, file_uri:, **options) params = { fileUri: file_uri }.merge(options) smartling.download(url: "/files-api/v2/projects/#{project_id}/locales/#{locale_id}/file", token: token, params: params) end
Temporarily uploads a file, then returns a translated version for requested locales.
@see docs.smartling.com/pages/API/v2/FileAPI/Get-Translations/
@example Get Translations
SmartlingApi::File.new.get_translations(file: 'translations.pot', file_uri: '/translations/website.pot') #=> { "code" => "SUCCESS" }
@param file_path [String] File
path of contents to upload @param file_uri [String] File
path within Smartling to base off @param locale_id [String] Locale id for the given file @param options [Hash] Additional options for the given request. @return [Hash] Details of tranlsations
# File lib/smartling_api/file.rb, line 92 def get_translations(file_path:, file_uri:, locale_id:, **options) body = { file: Faraday::UploadIO.new(file_path, 'text/plain'), fileUri: file_uri, }.merge(options) smartling.upload(url: "/files-api/v2/projects/#{project_id}/locales/#{locale_id}/file/get-translations", token: token, body: body) end
Access to Smartling files api to retrieve list of files for a given project
@see docs.smartling.com/pages/API/v2/FileAPI/List/
@example List Files
SmartlingApi::File.new.list_files(uriMask: '.json') #=> [{"fileUri" => "[/translate/file.json]", ...}]
@param options [Hash] Additional options for the given request. @return [Array] A list of files matching the criteria
# File lib/smartling_api/file.rb, line 23 def list_files(**options) files = smartling.get(url: "/files-api/v2/projects/#{project_id}/files/list", token: token, params: options) files.fetch("items") end
Access to Smartling files api to upload a file
@see docs.smartling.com/pages/API/v2/FileAPI/Upload-File/
@example Upload file
SmartlingApi::File.new.upload(file_path: 'website.pot', file_uri: '/translation/website', file_type: 'gettext') #=> { "code" => "SUCCESS" }
@param file_path [String] Location of file to upload @param file_uri [String] File
path within smartling @param file_type [String] Type of file to upload @param options [Hash] Additional options for the given request. @return [Hash] Details of upload
# File lib/smartling_api/file.rb, line 57 def upload(file_path:, file_uri:, file_type:, **options) body = { file: Faraday::UploadIO.new(file_path, 'text/plain'), fileUri: file_uri, fileType: file_type }.merge(options) smartling.upload(url: "/files-api/v2/projects/#{project_id}/file", token: token, body: body) end
Private Instance Methods
# File lib/smartling_api/file.rb, line 113 def access_token Authentication.new.access_token end
# File lib/smartling_api/file.rb, line 105 def current_project_id SmartlingApi.configuration.project_id end
# File lib/smartling_api/file.rb, line 109 def smartling_client Clients::Smartling.new end