Class: Sensi::Account
Constant Summary
Constants included from Sensi
Instance Attribute Summary collapse
-
#auth_cookie ⇒ Object
Returns the value of attribute auth_cookie.
-
#auth_response ⇒ Object
Returns the value of attribute auth_response.
-
#cookie_hash ⇒ Object
Returns the value of attribute cookie_hash.
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#token ⇒ Object
Returns the value of attribute token.
-
#token_response ⇒ Object
Returns the value of attribute token_response.
Instance Method Summary collapse
- #add_auth_cookie_to_headers(auth_cookie) ⇒ Object
- #authorize(username, password) ⇒ Object
- #get_connection_token ⇒ Object
-
#initialize(username, password) ⇒ Account
constructor
A new instance of Account.
- #login ⇒ Object
- #logout ⇒ Object
- #parse_cookies(response_cookies) ⇒ Object
- #save_auth_cookie ⇒ Object
Constructor Details
#initialize(username, password) ⇒ Account
Returns a new instance of Account.
22 23 24 25 26 |
# File 'lib/sensi/account.rb', line 22 def initialize(username, password) @username = username @password = password self end |
Instance Attribute Details
#auth_cookie ⇒ Object
Returns the value of attribute auth_cookie.
11 12 13 |
# File 'lib/sensi/account.rb', line 11 def @auth_cookie end |
#auth_response ⇒ Object
Returns the value of attribute auth_response.
11 12 13 |
# File 'lib/sensi/account.rb', line 11 def auth_response @auth_response end |
#cookie_hash ⇒ Object
Returns the value of attribute cookie_hash.
11 12 13 |
# File 'lib/sensi/account.rb', line 11 def @cookie_hash end |
#headers ⇒ Object
Returns the value of attribute headers.
11 12 13 |
# File 'lib/sensi/account.rb', line 11 def headers @headers end |
#token ⇒ Object
Returns the value of attribute token.
11 12 13 |
# File 'lib/sensi/account.rb', line 11 def token @token end |
#token_response ⇒ Object
Returns the value of attribute token_response.
11 12 13 |
# File 'lib/sensi/account.rb', line 11 def token_response @token_response end |
Instance Method Details
#add_auth_cookie_to_headers(auth_cookie) ⇒ Object
58 59 60 |
# File 'lib/sensi/account.rb', line 58 def () @headers = {'Accept' => 'application/json; version=1, */*; q=0.01','Cookie' => } end |
#authorize(username, password) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/sensi/account.rb', line 36 def (username, password) @auth_response = HTTParty.post( Sensi::API_URI + '/api/authorize', body: {UserName: username, Password: password}.to_json, headers: {'Accept' => 'application/json; version=1, */*; q=0.01', 'X-Requested-With' => 'XMLHttpRequest', 'Content-Type' => 'application/json'} ) end |
#get_connection_token ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/sensi/account.rb', line 44 def get_connection_token @token_response = Curl.get(Sensi::API_URI + '/realtime/negotiate') do |req| req.headers['Cookie'] = @auth_cookie req.headers['Accept'] = 'application/json; version=1, */*; q=0.01' end @token = JSON.parse(@token_response.body)['ConnectionToken'] # @token_response = HTTParty.get( # Sensi::API_URI + '/realtime/negotiate', # headers: Sensi::DEFAULT_HEADERS # ) # @token = @token_response['ConnectionToken'] end |
#login ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/sensi/account.rb', line 28 def login (@username, @password) (@auth_response.get_fields('Set-Cookie')) (@auth_cookie) get_connection_token end |
#logout ⇒ Object
73 74 75 76 77 78 |
# File 'lib/sensi/account.rb', line 73 def logout HTTParty.delete( Sensi::API_URI + '/api/authorize', headers: {'Coookie' => @auth_cookie, 'Accept' => 'application/json; version=1, */*; q=0.01'} ) end |
#parse_cookies(response_cookies) ⇒ Object
62 63 64 65 66 67 |
# File 'lib/sensi/account.rb', line 62 def () @cookie_hash = HTTParty::CookieHash.new .each do || @cookie_hash.() end end |
#save_auth_cookie ⇒ Object
69 70 71 |
# File 'lib/sensi/account.rb', line 69 def @auth_cookie = @cookie_hash. end |