Class: Clearbit::Resource
- Inherits:
-
Mash
- Object
- Hash
- Mash
- Clearbit::Resource
show all
- Defined in:
- lib/clearbit/resource.rb
Direct Known Subclasses
Base
Class Method Summary
collapse
-
.delete(action = '', params = {}, options = {}) ⇒ Object
-
.endpoint(value = nil) ⇒ Object
(also: endpoint=)
-
.get(action = '', params = {}, options = {}) ⇒ Object
-
.options(value = nil) ⇒ Object
(also: options=, add_options)
-
.path(value = nil) ⇒ Object
(also: path=)
-
.post(action = '', params = {}, options = {}) ⇒ Object
-
.put(action = '', params = {}, options = {}) ⇒ Object
-
.request(url, options = {}) ⇒ Object
-
.uri(*parts) ⇒ Object
-
.url ⇒ Object
Instance 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 Clearbit::Mash
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class Clearbit::Mash
Class Method Details
.delete(action = '', params = {}, options = {}) ⇒ Object
60
61
62
|
# File 'lib/clearbit/resource.rb', line 60
def self.delete(action = '', params = {}, options = {})
request(uri(action), options.merge(method: :delete, params: params))
end
|
.endpoint(value = nil) ⇒ Object
Also known as:
endpoint=
5
6
7
8
9
|
# File 'lib/clearbit/resource.rb', line 5
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
48
49
50
|
# File 'lib/clearbit/resource.rb', line 48
def self.get(action = '', params = {}, options = {})
request(uri(action), options.merge(method: :get, params: params))
end
|
.options(value = nil) ⇒ Object
Also known as:
options=, add_options
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/clearbit/resource.rb', line 17
def self.options(value = nil)
@options ||= {}
@options.merge!(value) if value
if superclass.respond_to?(:options)
Nestful::Helpers.deep_merge(superclass.options, @options)
else
@options
end
end
|
.path(value = nil) ⇒ Object
Also known as:
path=
11
12
13
14
15
|
# File 'lib/clearbit/resource.rb', line 11
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
56
57
58
|
# File 'lib/clearbit/resource.rb', line 56
def self.post(action = '', params = {}, options = {})
request(uri(action), options.merge(method: :post, params: params))
end
|
.put(action = '', params = {}, options = {}) ⇒ Object
52
53
54
|
# File 'lib/clearbit/resource.rb', line 52
def self.put(action = '', params = {}, options = {})
request(uri(action), options.merge(method: :put, params: params))
end
|
.request(url, options = {}) ⇒ Object
64
65
66
67
68
69
70
|
# File 'lib/clearbit/resource.rb', line 64
def self.request(url, options = {})
options = Nestful::Helpers.deep_merge(self.options, options)
Nestful::Request.new(
url, options
).execute
end
|
.uri(*parts) ⇒ Object
39
40
41
42
43
44
45
46
|
# File 'lib/clearbit/resource.rb', line 39
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
35
36
37
|
# File 'lib/clearbit/resource.rb', line 35
def self.url
URI.join(endpoint.to_s, path.to_s).to_s
end
|
Instance Method Details
#uri(*parts) ⇒ Object
72
73
74
|
# File 'lib/clearbit/resource.rb', line 72
def uri(*parts)
id ? self.class.uri(id, *parts) : self.class.uri(*parts)
end
|