chargify-loops 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0a3c39b9509a9820dd206cb25b34cbc70d86ba99
4
+ data.tar.gz: b66dec49887a8d82fa6a6d65ae1965b01163f40b
5
+ SHA512:
6
+ metadata.gz: 9f89a89df48b7d7508d2e6e4c1d7d0e7c1eebca93f3e96a38d2f9cce58bfaf8697545b09a36db04eb72d4c2f014b4a3943ddc8a120824d87e8f51e61497760a0
7
+ data.tar.gz: 65d4344ee232dc30e8830e0f7e34795e06825d815cfd7585b935ed4af5cde7549cb681a5aa35a222f2f2f71636274cd80bc185f67849b66858ba3a3bf37fffbe
data/Gemfile CHANGED
@@ -1,7 +1,5 @@
1
1
  source :rubygems
2
2
 
3
- gem 'combustion',
4
- :git => 'git://github.com/freelancing-god/combustion.git',
5
- :ref => 'cd3ccae'
3
+ gem 'combustion', '0.5.0'
6
4
 
7
5
  gemspec
@@ -8,7 +8,7 @@ h2. Installation and Usage
8
8
 
9
9
  Add the following to your Gemfile:
10
10
 
11
- <pre><code>gem 'chargify-loops', '~> 0.1.0'</code></pre>
11
+ <pre><code>gem 'chargify-loops', '~> 0.3.0'</code></pre>
12
12
 
13
13
  Then add an initializer for your loops, and provide your shared key:
14
14
 
@@ -21,6 +21,11 @@ end
21
21
 
22
22
  Chargify::Loops.loop! :payment_failure do |payload|
23
23
  Banker.loan payload['payment']['amount_in_cents']
24
+ end
25
+
26
+ # Or catch all events:
27
+ Chargify::Loops.loop! :all do |event, payload|
28
+ Events.store event, payload
24
29
  end</code></pre>
25
30
 
26
31
  If a web hook is invalid, it'll never hit your loops - so you're only dealing with valid hook requests. All hash keys will be strings (I normally prefer symbols, but hashes within hashes had string keys, so opting with that as a default).
@@ -1,18 +1,25 @@
1
1
  module Chargify
2
2
  module Loops
3
3
  def self.delegate_hook(event, payload)
4
- loops[event] && loops[event].each do |block|
4
+ loops[event].each do |block|
5
5
  block.call payload
6
6
  end
7
+
8
+ loops[:all].each do |block|
9
+ block.call event, payload
10
+ end
7
11
  end
8
12
 
9
13
  def self.loops
10
- @loops ||= {}
14
+ @loops ||= Hash.new { |hash, key| hash[key] = [] }
11
15
  end
12
16
 
13
17
  def self.loop!(event, &block)
14
- loops[event] ||= []
15
- loops[event] << block
18
+ events = event.kind_of?(Array) ? event : [event]
19
+ events.each do |event|
20
+ loops[event] ||= []
21
+ loops[event] << block
22
+ end
16
23
  end
17
24
 
18
25
  def self.shared_key
@@ -1,5 +1,5 @@
1
1
  module Chargify
2
2
  module Loops
3
- VERSION = '0.2.0'
3
+ VERSION = '0.3.0'
4
4
  end
5
5
  end
@@ -22,6 +22,15 @@ describe Chargify::Loops do
22
22
  it "does not complain if there's no loops for a given hook" do
23
23
  Chargify::Loops.delegate_hook :alpha, :foo
24
24
  end
25
+
26
+ it "calls :all loops for all hooks" do
27
+ Chargify::Loops.loops[:all] = [alpha_hook, beta_hook]
28
+
29
+ alpha_hook.should_receive(:call).with(:alpha, :foo)
30
+ beta_hook.should_receive(:call).with(:alpha, :foo)
31
+
32
+ Chargify::Loops.delegate_hook :alpha, :foo
33
+ end
25
34
  end
26
35
 
27
36
  describe '.loop!' do
@@ -32,5 +41,15 @@ describe Chargify::Loops do
32
41
 
33
42
  Chargify::Loops.loops[:test].length.should == 1
34
43
  end
44
+
45
+ it "appends loops for an array of events" do
46
+ Chargify::Loops.loop! [:test, :one, :two] do |payload|
47
+ #
48
+ end
49
+
50
+ Chargify::Loops.loops[:test].length.should == 1
51
+ Chargify::Loops.loops[:one].length.should == 1
52
+ Chargify::Loops.loops[:two].length.should == 1
53
+ end
35
54
  end
36
55
  end
metadata CHANGED
@@ -1,38 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chargify-loops
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
5
- prerelease:
4
+ version: 0.3.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Pat Allan
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-02-06 00:00:00.000000000 Z
11
+ date: 2014-02-04 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rails
16
- requirement: &70144716951620 !ruby/object:Gem::Requirement
17
- none: false
15
+ requirement: !ruby/object:Gem::Requirement
18
16
  requirements:
19
17
  - - ~>
20
18
  - !ruby/object:Gem::Version
21
19
  version: '3.0'
22
20
  type: :runtime
23
21
  prerelease: false
24
- version_requirements: *70144716951620
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '3.0'
25
27
  - !ruby/object:Gem::Dependency
26
28
  name: rspec-rails
27
- requirement: &70144716951120 !ruby/object:Gem::Requirement
28
- none: false
29
+ requirement: !ruby/object:Gem::Requirement
29
30
  requirements:
30
- - - =
31
+ - - '='
31
32
  - !ruby/object:Gem::Version
32
33
  version: 2.7.0
33
34
  type: :development
34
35
  prerelease: false
35
- version_requirements: *70144716951120
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 2.7.0
36
41
  description: A Rails Engine that handles Chargify Webhooks requests and validates
37
42
  and forwards them off to registered loops.
38
43
  email:
@@ -62,27 +67,26 @@ files:
62
67
  - spec/spec_helper.rb
63
68
  homepage: https://github.com/freelancing-god/chargify-loops
64
69
  licenses: []
70
+ metadata: {}
65
71
  post_install_message:
66
72
  rdoc_options: []
67
73
  require_paths:
68
74
  - lib
69
75
  required_ruby_version: !ruby/object:Gem::Requirement
70
- none: false
71
76
  requirements:
72
- - - ! '>='
77
+ - - '>='
73
78
  - !ruby/object:Gem::Version
74
79
  version: '0'
75
80
  required_rubygems_version: !ruby/object:Gem::Requirement
76
- none: false
77
81
  requirements:
78
- - - ! '>='
82
+ - - '>='
79
83
  - !ruby/object:Gem::Version
80
84
  version: '0'
81
85
  requirements: []
82
86
  rubyforge_project: chargify-loops
83
- rubygems_version: 1.8.10
87
+ rubygems_version: 2.1.11
84
88
  signing_key:
85
- specification_version: 3
89
+ specification_version: 4
86
90
  summary: A Rails Engine for Chargify Webhooks
87
91
  test_files:
88
92
  - spec/chargify/loops_spec.rb
@@ -90,4 +94,3 @@ test_files:
90
94
  - spec/internal/log/.gitignore
91
95
  - spec/internal/public/favicon.ico
92
96
  - spec/spec_helper.rb
93
- has_rdoc: