Class: Onfleet::API
- Inherits:
-
Object
- Object
- Onfleet::API
- Defined in:
- lib/onfleet/api.rb
Constant Summary collapse
- API_RESOURCES =
%w{organization admins workers teams destinations recipients tasks webhooks}
Class Attribute Summary collapse
-
.api_endpoint ⇒ Object
Returns the value of attribute api_endpoint.
-
.api_key ⇒ Object
Returns the value of attribute api_key.
-
.logger ⇒ Object
Returns the value of attribute logger.
-
.max_try_count ⇒ Object
Returns the value of attribute max_try_count.
-
.retry_if_fails ⇒ Object
Returns the value of attribute retry_if_fails.
-
.throws_exceptions ⇒ Object
Returns the value of attribute throws_exceptions.
-
.timeout ⇒ Object
Returns the value of attribute timeout.
Instance Attribute Summary collapse
-
#api_endpoint ⇒ Object
Returns the value of attribute api_endpoint.
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#throws_exceptions ⇒ Object
Returns the value of attribute throws_exceptions.
-
#timeout ⇒ Object
Returns the value of attribute timeout.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(api_key = nil, default_parameters = {}) ⇒ API
constructor
A new instance of API.
- #method_missing(method, *args) ⇒ Object
Constructor Details
#initialize(api_key = nil, default_parameters = {}) ⇒ API
Returns a new instance of API.
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/onfleet/api.rb', line 7 def initialize(api_key=nil, default_parameters={}) @api_key = api_key || self.class.api_key || ENV['ONFLEET_API_KEY'] @api_key = @api_key.strip if @api_key @api_endpoint = default_parameters.delete(:api_endpoint) || self.class.api_endpoint @timeout = default_parameters.delete(:timeout) || self.class.timeout @throws_exceptions = default_parameters.has_key?(:throws_exceptions) ? default_parameters.delete(:throws_exceptions) : self.class.throws_exceptions @default_params = default_parameters end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/onfleet/api.rb', line 18 def method_missing(method, *args) if API_RESOURCES.include?(method.to_s) api = APICategory.new(method.to_s, @api_key, @timeout, @throws_exceptions, @api_endpoint, @default_params) api.api_endpoint = @api_endpoint if @api_endpoint api else super end end |
Class Attribute Details
.api_endpoint ⇒ Object
Returns the value of attribute api_endpoint.
29 30 31 |
# File 'lib/onfleet/api.rb', line 29 def api_endpoint @api_endpoint end |
.api_key ⇒ Object
Returns the value of attribute api_key.
29 30 31 |
# File 'lib/onfleet/api.rb', line 29 def api_key @api_key end |
.logger ⇒ Object
Returns the value of attribute logger.
29 30 31 |
# File 'lib/onfleet/api.rb', line 29 def logger @logger end |
.max_try_count ⇒ Object
Returns the value of attribute max_try_count.
29 30 31 |
# File 'lib/onfleet/api.rb', line 29 def max_try_count @max_try_count end |
.retry_if_fails ⇒ Object
Returns the value of attribute retry_if_fails.
29 30 31 |
# File 'lib/onfleet/api.rb', line 29 def retry_if_fails @retry_if_fails end |
.throws_exceptions ⇒ Object
Returns the value of attribute throws_exceptions.
29 30 31 |
# File 'lib/onfleet/api.rb', line 29 def throws_exceptions @throws_exceptions end |
.timeout ⇒ Object
Returns the value of attribute timeout.
29 30 31 |
# File 'lib/onfleet/api.rb', line 29 def timeout @timeout end |
Instance Attribute Details
#api_endpoint ⇒ Object
Returns the value of attribute api_endpoint.
5 6 7 |
# File 'lib/onfleet/api.rb', line 5 def api_endpoint @api_endpoint end |
#api_key ⇒ Object
Returns the value of attribute api_key.
5 6 7 |
# File 'lib/onfleet/api.rb', line 5 def api_key @api_key end |
#throws_exceptions ⇒ Object
Returns the value of attribute throws_exceptions.
5 6 7 |
# File 'lib/onfleet/api.rb', line 5 def throws_exceptions @throws_exceptions end |
#timeout ⇒ Object
Returns the value of attribute timeout.
5 6 7 |
# File 'lib/onfleet/api.rb', line 5 def timeout @timeout end |
Class Method Details
.method_missing(sym, *args, &block) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/onfleet/api.rb', line 35 def method_missing(sym, *args, &block) if API_RESOURCES.include?(sym.to_s) new(self.api_key, {:api_endpoint => self.api_endpoint, :timeout => self.timeout, :throws_exceptions => self.throws_exceptions}).send(sym, *args, &block) else super end end |