stripe_event 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6d62c1dcd19a7c4efa5ac0a32ce6e0d01d65fb54
4
- data.tar.gz: 98148c9f17cdaab997eb100e04ef4aaa7b417e4c
3
+ metadata.gz: 0ea02ffe131e7f8b5fe2ffa94ba2c889a7b4eb00
4
+ data.tar.gz: 4c6c8d779fbedd63815d37a62f2cc23310fe5aa4
5
5
  SHA512:
6
- metadata.gz: 907c5f1b0888fcf5093cb5853a916d4ca280cebb1b6eace62d4926f145262f8c8deb13eff2d617b4c61837348c7af635271a52e7e6387809999952a2036d1143
7
- data.tar.gz: 256549e22835b44d8d933c46c636eb04cabf8d549899e535a4227b0befa53ec56687a6281308737710a3acdb4f42b79a2f9944977974f18b79fa092df1943648
6
+ metadata.gz: 77221858fe9843e705b89859f6a6d4c38c6e0106c0f01c7ce9ad2a83dd11927f275629feda73fb0cef500d60020e5ad888246f9df1c43441bafad958813585d3
7
+ data.tar.gz: 669c28fb841f16fb81b3421ca8f2cc9af14325407bb1db9d88cacaac2053c142027ff824d66ea873301aec773424329928c12117a61aa4e6bee1ad870213f615
data/.gitignore CHANGED
@@ -6,3 +6,4 @@ spec/dummy/log/*.log
6
6
  spec/dummy/tmp/
7
7
  spec/dummy/.sass-cache
8
8
  Gemfile.lock
9
+ coverage/*
@@ -1,3 +1,9 @@
1
+ ### 1.1.0 (January 8, 2014)
2
+ * Deprecate `StripeEvent.setup` in favor of `StripeEvent.configure`. Remove `setup` at next major release.
3
+ * `StripeEvent.configure` yields the module to the block for configuration.
4
+ * `StripeEvent.configure` will raise `ArgumentError` unless a block is given.
5
+ * Track test coverage
6
+
1
7
  ### 1.0.0 (December 19, 2013)
2
8
  * Internally namespace dispatched events to avoid maintaining a list of all possible event types.
3
9
  * Subscribe to all event types with `StripeEvent.all` instead of `StripeEvent.subscribe`.
data/README.md CHANGED
@@ -1,4 +1,5 @@
1
- # StripeEvent [![Build Status](https://secure.travis-ci.org/integrallis/stripe_event.png?branch=master)](http://travis-ci.org/integrallis/stripe_event) [![Dependency Status](https://gemnasium.com/integrallis/stripe_event.png)](https://gemnasium.com/integrallis/stripe_event) [![Gem Version](https://badge.fury.io/rb/stripe_event.png)](http://badge.fury.io/rb/stripe_event)
1
+ # StripeEvent
2
+ [![Build Status](https://secure.travis-ci.org/integrallis/stripe_event.png?branch=master)](http://travis-ci.org/integrallis/stripe_event) [![Dependency Status](https://gemnasium.com/integrallis/stripe_event.png)](https://gemnasium.com/integrallis/stripe_event) [![Gem Version](https://badge.fury.io/rb/stripe_event.png)](http://badge.fury.io/rb/stripe_event) [![Code Climate](https://codeclimate.com/github/integrallis/stripe_event.png)](https://codeclimate.com/github/integrallis/stripe_event) [![Coverage Status](https://coveralls.io/repos/integrallis/stripe_event/badge.png)](https://coveralls.io/r/integrallis/stripe_event)
2
3
 
3
4
  StripeEvent is built on the [ActiveSupport::Notifications API](http://api.rubyonrails.org/classes/ActiveSupport/Notifications.html). Incoming webhook requests are authenticated by [retrieving the event object](https://stripe.com/docs/api?lang=ruby#retrieve_event) from Stripe. Define subscribers to handle a single event type or all event types. Subscribers can be a block or any object that responds to `#call`.
4
5
 
@@ -20,15 +21,15 @@ mount StripeEvent::Engine => '/my-chosen-path' # provide a custom path
20
21
  # config/initializers/stripe.rb
21
22
  Stripe.api_key = ENV['STRIPE_API_KEY'] # Set your api key
22
23
 
23
- StripeEvent.setup do
24
- subscribe 'charge.failed' do |event|
24
+ StripeEvent.configure do |events|
25
+ events.subscribe 'charge.failed' do |event|
25
26
  # Define subscriber behavior based on the event object
26
27
  event.class #=> Stripe::Event
27
28
  event.type #=> "charge.failed"
28
29
  event.data.object #=> #<Stripe::Charge:0x3fcb34c115f8>
29
30
  end
30
31
 
31
- all do |event|
32
+ events.all do |event|
32
33
  # Handle all event types - logging, etc.
33
34
  end
34
35
  end
@@ -54,9 +55,15 @@ class BillingEventLogger
54
55
  end
55
56
  end
56
57
 
57
- StripeEvent.setup do
58
- all BillingEventLogger.new(Rails.logger)
59
- subscribe 'customer.created', CustomerCreated.new
58
+ StripeEvent.configure do |events|
59
+ events.all BillingEventLogger.new(Rails.logger)
60
+ events.subscribe 'customer.created', CustomerCreated.new
61
+ end
62
+
63
+ # Subscribing to a namespace of event types
64
+
65
+ StripeEvent.subscribe 'customer.card.' do |event|
66
+ # Will be triggered for any customer.card.* events
60
67
  end
61
68
  ```
62
69
 
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- stripe_event (1.0.0)
4
+ stripe_event (1.1.0)
5
5
  activesupport (>= 3.1)
6
6
  stripe (~> 1.6)
7
7
 
@@ -42,9 +42,16 @@ GEM
42
42
  rake
43
43
  arel (2.2.3)
44
44
  builder (3.0.4)
45
+ coveralls (0.7.0)
46
+ multi_json (~> 1.3)
47
+ rest-client
48
+ simplecov (>= 0.7)
49
+ term-ansicolor
50
+ thor
45
51
  crack (0.4.1)
46
52
  safe_yaml (~> 0.9.0)
47
53
  diff-lcs (1.2.5)
54
+ docile (1.1.1)
48
55
  erubis (2.7.0)
49
56
  hike (1.2.3)
50
57
  i18n (0.6.9)
@@ -97,6 +104,11 @@ GEM
97
104
  rspec-expectations (~> 2.14.0)
98
105
  rspec-mocks (~> 2.14.0)
99
106
  safe_yaml (0.9.7)
107
+ simplecov (0.8.2)
108
+ docile (~> 1.1.0)
109
+ multi_json
110
+ simplecov-html (~> 0.8.0)
111
+ simplecov-html (0.8.0)
100
112
  sprockets (2.0.4)
101
113
  hike (~> 1.2)
102
114
  rack (~> 1.0)
@@ -105,8 +117,11 @@ GEM
105
117
  mime-types (~> 1.25)
106
118
  multi_json (>= 1.0.4, < 2)
107
119
  rest-client (~> 1.4)
120
+ term-ansicolor (1.2.2)
121
+ tins (~> 0.8)
108
122
  thor (0.14.6)
109
123
  tilt (1.4.1)
124
+ tins (0.13.1)
110
125
  treetop (1.4.15)
111
126
  polyglot
112
127
  polyglot (>= 0.3.1)
@@ -120,6 +135,7 @@ PLATFORMS
120
135
 
121
136
  DEPENDENCIES
122
137
  appraisal
138
+ coveralls
123
139
  rails (~> 3.1.0)
124
140
  rspec-rails (~> 2.12)
125
141
  stripe_event!
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- stripe_event (1.0.0)
4
+ stripe_event (1.1.0)
5
5
  activesupport (>= 3.1)
6
6
  stripe (~> 1.6)
7
7
 
@@ -41,9 +41,16 @@ GEM
41
41
  rake
42
42
  arel (3.0.3)
43
43
  builder (3.0.4)
44
+ coveralls (0.7.0)
45
+ multi_json (~> 1.3)
46
+ rest-client
47
+ simplecov (>= 0.7)
48
+ term-ansicolor
49
+ thor
44
50
  crack (0.4.1)
45
51
  safe_yaml (~> 0.9.0)
46
52
  diff-lcs (1.2.5)
53
+ docile (1.1.1)
47
54
  erubis (2.7.0)
48
55
  hike (1.2.3)
49
56
  i18n (0.6.9)
@@ -94,6 +101,11 @@ GEM
94
101
  rspec-expectations (~> 2.14.0)
95
102
  rspec-mocks (~> 2.14.0)
96
103
  safe_yaml (0.9.7)
104
+ simplecov (0.8.2)
105
+ docile (~> 1.1.0)
106
+ multi_json
107
+ simplecov-html (~> 0.8.0)
108
+ simplecov-html (0.8.0)
97
109
  sprockets (2.2.2)
98
110
  hike (~> 1.2)
99
111
  multi_json (~> 1.0)
@@ -103,8 +115,11 @@ GEM
103
115
  mime-types (~> 1.25)
104
116
  multi_json (>= 1.0.4, < 2)
105
117
  rest-client (~> 1.4)
118
+ term-ansicolor (1.2.2)
119
+ tins (~> 0.8)
106
120
  thor (0.18.1)
107
121
  tilt (1.4.1)
122
+ tins (0.13.1)
108
123
  treetop (1.4.15)
109
124
  polyglot
110
125
  polyglot (>= 0.3.1)
@@ -118,6 +133,7 @@ PLATFORMS
118
133
 
119
134
  DEPENDENCIES
120
135
  appraisal
136
+ coveralls
121
137
  rails (~> 3.2.0)
122
138
  rspec-rails (~> 2.12)
123
139
  stripe_event!
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- stripe_event (1.0.0)
4
+ stripe_event (1.1.0)
5
5
  activesupport (>= 3.1)
6
6
  stripe (~> 1.6)
7
7
 
@@ -39,9 +39,16 @@ GEM
39
39
  arel (4.0.1)
40
40
  atomic (1.1.14)
41
41
  builder (3.1.4)
42
+ coveralls (0.7.0)
43
+ multi_json (~> 1.3)
44
+ rest-client
45
+ simplecov (>= 0.7)
46
+ term-ansicolor
47
+ thor
42
48
  crack (0.4.1)
43
49
  safe_yaml (~> 0.9.0)
44
50
  diff-lcs (1.2.5)
51
+ docile (1.1.1)
45
52
  erubis (2.7.0)
46
53
  hike (1.2.3)
47
54
  i18n (0.6.9)
@@ -83,6 +90,11 @@ GEM
83
90
  rspec-expectations (~> 2.14.0)
84
91
  rspec-mocks (~> 2.14.0)
85
92
  safe_yaml (0.9.7)
93
+ simplecov (0.8.2)
94
+ docile (~> 1.1.0)
95
+ multi_json
96
+ simplecov-html (~> 0.8.0)
97
+ simplecov-html (0.8.0)
86
98
  sprockets (2.10.1)
87
99
  hike (~> 1.2)
88
100
  multi_json (~> 1.0)
@@ -96,10 +108,13 @@ GEM
96
108
  mime-types (~> 1.25)
97
109
  multi_json (>= 1.0.4, < 2)
98
110
  rest-client (~> 1.4)
111
+ term-ansicolor (1.2.2)
112
+ tins (~> 0.8)
99
113
  thor (0.18.1)
100
114
  thread_safe (0.1.3)
101
115
  atomic
102
116
  tilt (1.4.1)
117
+ tins (0.13.1)
103
118
  treetop (1.4.15)
104
119
  polyglot
105
120
  polyglot (>= 0.3.1)
@@ -113,6 +128,7 @@ PLATFORMS
113
128
 
114
129
  DEPENDENCIES
115
130
  appraisal
131
+ coveralls
116
132
  rails (~> 4.0.0)
117
133
  rspec-rails (~> 2.12)
118
134
  stripe_event!
@@ -6,9 +6,11 @@ module StripeEvent
6
6
  class << self
7
7
  attr_accessor :adapter, :backend, :event_retriever, :namespace
8
8
 
9
- def setup(&block)
10
- instance_eval(&block)
9
+ def configure(&block)
10
+ raise ArgumentError, "must provide a block" unless block_given?
11
+ block.arity.zero? ? instance_eval(&block) : yield(self)
11
12
  end
13
+ alias :setup :configure
12
14
 
13
15
  def instrument(params)
14
16
  begin
@@ -31,7 +33,7 @@ module StripeEvent
31
33
 
32
34
  class Namespace < Struct.new(:value, :delimiter)
33
35
  def call(name = nil)
34
- name ? "#{value}#{delimiter}#{name}" : value
36
+ "#{value}#{delimiter}#{name}"
35
37
  end
36
38
 
37
39
  def to_regexp(name = nil)
@@ -1,3 +1,3 @@
1
1
  module StripeEvent
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -6,6 +6,26 @@ describe StripeEvent do
6
6
  let(:charge_succeeded) { double('charge succeeded') }
7
7
  let(:charge_failed) { double('charge failed') }
8
8
 
9
+ describe ".configure" do
10
+ it "yields itself to the block" do
11
+ yielded = nil
12
+ StripeEvent.configure { |events| yielded = events }
13
+ expect(yielded).to eq StripeEvent
14
+ end
15
+
16
+ it "requires a block argument" do
17
+ expect { StripeEvent.configure }.to raise_error ArgumentError
18
+ end
19
+
20
+ describe ".setup - deprecated" do
21
+ it "evaluates the block in its own context" do
22
+ ctx = nil
23
+ StripeEvent.setup { ctx = self }
24
+ expect(ctx).to eq StripeEvent
25
+ end
26
+ end
27
+ end
28
+
9
29
  describe "subscribing to a specific event type" do
10
30
  before do
11
31
  expect(charge_succeeded).to receive(:[]).with(:type).and_return('charge.succeeded')
@@ -33,6 +53,41 @@ describe StripeEvent do
33
53
  end
34
54
  end
35
55
 
56
+ describe "subscribing to a namespace of event types" do
57
+ let(:card_created) { double('card created') }
58
+ let(:card_updated) { double('card updated') }
59
+
60
+ before do
61
+ expect(card_created).to receive(:[]).with(:type).and_return('customer.card.created')
62
+ expect(Stripe::Event).to receive(:retrieve).with('evt_card_created').and_return(card_created)
63
+
64
+ expect(card_updated).to receive(:[]).with(:type).and_return('customer.card.updated')
65
+ expect(Stripe::Event).to receive(:retrieve).with('evt_card_updated').and_return(card_updated)
66
+ end
67
+
68
+ context "with a block subscriber" do
69
+ it "calls the subscriber with any events in the namespace" do
70
+ StripeEvent.subscribe('customer.card', &subscriber)
71
+
72
+ StripeEvent.instrument(id: 'evt_card_created', type: 'customer.card.created')
73
+ StripeEvent.instrument(id: 'evt_card_updated', type: 'customer.card.updated')
74
+
75
+ expect(events).to eq [card_created, card_updated]
76
+ end
77
+ end
78
+
79
+ context "with a subscriber that responds to #call" do
80
+ it "calls the subscriber with any events in the namespace" do
81
+ StripeEvent.subscribe('customer.card.', subscriber)
82
+
83
+ StripeEvent.instrument(id: 'evt_card_updated', type: 'customer.card.updated')
84
+ StripeEvent.instrument(id: 'evt_card_created', type: 'customer.card.created')
85
+
86
+ expect(events).to eq [card_updated, card_created]
87
+ end
88
+ end
89
+ end
90
+
36
91
  describe "subscribing to all event types" do
37
92
  before do
38
93
  expect(charge_succeeded).to receive(:[]).with(:type).and_return('charge.succeeded')
@@ -84,7 +139,7 @@ describe StripeEvent do
84
139
  end
85
140
 
86
141
  it "returns the namespace given no arguments" do
87
- expect(namespace.call).to eq 'stripe_event'
142
+ expect(namespace.call).to eq 'stripe_event.'
88
143
  end
89
144
  end
90
145
 
@@ -1,3 +1,6 @@
1
+ require 'coveralls'
2
+ Coveralls.wear!
3
+
1
4
  require 'webmock/rspec'
2
5
  require File.expand_path('../../lib/stripe_event', __FILE__)
3
6
  Dir[File.expand_path('../spec/support/**/*.rb', __FILE__)].each { |f| require f }
@@ -24,4 +24,5 @@ Gem::Specification.new do |s|
24
24
  s.add_development_dependency "rspec-rails", "~> 2.12"
25
25
  s.add_development_dependency "webmock", "~> 1.9"
26
26
  s.add_development_dependency "appraisal"
27
+ s.add_development_dependency "coveralls"
27
28
  end
metadata CHANGED
@@ -1,97 +1,111 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stripe_event
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Danny Whalen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-19 00:00:00.000000000 Z
11
+ date: 2014-01-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '3.1'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '3.1'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: stripe
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '1.6'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.6'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rails
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '3.1'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.1'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec-rails
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ~>
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
61
  version: '2.12'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ~>
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '2.12'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: webmock
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ~>
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
75
  version: '1.9'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ~>
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '1.9'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: appraisal
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - '>='
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - '>='
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: coveralls
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
95
109
  - !ruby/object:Gem::Version
96
110
  version: '0'
97
111
  description: Stripe webhook integration for Rails applications.
@@ -100,9 +114,9 @@ executables: []
100
114
  extensions: []
101
115
  extra_rdoc_files: []
102
116
  files:
103
- - .gitignore
104
- - .rspec
105
- - .travis.yml
117
+ - ".gitignore"
118
+ - ".rspec"
119
+ - ".travis.yml"
106
120
  - Appraisals
107
121
  - CHANGELOG.md
108
122
  - Gemfile
@@ -168,17 +182,17 @@ require_paths:
168
182
  - lib
169
183
  required_ruby_version: !ruby/object:Gem::Requirement
170
184
  requirements:
171
- - - '>='
185
+ - - ">="
172
186
  - !ruby/object:Gem::Version
173
187
  version: '0'
174
188
  required_rubygems_version: !ruby/object:Gem::Requirement
175
189
  requirements:
176
- - - '>='
190
+ - - ">="
177
191
  - !ruby/object:Gem::Version
178
192
  version: '0'
179
193
  requirements: []
180
194
  rubyforge_project:
181
- rubygems_version: 2.0.14
195
+ rubygems_version: 2.2.0
182
196
  signing_key:
183
197
  specification_version: 4
184
198
  summary: Stripe webhook integration for Rails applications.