Class: Toptranslation::Resource::Project

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection, options = {}) ⇒ Project

Returns a new instance of Project.



6
7
8
9
10
11
# File 'lib/toptranslation/resource/project.rb', line 6

def initialize(connection, options = {})
  @connection = connection
  @options = options

  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/project.rb', line 3

def created_at
  @created_at
end

#identifierObject (readonly)

Returns the value of attribute identifier.



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

def identifier
  @identifier
end

#localesObject (readonly)

Returns the value of attribute locales.



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

def locales
  @locales
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#source_localeObject (readonly)

Returns the value of attribute source_locale.



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

def source_locale
  @source_locale
end

Instance Method Details

#documentsObject



30
31
32
# File 'lib/toptranslation/resource/project.rb', line 30

def documents
  ProjectDocumentList.new(@connection, project_identifier: @identifier)
end

#saveObject



38
39
40
41
# File 'lib/toptranslation/resource/project.rb', line 38

def save
  response = @identifier ? update_remote_project : create_remote_project
  update_and_return_from_response(response)
end

#stringsObject



34
35
36
# File 'lib/toptranslation/resource/project.rb', line 34

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

#upload_document(filepath, locale_code, options = {}) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/toptranslation/resource/project.rb', line 13

def upload_document(filepath, locale_code, options = {})
  upload = Upload.new(@connection).upload(filepath)

  attr_hash = {
    document_store_id: upload.document_store_id,
    document_token: upload.document_token,
    locale_code: locale_code
  }

  attr_hash[:path] = options[:path] if options[:path]
  attr_hash[:name] = options[:name] if options[:name]

  response = @connection.post("/projects/#{@identifier}/documents", attr_hash)

  Document.new(@connection, response)
end