Class: Octobat::Item
Instance Attribute Summary
#api_key, #parent_obj
Class Method Summary
collapse
Instance Method Summary
collapse
list, set_parent_resource
#delete
#save, #serialize_metadata, #serialize_params
included
Methods inherited from APIResource
class_name, #refresh, retrieve
#[], #[]=, #_dump, _load, #as_json, construct_from, #each, #initialize, #inspect, #keys, #refresh_from, #respond_to?, #to_hash, #to_json, #to_s, #values
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class Octobat::OctobatObject
Class Method Details
.set_parent_resource(filters) ⇒ Object
58
59
60
|
# File 'lib/octobat/item.rb', line 58
def self.set_parent_resource(filters)
@parent_resource = filters.select{|k, v| [:transaction, :invoice, :credit_note].include?(k)}
end
|
.url ⇒ Object
48
49
50
51
52
53
54
55
56
|
# File 'lib/octobat/item.rb', line 48
def self.url
if @parent_resource.include?(:transaction)
"#{Transaction.url}/#{CGI.escape(@parent_resource[:transaction])}/items"
elsif @parent_resource.include?(:invoice)
"#{Invoice.url}/#{CGI.escape(@parent_resource[:invoice])}/items"
elsif @parent_resource.include?(:credit_note)
"#{CreditNote.url}/#{CGI.escape(@parent_resource[:credit_note])}/items"
end
end
|
Instance Method Details
#parentize_url ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/octobat/item.rb', line 23
def parentize_url
if parent_obj.include?(:transaction)
"#{Transaction.url}/#{CGI.escape(parent_obj[:transaction])}/items/#{CGI.escape(id)}"
elsif parent_obj.include?(:invoice)
"#{Invoice.url}/#{CGI.escape(parent_obj[:invoice])}/items/#{CGI.escape(id)}"
elsif parent_obj.include?(:credit_note)
"#{CreditNote.url}/#{CGI.escape(parent_obj[:credit_note])}/items/#{CGI.escape(id)}"
else
url
end
end
|
#relative_save_url ⇒ Object
37
38
39
40
41
42
43
44
45
|
# File 'lib/octobat/item.rb', line 37
def relative_save_url
if self[:transaction]
"#{Transaction.url}/#{CGI.escape(self[:transaction])}/items"
elsif self[:invoice]
"#{Invoice.url}/#{CGI.escape(self[:invoice])}/items"
elsif self[:credit_note]
"#{CreditNote.url}/#{CGI.escape(self[:credit_note])}/items"
end
end
|
#save_url ⇒ Object
14
15
16
17
18
19
20
|
# File 'lib/octobat/item.rb', line 14
def save_url
if self[:id] == nil && self.class.respond_to?(:create)
self.relative_save_url
else
url
end
end
|
#url ⇒ Object
9
10
11
|
# File 'lib/octobat/item.rb', line 9
def url
!parent_obj.nil? ? parentize_url : super
end
|