Sha256: bad185d47c8b937d444d5a7c21500bca0b8d96e3840afd116952565ae9d70503

Contents?: true

Size: 1.18 KB

Versions: 11

Compression:

Stored size: 1.18 KB

Contents

require "stripe"
require_relative "./webhook/subscriber"
require_relative "./webhook/types"

module StripeLocal

	#
	# basically taken straight from the StripeEvents gem
	# https://github.com/integrallis/stripe_event
	#
	#
	module Webhook
	  class << self
	    alias :setup :instance_eval

		  def publish event_obj
		    ActiveSupport::Notifications.instrument event_obj.type, event: event_obj
		  end

		  def subscribe *names, &block
		    Subscriber.new(*names, &block).register
		  end

		  def subscribers name
		    ActiveSupport::Notifications.notifier.listeners_for name
		  end

		  def clear_subscribers!
		    TYPE_LIST.each do |type|
		      subscribers(type).each { |s| unsubscribe(s) }
		    end
		  end

		  def unsubscribe subscriber
		    ActiveSupport::Notifications.notifier.unsubscribe subscriber
		  end

			def translate object, action, event
				klass = object.camelize.constantize
				klass.send action, event
			end

			def dispatch event
				object,action,sub_action = event.type.split('.')
				unless sub_action.nil?
					object = [object,action].join('_')
					action = sub_action
				end
				translate object, action, event
			end
		end
	end
end

require_relative "./webhooks"

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
stripe_local-0.2.5 lib/stripe_local/webhook.rb
stripe_local-0.2.4 lib/stripe_local/webhook.rb
stripe_local-0.2.3 lib/stripe_local/webhook.rb
stripe_local-0.2.2 lib/stripe_local/webhook.rb
stripe_local-0.2.1 lib/stripe_local/webhook.rb
stripe_local-0.2.0 lib/stripe_local/webhook.rb
stripe_local-0.1.3 lib/stripe_local/webhook.rb
stripe_local-0.1.2 lib/stripe_local/webhook.rb
stripe_local-0.1.1 lib/stripe_local/webhook.rb
stripe_local-0.1.0 lib/stripe_local/webhook.rb
stripe_local-0.0.2 lib/stripe_local/webhook.rb