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

#documents(options = {}) ⇒ Object



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

def documents(options = {})
  options.merge!(project_identifier: @identifier)
  ProjectDocumentList.new(@connection, options)
end

#saveObject



40
41
42
43
# File 'lib/toptranslation/resource/project.rb', line 40

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

#stringsObject



36
37
38
# File 'lib/toptranslation/resource/project.rb', line 36

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

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



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

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

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

  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