webhookr-recurly 0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/.travis.yml +9 -0
- data/Gemfile +20 -0
- data/Guardfile +26 -0
- data/MIT-LICENSE +22 -0
- data/README.md +118 -0
- data/Rakefile +51 -0
- data/lib/generators/webhookr/recurly/example_hooks_generator.rb +16 -0
- data/lib/generators/webhookr/recurly/init_generator.rb +24 -0
- data/lib/generators/webhookr/recurly/templates/recurly_hooks.rb +16 -0
- data/lib/webhookr-recurly.rb +54 -0
- data/lib/webhookr-recurly/version.rb +5 -0
- data/test/generators/webhookr/recurly/example_hooks_generator_tests.rb +24 -0
- data/test/generators/webhookr/recurly/init_generator_tests.rb +26 -0
- data/test/test_helper.rb +18 -0
- data/test/unit/webhookr-recurly/version_tests.rb +8 -0
- data/test/unit/webhookr-recurly_tests.rb +123 -0
- data/webhookr-recurly.gemspec +24 -0
- metadata +96 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 66d23a50439f5eca817d93a19ca1da8a40f03acc
|
4
|
+
data.tar.gz: f96b2e3e14633a5ac31f978badeb729fdc191e10
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 27d9377d0f06ef3cd3eb1b388ca639c967384afbaa6792bde0a02f1e734925c58ef39d525535c3a57c09244ba8a184cc11703c3baca225d2313525f86a53e948
|
7
|
+
data.tar.gz: 2c22dd453aeb8e634fb92891635dd448cbaa51482e4f4722244eb0a870ded37d5cce31104d76bfff638c36fa98034d6eda678028b7b341421ad23e0a5e162218
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.ruby-version
|
4
|
+
.ruby-gemset
|
5
|
+
.bundle
|
6
|
+
.config
|
7
|
+
.yardoc
|
8
|
+
Gemfile.lock
|
9
|
+
Gemfile.local
|
10
|
+
Guardfile.local
|
11
|
+
README.html
|
12
|
+
InstalledFiles
|
13
|
+
_yardoc
|
14
|
+
coverage
|
15
|
+
doc/
|
16
|
+
lib/bundler/man
|
17
|
+
pkg
|
18
|
+
rdoc
|
19
|
+
spec/reports
|
20
|
+
test/tmp
|
21
|
+
test/version_tmp
|
22
|
+
tmp
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
gemspec
|
4
|
+
|
5
|
+
group :development, :test do
|
6
|
+
gem "rake", "~> 10.0"
|
7
|
+
gem "minitest"
|
8
|
+
gem "minitest-reporters"
|
9
|
+
gem "em-websocket"
|
10
|
+
gem "guard"
|
11
|
+
gem "guard-minitest"
|
12
|
+
gem "guard-markdown"
|
13
|
+
gem "guard-livereload"
|
14
|
+
gem "simplecov", :require => false
|
15
|
+
end
|
16
|
+
|
17
|
+
if File.exists?('Gemfile.local')
|
18
|
+
instance_eval File.read('Gemfile.local')
|
19
|
+
end
|
20
|
+
|
data/Guardfile
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
|
2
|
+
guard 'minitest', :test_folders => 'test', :test_file_patterns => '*_tests.rb' do
|
3
|
+
watch(%r|^test/(.+)_test\.rb|)
|
4
|
+
watch(%r|^test/(.+)_tests\.rb|)
|
5
|
+
|
6
|
+
watch(%r|^lib/(.*)([^/]+)\.rb|) do |m|
|
7
|
+
"test/#{m[1]}#{m[2]}_tests.rb"
|
8
|
+
end
|
9
|
+
|
10
|
+
watch(%r|^test/test_helper\.rb|) do
|
11
|
+
"test"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
guard 'markdown', :convert_on_start => true do
|
16
|
+
watch ('README.md') { "./README.md|./README.html" }
|
17
|
+
end
|
18
|
+
|
19
|
+
guard 'livereload' do
|
20
|
+
watch('README.html')
|
21
|
+
end
|
22
|
+
|
23
|
+
if File.exists?('Guardfile.local')
|
24
|
+
instance_eval File.read('Guardfile.local')
|
25
|
+
end
|
26
|
+
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Todd Eichel <todd@toddeichel.com> and Zoocasa, Brokerage <code@zoocasa.com>
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person
|
4
|
+
obtaining a copy of this software and associated documentation
|
5
|
+
files (the "Software"), to deal in the Software without
|
6
|
+
restriction, including without limitation the rights to use,
|
7
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
copies of the Software, and to permit persons to whom the
|
9
|
+
Software is furnished to do so, subject to the following
|
10
|
+
conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
17
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
19
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
20
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
21
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
22
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
# Webhookr::Recurly
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/tfe/webhookr-recurly.png?branch=master)](https://travis-ci.org/tfe/webhookr-recurly)
|
4
|
+
[![Dependency Status](https://gemnasium.com/tfe/webhookr-recurly.png)](https://gemnasium.com/tfe/webhookr-recurly)
|
5
|
+
[![Code Climate](https://codeclimate.com/github/tfe/webhookr-recurly.png)](https://codeclimate.com/github/tfe/webhookr-recurly)
|
6
|
+
|
7
|
+
This gem is a plugin for [Webhookr](https://github.com/zoocasa/webhookr) that enables
|
8
|
+
your application to accept [webhooks from Recurly](https://docs.recurly.com/push-notifications).
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Add this line to your application's Gemfile:
|
13
|
+
|
14
|
+
gem 'webhookr-recurly'
|
15
|
+
|
16
|
+
Or install it yourself:
|
17
|
+
|
18
|
+
$ gem install webhookr-recurly
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
Once you have the gem installed run the generator to add the code to your initializer.
|
23
|
+
An initializer will be created if you do not have one.
|
24
|
+
|
25
|
+
```console
|
26
|
+
rails g webhookr:recurly:init *initializer_name* -s
|
27
|
+
```
|
28
|
+
|
29
|
+
Run the generator to create an example file to handle Recurly webhooks.
|
30
|
+
|
31
|
+
```console
|
32
|
+
rails g webhookr:recurly:example_hooks
|
33
|
+
```
|
34
|
+
|
35
|
+
Or create a Recurly handler class for any event that you want to handle. For example
|
36
|
+
to handle unsubscribes you would create a class as follows:
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
class RecurlyHooks
|
40
|
+
def canceled_subscription_notification(incoming)
|
41
|
+
# Your custom logic goes here.
|
42
|
+
User.sync_recurly_subscription(incoming.payload.account.account_code)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
```
|
46
|
+
|
47
|
+
For a complete list of events, and the payload format, see below.
|
48
|
+
|
49
|
+
Edit config/initializers/*initializer_name* and change the commented line to point to
|
50
|
+
your custom Recurly event handling class. If your class was called *RecurlyHooks*
|
51
|
+
the configuration line would look like this:
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
Webhookr::Recurly::Adapter.config.callback = RecurlyHooks
|
55
|
+
```
|
56
|
+
|
57
|
+
To see the list of Recurly URLs for your application can use when you configure
|
58
|
+
Recurly webhooks (https://[yoursite].recurly.com/configuration/notifications),
|
59
|
+
run the provided webhookr rake task:
|
60
|
+
|
61
|
+
```console
|
62
|
+
rake webhookr:services
|
63
|
+
```
|
64
|
+
|
65
|
+
Example output:
|
66
|
+
|
67
|
+
```console
|
68
|
+
recurly:
|
69
|
+
GET /webhookr/events/recurly/19xl64emxvn
|
70
|
+
POST /webhookr/events/recurly/19xl64emxvn
|
71
|
+
```
|
72
|
+
|
73
|
+
## Recurly Events & Payload
|
74
|
+
|
75
|
+
### Events
|
76
|
+
|
77
|
+
All webhook events are supported. For further information on events, see the
|
78
|
+
[Recurly documentation](https://docs.recurly.com/api/push-notifications).
|
79
|
+
|
80
|
+
### Payload
|
81
|
+
|
82
|
+
The payload is the full payload data from as per the [Recurly
|
83
|
+
documentation](https://docs.recurly.com/api/push-notifications), converted to an
|
84
|
+
OpenStruct for ease of access. Examples for the subscription canceled webhook:
|
85
|
+
|
86
|
+
```ruby
|
87
|
+
incoming.payload.account.account_code
|
88
|
+
incoming.payload.account.email
|
89
|
+
incoming.payload.subscription.state
|
90
|
+
incoming.payload.subscription.canceled_at
|
91
|
+
incoming.payload.subscription.expires_at
|
92
|
+
incoming.payload.subscription.plan.plan_code
|
93
|
+
incoming.payload.subscription.plan.name
|
94
|
+
```
|
95
|
+
|
96
|
+
### Versioning
|
97
|
+
This library aims to adhere to [Semantic Versioning 2.0.0](http://semver.org/). Violations of this scheme should be reported as
|
98
|
+
bugs. Specifically, if a minor or patch version is released that breaks backward compatibility, that
|
99
|
+
version should be immediately yanked and/or a new version should be immediately released that restores
|
100
|
+
compatibility. Breaking changes to the public API will only be introduced with new major versions. As a
|
101
|
+
result of this policy, once this gem reaches a 1.0 release, you can (and should) specify a dependency on
|
102
|
+
this gem using the [Pessimistic Version Constraint](http://docs.rubygems.org/read/chapter/16#page74) with
|
103
|
+
two digits of precision. For example:
|
104
|
+
|
105
|
+
spec.add_dependency 'webhookr-recurly', '~> 1.0'
|
106
|
+
|
107
|
+
While this gem is currently a 0.x release, suggestion is to require the exact version that works for your code:
|
108
|
+
|
109
|
+
spec.add_dependency 'webhookr-recurly', '0.1'
|
110
|
+
|
111
|
+
## License
|
112
|
+
|
113
|
+
webhookr-recurly is released under the [MIT license](http://www.opensource.org/licenses/MIT).
|
114
|
+
|
115
|
+
## Authors
|
116
|
+
|
117
|
+
* [Todd Eichel](https://github.com/tfe)
|
118
|
+
* [Gerry Power](https://github.com/gerrypower)
|
data/Rakefile
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
|
2
|
+
# -*- ruby -*-
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
require 'rubygems/package_task'
|
6
|
+
require 'rake/testtask'
|
7
|
+
require 'rdoc/task'
|
8
|
+
require 'bundler/gem_tasks'
|
9
|
+
|
10
|
+
$:.push File.expand_path(File.dirname(__FILE__), 'lib')
|
11
|
+
|
12
|
+
version = Webhookr::Recurly::VERSION
|
13
|
+
|
14
|
+
desc 'Test Webhookr Recurly'
|
15
|
+
Rake::TestTask.new(:test) do |t|
|
16
|
+
t.test_files = FileList['test/**/*_tests.rb']
|
17
|
+
t.verbose = !!ENV['VERBOSE_TESTS']
|
18
|
+
t.warning = !!ENV['WARNINGS']
|
19
|
+
end
|
20
|
+
|
21
|
+
desc 'Build docs'
|
22
|
+
Rake::RDocTask.new do |t|
|
23
|
+
t.main = 'README.md'
|
24
|
+
t.title = "Webhookr Recurly #{version}"
|
25
|
+
t.rdoc_dir = 'doc'
|
26
|
+
t.rdoc_files.include('README.md', 'MIT-LICENSE', 'lib/**/*.rb')
|
27
|
+
end
|
28
|
+
|
29
|
+
namespace :webhookr do
|
30
|
+
namespace:test do
|
31
|
+
desc 'Install gems in all Rubies'
|
32
|
+
task :install do
|
33
|
+
sh %{rbenv each -v bundle install}
|
34
|
+
end
|
35
|
+
|
36
|
+
desc 'Test with all Rubies'
|
37
|
+
task :test_versions do
|
38
|
+
sh %{rbenv each -v bundle exec rake test}
|
39
|
+
end
|
40
|
+
|
41
|
+
desc 'Update rails'
|
42
|
+
task :update_rails do
|
43
|
+
sh %{rbenv each -v bundle update rails}
|
44
|
+
end
|
45
|
+
|
46
|
+
desc 'Install and test all'
|
47
|
+
task :all => [:install, :test_versions]
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
task :default => :test
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Webhookr
|
2
|
+
module Recurly
|
3
|
+
module Generators
|
4
|
+
|
5
|
+
class ExampleHooksGenerator < Rails::Generators::Base
|
6
|
+
source_root File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
|
7
|
+
|
8
|
+
desc "Creates an example Recurly hook file: 'app/models/recurly_hooks.rb'"
|
9
|
+
def example_hooks
|
10
|
+
copy_file( "recurly_hooks.rb", "app/models/recurly_hooks.rb")
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'generators/webhookr/init_generator'
|
2
|
+
|
3
|
+
module Webhookr
|
4
|
+
module Recurly
|
5
|
+
module Generators
|
6
|
+
class InitGenerator < Webhookr::Generators::InitGenerator
|
7
|
+
|
8
|
+
desc "This generator updates the named initializer with Recurly options"
|
9
|
+
def init
|
10
|
+
super
|
11
|
+
append_to_file "config/initializers/#{file_name}.rb" do
|
12
|
+
plugin_initializer_text
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def plugin_initializer_text
|
17
|
+
"\nWebhookr::Recurly::Adapter.config.security_token = '#{generate_security_token}'" +
|
18
|
+
"\n# Uncomment the next line to include your custom Recurly handler\n" +
|
19
|
+
"# <-- Webhookr::Recurly::Adapter.config.callback = your_custom_class --> \n"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class RecurlyHooks
|
2
|
+
|
3
|
+
# All 'on_' handlers are optional. Omit any you do not require.
|
4
|
+
|
5
|
+
def on_canceled_subscription_notification(incoming)
|
6
|
+
payload = incoming.payload
|
7
|
+
# puts payload.account.account_code
|
8
|
+
# puts payload.account.email
|
9
|
+
# puts payload.subscription.state
|
10
|
+
# puts payload.subscription.canceled_at
|
11
|
+
# puts payload.subscription.expires_at
|
12
|
+
# puts payload.subscription.plan.plan_code
|
13
|
+
# puts payload.subscription.plan.name
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require "webhookr"
|
2
|
+
require "webhookr-recurly/version"
|
3
|
+
require "active_support/core_ext/module/attribute_accessors"
|
4
|
+
require "webhookr/ostruct_utils"
|
5
|
+
|
6
|
+
module Webhookr
|
7
|
+
module Recurly
|
8
|
+
class Adapter
|
9
|
+
SERVICE_NAME = 'recurly'
|
10
|
+
|
11
|
+
include Webhookr::Services::Adapter::Base
|
12
|
+
|
13
|
+
def self.process(raw_response)
|
14
|
+
new.process(raw_response)
|
15
|
+
end
|
16
|
+
|
17
|
+
def process(raw_response)
|
18
|
+
response = parse(raw_response)
|
19
|
+
event_type, payload = response.first
|
20
|
+
Webhookr::AdapterResponse.new(
|
21
|
+
SERVICE_NAME,
|
22
|
+
event_type,
|
23
|
+
OstructUtils.to_ostruct(payload)
|
24
|
+
)
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def parse(raw_response)
|
30
|
+
assert_valid_packet(
|
31
|
+
Hash.from_xml(raw_response)
|
32
|
+
)
|
33
|
+
end
|
34
|
+
|
35
|
+
def assert_valid_packet(parsed_response)
|
36
|
+
raise(Webhookr::InvalidPayloadError,
|
37
|
+
"Missing data"
|
38
|
+
) unless parsed_response.present?
|
39
|
+
|
40
|
+
raise(Webhookr::InvalidPayloadError,
|
41
|
+
"Missing event key in packet"
|
42
|
+
) unless parsed_response.keys.first.present?
|
43
|
+
|
44
|
+
raise(Webhookr::InvalidPayloadError,
|
45
|
+
"No data in the response"
|
46
|
+
) unless parsed_response[parsed_response.keys.first].present?
|
47
|
+
|
48
|
+
parsed_response
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
|
2
|
+
$: << File.join(File.dirname(__FILE__), %w{ .. .. .. })
|
3
|
+
require 'test_helper'
|
4
|
+
require 'generators/webhookr/recurly/example_hooks_generator'
|
5
|
+
|
6
|
+
class ExampleHooksGeneratorTests < Rails::Generators::TestCase
|
7
|
+
tests Webhookr::Recurly::Generators::ExampleHooksGenerator
|
8
|
+
destination File.expand_path("../../../tmp", File.dirname(__FILE__))
|
9
|
+
setup :prepare_destination
|
10
|
+
|
11
|
+
def setup
|
12
|
+
run_generator
|
13
|
+
end
|
14
|
+
|
15
|
+
test "it should create the example hook file" do
|
16
|
+
assert_file "app/models/recurly_hooks.rb"
|
17
|
+
end
|
18
|
+
|
19
|
+
test "it should on handlers" do
|
20
|
+
assert_file "app/models/recurly_hooks.rb" do |content|
|
21
|
+
assert_match(%r{on_canceled_subscription_notification}m, content)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
|
2
|
+
$: << File.join(File.dirname(__FILE__), %w{ .. .. .. })
|
3
|
+
require 'test_helper'
|
4
|
+
require 'generators/webhookr/recurly/init_generator'
|
5
|
+
|
6
|
+
class InitGeneratorTests < Rails::Generators::TestCase
|
7
|
+
tests Webhookr::Recurly::Generators::InitGenerator
|
8
|
+
destination File.expand_path("../../../tmp", File.dirname(__FILE__))
|
9
|
+
setup :prepare_destination
|
10
|
+
|
11
|
+
def setup
|
12
|
+
@name = "test_initializer"
|
13
|
+
@initializer = "config/initializers/#{@name}.rb"
|
14
|
+
run_generator Array.wrap(@name)
|
15
|
+
end
|
16
|
+
|
17
|
+
test "it should create the initializer" do
|
18
|
+
assert_file @initializer
|
19
|
+
end
|
20
|
+
|
21
|
+
test "it should have authorization information" do
|
22
|
+
assert_file @initializer do |content|
|
23
|
+
assert_match(%r{Webhookr::Recurly::Adapter\.config\.security_token}, content)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
SimpleCov.start
|
3
|
+
|
4
|
+
require 'minitest/autorun'
|
5
|
+
require 'minitest/reporters'
|
6
|
+
require 'rails'
|
7
|
+
require "rails/generators/test_case"
|
8
|
+
require File.expand_path('../../lib/webhookr-recurly.rb', __FILE__)
|
9
|
+
|
10
|
+
if RUBY_VERSION >= "1.9"
|
11
|
+
MiniTest::Reporters.use!(MiniTest::Reporters::SpecReporter.new)
|
12
|
+
end
|
13
|
+
|
14
|
+
puts "Webhookr #{Webhookr::VERSION}"
|
15
|
+
puts "Webhookr::Recurly #{Webhookr::Recurly::VERSION}"
|
16
|
+
puts "Rails #{Rails::VERSION::STRING}"
|
17
|
+
puts "Ruby #{RUBY_VERSION}-p#{RUBY_PATCHLEVEL} - #{RbConfig::CONFIG['RUBY_INSTALL_NAME']}"
|
18
|
+
|
@@ -0,0 +1,123 @@
|
|
1
|
+
|
2
|
+
$: << File.join(File.dirname(__FILE__), "..")
|
3
|
+
require 'test_helper'
|
4
|
+
|
5
|
+
describe Webhookr::Recurly::Adapter do
|
6
|
+
|
7
|
+
before do
|
8
|
+
@valid_response = <<-XML
|
9
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
10
|
+
<canceled_subscription_notification>
|
11
|
+
<account>
|
12
|
+
<account_code>1</account_code>
|
13
|
+
<username nil="true"></username>
|
14
|
+
<email>verena@example.com</email>
|
15
|
+
<first_name>Verena</first_name>
|
16
|
+
<last_name>Example</last_name>
|
17
|
+
<company_name nil="true"></company_name>
|
18
|
+
</account>
|
19
|
+
<subscription>
|
20
|
+
<plan>
|
21
|
+
<plan_code>1dpt</plan_code>
|
22
|
+
<name>Subscription One</name>
|
23
|
+
</plan>
|
24
|
+
<uuid>dccd742f4710e78515714d275839f891</uuid>
|
25
|
+
<state>canceled</state>
|
26
|
+
<quantity type="integer">1</quantity>
|
27
|
+
<total_amount_in_cents type="integer">200</total_amount_in_cents>
|
28
|
+
<activated_at type="datetime">2010-09-23T22:05:03Z</activated_at>
|
29
|
+
<canceled_at type="datetime">2010-09-23T22:05:43Z</canceled_at>
|
30
|
+
<expires_at type="datetime">2010-09-24T22:05:03Z</expires_at>
|
31
|
+
<current_period_started_at type="datetime">2010-09-23T22:05:03Z</current_period_started_at>
|
32
|
+
<current_period_ends_at type="datetime">2010-09-24T22:05:03Z</current_period_ends_at>
|
33
|
+
<trial_started_at nil="true" type="datetime"></trial_started_at>
|
34
|
+
<trial_ends_at nil="true" type="datetime"></trial_ends_at>
|
35
|
+
<collection_method>automatic</collection_method>
|
36
|
+
</subscription>
|
37
|
+
</canceled_subscription_notification>
|
38
|
+
XML
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "class" do
|
42
|
+
|
43
|
+
subject { Webhookr::Recurly::Adapter }
|
44
|
+
|
45
|
+
it "must support process" do
|
46
|
+
subject.must_respond_to(:process)
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should not return an error for a valid payload" do
|
50
|
+
lambda {
|
51
|
+
subject.process(@valid_response)
|
52
|
+
}.must_be_silent
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "instance" do
|
58
|
+
subject { Webhookr::Recurly::Adapter.new }
|
59
|
+
|
60
|
+
it "should not return an error for a valid packet" do
|
61
|
+
lambda {
|
62
|
+
subject.process(@valid_response)
|
63
|
+
}.must_be_silent
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should raise Webhookr::InvalidPayloadError for no data" do
|
67
|
+
lambda {
|
68
|
+
subject.process("")
|
69
|
+
}.must_raise(Webhookr::InvalidPayloadError)
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should raise Webhookr::InvalidPayloadError for a missing event type" do
|
73
|
+
lambda {
|
74
|
+
subject.process("<canceled_subscription_notification />")
|
75
|
+
}.must_raise(Webhookr::InvalidPayloadError)
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should raise Webhookr::InvalidPayloadError for a missing payload" do
|
79
|
+
lambda {
|
80
|
+
subject.process("<canceled_subscription_notification />")
|
81
|
+
}.must_raise(Webhookr::InvalidPayloadError)
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
|
86
|
+
describe "response" do
|
87
|
+
before do
|
88
|
+
@adapter = Webhookr::Recurly::Adapter.new
|
89
|
+
end
|
90
|
+
|
91
|
+
subject { @adapter.process(@valid_response) }
|
92
|
+
|
93
|
+
it "must respond to service_name" do
|
94
|
+
subject.must_respond_to(:service_name)
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should return the correct service name" do
|
98
|
+
assert_equal(Webhookr::Recurly::Adapter::SERVICE_NAME, subject.service_name)
|
99
|
+
end
|
100
|
+
|
101
|
+
it "must respond to event_type" do
|
102
|
+
subject.must_respond_to(:event_type)
|
103
|
+
end
|
104
|
+
|
105
|
+
it "should return the correct event type" do
|
106
|
+
assert_equal("canceled_subscription_notification", subject.event_type)
|
107
|
+
end
|
108
|
+
|
109
|
+
it "must respond to payload" do
|
110
|
+
subject.must_respond_to(:payload)
|
111
|
+
end
|
112
|
+
|
113
|
+
it "should return the correct data" do
|
114
|
+
assert_equal("canceled", subject.payload.subscription.state)
|
115
|
+
end
|
116
|
+
|
117
|
+
it "should return nested data correctly" do
|
118
|
+
assert_equal("Subscription One", subject.payload.subscription.plan.name)
|
119
|
+
end
|
120
|
+
|
121
|
+
end
|
122
|
+
|
123
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'webhookr-recurly/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "webhookr-recurly"
|
8
|
+
gem.version = Webhookr::Recurly::VERSION
|
9
|
+
gem.required_rubygems_version = Gem::Requirement.new(">= 0") if gem.respond_to? :required_rubygems_version=
|
10
|
+
gem.authors = ["Todd Eichel", "Gerry Power"]
|
11
|
+
gem.email = ["todd@toddeichel.com", "code@zoocasa.com"]
|
12
|
+
gem.description = "A webhookr extension to support Recurly webhooks."
|
13
|
+
gem.summary = gem.description
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($\)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.homepage = "http://github.com/tfe/webhookr-recurly"
|
19
|
+
gem.require_paths = ["lib"]
|
20
|
+
|
21
|
+
gem.add_dependency("webhookr")
|
22
|
+
gem.add_dependency("activesupport", [">= 3.1"])
|
23
|
+
end
|
24
|
+
|
metadata
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: webhookr-recurly
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Todd Eichel
|
8
|
+
- Gerry Power
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-09-18 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: webhookr
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ">="
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: activesupport
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '3.1'
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '3.1'
|
42
|
+
description: A webhookr extension to support Recurly webhooks.
|
43
|
+
email:
|
44
|
+
- todd@toddeichel.com
|
45
|
+
- code@zoocasa.com
|
46
|
+
executables: []
|
47
|
+
extensions: []
|
48
|
+
extra_rdoc_files: []
|
49
|
+
files:
|
50
|
+
- ".gitignore"
|
51
|
+
- ".travis.yml"
|
52
|
+
- Gemfile
|
53
|
+
- Guardfile
|
54
|
+
- MIT-LICENSE
|
55
|
+
- README.md
|
56
|
+
- Rakefile
|
57
|
+
- lib/generators/webhookr/recurly/example_hooks_generator.rb
|
58
|
+
- lib/generators/webhookr/recurly/init_generator.rb
|
59
|
+
- lib/generators/webhookr/recurly/templates/recurly_hooks.rb
|
60
|
+
- lib/webhookr-recurly.rb
|
61
|
+
- lib/webhookr-recurly/version.rb
|
62
|
+
- test/generators/webhookr/recurly/example_hooks_generator_tests.rb
|
63
|
+
- test/generators/webhookr/recurly/init_generator_tests.rb
|
64
|
+
- test/test_helper.rb
|
65
|
+
- test/unit/webhookr-recurly/version_tests.rb
|
66
|
+
- test/unit/webhookr-recurly_tests.rb
|
67
|
+
- webhookr-recurly.gemspec
|
68
|
+
homepage: http://github.com/tfe/webhookr-recurly
|
69
|
+
licenses: []
|
70
|
+
metadata: {}
|
71
|
+
post_install_message:
|
72
|
+
rdoc_options: []
|
73
|
+
require_paths:
|
74
|
+
- lib
|
75
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
requirements: []
|
86
|
+
rubyforge_project:
|
87
|
+
rubygems_version: 2.2.2
|
88
|
+
signing_key:
|
89
|
+
specification_version: 4
|
90
|
+
summary: A webhookr extension to support Recurly webhooks.
|
91
|
+
test_files:
|
92
|
+
- test/generators/webhookr/recurly/example_hooks_generator_tests.rb
|
93
|
+
- test/generators/webhookr/recurly/init_generator_tests.rb
|
94
|
+
- test/test_helper.rb
|
95
|
+
- test/unit/webhookr-recurly/version_tests.rb
|
96
|
+
- test/unit/webhookr-recurly_tests.rb
|