Class: PurchaseKit::Configuration
- Inherits:
-
Object
- Object
- PurchaseKit::Configuration
- Defined in:
- lib/purchasekit/configuration.rb
Instance Attribute Summary collapse
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#api_url ⇒ Object
Returns the value of attribute api_url.
-
#app_id ⇒ Object
Returns the value of attribute app_id.
-
#demo_mode ⇒ Object
Returns the value of attribute demo_mode.
-
#demo_products ⇒ Object
Returns the value of attribute demo_products.
-
#webhook_secret ⇒ Object
Returns the value of attribute webhook_secret.
Instance Method Summary collapse
- #base_api_url ⇒ Object
- #demo_mode? ⇒ Boolean
-
#handlers_for(event_type) ⇒ Object
Get handlers for an event type (internal use).
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
-
#listening?(event_type) ⇒ Boolean
Check if any handlers are registered for an event type.
-
#on(event_type, &block) ⇒ Object
Register a callback for an event type.
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
6 7 8 9 10 11 |
# File 'lib/purchasekit/configuration.rb', line 6 def initialize @api_url = "https://purchasekit.com" @demo_mode = false @demo_products = {} @event_handlers = Hash.new { |h, k| h[k] = [] } end |
Instance Attribute Details
#api_key ⇒ Object
Returns the value of attribute api_key.
3 4 5 |
# File 'lib/purchasekit/configuration.rb', line 3 def api_key @api_key end |
#api_url ⇒ Object
Returns the value of attribute api_url.
3 4 5 |
# File 'lib/purchasekit/configuration.rb', line 3 def api_url @api_url end |
#app_id ⇒ Object
Returns the value of attribute app_id.
3 4 5 |
# File 'lib/purchasekit/configuration.rb', line 3 def app_id @app_id end |
#demo_mode ⇒ Object
Returns the value of attribute demo_mode.
4 5 6 |
# File 'lib/purchasekit/configuration.rb', line 4 def demo_mode @demo_mode end |
#demo_products ⇒ Object
Returns the value of attribute demo_products.
4 5 6 |
# File 'lib/purchasekit/configuration.rb', line 4 def demo_products @demo_products end |
#webhook_secret ⇒ Object
Returns the value of attribute webhook_secret.
3 4 5 |
# File 'lib/purchasekit/configuration.rb', line 3 def webhook_secret @webhook_secret end |
Instance Method Details
#base_api_url ⇒ Object
17 18 19 |
# File 'lib/purchasekit/configuration.rb', line 17 def base_api_url "#{api_url}/api/v1" end |
#demo_mode? ⇒ Boolean
13 14 15 |
# File 'lib/purchasekit/configuration.rb', line 13 def demo_mode? @demo_mode end |
#handlers_for(event_type) ⇒ Object
Get handlers for an event type (internal use)
42 43 44 |
# File 'lib/purchasekit/configuration.rb', line 42 def handlers_for(event_type) @event_handlers[event_type.to_sym] end |
#listening?(event_type) ⇒ Boolean
Check if any handlers are registered for an event type
47 48 49 |
# File 'lib/purchasekit/configuration.rb', line 47 def listening?(event_type) @event_handlers[event_type.to_sym].any? end |
#on(event_type, &block) ⇒ Object
Register a callback for an event type.
Available events:
-
:subscription_created
-
:subscription_updated
-
:subscription_canceled
-
:subscription_expired
Example:
PurchaseKit.configure do |config|
config.on(:subscription_created) do |event|
user = User.find(event.customer_id)
user.update!(subscribed: true)
end
end
37 38 39 |
# File 'lib/purchasekit/configuration.rb', line 37 def on(event_type, &block) @event_handlers[event_type.to_sym] << block end |