Class: NovaposhtaApi::Client
- Inherits:
-
Object
- Object
- NovaposhtaApi::Client
show all
- Defined in:
- lib/novaposhta_api/client.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(api_key: nil) {|http.connection| ... } ⇒ Client
Returns a new instance of Client.
7
8
9
10
11
|
# File 'lib/novaposhta_api/client.rb', line 7
def initialize(api_key: nil)
@api_key = api_key
yield(http.connection) if block_given?
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
24
25
26
27
28
29
30
31
|
# File 'lib/novaposhta_api/client.rb', line 24
def method_missing(name, *args, &block)
if with_resource?(name)
resources[name] ||= self.class.resources[name].new(http: http)
resources[name]
else
super
end
end
|
Instance Attribute Details
#api_key ⇒ Object
Returns the value of attribute api_key.
5
6
7
|
# File 'lib/novaposhta_api/client.rb', line 5
def api_key
@api_key
end
|
Instance Method Details
#resources ⇒ Object
41
42
43
|
# File 'lib/novaposhta_api/client.rb', line 41
def resources
@resources ||= {}
end
|
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
33
34
35
|
# File 'lib/novaposhta_api/client.rb', line 33
def respond_to_missing?(method_name, include_private = false)
with_resource?(method_name) || super
end
|
#with_resource?(resource_name) ⇒ Boolean
37
38
39
|
# File 'lib/novaposhta_api/client.rb', line 37
def with_resource?(resource_name)
self.class.resources.keys.include?(resource_name)
end
|