Class: APIHub::Resource
- Inherits:
-
Mash
- Object
- Hash
- Mash
- APIHub::Resource
show all
- Defined in:
- lib/apihub/resource.rb
Direct Known Subclasses
Base
Class Method Summary
collapse
Methods inherited from Mash
#custom_reader, #custom_writer, #deep_merge, #deep_update, #delete, #dup, #fetch, #id, #initialize, #initializing_reader, #key?, #method_missing, new, #regular_dup, #replace, #respond_to?, #shallow_merge, #shallow_update, #type, #underbang_reader
Constructor Details
This class inherits a constructor from APIHub::Mash
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class APIHub::Mash
Class Method Details
.delete(action = '', params = {}, options = {}) ⇒ Object
52
53
54
|
# File 'lib/apihub/resource.rb', line 52
def self.delete(action = '', params = {}, options = {})
request(uri(action), options.merge(method: :delete, params: params))
end
|
.endpoint(value = nil) ⇒ Object
Also known as:
endpoint=
3
4
5
6
7
|
# File 'lib/apihub/resource.rb', line 3
def self.endpoint(value = nil)
@endpoint = value if value
return @endpoint if @endpoint
superclass.respond_to?(:endpoint) ? superclass.endpoint : nil
end
|
.get(action = '', params = {}, options = {}) ⇒ Object
40
41
42
|
# File 'lib/apihub/resource.rb', line 40
def self.get(action = '', params = {}, options = {})
request(uri(action), options.merge(method: :get, params: params))
end
|
.options(value = nil) ⇒ Object
Also known as:
options=
15
16
17
18
19
|
# File 'lib/apihub/resource.rb', line 15
def self.options(value = nil)
@options = value if value
return @options if @options
superclass.respond_to?(:options) ? superclass.options : {}
end
|
.path(value = nil) ⇒ Object
Also known as:
path=
9
10
11
12
13
|
# File 'lib/apihub/resource.rb', line 9
def self.path(value = nil)
@path = value if value
return @path if @path
superclass.respond_to?(:path) ? superclass.path : nil
end
|
.post(action = '', params = {}, options = {}) ⇒ Object
48
49
50
|
# File 'lib/apihub/resource.rb', line 48
def self.post(action = '', params = {}, options = {})
request(uri(action), options.merge(method: :post, params: params))
end
|
.put(action = '', params = {}, options = {}) ⇒ Object
44
45
46
|
# File 'lib/apihub/resource.rb', line 44
def self.put(action = '', params = {}, options = {})
request(uri(action), options.merge(method: :put, params: params))
end
|
.request(url, options = {}) ⇒ Object
56
57
58
59
60
61
62
|
# File 'lib/apihub/resource.rb', line 56
def self.request(url, options = {})
options = Nestful::Helpers.deep_merge(self.options, options)
self.new Nestful::Request.new(
url, options
).execute
end
|
.uri(*parts) ⇒ Object
31
32
33
34
35
36
37
38
|
# File 'lib/apihub/resource.rb', line 31
def self.uri(*parts)
if (uri = parts.first) && uri.is_a?(URI)
return uri if uri.host
end
URI.parse(Nestful::Helpers.to_path(url, *parts))
end
|
.url ⇒ Object
27
28
29
|
# File 'lib/apihub/resource.rb', line 27
def self.url
URI.join(endpoint.to_s, path.to_s).to_s
end
|