Class: Nurego::Subscription

Inherits:
APIResource show all
Includes:
APIOperations::Update
Defined in:
lib/nurego/subscription.rb

Instance Attribute Summary

Attributes inherited from NuregoObject

#api_key

Class Method Summary collapse

Instance Method Summary collapse

Methods included from APIOperations::Update

#serialize_params

Methods inherited from APIResource

class_name, #refresh, retrieve

Methods inherited from NuregoObject

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

Constructor Details

This class inherits a constructor from Nurego::NuregoObject

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Nurego::NuregoObject

Class Method Details

.create(org_id, params = {}, api_key = nil) ⇒ Object

Create override



8
9
10
11
# File 'lib/nurego/subscription.rb', line 8

def self.create(org_id, params={}, api_key=nil)
  response, api_key = Nurego.request(:post, self.url(org_id), api_key, params)
  Util.convert_to_nurego_object(response, api_key)
end

.url(org_id = nil) ⇒ Object

override class url



35
36
37
38
# File 'lib/nurego/subscription.rb', line 35

def self.url(org_id = nil)
  return super() unless org_id
  "/v1/organizations/#{CGI.escape(org_id)}/#{CGI.escape(class_name.downcase)}s"
end

Instance Method Details

#delete(params = {}) ⇒ Object

Delete override



27
28
29
30
31
32
# File 'lib/nurego/subscription.rb', line 27

def delete(params={})
  # use params to pass extra parameters to Nurego backend
  response, api_key = Nurego.request(:delete, url(self.organization_id), @api_key, params)
  refresh_from(response, api_key)
  self
end

#saveObject

Update override



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/nurego/subscription.rb', line 14

def save
  values = serialize_params(self)

  if values.length > 0
    values.delete(:id)

    response, api_key = Nurego.request(:post, url(self.organization_id), @api_key, values)
    refresh_from(response, api_key)
  end
  self
end

#url(org_id = nil) ⇒ Object

override instance url



41
42
43
44
45
46
47
# File 'lib/nurego/subscription.rb', line 41

def url(org_id = nil)
  return super() unless org_id
  unless id = self['id']
    raise InvalidRequestError.new("Could not determine which URL to request: #{self.class} instance has no ID: #{self.inspect}", 'id')
  end
  "#{self.class.url(org_id)}/#{CGI.escape(id)}"
end