Class: Geocoder::EsriToken
- Inherits:
- 
      Object
      
        - Object
- Geocoder::EsriToken
 
- Defined in:
- lib/geocoder/esri_token.rb
Instance Attribute Summary collapse
- 
  
    
      #expires_at  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    Returns the value of attribute expires_at. 
- 
  
    
      #value  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    Returns the value of attribute value. 
Class Method Summary collapse
Instance Method Summary collapse
- #active? ⇒ Boolean
- 
  
    
      #initialize(value, expires_at)  ⇒ EsriToken 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    A new instance of EsriToken. 
- #to_s ⇒ Object
Constructor Details
#initialize(value, expires_at) ⇒ EsriToken
Returns a new instance of EsriToken.
| 5 6 7 8 | # File 'lib/geocoder/esri_token.rb', line 5 def initialize(value, expires_at) @value = value @expires_at = expires_at end | 
Instance Attribute Details
#expires_at ⇒ Object
Returns the value of attribute expires_at.
| 3 4 5 | # File 'lib/geocoder/esri_token.rb', line 3 def expires_at @expires_at end | 
#value ⇒ Object
Returns the value of attribute value.
| 3 4 5 | # File 'lib/geocoder/esri_token.rb', line 3 def value @value end | 
Class Method Details
.generate_token(client_id, client_secret, expires = 1440) ⇒ Object
| 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | # File 'lib/geocoder/esri_token.rb', line 18 def self.generate_token(client_id, client_secret, expires=1440) # creates a new token that will expire in 1 day by default getToken = Net::HTTP.post_form URI('https://www.arcgis.com/sharing/rest/oauth2/token'), f: 'json', client_id: client_id, client_secret: client_secret, grant_type: 'client_credentials', expiration: expires # (minutes) max: 20160, default: 1 day response = JSON.parse(getToken.body) if response['error'] Geocoder.log(:warn, response['error']) else token_value = response['access_token'] expires_at = Time.now + (expires * 60) new(token_value, expires_at) end end | 
Instance Method Details
#active? ⇒ Boolean
| 14 15 16 | # File 'lib/geocoder/esri_token.rb', line 14 def active? @expires_at > Time.now end | 
#to_s ⇒ Object
| 10 11 12 | # File 'lib/geocoder/esri_token.rb', line 10 def to_s @value end |