Class: CleaverClient

Inherits:
Object
  • Object
show all
Defined in:
lib/cleaver_client.rb

Overview

This class creates a new cleaver client instance

Defined Under Namespace

Classes: ApiError

Instance Method Summary collapse

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(, password)
  @token = nil
  @api_url = 'https://cleaver.facetz.net/API/REST'
  @login, @password = , 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(options = {})
  require_auth!
  post "person/#{@token}/reports/Traffic/data/0/10000", options
end

#get_fields(options = {}) ⇒ Object

Get available fields



36
37
38
39
# File 'lib/cleaver_client.rb', line 36

def get_fields(options = {})
  require_auth!
  get "person/#{@token}/fields", options
end

#loginObject

Perform a login with login and password



24
25
26
27
# File 'lib/cleaver_client.rb', line 24

def 
  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(options = {})
  require_auth!
  get "#{@token}/logout", options
end

#respond_to?(method_name, *arguments, &block) ⇒ Boolean

Let class instance respond to post, get, delete, put and patch

Returns:

  • (Boolean)


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_sObject



61
62
63
# File 'lib/cleaver_client.rb', line 61

def to_s
  "#{@login}"
end