Class: CleaverClient
- Inherits:
-
Object
- Object
- CleaverClient
- Defined in:
- lib/cleaver_client.rb
Overview
This class creates a new cleaver client instance
Defined Under Namespace
Classes: ApiError
Instance Method Summary collapse
-
#get_data(options = {}) ⇒ Object
Get data.
-
#get_fields(options = {}) ⇒ Object
Get available fields.
-
#initialize(login, password) ⇒ CleaverClient
constructor
Create a new connector instance.
-
#login ⇒ Object
Perform a login with login and password.
-
#logout(options = {}) ⇒ Object
Perform logout.
-
#method_missing(method_name, *arguments, &block) ⇒ Object
Pass post, get, delete, put and patch to the request method.
-
#respond_to?(method_name, *arguments, &block) ⇒ Boolean
Let class instance respond to post, get, delete, put and patch.
- #to_s ⇒ Object
Constructor Details
#initialize(login, password) ⇒ CleaverClient
Create a new connector instance
17 18 19 20 21 |
# File 'lib/cleaver_client.rb', line 17 def initialize(login, password) @token = nil @api_url = 'https://cleaver.facetz.net/API/REST' @login, @password = login, password end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *arguments, &block) ⇒ Object
Pass post, get, delete, put and patch to the request method
48 49 50 51 52 53 54 |
# File 'lib/cleaver_client.rb', line 48 def method_missing(method_name, *arguments, &block) if method_name.to_s =~ /(post|get|put|patch|delete)/ request($1.to_sym, *arguments, &block) else super end end |
Instance Method Details
#get_data(options = {}) ⇒ Object
Get data
42 43 44 45 |
# File 'lib/cleaver_client.rb', line 42 def get_data( = {}) require_auth! post "person/#{@token}/reports/Traffic/data/0/10000", end |
#get_fields(options = {}) ⇒ Object
Get available fields
36 37 38 39 |
# File 'lib/cleaver_client.rb', line 36 def get_fields( = {}) require_auth! get "person/#{@token}/fields", end |
#login ⇒ Object
Perform a login with login and password
24 25 26 27 |
# File 'lib/cleaver_client.rb', line 24 def login response = post "login", Username: @login, Password: @password @token = response['Token'] end |
#logout(options = {}) ⇒ Object
Perform logout
30 31 32 33 |
# File 'lib/cleaver_client.rb', line 30 def logout( = {}) require_auth! get "#{@token}/logout", end |
#respond_to?(method_name, *arguments, &block) ⇒ Boolean
Let class instance respond to post, get, delete, put and patch
57 58 59 |
# File 'lib/cleaver_client.rb', line 57 def respond_to?(method_name, *arguments, &block) !!method_name.to_s.match(/(post|get|put|patch|delete)/) || super end |
#to_s ⇒ Object
61 62 63 |
# File 'lib/cleaver_client.rb', line 61 def to_s "#{@login}" end |