stripe_event 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +11 -1
- data/Rakefile +19 -14
- data/lib/stripe_event.rb +3 -9
- data/lib/stripe_event/subscriber.rb +30 -0
- data/lib/stripe_event/version.rb +1 -1
- metadata +20 -19
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
## stripe_event
|
2
2
|
|
3
|
+
[![Build Status](https://secure.travis-ci.org/integrallis/stripe_event.png?branch=master)](http://travis-ci.org/integrallis/stripe_event)
|
4
|
+
|
3
5
|
stripe_event is built on the ActiveSupport::Notifications API. Incoming webhook requests are authenticated by retrieving the event from Stripe. Authenticated events are published to subscribers.
|
4
6
|
|
5
7
|
## Install
|
@@ -21,10 +23,18 @@ mount StripeEvent::Engine => "/stripe_event" # or provide a custom path
|
|
21
23
|
# config/initializers/stripe.rb
|
22
24
|
Stripe.api_key = ENV['STRIPE_API_KEY'] # Set your api key
|
23
25
|
|
24
|
-
# Define subscriber behavior
|
25
26
|
StripeEvent.subscribe 'charge.failed' do |event|
|
27
|
+
# Define subscriber behavior
|
26
28
|
MyClass.handle_failed_charge(event)
|
27
29
|
end
|
30
|
+
|
31
|
+
StripeEvent.subscribe 'customer.created', 'customer.updated' do |event|
|
32
|
+
# Handle multiple event types
|
33
|
+
end
|
34
|
+
|
35
|
+
StripeEvent.subscribe do |event|
|
36
|
+
# Handle all event types - logging, etc.
|
37
|
+
end
|
28
38
|
```
|
29
39
|
|
30
40
|
## Register webhook url with Stripe
|
data/Rakefile
CHANGED
@@ -4,19 +4,24 @@ begin
|
|
4
4
|
rescue LoadError
|
5
5
|
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
6
6
|
end
|
7
|
-
begin
|
8
|
-
|
9
|
-
rescue LoadError
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
end
|
14
|
-
|
15
|
-
RDoc::Task.new(:rdoc) do |rdoc|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
end
|
7
|
+
# begin
|
8
|
+
# require 'rdoc/task'
|
9
|
+
# rescue LoadError
|
10
|
+
# require 'rdoc/rdoc'
|
11
|
+
# require 'rake/rdoctask'
|
12
|
+
# RDoc::Task = Rake::RDocTask
|
13
|
+
# end
|
14
|
+
#
|
15
|
+
# RDoc::Task.new(:rdoc) do |rdoc|
|
16
|
+
# rdoc.rdoc_dir = 'rdoc'
|
17
|
+
# rdoc.title = 'StripeEvent'
|
18
|
+
# rdoc.options << '--line-numbers'
|
19
|
+
# rdoc.rdoc_files.include('lib/**/*.rb')
|
20
|
+
# end
|
21
21
|
|
22
22
|
Bundler::GemHelper.install_tasks
|
23
|
+
|
24
|
+
require 'rake'
|
25
|
+
require 'rspec/core/rake_task'
|
26
|
+
RSpec::Core::RakeTask.new(:spec)
|
27
|
+
task :default => :spec
|
data/lib/stripe_event.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require "stripe"
|
2
2
|
require "stripe_event/engine"
|
3
|
+
require "stripe_event/subscriber"
|
3
4
|
require "stripe_event/types"
|
4
5
|
|
5
6
|
module StripeEvent
|
@@ -13,9 +14,8 @@ module StripeEvent
|
|
13
14
|
ActiveSupport::Notifications.instrument(event_obj.type, :event => event_obj)
|
14
15
|
end
|
15
16
|
|
16
|
-
def self.subscribe(
|
17
|
-
|
18
|
-
ActiveSupport::Notifications.subscribe(name, proxy(&block))
|
17
|
+
def self.subscribe(*names, &block)
|
18
|
+
Subscriber.new(names, &block).register
|
19
19
|
end
|
20
20
|
|
21
21
|
def self.subscribers(name)
|
@@ -31,10 +31,4 @@ module StripeEvent
|
|
31
31
|
def self.unsubscribe(subscriber)
|
32
32
|
ActiveSupport::Notifications.notifier.unsubscribe(subscriber)
|
33
33
|
end
|
34
|
-
|
35
|
-
def self.proxy(&block)
|
36
|
-
lambda do |name, started, finished, id, payload|
|
37
|
-
block.call(payload[:event])
|
38
|
-
end
|
39
|
-
end
|
40
34
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module StripeEvent
|
2
|
+
class Subscriber
|
3
|
+
def initialize(names, &block)
|
4
|
+
@names = Array(names)
|
5
|
+
@block = block
|
6
|
+
ensure_valid_types!
|
7
|
+
end
|
8
|
+
|
9
|
+
def register
|
10
|
+
ActiveSupport::Notifications.subscribe(pattern, proxied_block)
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def pattern
|
16
|
+
Regexp.union(@names.empty? ? TYPES : @names)
|
17
|
+
end
|
18
|
+
|
19
|
+
def proxied_block
|
20
|
+
lambda do |name, started, finished, id, payload|
|
21
|
+
@block.call(payload[:event])
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def ensure_valid_types!
|
26
|
+
invalid_names = @names.select { |name| !TYPES.include?(name) }
|
27
|
+
raise InvalidEventType.new(invalid_names) if invalid_names.any?
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/stripe_event/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stripe_event
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-07-
|
12
|
+
date: 2012-07-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
16
|
-
requirement: &
|
16
|
+
requirement: &70166290190600 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '3.1'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70166290190600
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: stripe
|
27
|
-
requirement: &
|
27
|
+
requirement: &70166290190080 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,40 +32,40 @@ dependencies:
|
|
32
32
|
version: '1.6'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70166290190080
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
|
-
name:
|
38
|
-
requirement: &
|
37
|
+
name: rspec-rails
|
38
|
+
requirement: &70166290189520 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
42
42
|
- !ruby/object:Gem::Version
|
43
|
-
version: '
|
43
|
+
version: '2.10'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70166290189520
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
|
-
name:
|
49
|
-
requirement: &
|
48
|
+
name: webmock
|
49
|
+
requirement: &70166290188940 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '1.8'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70166290188940
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
|
-
name:
|
60
|
-
requirement: &
|
59
|
+
name: rake
|
60
|
+
requirement: &70166290188440 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
|
-
- -
|
63
|
+
- - ! '>='
|
64
64
|
- !ruby/object:Gem::Version
|
65
|
-
version: '
|
65
|
+
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70166290188440
|
69
69
|
description: Stripe webhook integration for Rails applications.
|
70
70
|
email:
|
71
71
|
- dwhalen@integrallis.com
|
@@ -77,6 +77,7 @@ files:
|
|
77
77
|
- app/controllers/stripe_event/webhook_controller.rb
|
78
78
|
- config/routes.rb
|
79
79
|
- lib/stripe_event/engine.rb
|
80
|
+
- lib/stripe_event/subscriber.rb
|
80
81
|
- lib/stripe_event/types.rb
|
81
82
|
- lib/stripe_event/version.rb
|
82
83
|
- lib/stripe_event.rb
|