Class: ResourceParty::Base

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/resource_party.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}, query = {}, no_defaults = false) ⇒ Base

Returns a new instance of Base.



20
21
22
23
24
25
26
27
# File 'lib/resource_party.rb', line 20

def initialize(params = {}, query = {}, no_defaults = false) 
  return self if no_defaults
  response = self.class.get("/#{self.class.route}/new.xml")
  handle_errors(response)
  hash = Hash.from_xml(response.body).values.first
  hash.merge! params
  self.class.from_xml hash, self
end

Instance Attribute Details

#attributesObject

Returns the value of attribute attributes.



10
11
12
# File 'lib/resource_party.rb', line 10

def attributes
  @attributes
end

Class Method Details

.all(query = {}) ⇒ Object



64
65
66
67
68
69
# File 'lib/resource_party.rb', line 64

def self.all(query = {})
  response = self.get("/#{self.route}.xml", :query => query) 
  handle_errors(response)
  items = response.values.first
  items.map{|hash| self.from_xml hash }        
end

.create(params = {}, query = {}) ⇒ Object



36
37
38
39
40
# File 'lib/resource_party.rb', line 36

def self.create(params = {}, query = {})
  response = self.post("/#{self.route}.xml", :body => body_for(params), :query => query) 
  handle_errors(response)
  handle_response(response)
end

.destroy(id, query = {}) ⇒ Object



53
54
55
56
57
58
# File 'lib/resource_party.rb', line 53

def self.destroy(id, query = {}) 
  response = self.delete("/#{self.route}/#{id}.xml", :query => query) 
  handle_not_found(response)
  handle_errors(response)
  handle_response(response)
end

.find(param, query = {}) ⇒ Object



29
30
31
32
33
34
# File 'lib/resource_party.rb', line 29

def self.find(param, query = {})
  response = self.get("/#{self.route}/#{param}.xml", :query => query) 
  handle_not_found(response)
  handle_errors(response)
  handle_response(response)
end

.resource_for(val) ⇒ Object



16
17
18
# File 'lib/resource_party.rb', line 16

def self.resource_for(val)
  class_eval("def self.resource; '#{val}'; end")
end

.route_for(val) ⇒ Object



12
13
14
# File 'lib/resource_party.rb', line 12

def self.route_for(val)
  class_eval("def self.route; '#{val}'; end")
end

.update(param, params = {}, query = {}) ⇒ Object



42
43
44
45
46
47
# File 'lib/resource_party.rb', line 42

def self.update(param, params = {}, query = {})
  response = self.put("/#{self.route}/#{param}.xml", :body => body_for(params), :query => query) 
  handle_not_found(response)
  handle_errors(response)
  handle_response(response)
end

Instance Method Details

#destroy(query = {}) ⇒ Object



60
61
62
# File 'lib/resource_party.rb', line 60

def destroy(query = {})
  self.class.destroy(self.id, query)
end

#update(params = {}, query = {}) ⇒ Object



49
50
51
# File 'lib/resource_party.rb', line 49

def update(params = {}, query = {})
  self.class.update(self.id, params, query)
end