Class: Toptranslation::Resource::Document
- Inherits:
-
Object
- Object
- Toptranslation::Resource::Document
- Defined in:
- lib/toptranslation/resource/document.rb
Instance Attribute Summary collapse
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#has_missing_strings ⇒ Object
readonly
Returns the value of attribute has_missing_strings.
-
#identifier ⇒ Object
readonly
Returns the value of attribute identifier.
-
#name ⇒ Object
Returns the value of attribute name.
-
#path ⇒ Object
Returns the value of attribute path.
-
#sha1 ⇒ Object
readonly
Returns the value of attribute sha1.
-
#string_count ⇒ Object
readonly
Returns the value of attribute string_count.
-
#translations ⇒ Object
readonly
Returns the value of attribute translations.
-
#updated_at ⇒ Object
readonly
Returns the value of attribute updated_at.
Instance Method Summary collapse
- #add_translation(filepath, locale_code, options = {}) ⇒ Object
- #download(locale_code, options = {}, &block) ⇒ Object
- #download_url(locale_code, options = {}) ⇒ Object
-
#initialize(connection, options = {}) ⇒ Document
constructor
A new instance of Document.
- #save ⇒ Object
- #strings ⇒ Object
Constructor Details
#initialize(connection, options = {}) ⇒ Document
Returns a new instance of Document.
6 7 8 9 |
# File 'lib/toptranslation/resource/document.rb', line 6 def initialize(connection, = {}) @connection = connection update_from_response() end |
Instance Attribute Details
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
3 4 5 |
# File 'lib/toptranslation/resource/document.rb', line 3 def created_at @created_at end |
#has_missing_strings ⇒ Object (readonly)
Returns the value of attribute has_missing_strings.
3 4 5 |
# File 'lib/toptranslation/resource/document.rb', line 3 def has_missing_strings @has_missing_strings end |
#identifier ⇒ Object (readonly)
Returns the value of attribute identifier.
3 4 5 |
# File 'lib/toptranslation/resource/document.rb', line 3 def identifier @identifier end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/toptranslation/resource/document.rb', line 4 def name @name end |
#path ⇒ Object
Returns the value of attribute path.
4 5 6 |
# File 'lib/toptranslation/resource/document.rb', line 4 def path @path end |
#sha1 ⇒ Object (readonly)
Returns the value of attribute sha1.
3 4 5 |
# File 'lib/toptranslation/resource/document.rb', line 3 def sha1 @sha1 end |
#string_count ⇒ Object (readonly)
Returns the value of attribute string_count.
3 4 5 |
# File 'lib/toptranslation/resource/document.rb', line 3 def string_count @string_count end |
#translations ⇒ Object (readonly)
Returns the value of attribute translations.
3 4 5 |
# File 'lib/toptranslation/resource/document.rb', line 3 def translations @translations end |
#updated_at ⇒ Object (readonly)
Returns the value of attribute updated_at.
3 4 5 |
# File 'lib/toptranslation/resource/document.rb', line 3 def updated_at @updated_at end |
Instance Method Details
#add_translation(filepath, locale_code, options = {}) ⇒ Object
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/toptranslation/resource/document.rb', line 11 def add_translation(filepath, locale_code, = {}) upload = Upload.new(@connection).upload(filepath) response = @connection.post("/documents/#{@identifier}/translations", .merge( document_store_id: upload.document_store_id, document_token: upload.document_token, locale_code: locale_code, sha1: upload.sha1 )) end |
#download(locale_code, options = {}, &block) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/toptranslation/resource/document.rb', line 27 def download(locale_code, = {}, &block) download_path = if [:path] [:path] else tempfile = Tempfile.new temp_path = tempfile.path tempfile.close temp_path end @connection.download(download_url(locale_code, ), download_path, &block) end |
#download_url(locale_code, options = {}) ⇒ Object
22 23 24 25 |
# File 'lib/toptranslation/resource/document.rb', line 22 def download_url(locale_code, = {}) params = { file_format: [:file_format], locale_code: locale_code }.compact @connection.get("/documents/#{@identifier}/download", params: params)['download_url'] end |
#save ⇒ Object
39 40 41 42 |
# File 'lib/toptranslation/resource/document.rb', line 39 def save response = @connection.patch("/documents/#{@identifier}", remote_hash) update_and_return_from_response(response) end |
#strings ⇒ Object
44 45 46 |
# File 'lib/toptranslation/resource/document.rb', line 44 def strings StringList.new(@connection, document_identifier: @identifier) end |