Module: Qingting::Api::Account

Extended by:
Account
Included in:
Account, QingtingApi
Defined in:
lib/qingting/api/account.rb

Instance Method Summary collapse

Instance Method Details

#access_tokenObject

获取账户 token



9
10
11
# File 'lib/qingting/api/account.rb', line 9

def access_token
  token_hash['access_token']
end

#token_hashObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/qingting/api/account.rb', line 13

def token_hash
  validate_token_hash
  @token_hash ||=
    begin
      @token_request_at = Time.now
      params = {
        grant_type: Base.get_grant_type,
        client_id: Base.get_client_id,
        client_secret: Base.get_client_secret
      }
      url = Base.access_url
      result = Utils::Request.post(url, params: params)
      result
    end
end

#validate_token_hashObject

Check token expired or not



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/qingting/api/account.rb', line 30

def validate_token_hash
  if @token_request_at and
      @token_hash and @token_hash['expires_in'] and
      (Time.now - @token_request_at) > @token_hash['expires_in'].to_i
    @token_hash = nil
  elsif @token_request_at and
      @token_hash and @token_hash['expires_in']
    @token_hash['access_token']
  else
    puts "start get token ..."
  end
end