Class: Octobat::Plaza::Capability

Inherits:
APIResource show all
Extended by:
APIOperations::List
Defined in:
lib/octobat/plaza/capability.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 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



50
51
52
# File 'lib/octobat/plaza/capability.rb', line 50

def self.set_parent_resource(filters)
  @parent_resource = filters.select{|k, v| [:account].include?(k)}
end

.urlObject



44
45
46
47
48
# File 'lib/octobat/plaza/capability.rb', line 44

def self.url
  if @parent_resource.include?(:account)
    "#{Account.url}/#{CGI.escape(@parent_resource[:account])}/capabilities"
  end
end

Instance Method Details

#ask(params = {}, opts = {}) ⇒ Object



10
11
12
13
# File 'lib/octobat/plaza/capability.rb', line 10

def ask(params = {}, opts = {})
  response, api_key = Octobat.request(:patch, ask_url, @api_key, params, opts)
  refresh_from(response, api_key)
end

#ask_urlObject



40
41
42
# File 'lib/octobat/plaza/capability.rb', line 40

def ask_url
  "#{parentize_url}/request"
end

#parentize_urlObject



24
25
26
27
28
29
30
# File 'lib/octobat/plaza/capability.rb', line 24

def parentize_url
  if parent_obj.include?(:account)
    "#{Account.url}/#{CGI.escape(parent_obj[:account])}/capabilities/#{CGI.escape(id)}"
  else
    url
  end
end

#relative_save_urlObject



34
35
36
37
38
# File 'lib/octobat/plaza/capability.rb', line 34

def relative_save_url
  if self[:account]
    "#{Account.url}/#{CGI.escape(self[:account])}/capabilities"
  end
end

#save_urlObject



15
16
17
18
19
20
21
# File 'lib/octobat/plaza/capability.rb', line 15

def save_url
  if self[:id] == nil && self.class.respond_to?(:create)
    self.relative_save_url
  else
    url
  end
end

#urlObject



6
7
8
# File 'lib/octobat/plaza/capability.rb', line 6

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