Class: Toptranslation::Resource::Document

Inherits:
Object
  • Object
show all
Defined in:
lib/toptranslation/resource/document.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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, options = {})
  @connection = connection
  update_from_response(options)
end

Instance Attribute Details

#created_atObject (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_stringsObject (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

#identifierObject (readonly)

Returns the value of attribute identifier.



3
4
5
# File 'lib/toptranslation/resource/document.rb', line 3

def identifier
  @identifier
end

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/toptranslation/resource/document.rb', line 4

def name
  @name
end

#pathObject

Returns the value of attribute path.



4
5
6
# File 'lib/toptranslation/resource/document.rb', line 4

def path
  @path
end

#sha1Object (readonly)

Returns the value of attribute sha1.



3
4
5
# File 'lib/toptranslation/resource/document.rb', line 3

def sha1
  @sha1
end

#string_countObject (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

#translationsObject (readonly)

Returns the value of attribute translations.



3
4
5
# File 'lib/toptranslation/resource/document.rb', line 3

def translations
  @translations
end

#updated_atObject (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, options = {})
  upload = Upload.new(@connection).upload(filepath)

  response = @connection.post("/documents/#{@identifier}/translations", options.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, options = {}, &block)
  download_path = if options[:path]
                    options[:path]
                  else
                    tempfile = Tempfile.new
                    temp_path = tempfile.path
                    tempfile.close
                    temp_path
                  end
  @connection.download(download_url(locale_code, options), 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, options = {})
  params = { file_format: options[:file_format], locale_code: locale_code }.compact
  @connection.get("/documents/#{@identifier}/download", params: params)['download_url']
end

#saveObject



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

#stringsObject



44
45
46
# File 'lib/toptranslation/resource/document.rb', line 44

def strings
  StringList.new(@connection, document_identifier: @identifier)
end