Class: VaultedBilling::Gateways::Ipcommerce::ServiceKeyStore
- Inherits:
-
Object
- Object
- VaultedBilling::Gateways::Ipcommerce::ServiceKeyStore
- Defined in:
- lib/vaulted_billing/gateways/ipcommerce.rb
Constant Summary collapse
Class.new(VaultedBilling::CredentialError)
Instance Attribute Summary collapse
-
#identity_token ⇒ Object
readonly
Returns the value of attribute identity_token.
Instance Method Summary collapse
- #before_request(request) ⇒ Object
-
#initialize(identity_token) ⇒ ServiceKeyStore
constructor
A new instance of ServiceKeyStore.
- #key ⇒ Object
- #read_key ⇒ Object
- #renew! ⇒ Object
- #store_key(key) ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(identity_token) ⇒ ServiceKeyStore
Returns a new instance of ServiceKeyStore.
63 64 65 66 |
# File 'lib/vaulted_billing/gateways/ipcommerce.rb', line 63 def initialize(identity_token) @identity_token = identity_token @expires_at = nil end |
Instance Attribute Details
#identity_token ⇒ Object (readonly)
Returns the value of attribute identity_token.
61 62 63 |
# File 'lib/vaulted_billing/gateways/ipcommerce.rb', line 61 def identity_token @identity_token end |
Instance Method Details
#before_request(request) ⇒ Object
85 86 87 |
# File 'lib/vaulted_billing/gateways/ipcommerce.rb', line 85 def before_request(request) request.delete "accept" end |
#key ⇒ Object
68 69 70 71 |
# File 'lib/vaulted_billing/gateways/ipcommerce.rb', line 68 def key renew! unless valid? read_key || raise(UnavailableKeyError, 'A service key could not be retrieved for this session.') end |
#read_key ⇒ Object
73 74 75 |
# File 'lib/vaulted_billing/gateways/ipcommerce.rb', line 73 def read_key @key end |
#renew! ⇒ Object
89 90 91 92 93 94 |
# File 'lib/vaulted_billing/gateways/ipcommerce.rb', line 89 def renew! response = http.get raise(UnavailableKeyError, 'Unable to renew service keys.') unless response.success? @expires_at = Time.now + 30.minutes store_key(response.body.try(:[], 1...-1)) end |
#store_key(key) ⇒ Object
77 78 79 |
# File 'lib/vaulted_billing/gateways/ipcommerce.rb', line 77 def store_key(key) @key = key end |
#valid? ⇒ Boolean
81 82 83 |
# File 'lib/vaulted_billing/gateways/ipcommerce.rb', line 81 def valid? @expires_at && (@expires_at > Time.now + 5.minutes) end |