Class: XodClient::TokenRefresher

Inherits:
Object
  • Object
show all
Includes:
ParseUtil
Defined in:
lib/xod_client/token_refresher.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ParseUtil

#parse_xod_response

Constructor Details

#initialize(xod_conn) ⇒ TokenRefresher

Returns a new instance of TokenRefresher.



7
8
9
# File 'lib/xod_client/token_refresher.rb', line 7

def initialize(xod_conn)
  @xod_conn = xod_conn
end

Instance Attribute Details

#xod_connObject (readonly)

Returns the value of attribute xod_conn.



5
6
7
# File 'lib/xod_client/token_refresher.rb', line 5

def xod_conn
  @xod_conn
end

Instance Method Details

#performObject



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

def perform
  res = xod_conn.faraday.post do |req|
    req.url xod_conn.config.
    req.headers['Content-Type'] = 'application/json'
    req.body = {
      relyingParty: xod_conn.relying_party,
      thirdPartyId: 'XporterOnDemand',
      estab: xod_conn.estab,
      password: xod_conn.secret
    }.to_json
  end
  token_json = parse_xod_response(res)
  token = token_json[:token]
  token_expires_at = Time.iso8601(token_json[:expires])

  [token, token_expires_at]
end