Class: VtigerRuby::Client
- Inherits:
-
Object
- Object
- VtigerRuby::Client
- Defined in:
- lib/vtiger-ruby/client.rb
Instance Attribute Summary collapse
-
#accesskey ⇒ Object
Returns the value of attribute accesskey.
-
#endpoint ⇒ Object
Returns the value of attribute endpoint.
-
#session_id ⇒ Object
Returns the value of attribute session_id.
-
#username ⇒ Object
Returns the value of attribute username.
Instance Method Summary collapse
- #account ⇒ Object
- #connect ⇒ Object
- #get_challenge ⇒ Object
-
#initialize(endpoint: nil, username: nil, accesskey: nil) ⇒ Client
constructor
A new instance of Client.
- #login ⇒ Object
- #logout ⇒ Object
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
#accesskey ⇒ Object
Returns the value of attribute accesskey.
6 7 8 |
# File 'lib/vtiger-ruby/client.rb', line 6 def accesskey @accesskey end |
#endpoint ⇒ Object
Returns the value of attribute endpoint.
6 7 8 |
# File 'lib/vtiger-ruby/client.rb', line 6 def endpoint @endpoint end |
#session_id ⇒ Object
Returns the value of attribute session_id.
6 7 8 |
# File 'lib/vtiger-ruby/client.rb', line 6 def session_id @session_id end |
#username ⇒ Object
Returns the value of attribute username.
6 7 8 |
# File 'lib/vtiger-ruby/client.rb', line 6 def username @username end |
Instance Method Details
#account ⇒ Object
70 71 72 73 |
# File 'lib/vtiger-ruby/client.rb', line 70 def account VtigerRuby::Account.class_config(self) VtigerRuby::Account end |
#connect ⇒ Object
46 47 48 49 |
# File 'lib/vtiger-ruby/client.rb', line 46 def connect get_challenge login end |
#get_challenge ⇒ Object
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 |
#login ⇒ Object
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 login login_params = { '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 = login_params end body = JSON.parse(response.body) @session_id = body['result']['sessionName'] body end |
#logout ⇒ Object
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 |