Class: Toptranslation::Resource::Order

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Order.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/toptranslation/resource/order.rb', line 8

def initialize(connection, options = {})
  @connection = connection
  @options = options
  @name = @options[:name]
  @reference = @options[:reference]
  @comment = @options[:comment]
  @coupon_code = @options[:coupon_code]
  @service_level = @options[:service_level]
  @desired_delivery_date = @options[:desired_delivery_date]
  @quote_required = @options[:quote_required]
  @delivery_date = nil
  @identifier = nil

  update_from_response(options)
end

Instance Attribute Details

#commentObject

Returns the value of attribute comment.



6
7
8
# File 'lib/toptranslation/resource/order.rb', line 6

def comment
  @comment
end

#coupon_codeObject

Returns the value of attribute coupon_code.



6
7
8
# File 'lib/toptranslation/resource/order.rb', line 6

def coupon_code
  @coupon_code
end

#created_atObject (readonly)

Returns the value of attribute created_at.



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

def created_at
  @created_at
end

#creator_hashObject (readonly)

Returns the value of attribute creator_hash.



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

def creator_hash
  @creator_hash
end

#desired_delivery_dateObject

Returns the value of attribute desired_delivery_date.



6
7
8
# File 'lib/toptranslation/resource/order.rb', line 6

def desired_delivery_date
  @desired_delivery_date
end

#estimated_delivery_dateObject (readonly)

Returns the value of attribute estimated_delivery_date.



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

def estimated_delivery_date
  @estimated_delivery_date
end

#identifierObject (readonly)

Returns the value of attribute identifier.



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

def identifier
  @identifier
end

#nameObject

Returns the value of attribute name.



6
7
8
# File 'lib/toptranslation/resource/order.rb', line 6

def name
  @name
end

#order_numberObject (readonly)

Returns the value of attribute order_number.



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

def order_number
  @order_number
end

#ordered_atObject (readonly)

Returns the value of attribute ordered_at.



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

def ordered_at
  @ordered_at
end

#progressObject (readonly)

Returns the value of attribute progress.



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

def progress
  @progress
end

#quote_requiredObject

Returns the value of attribute quote_required.



6
7
8
# File 'lib/toptranslation/resource/order.rb', line 6

def quote_required
  @quote_required
end

#referenceObject

Returns the value of attribute reference.



6
7
8
# File 'lib/toptranslation/resource/order.rb', line 6

def reference
  @reference
end

#requested_atObject (readonly)

Returns the value of attribute requested_at.



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

def requested_at
  @requested_at
end

#service_levelObject

Returns the value of attribute service_level.



6
7
8
# File 'lib/toptranslation/resource/order.rb', line 6

def service_level
  @service_level
end

#stateObject (readonly)

Returns the value of attribute state.



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

def state
  @state
end

Instance Method Details

#add_document(document_store_id, document_token, source_locale_code, target_locale_codes) ⇒ Object



24
25
26
27
28
29
30
31
32
33
# File 'lib/toptranslation/resource/order.rb', line 24

def add_document(document_store_id, document_token, source_locale_code, target_locale_codes)
  response = @connection.post("/orders/#{@identifier}/documents",
                              document_store_id: document_store_id,
                              document_token: document_token,
                              source_locale_code: source_locale_code,
                              target_locale_codes: target_locale_codes,
                              version: 2)

  Document.new(@connection, response)
end

#creatorObject



53
54
55
# File 'lib/toptranslation/resource/order.rb', line 53

def creator
  @creator ||= User.new(@connection, @options['creator'])
end

#documentsObject



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

def documents
  @connection.get("/orders/#{@identifier}/documents", version: 2)
end

#quotesObject



45
46
47
# File 'lib/toptranslation/resource/order.rb', line 45

def quotes
  @quotes ||= @options['quotes'].map { |quote| Quote.new(@connection, quote) }
end

#requestObject



62
63
64
65
# File 'lib/toptranslation/resource/order.rb', line 62

def request
  response = @connection.patch("/orders/#{@identifier}/request", version: 2)
  update_and_return_from_response(response)
end

#saveObject



57
58
59
60
# File 'lib/toptranslation/resource/order.rb', line 57

def save
  response = @identifier ? update_remote_order : create_remote_order
  update_and_return_from_response(response)
end

#translationsObject



49
50
51
# File 'lib/toptranslation/resource/order.rb', line 49

def translations
  TranslationList.new(@connection, order_identifier: @identifier)
end

#upload_document(filepath, source_locale_code, target_locale_codes) ⇒ Object



35
36
37
38
39
# File 'lib/toptranslation/resource/order.rb', line 35

def upload_document(filepath, source_locale_code, target_locale_codes)
  upload = Upload.new(@connection).upload(filepath)

  add_document(upload.document_store_id, upload.document_token, source_locale_code, target_locale_codes)
end