Class: Fulcrum::Resource

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Resource

Returns a new instance of Resource.



5
6
7
# File 'lib/fulcrum/resource.rb', line 5

def initialize(client)
  self.client = client
end

Instance Attribute Details

#clientObject

Returns the value of attribute client.



3
4
5
# File 'lib/fulcrum/resource.rb', line 3

def client
  @client
end

Instance Method Details

#attributes_for_object(object) ⇒ Object



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

def attributes_for_object(object)
  attributes = {}
  attributes[resource_name] = object
  attributes
end

#call(method = :get, path = '', params = {}) ⇒ Object



17
18
19
# File 'lib/fulcrum/resource.rb', line 17

def call(method = :get, path = '', params = {})
  client.call(method, path, params)
end

#collection(format = 'json') ⇒ Object



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

def collection(format = 'json')
  "#{resources_name}.#{format}"
end

#member(id, format = 'json') ⇒ Object



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

def member(id, format = 'json')
  "#{resources_name}/#{id}.#{format}"
end

#member_action(id, action, format = 'json') ⇒ Object



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

def member_action(id, action, format = 'json')
  "#{resources_name}/#{id}/#{action}.#{format}"
end

#resource_nameObject



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

def resource_name
  self.class.to_s.split('::').last.underscore
end

#resources_nameObject



13
14
15
# File 'lib/fulcrum/resource.rb', line 13

def resources_name
  resource_name.pluralize
end