Class: OneEye::API
- Inherits:
-
Object
show all
- Includes:
- HTTParty
- Defined in:
- lib/api.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(api_token = ) ⇒ API
Returns a new instance of API.
12
13
14
|
# File 'lib/api.rb', line 12
def initialize(api_token=ENV["ONE_EYE_API_KEY"])
@options = { query: {api_token: api_token} }
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, options = {}) ⇒ Object
42
43
44
45
|
# File 'lib/api.rb', line 42
def method_missing(name, options={})
name, options = standardize_request(:get, name, options)
self.class.get name, options
end
|
Class Method Details
.debug(options = {}) ⇒ Object
16
17
18
19
|
# File 'lib/api.rb', line 16
def self.debug(options={})
OneEye::API.debug_output $stdout unless options[:stop]
OneEye::API.debug_output $stderr if options[:stop]
end
|
.http_methods ⇒ Object
8
9
10
|
# File 'lib/api.rb', line 8
def self.http_methods
[:get, :post, :put, :patch, :delete]
end
|
Instance Method Details
#handle_errors(&block) ⇒ Object
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/api.rb', line 21
def handle_errors(&block)
@response = block.call
@code_level = @response.code.to_s[0]
if @code_level == "4" || @code_level == "5"
def @response.to_hash
{:status_code => @response.code, :error => @response.message}
end
end
@response
end
|