Class: Baiwang::TokenStore::AppToken

Inherits:
Base
  • Object
show all
Defined in:
lib/baiwang/token_store/app_token.rb

Instance Attribute Summary

Attributes inherited from Base

#client

Instance Method Summary collapse

Methods inherited from Base

#initialize, #token, #update_token, #valid?

Constructor Details

This class inherits a constructor from Baiwang::TokenStore::Base

Instance Method Details

#fetch_tokenObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/baiwang/token_store/app_token.rb', line 11

def fetch_token
  q = build_sorted_params(
    {
      method: 'baiwang.oauth.token',
      grant_type: 'password',
      client_id: client.app_key,
      client_secret: client.app_secret,
      username: client.admin_username,
      password: digest_password,
      version: '3.0',
      timestamp: Time.now.to_i
    }
  )
  http = HTTP.timeout(**Baiwang.http_timeout_options)
  header = { 'Content-Type': 'application/x-www-form-urlencoded' }
  response = http.headers(header).post("#{Baiwang.api_base_url}/router/rest?#{q}")
  Baiwang::Result.new JSON.parse(response.body.to_s)
end

#token_keyObject



7
8
9
# File 'lib/baiwang/token_store/app_token.rb', line 7

def token_key
  'access_token'
end