Class: Resterl::BaseObject
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
included
Constructor Details
#initialize(data = {}, response = nil) ⇒ BaseObject
Returns a new instance of BaseObject.
10
11
12
13
|
# File 'lib/resterl/base_object.rb', line 10
def initialize data = {}, response = nil
@data = Hashie::Mash.new data
@response = response
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args, &block) ⇒ Object
15
16
17
|
# File 'lib/resterl/base_object.rb', line 15
def method_missing sym, *args, &block
@data.send sym, *args, &block
end
|
Instance Attribute Details
#response ⇒ Object
Returns the value of attribute response.
8
9
10
|
# File 'lib/resterl/base_object.rb', line 8
def response
@response
end
|
Class Method Details
.delete_object(url) ⇒ Object
33
34
35
|
# File 'lib/resterl/base_object.rb', line 33
def delete_object url
resterl_client.delete(url, {}, , {})
end
|
.get_object(url, params = {}) ⇒ Object
24
25
26
27
|
# File 'lib/resterl/base_object.rb', line 24
def get_object url, params = {}
response = resterl_client.get(url, params, )
new_from_response(response)
end
|
.mime_type=(t) ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/resterl/base_object.rb', line 41
def mime_type= t
self.parser, self.composer, self.complete_mime_type =
case t
when :json
[proc { |str| JSON.parse(str) },
proc(&:to_json),
'application/json'
]
when :xml
[proc { |str| Hash.from_xml(str) },
proc(&:to_xml),
'application/xml'
]
end
end
|
.post_to_object(url, params = {}, data = {}) ⇒ Object
29
30
31
|
# File 'lib/resterl/base_object.rb', line 29
def post_to_object url, params = {}, data = {}
post_put_object(:post, url, params, data)
end
|
.put_object(url, params = {}, data = {}) ⇒ Object
37
38
39
|
# File 'lib/resterl/base_object.rb', line 37
def put_object url, params = {}, data = {}
post_put_object(:put, url, params, data)
end
|
Instance Method Details
#respond_to?(sym, include_private = false) ⇒ Boolean
19
20
21
|
# File 'lib/resterl/base_object.rb', line 19
def respond_to? sym, include_private = false
super || @data.respond_to?(sym, include_private)
end
|