Class: Nurego::User

Inherits:
APIResource show all
Includes:
APIOperations::List
Defined in:
lib/nurego/user.rb

Instance Attribute Summary

Attributes inherited from NuregoObject

#api_key

Class Method Summary collapse

Instance Method Summary collapse

Methods included from APIOperations::List

included

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

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



19
20
21
22
# File 'lib/nurego/user.rb', line 19

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

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

Create override



6
7
8
9
# File 'lib/nurego/user.rb', line 6

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

.url(org_id = nil) ⇒ Object

override class url



25
26
27
28
# File 'lib/nurego/user.rb', line 25

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

#cancel(params = {}) ⇒ Object

Delete override



12
13
14
15
16
17
# File 'lib/nurego/user.rb', line 12

def cancel(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

#url(org_id = nil) ⇒ Object

override instance url



31
32
33
34
35
36
37
# File 'lib/nurego/user.rb', line 31

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