stripe_event 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. data/.gitignore +8 -0
  2. data/.rspec +2 -0
  3. data/.travis.yml +16 -0
  4. data/Appraisals +11 -0
  5. data/CHANGELOG.md +42 -0
  6. data/Gemfile +2 -0
  7. data/LICENSE.md +3 -1
  8. data/README.md +8 -6
  9. data/Rakefile +12 -1
  10. data/app/controllers/stripe_event/webhook_controller.rb +1 -2
  11. data/config/routes.rb +1 -1
  12. data/dashboard-webhook.png +0 -0
  13. data/gemfiles/rails3.1.gemfile +7 -0
  14. data/gemfiles/rails3.1.gemfile.lock +122 -0
  15. data/gemfiles/rails3.2.gemfile +7 -0
  16. data/gemfiles/rails3.2.gemfile.lock +122 -0
  17. data/gemfiles/rails_master.gemfile +7 -0
  18. data/gemfiles/rails_master.gemfile.lock +126 -0
  19. data/lib/stripe_event.rb +23 -14
  20. data/lib/stripe_event/version.rb +1 -1
  21. data/spec/controllers/webhook_controller_spec.rb +28 -0
  22. data/spec/dummy/README.rdoc +261 -0
  23. data/spec/dummy/Rakefile +7 -0
  24. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  25. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  26. data/spec/dummy/app/mailers/.gitkeep +0 -0
  27. data/spec/dummy/app/models/.gitkeep +0 -0
  28. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  29. data/spec/dummy/config.ru +4 -0
  30. data/spec/dummy/config/application.rb +64 -0
  31. data/spec/dummy/config/boot.rb +10 -0
  32. data/spec/dummy/config/database.yml +25 -0
  33. data/spec/dummy/config/environment.rb +5 -0
  34. data/spec/dummy/config/environments/development.rb +37 -0
  35. data/spec/dummy/config/environments/production.rb +67 -0
  36. data/spec/dummy/config/environments/test.rb +40 -0
  37. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  38. data/spec/dummy/config/initializers/inflections.rb +15 -0
  39. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  40. data/spec/dummy/config/initializers/secret_token.rb +16 -0
  41. data/spec/dummy/config/initializers/session_store.rb +8 -0
  42. data/spec/dummy/config/initializers/stripe.rb +1 -0
  43. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  44. data/spec/dummy/config/locales/en.yml +5 -0
  45. data/spec/dummy/config/routes.rb +3 -0
  46. data/spec/dummy/lib/assets/.gitkeep +0 -0
  47. data/spec/dummy/log/.gitkeep +0 -0
  48. data/spec/dummy/public/404.html +26 -0
  49. data/spec/dummy/public/422.html +26 -0
  50. data/spec/dummy/public/500.html +25 -0
  51. data/spec/dummy/public/favicon.ico +0 -0
  52. data/spec/dummy/script/rails +6 -0
  53. data/spec/lib/stripe_event_spec.rb +45 -0
  54. data/spec/spec_helper.rb +32 -0
  55. data/spec/support/active_support_helper.rb +15 -0
  56. data/spec/support/core_ext.rb +4 -0
  57. data/spec/support/fixture_helper.rb +10 -0
  58. data/spec/support/fixtures/evt_charge_succeeded.json +46 -0
  59. data/spec/support/fixtures/evt_invalid_id.json +7 -0
  60. data/stripe_event.gemspec +26 -0
  61. metadata +125 -12
  62. data/lib/stripe_event/publisher.rb +0 -12
  63. data/lib/stripe_event/subscriber.rb +0 -26
@@ -0,0 +1,25 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/500.html -->
21
+ <div class="dialog">
22
+ <h1>We're sorry, but something went wrong.</h1>
23
+ </div>
24
+ </body>
25
+ </html>
File without changes
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
3
+
4
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
5
+ require File.expand_path('../../config/boot', __FILE__)
6
+ require 'rails/commands'
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+
3
+ describe StripeEvent do
4
+ let(:event_type) { StripeEvent::TYPE_LIST.sample }
5
+
6
+ it "backend defaults to AS::Notifications" do
7
+ expect(described_class.backend).to eq ActiveSupport::Notifications
8
+ end
9
+
10
+ it "registers a subscriber" do
11
+ subscriber = described_class.subscribe(event_type) { |e| }
12
+ subscribers = subscribers_for_type(event_type)
13
+ expect(subscribers).to eq [subscriber]
14
+ end
15
+
16
+ it "registers subscribers within a parent block" do
17
+ described_class.setup do
18
+ subscribe('invoice.payment_succeeded') { |e| }
19
+ end
20
+ subscribers = subscribers_for_type('invoice.payment_succeeded')
21
+ expect(subscribers).to_not be_empty
22
+ end
23
+
24
+ it "passes only the event object to the subscribed block" do
25
+ event = { :type => event_type }
26
+
27
+ expect { |block|
28
+ described_class.subscribe(event_type, &block)
29
+ described_class.publish(event)
30
+ }.to yield_with_args(event)
31
+ end
32
+
33
+ it "uses Stripe::Event as the default event retriever" do
34
+ Stripe::Event.should_receive(:retrieve).with('1')
35
+ described_class.event_retriever.call(:id => '1')
36
+ end
37
+
38
+ it "allows setting an event_retriever" do
39
+ params = { :id => '1' }
40
+
41
+ described_class.event_retriever = Proc.new { |arg| arg }
42
+ event = described_class.event_retriever.call(params)
43
+ expect(event).to eq params
44
+ end
45
+ end
@@ -0,0 +1,32 @@
1
+ # This file is copied to spec/ when you run 'rails generate rspec:install'
2
+ ENV["RAILS_ENV"] ||= 'test'
3
+ require File.expand_path("../dummy/config/environment", __FILE__)
4
+ require 'rspec/rails'
5
+ require 'rspec/autorun'
6
+ require 'webmock/rspec'
7
+
8
+ ENGINE_RAILS_ROOT = File.join(File.dirname(__FILE__), '../')
9
+
10
+ # Requires supporting ruby files with custom matchers and macros, etc,
11
+ # in spec/support/ and its subdirectories.
12
+ Dir[File.join(ENGINE_RAILS_ROOT, "spec/support/**/*.rb")].each {|f| require f }
13
+
14
+ RSpec.configure do |config|
15
+ config.include(FixtureHelper)
16
+ config.include(ActiveSupportHelper)
17
+
18
+ config.order = 'random'
19
+
20
+ config.expect_with :rspec do |c|
21
+ c.syntax = :expect
22
+ end
23
+
24
+ config.before do
25
+ @_event_retriever = StripeEvent.event_retriever
26
+ clear_subscribers_for_list(StripeEvent::TYPE_LIST)
27
+ end
28
+
29
+ config.after do
30
+ StripeEvent.event_retriever = @_event_retriever
31
+ end
32
+ end
@@ -0,0 +1,15 @@
1
+ module ActiveSupportHelper
2
+ def clear_subscribers_for_list(type_list)
3
+ type_list.each do |type|
4
+ subscribers_for_type(type).each { |s| unsubscribe(s) }
5
+ end
6
+ end
7
+
8
+ def subscribers_for_type(name)
9
+ ActiveSupport::Notifications.notifier.listeners_for(name)
10
+ end
11
+
12
+ def unsubscribe(subscriber)
13
+ ActiveSupport::Notifications.notifier.unsubscribe(subscriber)
14
+ end
15
+ end
@@ -0,0 +1,4 @@
1
+ class Set
2
+ # Just for tests
3
+ delegate :sample, :to => :to_a
4
+ end
@@ -0,0 +1,10 @@
1
+ module FixtureHelper
2
+ def stub_event(identifier, status = 200)
3
+ stub_request(:get, "https://api.stripe.com/v1/events/#{identifier}").
4
+ to_return(:status => status, :body => get_fixture(identifier), :headers => {})
5
+ end
6
+
7
+ def get_fixture(name)
8
+ File.read("spec/support/fixtures/#{name}.json")
9
+ end
10
+ end
@@ -0,0 +1,46 @@
1
+ {
2
+ "created": 1335427082,
3
+ "id": "evt_charge_succeeded",
4
+ "livemode": false,
5
+ "object": "event",
6
+ "pending_webhooks": 0,
7
+ "type": "charge.succeeded",
8
+ "data": {
9
+ "object": {
10
+ "amount": 3279,
11
+ "amount_refunded": 0,
12
+ "created": 1335427082,
13
+ "currency": "usd",
14
+ "customer": null,
15
+ "description": "order_id=21 email=jimmorrison@example.com",
16
+ "disputed": false,
17
+ "failure_message": null,
18
+ "fee": 0,
19
+ "id": "ch_00000000000000",
20
+ "invoice": null,
21
+ "livemode": false,
22
+ "object": "charge",
23
+ "paid": true,
24
+ "refunded": false,
25
+ "card": {
26
+ "address_country": null,
27
+ "address_line1": "4130 N. Paradise Way",
28
+ "address_line1_check": "pass",
29
+ "address_line2": "",
30
+ "address_state": "AZ",
31
+ "address_zip": "85251",
32
+ "address_zip_check": "pass",
33
+ "country": "US",
34
+ "cvc_check": "pass",
35
+ "exp_month": 1,
36
+ "exp_year": 2013,
37
+ "fingerprint": "5twio8INGMQkPl6M",
38
+ "id": "cc_00000000000000",
39
+ "last4": "4242",
40
+ "name": "Jim Morrison",
41
+ "object": "card",
42
+ "type": "Visa"
43
+ }
44
+ }
45
+ }
46
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "error": {
3
+ "message": "No such notification: invalid-id",
4
+ "param": "id",
5
+ "type": "invalid_request_error"
6
+ }
7
+ }
@@ -0,0 +1,26 @@
1
+ $:.push File.expand_path("../lib", __FILE__)
2
+
3
+ # Maintain your gem's version:
4
+ require "stripe_event/version"
5
+
6
+ # Describe your gem and declare its dependencies:
7
+ Gem::Specification.new do |s|
8
+ s.name = "stripe_event"
9
+ s.version = StripeEvent::VERSION
10
+ s.license = "MIT"
11
+ s.authors = ["Danny Whalen"]
12
+ s.email = ["dwhalen@integrallis.com"]
13
+ s.homepage = "https://github.com/integrallis/stripe_event"
14
+ s.summary = "Stripe webhook integration for Rails applications."
15
+ s.description = "Stripe webhook integration for Rails applications."
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- Appraisals {spec,gemfiles}/*`.split("\n")
19
+
20
+ s.add_dependency "rails", ">= 3.1"
21
+ s.add_dependency "stripe", "~> 1.6"
22
+
23
+ s.add_development_dependency "rspec-rails", "~> 2.12"
24
+ s.add_development_dependency "webmock", "~> 1.9"
25
+ s.add_development_dependency "appraisal"
26
+ end
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.5.0
4
+ version: 0.6.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,14 +9,14 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-16 00:00:00.000000000 Z
12
+ date: 2013-03-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
- - - ~>
19
+ - - ! '>='
20
20
  - !ruby/object:Gem::Version
21
21
  version: '3.1'
22
22
  type: :runtime
@@ -24,7 +24,7 @@ dependencies:
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  none: false
26
26
  requirements:
27
- - - ~>
27
+ - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
29
  version: '3.1'
30
30
  - !ruby/object:Gem::Dependency
@@ -75,6 +75,22 @@ dependencies:
75
75
  - - ~>
76
76
  - !ruby/object:Gem::Version
77
77
  version: '1.9'
78
+ - !ruby/object:Gem::Dependency
79
+ name: appraisal
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
78
94
  description: Stripe webhook integration for Rails applications.
79
95
  email:
80
96
  - dwhalen@integrallis.com
@@ -82,16 +98,67 @@ executables: []
82
98
  extensions: []
83
99
  extra_rdoc_files: []
84
100
  files:
101
+ - .gitignore
102
+ - .rspec
103
+ - .travis.yml
104
+ - Appraisals
105
+ - CHANGELOG.md
106
+ - Gemfile
107
+ - LICENSE.md
108
+ - README.md
109
+ - Rakefile
85
110
  - app/controllers/stripe_event/webhook_controller.rb
86
111
  - config/routes.rb
112
+ - dashboard-webhook.png
113
+ - gemfiles/rails3.1.gemfile
114
+ - gemfiles/rails3.1.gemfile.lock
115
+ - gemfiles/rails3.2.gemfile
116
+ - gemfiles/rails3.2.gemfile.lock
117
+ - gemfiles/rails_master.gemfile
118
+ - gemfiles/rails_master.gemfile.lock
119
+ - lib/stripe_event.rb
87
120
  - lib/stripe_event/engine.rb
88
- - lib/stripe_event/publisher.rb
89
- - lib/stripe_event/subscriber.rb
90
121
  - lib/stripe_event/version.rb
91
- - lib/stripe_event.rb
92
- - LICENSE.md
93
- - Rakefile
94
- - README.md
122
+ - spec/controllers/webhook_controller_spec.rb
123
+ - spec/dummy/README.rdoc
124
+ - spec/dummy/Rakefile
125
+ - spec/dummy/app/controllers/application_controller.rb
126
+ - spec/dummy/app/helpers/application_helper.rb
127
+ - spec/dummy/app/mailers/.gitkeep
128
+ - spec/dummy/app/models/.gitkeep
129
+ - spec/dummy/app/views/layouts/application.html.erb
130
+ - spec/dummy/config.ru
131
+ - spec/dummy/config/application.rb
132
+ - spec/dummy/config/boot.rb
133
+ - spec/dummy/config/database.yml
134
+ - spec/dummy/config/environment.rb
135
+ - spec/dummy/config/environments/development.rb
136
+ - spec/dummy/config/environments/production.rb
137
+ - spec/dummy/config/environments/test.rb
138
+ - spec/dummy/config/initializers/backtrace_silencers.rb
139
+ - spec/dummy/config/initializers/inflections.rb
140
+ - spec/dummy/config/initializers/mime_types.rb
141
+ - spec/dummy/config/initializers/secret_token.rb
142
+ - spec/dummy/config/initializers/session_store.rb
143
+ - spec/dummy/config/initializers/stripe.rb
144
+ - spec/dummy/config/initializers/wrap_parameters.rb
145
+ - spec/dummy/config/locales/en.yml
146
+ - spec/dummy/config/routes.rb
147
+ - spec/dummy/lib/assets/.gitkeep
148
+ - spec/dummy/log/.gitkeep
149
+ - spec/dummy/public/404.html
150
+ - spec/dummy/public/422.html
151
+ - spec/dummy/public/500.html
152
+ - spec/dummy/public/favicon.ico
153
+ - spec/dummy/script/rails
154
+ - spec/lib/stripe_event_spec.rb
155
+ - spec/spec_helper.rb
156
+ - spec/support/active_support_helper.rb
157
+ - spec/support/core_ext.rb
158
+ - spec/support/fixture_helper.rb
159
+ - spec/support/fixtures/evt_charge_succeeded.json
160
+ - spec/support/fixtures/evt_invalid_id.json
161
+ - stripe_event.gemspec
95
162
  homepage: https://github.com/integrallis/stripe_event
96
163
  licenses:
97
164
  - MIT
@@ -113,8 +180,54 @@ required_rubygems_version: !ruby/object:Gem::Requirement
113
180
  version: '0'
114
181
  requirements: []
115
182
  rubyforge_project:
116
- rubygems_version: 1.8.24
183
+ rubygems_version: 1.8.25
117
184
  signing_key:
118
185
  specification_version: 3
119
186
  summary: Stripe webhook integration for Rails applications.
120
- test_files: []
187
+ test_files:
188
+ - Appraisals
189
+ - gemfiles/rails3.1.gemfile
190
+ - gemfiles/rails3.1.gemfile.lock
191
+ - gemfiles/rails3.2.gemfile
192
+ - gemfiles/rails3.2.gemfile.lock
193
+ - gemfiles/rails_master.gemfile
194
+ - gemfiles/rails_master.gemfile.lock
195
+ - spec/controllers/webhook_controller_spec.rb
196
+ - spec/dummy/README.rdoc
197
+ - spec/dummy/Rakefile
198
+ - spec/dummy/app/controllers/application_controller.rb
199
+ - spec/dummy/app/helpers/application_helper.rb
200
+ - spec/dummy/app/mailers/.gitkeep
201
+ - spec/dummy/app/models/.gitkeep
202
+ - spec/dummy/app/views/layouts/application.html.erb
203
+ - spec/dummy/config.ru
204
+ - spec/dummy/config/application.rb
205
+ - spec/dummy/config/boot.rb
206
+ - spec/dummy/config/database.yml
207
+ - spec/dummy/config/environment.rb
208
+ - spec/dummy/config/environments/development.rb
209
+ - spec/dummy/config/environments/production.rb
210
+ - spec/dummy/config/environments/test.rb
211
+ - spec/dummy/config/initializers/backtrace_silencers.rb
212
+ - spec/dummy/config/initializers/inflections.rb
213
+ - spec/dummy/config/initializers/mime_types.rb
214
+ - spec/dummy/config/initializers/secret_token.rb
215
+ - spec/dummy/config/initializers/session_store.rb
216
+ - spec/dummy/config/initializers/stripe.rb
217
+ - spec/dummy/config/initializers/wrap_parameters.rb
218
+ - spec/dummy/config/locales/en.yml
219
+ - spec/dummy/config/routes.rb
220
+ - spec/dummy/lib/assets/.gitkeep
221
+ - spec/dummy/log/.gitkeep
222
+ - spec/dummy/public/404.html
223
+ - spec/dummy/public/422.html
224
+ - spec/dummy/public/500.html
225
+ - spec/dummy/public/favicon.ico
226
+ - spec/dummy/script/rails
227
+ - spec/lib/stripe_event_spec.rb
228
+ - spec/spec_helper.rb
229
+ - spec/support/active_support_helper.rb
230
+ - spec/support/core_ext.rb
231
+ - spec/support/fixture_helper.rb
232
+ - spec/support/fixtures/evt_charge_succeeded.json
233
+ - spec/support/fixtures/evt_invalid_id.json
@@ -1,12 +0,0 @@
1
- module StripeEvent
2
- class Publisher < Struct.new(:event)
3
- def instrument
4
- ActiveSupport::Notifications.instrument(type, event)
5
- end
6
-
7
- def type
8
- return event[:type] if event[:type].present?
9
- raise InvalidEventTypeError.new("Event type was not present for: #{event}")
10
- end
11
- end
12
- end
@@ -1,26 +0,0 @@
1
- module StripeEvent
2
- class Subscriber
3
- def initialize(*names)
4
- @names = names
5
- assert_valid_types!
6
- end
7
-
8
- def register(&block)
9
- ActiveSupport::Notifications.subscribe(pattern) do |*args|
10
- event = ActiveSupport::Notifications::Event.new(*args)
11
- block.call(event.payload)
12
- end
13
- end
14
-
15
- def pattern
16
- Regexp.union(@names.empty? ? TYPE_LIST.to_a : @names)
17
- end
18
-
19
- private
20
-
21
- def assert_valid_types!
22
- invalid_names = @names.select { |name| !TYPE_LIST.include?(name) }
23
- raise InvalidEventTypeError.new(invalid_names) if invalid_names.any?
24
- end
25
- end
26
- end