Class: Tenk::Resource

Inherits:
Object
  • Object
show all
Defined in:
lib/resource.rb

Overview

The base class for all API resources

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Resource

Initialize a base API resource from the client



9
10
11
# File 'lib/resource.rb', line 9

def initialize(client)
  @_client = client
end

Instance Method Details

#create(options) ⇒ Object

The base method for create requests on all resources



30
31
32
# File 'lib/resource.rb', line 30

def create(options)
  @_client.post(resource_root, options)
end

#get(id, options) ⇒ Object

The base method for get requests on all resources



25
26
27
# File 'lib/resource.rb', line 25

def get(id, options)
  @_client.get("#{resource_root}/#{id}", options)
end

#list(options) ⇒ Object

The base method for list requests on all resources



20
21
22
# File 'lib/resource.rb', line 20

def list(options)
  @_client.get(resource_root, options)
end

#resource_rootString

The root for this resource. Default is based on class name tableized

Returns:

  • (String)

    the root url for actions on this resource



15
16
17
# File 'lib/resource.rb', line 15

def resource_root
  "/#{self.class.name.demodulize.tableize}"
end

#update(id, options) ⇒ Object

The base method for update requests on all resources



35
36
37
# File 'lib/resource.rb', line 35

def update(id, options)
  @_client.put("#{resource_root}/#{id}", options)
end