Class: Vng::SecurityToken
- Defined in:
 - lib/vng/security_token.rb
 
Overview
Provides methods to interact with Vonigo work security tokens.
Constant Summary collapse
- PATH =
 '/api/v1/security/login/'
Instance Attribute Summary collapse
- 
  
    
      #token  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
Returns the value of attribute token.
 
Class Method Summary collapse
Instance Method Summary collapse
- #assign_to(franchise_id:) ⇒ Object
 - #destroy ⇒ Object
 - 
  
    
      #initialize(token:)  ⇒ SecurityToken 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    
A new instance of SecurityToken.
 
Constructor Details
#initialize(token:) ⇒ SecurityToken
Returns a new instance of SecurityToken.
      10 11 12  | 
    
      # File 'lib/vng/security_token.rb', line 10 def initialize(token:) @token = token end  | 
  
Instance Attribute Details
#token ⇒ Object (readonly)
Returns the value of attribute token.
      8 9 10  | 
    
      # File 'lib/vng/security_token.rb', line 8 def token @token end  | 
  
Class Method Details
.create ⇒ Object
      14 15 16 17 18 19 20 21 22 23 24 25  | 
    
      # File 'lib/vng/security_token.rb', line 14 def self.create body = { app_version: '1', company: 'Vonigo', username: Vng.configuration.username, password: Digest::MD5.hexdigest(Vng.configuration.password), } data = request path: PATH, body: body, include_security_token: false new token: data['securityToken'] end  | 
  
Instance Method Details
#assign_to(franchise_id:) ⇒ Object
      27 28 29 30 31 32 33 34 35 36 37  | 
    
      # File 'lib/vng/security_token.rb', line 27 def assign_to(franchise_id:) body = { securityToken: @token, method: "2", franchiseID: franchise_id, } self.class.request path: '/api/v1/security/session/', body: body, include_security_token: false rescue Vng::Error => e raise unless e..include? 'Same franchise ID supplied' end  | 
  
#destroy ⇒ Object
      39 40 41 42 43 44  | 
    
      # File 'lib/vng/security_token.rb', line 39 def destroy query = { securityToken: @token } self.class.request path: '/api/v1/security/logout/', query: query rescue Vng::Error => e raise unless e..include?('Session expired') || e..include?('Session does not exist') end  |