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



31
32
33
34
35
# File 'lib/cleaver_client.rb', line 31

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



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(options = {})
  require_auth!
  post "person/#{@token}/reports/Traffic/data/0/10000", options
end

#get_fields(options = {}) ⇒ Object

Get available fields



50
51
52
53
# File 'lib/cleaver_client.rb', line 50

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

#loginObject

Perform a login with login and password



38
39
40
41
# File 'lib/cleaver_client.rb', line 38

def 
  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(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)


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_sObject



75
76
77
# File 'lib/cleaver_client.rb', line 75

def to_s
  "#{@login}"
end