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
31 32 33 34 35 |
# File 'lib/cleaver_client.rb', line 31 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
62 63 64 65 66 67 68 |
# File 'lib/cleaver_client.rb', line 62 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
56 57 58 59 |
# File 'lib/cleaver_client.rb', line 56 def get_data( = {}) require_auth! post "person/#{@token}/reports/Traffic/data/0/10000", end |
#get_fields(options = {}) ⇒ Object
Get available fields
50 51 52 53 |
# File 'lib/cleaver_client.rb', line 50 def get_fields( = {}) require_auth! get "person/#{@token}/fields", end |
#login ⇒ Object
Perform a login with login and password
38 39 40 41 |
# File 'lib/cleaver_client.rb', line 38 def login response = post "login", Username: @login, Password: @password @token = response['Token'] end |
#logout(options = {}) ⇒ Object
Perform logout
44 45 46 47 |
# File 'lib/cleaver_client.rb', line 44 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
71 72 73 |
# File 'lib/cleaver_client.rb', line 71 def respond_to?(method_name, *arguments, &block) !!method_name.to_s.match(/(post|get|put|patch|delete)/) || super end |
#to_s ⇒ Object
75 76 77 |
# File 'lib/cleaver_client.rb', line 75 def to_s "#{@login}" end |