Class: WxOpendata::Token

Inherits:
Object
  • Object
show all
Defined in:
lib/wx_opendata/token.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(appid, appsecret, token_file) ⇒ Token

Returns a new instance of Token.



8
9
10
11
12
13
# File 'lib/wx_opendata/token.rb', line 8

def initialize(appid, appsecret, token_file)
  @appid = appid
  @appsecret = appsecret
  @token_file = token_file
  @random_generator = Random.new
end

Instance Attribute Details

#access_tokenObject (readonly)

Returns the value of attribute access_token.



6
7
8
# File 'lib/wx_opendata/token.rb', line 6

def access_token
  @access_token
end

#appidObject (readonly)

Returns the value of attribute appid.



6
7
8
# File 'lib/wx_opendata/token.rb', line 6

def appid
  @appid
end

#secretObject (readonly)

Returns the value of attribute secret.



6
7
8
# File 'lib/wx_opendata/token.rb', line 6

def secret
  @secret
end

#store_token_atObject (readonly)

Returns the value of attribute store_token_at.



6
7
8
# File 'lib/wx_opendata/token.rb', line 6

def store_token_at
  @store_token_at
end

#token_expires_inObject (readonly)

Returns the value of attribute token_expires_in.



6
7
8
# File 'lib/wx_opendata/token.rb', line 6

def token_expires_in
  @token_expires_in
end

#token_fileObject (readonly)

Returns the value of attribute token_file.



6
7
8
# File 'lib/wx_opendata/token.rb', line 6

def token_file
  @token_file
end

Instance Method Details

#tokenObject



15
16
17
18
19
# File 'lib/wx_opendata/token.rb', line 15

def token
  read_token_from_cache
  refresh_token if remain_seconds < @random_generator.rand(30..3 * 60)
  access_token
end