Class: Clientele::API
- Inherits:
-
Object
show all
- Extended by:
- BlockParty::Configurable, Forwardable, SingleForwardable
- Defined in:
- lib/clientele/api.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(opts = {}) ⇒ API
Returns a new instance of API.
81
82
83
84
85
86
|
# File 'lib/clientele/api.rb', line 81
def initialize(opts={})
self.extend BlockParty::Configurable
self.configure_with self.class.configuration.class
self.configuration = self.class.configuration.clone
self.configuration.load_hash opts
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
96
97
98
99
100
101
102
|
# File 'lib/clientele/api.rb', line 96
def method_missing(method_name, *args, &block)
if resources.keys.include? method_name.to_s
RequestBuilder.new(resources[method_name.to_s], client: self)
elsif Request::VERBS.include? method_name.to_s
RequestBuilder.new(Request.send(method_name.to_s, *args), client: self)
else; super; end
end
|
Class Method Details
.client(opts = {}) ⇒ Object
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/clientele/api.rb', line 28
def client(opts={})
autoconfigure!
if @client
@client.tap do |client|
client.configuration.load_hash(opts)
end
else
@client = new(opts)
end
end
|
.has_resource?(resource) ⇒ Boolean
49
50
51
|
# File 'lib/clientele/api.rb', line 49
def has_resource?(resource)
resources.keys.include? resource.to_s
end
|
.logger ⇒ Object
39
40
41
42
|
# File 'lib/clientele/api.rb', line 39
def logger
autoconfigure!
configuration.logger
end
|
57
58
59
60
|
# File 'lib/clientele/api.rb', line 57
def reconfigure_global_client!(opts={})
reset_global_client!
client(opts)
end
|
.reset_global_client! ⇒ Object
53
54
55
|
# File 'lib/clientele/api.rb', line 53
def reset_global_client!
@client = nil
end
|
.resource(klass) ⇒ Object
44
45
46
47
|
# File 'lib/clientele/api.rb', line 44
def resource(klass)
klass.client = self
self.resources = resources.merge(klass.method_name.to_sym => klass)
end
|
Instance Method Details
#client ⇒ Object
88
|
# File 'lib/clientele/api.rb', line 88
def client; self; end
|