Class: FbResource::AbstractResource
- Inherits:
-
Object
- Object
- FbResource::AbstractResource
show all
- Defined in:
- lib/resources/abstract_resource.rb
Class Attribute Summary collapse
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of AbstractResource.
16
17
18
|
# File 'lib/resources/abstract_resource.rb', line 16
def initialize(conf)
@conf = conf
end
|
Class Attribute Details
.path ⇒ Object
8
9
10
11
|
# File 'lib/resources/abstract_resource.rb', line 8
def path
@path or
raise "Set a resource path on your resource class via self.path="
end
|
Instance Attribute Details
#conf ⇒ Object
Returns the value of attribute conf.
14
15
16
|
# File 'lib/resources/abstract_resource.rb', line 14
def conf
@conf
end
|
Instance Method Details
#all ⇒ Object
40
41
42
|
# File 'lib/resources/abstract_resource.rb', line 40
def all
@all || fetch
end
|
#fetch ⇒ Object
20
21
22
23
24
25
|
# File 'lib/resources/abstract_resource.rb', line 20
def fetch
Http
.get(conf.url + self.class.path, conf.)
.no { |obj, req, res| fetch_no(obj, req, res) }
.ok { |obj, req, res| fetch_ok(obj, req, res) }
end
|
#fetch_no(obj, req, res) ⇒ Object
27
28
29
30
31
32
33
34
|
# File 'lib/resources/abstract_resource.rb', line 27
def fetch_no(obj, req, res)
raise FetchError, """\n
Error Fetching Farmbot resource:\n
#{obj || "\n"}\n
#{req && req.url}\n
#{res && res.message}\n
#{res && res.class}\n"""
end
|
#fetch_ok(obj, request, response) ⇒ Object
36
37
38
|
# File 'lib/resources/abstract_resource.rb', line 36
def fetch_ok(obj, request, response)
@all = obj
end
|