Class: Smartling::File

Inherits:
Api
  • Object
show all
Defined in:
lib/smartling/fileapi.rb

Constant Summary

Constants inherited from Api

Api::EXPIRATION_OFFSET

Instance Attribute Summary

Attributes inherited from Api

#baseUrl, #prefix

Instance Method Summary collapse

Methods inherited from Api

#call, #check_response, #format_api_error, #get, #get_raw, #log=, #post, #post_file, #post_file_raw, #process, #process_auth, #proxy=, #refresh, #token, #token_header, #uri

Constructor Details

#initialize(args = {}) ⇒ File


21
22
23
24
# File 'lib/smartling/fileapi.rb', line 21

def initialize(args = {})
  super(args)
  @projectId = args[:projectId]
end

Instance Method Details

#delete(name, params = nil) ⇒ Object

Delete - /files-api/v2/projects/projectId/file/delete (POST)


103
104
105
106
107
# File 'lib/smartling/fileapi.rb', line 103

def delete(name, params = nil)
  keys = { :fileUri => name }
  uri = uri("files-api/v2/projects/#{@projectId}/file/delete", keys, params).require(:fileUri)
  return post(uri)
end

#download(name, params = nil) ⇒ Object

Download Original File - /files-api/v2/projects/projectId/file (GET)


53
54
55
56
57
# File 'lib/smartling/fileapi.rb', line 53

def download(name, params = nil)
  keys = { :fileUri => name }
  uri = uri("files-api/v2/projects/#{@projectId}/file", keys, params).require(:fileUri)
  return get_raw(uri)
end

#download_all_translated_csv(name, params = nil) ⇒ Object

Download Translated File - All Locales in one File - CSV - /files-api/v2/projects/projectId/locales/all/file (GET)


81
82
83
84
85
# File 'lib/smartling/fileapi.rb', line 81

def download_all_translated_csv(name, params = nil)
  keys = { :fileUri => name }
  uri = uri("files-api/v2/projects/#{@projectId}/locales/all/file", keys, params).require(:fileUri)
  return get_raw(uri)
end

#download_all_translated_zip(name, params = nil) ⇒ Object

Download Translated File - All Locales as .ZIP - /files-api/v2/projects/projectId/locales/all/file/zip (GET)


74
75
76
77
78
# File 'lib/smartling/fileapi.rb', line 74

def download_all_translated_zip(name, params = nil)
  keys = { :fileUri => name }
  uri = uri("files-api/v2/projects/#{@projectId}/locales/all/file/zip", keys, params).require(:fileUri)
  return get_raw(uri)
end

#download_translated(name, locale, params = nil) ⇒ Object

Download Translated File - Single Locale - /files-api/v2/projects/projectId/locales/localeId/file (GET)


60
61
62
63
64
# File 'lib/smartling/fileapi.rb', line 60

def download_translated(name, locale, params = nil)
  keys = { :fileUri => name }
  uri = uri("files-api/v2/projects/#{@projectId}/locales/#{locale}/file", keys, params).require(:fileUri)
  return get_raw(uri)
end

#download_translated_zip(names, params = nil) ⇒ Object

Download Translated Files - Multiple Locales as .ZIP - /files-api/v2/projects/projectId/files/zip (GET)


67
68
69
70
71
# File 'lib/smartling/fileapi.rb', line 67

def download_translated_zip(names, params = nil)
  keys = { :fileUris => names, :localeIds => locales }
  uri = uri("files-api/v2/projects/#{@projectId}/files/zip", keys, params).require(:fileUris, :localeIds)
  return get_raw(uri)
end

#import(locale, file, name, type, state, params = nil) ⇒ Object

Import Translations - /files-api/v2/projects/projectId/locales/localeId/file/import (POST or PUT)


131
132
133
134
135
136
# File 'lib/smartling/fileapi.rb', line 131

def import(locale, file, name, type, state, params = nil)
    keys = { :fileUri => name, :fileType => type, :translationState => state}
    uri = uri("files-api/v2/projects/#{@projectId}/locales/#{locale}/file/import", keys, params).require(:fileUri, :fileType, :translationState)
    file = ::File.open(file, 'rb') if file.is_a?(String)
    return post_file(uri, :file => file)
end

#last_modified(name, locale, params = nil) ⇒ Object

Last Modified (by locale) - /files-api/v2/projects/projectId/locales/localeId/file/last-modified (GET)


110
111
112
113
114
# File 'lib/smartling/fileapi.rb', line 110

def last_modified(name, locale, params = nil)
  keys = { :fileUri => name }
  uri = uri("files-api/v2/projects/#{@projectId}/locales/#{locale}/file/last-modified", keys, params).require(:fileUri)
  return get(uri)
end

#last_modified_all(name, params = nil) ⇒ Object

Last Modified (all locales) - /files-api/v2/projects/projectId/file/last-modified (GET)


117
118
119
120
121
# File 'lib/smartling/fileapi.rb', line 117

def last_modified_all(name, params = nil)
  keys = { :fileUri => name }
  uri = uri("files-api/v2/projects/#{@projectId}/file/last-modified", keys, params).require(:fileUri)
  return get(uri)
end

#list(params = nil) ⇒ Object

List Files - /files-api/v2/projects/projectId/files/list (GET)


27
28
29
30
# File 'lib/smartling/fileapi.rb', line 27

def list(params = nil)
  uri = uri("files-api/v2/projects/#{@projectId}/files/list", params)
  return get(uri)
end

#list_types(params = nil) ⇒ Object

List File Types - /files-api/v2/projects/projectId/file-types (GET)


33
34
35
36
# File 'lib/smartling/fileapi.rb', line 33

def list_types(params = nil)
  uri = uri("files-api/v2/projects/#{@projectId}/file-types", params)
  return get(uri)
end

#rename(name, newname, params = nil) ⇒ Object

Rename - /files-api/v2/projects/projectId/file/rename (POST)


96
97
98
99
100
# File 'lib/smartling/fileapi.rb', line 96

def rename(name, newname, params = nil)
  keys = { :fileUri => name, :newFileUri => newname }
  uri = uri("files-api/v2/projects/#{@projectId}/file/rename", keys, params).require(:fileUri, :newFileUri)
  return post(uri)
end

#status(name, locale) ⇒ Object

Status - Single Locale / Extended Response - /files-api/v2/projects/projectId/locales/localeId/file/status (GET)


46
47
48
49
50
# File 'lib/smartling/fileapi.rb', line 46

def status(name, locale)
  keys = { :fileUri => name }
  uri = uri("files-api/v2/projects/#{@projectId}/locales/#{locale}/file/status", keys, {}).require(:fileUri)
  return get(uri)
end

#status_all(name) ⇒ Object

Status - All Locales - /files-api/v2/projects/projectId/file/status (GET)


39
40
41
42
43
# File 'lib/smartling/fileapi.rb', line 39

def status_all(name)
  keys = { :fileUri => name }
  uri = uri("files-api/v2/projects/#{@projectId}/file/status", keys, {}).require(:fileUri)
  return get(uri)
end

#translations(locale, file, fileUri, params = nil) ⇒ Object

Get Translations - /files-api/v2/projects/projectId/locales/localeId/file/get-translations (POST)


124
125
126
127
128
# File 'lib/smartling/fileapi.rb', line 124

def translations(locale, file, fileUri, params = nil)
  keys = { :fileUri => fileUri }
  uri = uri("files-api/v2/projects/#{@projectId}/locales/#{locale}/file/get-translations", keys, params).require(:fileUri)
  return post_file_raw(uri, :file => file)
end

#upload(file, name, type, params = nil) ⇒ Object

Upload File - /files-api/v2/projects/projectId/file (POST)


88
89
90
91
92
93
# File 'lib/smartling/fileapi.rb', line 88

def upload(file, name, type, params = nil)
  keys = { :fileUri => name, :fileType => type }
  uri = uri("files-api/v2/projects/#{@projectId}/file", keys, params).require(:fileUri, :fileType)
  file = ::File.open(file, 'rb') if file.is_a?(String)
  return post_file(uri, :file => file)
end