Class: Octobat::UsageItem

Inherits:
APIResource show all
Extended by:
APIOperations::List
Includes:
APIOperations::Create, APIOperations::Delete
Defined in:
lib/octobat/usage_item.rb

Instance Attribute Summary

Attributes inherited from OctobatObject

#api_key, #parent_obj

Class Method Summary collapse

Instance Method Summary collapse

Methods included from APIOperations::List

list, set_parent_resource

Methods included from APIOperations::Delete

#delete

Methods included from APIOperations::Create

included

Methods inherited from APIResource

class_name, #refresh, retrieve

Methods inherited from OctobatObject

#[], #[]=, #_dump, _load, #as_json, construct_from, #each, #initialize, #inspect, #keys, #refresh_from, #respond_to?, #to_hash, #to_json, #to_s, #values

Constructor Details

This class inherits a constructor from Octobat::OctobatObject

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

.urlObject



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_urlObject



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_urlObject



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_urlObject



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

#urlObject



8
9
10
# File 'lib/octobat/usage_item.rb', line 8

def url
  !parent_obj.nil? ? parentize_url : super
end