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, test_mode = false) ⇒ 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, test_mode = false) ⇒ ServiceKeyStore
Returns a new instance of ServiceKeyStore.
84 85 86 87 88 |
# File 'lib/vaulted_billing/gateways/ipcommerce.rb', line 84 def initialize(identity_token, test_mode = false) @identity_token = identity_token @expires_at = nil @test_mode = test_mode end |
Instance Attribute Details
#identity_token ⇒ Object (readonly)
Returns the value of attribute identity_token.
82 83 84 |
# File 'lib/vaulted_billing/gateways/ipcommerce.rb', line 82 def identity_token @identity_token end |
Instance Method Details
#before_request(request) ⇒ Object
107 108 109 |
# File 'lib/vaulted_billing/gateways/ipcommerce.rb', line 107 def before_request(request) request.delete "accept" end |
#key ⇒ Object
90 91 92 93 |
# File 'lib/vaulted_billing/gateways/ipcommerce.rb', line 90 def key renew! unless valid? read_key || raise(UnavailableKeyError, 'A service key could not be retrieved for this session.') end |
#read_key ⇒ Object
95 96 97 |
# File 'lib/vaulted_billing/gateways/ipcommerce.rb', line 95 def read_key @key end |
#renew! ⇒ Object
111 112 113 114 115 116 |
# File 'lib/vaulted_billing/gateways/ipcommerce.rb', line 111 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
99 100 101 |
# File 'lib/vaulted_billing/gateways/ipcommerce.rb', line 99 def store_key(key) @key = key end |
#valid? ⇒ Boolean
103 104 105 |
# File 'lib/vaulted_billing/gateways/ipcommerce.rb', line 103 def valid? @expires_at && (@expires_at > Time.now + 5.minutes) end |