Class: Octobat::UsageItem
Instance Attribute Summary
#api_key, #parent_obj
Class Method Summary
collapse
Instance Method Summary
collapse
list, set_parent_resource
#delete
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
45
46
47
|
# File 'lib/octobat/usage_item.rb', line 45
def self.set_parent_resource(filters)
@parent_resource = filters.select{|k, v| [:subscription].include?(k)}
end
|
.url ⇒ Object
39
40
41
42
43
|
# File 'lib/octobat/usage_item.rb', line 39
def self.url
if @parent_resource.include?(:subscription)
"#{Subscription.url}/#{CGI.escape(@parent_resource[:subscription])}/usage_items"
end
end
|
Instance Method Details
#parentize_url ⇒ Object
22
23
24
25
26
27
28
|
# File 'lib/octobat/usage_item.rb', line 22
def parentize_url
if parent_obj.include?(:subscription)
"#{Subscription.url}/#{CGI.escape(parent_obj[:subscription])}/usage_items/#{CGI.escape(id)}"
else
url
end
end
|
#relative_save_url ⇒ Object
32
33
34
35
36
|
# File 'lib/octobat/usage_item.rb', line 32
def relative_save_url
if self[:subscription]
"#{Subscription.url}/#{CGI.escape(self[:subscription])}/usage_items"
end
end
|
#save_url ⇒ Object
13
14
15
16
17
18
19
|
# File 'lib/octobat/usage_item.rb', line 13
def save_url
if self[:id] == nil && self.class.respond_to?(:create)
self.relative_save_url
else
url
end
end
|
#url ⇒ Object
8
9
10
|
# File 'lib/octobat/usage_item.rb', line 8
def url
!parent_obj.nil? ? parentize_url : super
end
|