Class: VtigerRuby::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/vtiger-ruby/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(endpoint: nil, username: nil, accesskey: nil) ⇒ Client

Returns a new instance of Client.



8
9
10
11
12
# File 'lib/vtiger-ruby/client.rb', line 8

def initialize(endpoint: nil, username: nil, accesskey: nil)
  @endpoint = endpoint
  @username = username
  @accesskey = accesskey
end

Instance Attribute Details

#accesskeyObject

Returns the value of attribute accesskey.



6
7
8
# File 'lib/vtiger-ruby/client.rb', line 6

def accesskey
  @accesskey
end

#endpointObject

Returns the value of attribute endpoint.



6
7
8
# File 'lib/vtiger-ruby/client.rb', line 6

def endpoint
  @endpoint
end

#session_idObject

Returns the value of attribute session_id.



6
7
8
# File 'lib/vtiger-ruby/client.rb', line 6

def session_id
  @session_id
end

#usernameObject

Returns the value of attribute username.



6
7
8
# File 'lib/vtiger-ruby/client.rb', line 6

def username
  @username
end

Instance Method Details

#accountObject



70
71
72
73
# File 'lib/vtiger-ruby/client.rb', line 70

def 
  VtigerRuby::Account.class_config(self)
  VtigerRuby::Account
end

#connectObject



46
47
48
49
# File 'lib/vtiger-ruby/client.rb', line 46

def connect
  get_challenge
  
end

#get_challengeObject



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/vtiger-ruby/client.rb', line 14

def get_challenge
  challenge_params = { operation: 'getchallenge', username: username }

  response = Faraday.get(endpoint, challenge_params) do |req|
    req.headers['User-Agent'] = 'VtigerRuby'
  end

  body = JSON.parse(response.body)
  @token = body['result']['token']

  body
end

#loginObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/vtiger-ruby/client.rb', line 27

def 
   = {
    'operation': 'login',
    'username': username,
    'accessKey': md5_token
  }

  response = Faraday.post(endpoint) do |req|
    req.headers['Content-Type'] = 'application/x-www-form-urlencoded'
    req.headers['User-Agent'] = 'VtigerRuby'
    req.body = 
  end

  body = JSON.parse(response.body)
  @session_id = body['result']['sessionName']

  body
end

#logoutObject



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/vtiger-ruby/client.rb', line 51

def logout
  logout_params = {
    'operation': 'logout',
    'sessionName': @session_id
  }

  response = Faraday.post(endpoint) do |req|
    req.headers['Content-Type'] = 'application/x-www-form-urlencoded'
    req.headers['User-Agent'] = 'VtigerRuby'
    req.body = logout_params
  end

  remove_instance_variable(:@token)
  remove_instance_variable(:@session_id)
  remove_instance_variable(:@md5_token)

  JSON.parse(response.body)
end