Class: SendpulseClient::Connection::Token
- Inherits:
-
Struct
- Object
- Struct
- SendpulseClient::Connection::Token
- Defined in:
- lib/sendpulse_client/connection.rb
Constant Summary collapse
- URL =
'https://api.sendpulse.com/oauth/access_token'.freeze
Instance Attribute Summary collapse
-
#created_at ⇒ Object
Returns the value of attribute created_at.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
-
#initialize(value = nil, created_at = nil) ⇒ Token
constructor
A new instance of Token.
- #set! ⇒ Object
- #to_s ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(value = nil, created_at = nil) ⇒ Token
Returns a new instance of Token.
10 11 12 13 |
# File 'lib/sendpulse_client/connection.rb', line 10 def initialize(value = nil, created_at = nil) @value = value @created_at = created_at end |
Instance Attribute Details
#created_at ⇒ Object
Returns the value of attribute created_at
7 8 9 |
# File 'lib/sendpulse_client/connection.rb', line 7 def created_at @created_at end |
#value ⇒ Object
Returns the value of attribute value
7 8 9 |
# File 'lib/sendpulse_client/connection.rb', line 7 def value @value end |
Instance Method Details
#set! ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/sendpulse_client/connection.rb', line 15 def set! body = { client_id: SendpulseClient.configuration.client_id, client_secret: SendpulseClient.configuration.client_secret, grant_type: 'client_credentials' } @value = HTTParty.post(URL, body: body)['access_token'] @created_at = Time.now end |
#to_s ⇒ Object
26 27 28 |
# File 'lib/sendpulse_client/connection.rb', line 26 def to_s "Bearer #{@value}" end |
#valid? ⇒ Boolean
30 31 32 |
# File 'lib/sendpulse_client/connection.rb', line 30 def valid? (Time.now - @created_at) / 3600 < 1.0 end |