Class: RallyUp::Partner::Token

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(json) ⇒ Token

Returns a new instance of Token.



9
10
11
12
13
14
15
16
# File 'lib/rally_up/partner/token.rb', line 9

def initialize(json)
  @access_token = json[:access_token]
  @token_type = json[:token_type]
  @expires_in = json[:expires_in]
  @user_name = json[:UserName]
  @issued = json[:'.issued']
  @expires = json[:'.expires']
end

Instance Attribute Details

#access_tokenObject

Returns the value of attribute access_token.



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

def access_token
  @access_token
end

#expiresObject

Returns the value of attribute expires.



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

def expires
  @expires
end

#expires_inObject

Returns the value of attribute expires_in.



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

def expires_in
  @expires_in
end

#issuedObject

Returns the value of attribute issued.



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

def issued
  @issued
end

#token_typeObject

Returns the value of attribute token_type.



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

def token_type
  @token_type
end

#user_nameObject

Returns the value of attribute user_name.



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

def user_name
  @user_name
end

Class Method Details

.access_token_responseObject



30
31
32
33
34
35
36
37
38
# File 'lib/rally_up/partner/token.rb', line 30

def access_token_response
  params = {
    grant_type: 'password',
    username: RallyUp::Partner.,
    password: RallyUp::Partner.secret
  }
  HTTP.post("https://#{RallyUp::Partner.domain}/v1/partnertoken", body: URI.encode_www_form(params))
      .body.to_s
end

.retrieve(set: true) ⇒ Object



23
24
25
26
27
28
# File 'lib/rally_up/partner/token.rb', line 23

def retrieve(set: true)
  json = JSON.parse(access_token_response, symbolize_names: true)
  token = new(json)
  RallyUp::Partner.token = token if set
  token
end

Instance Method Details

#expired?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/rally_up/partner/token.rb', line 18

def expired?
  expires.nil? || Time.parse(expires).utc < Time.now.utc
end