webhookr-vero 0.0.1
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.
- checksums.yaml +7 -0
- data/.gitignore +20 -0
- data/Gemfile +20 -0
- data/Guardfile +20 -0
- data/LICENSE +22 -0
- data/README.md +156 -0
- data/Rakefile +37 -0
- data/lib/generators/webhookr/vero/example_hooks_generator.rb +17 -0
- data/lib/generators/webhookr/vero/init_generator.rb +24 -0
- data/lib/generators/webhookr/vero/templates/vero_hooks.rb +41 -0
- data/lib/webhookr-vero.rb +48 -0
- data/lib/webhookr-vero/version.rb +5 -0
- data/test/generators/webhookr/vero_plugin/init_generator_tests.rb +26 -0
- data/test/test_helper.rb +15 -0
- data/test/unit/webhookr-vero/version_tests.rb +8 -0
- data/test/unit/webhookr-vero_tests.rb +148 -0
- data/webhookr-vero.gemspec +24 -0
- metadata +92 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4645ed793f7e644f925f53ec059e141f7e1980a6
|
4
|
+
data.tar.gz: 172a2a56ae0a002dd1e9e73c645afba78e3a9826
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5bc3c4c1331b3a9166cc493e233ab6b931d56b18bea3502dd82b684f108401a8e3c13c778238827281751a160dff945f8e3a5ce75f48fa705e4f6fefe0a7b3d6
|
7
|
+
data.tar.gz: 1369103bfc9e265e8d798aa19cdbe33749951fb8829cd650872b5698d372c8ead0dbfd0ae2e4dfb0b41751c352397ef4d6c579683f1dd7710b67d5224cf01ea3
|
data/.gitignore
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
Gemfile.local
|
8
|
+
Guardfile.local
|
9
|
+
README.html
|
10
|
+
InstalledFiles
|
11
|
+
_yardoc
|
12
|
+
coverage
|
13
|
+
doc/
|
14
|
+
lib/bundler/man
|
15
|
+
pkg
|
16
|
+
rdoc
|
17
|
+
spec/reports
|
18
|
+
test/tmp
|
19
|
+
test/version_tmp
|
20
|
+
tmp
|
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
|
+
gem "coveralls", :require => false
|
16
|
+
end
|
17
|
+
|
18
|
+
if File.exists?('Gemfile.local')
|
19
|
+
instance_eval File.read('Gemfile.local')
|
20
|
+
end
|
data/Guardfile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
|
2
|
+
guard 'minitest', :test_folders => 'test', :test_file_patterns => '*_tests.rb' do
|
3
|
+
watch(%r|^test/(.+)_tests\.rb|)
|
4
|
+
|
5
|
+
watch(%r|^lib/(.*)([^/]+)\.rb|) do |m|
|
6
|
+
"test/#{m[1]}#{m[2]}_tests.rb"
|
7
|
+
end
|
8
|
+
|
9
|
+
watch(%r|^test/test_helper\.rb|) do
|
10
|
+
"test"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
guard 'livereload' do
|
15
|
+
watch('README.html')
|
16
|
+
end
|
17
|
+
|
18
|
+
if File.exists?('Guardfile.local')
|
19
|
+
instance_eval File.read('Guardfile.local')
|
20
|
+
end
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Tailor
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
22
|
+
|
data/README.md
ADDED
@@ -0,0 +1,156 @@
|
|
1
|
+
# Webhookr::Vero
|
2
|
+
|
3
|
+
[](https://circleci.com/gh/TailorBrands/webhookr-vero)
|
4
|
+
[](https://codeclimate.com/github/TailorBrands/webhookr-vero)
|
5
|
+
|
6
|
+
This gem is a plugin for [Webhookr](https://github.com/zoocasa/webhookr) that enables
|
7
|
+
your application to accept [webhooks from vero](http://www.getvero.com/help/reporting/setting-up-veros-webhooks/).
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
gem 'webhookr-vero'
|
14
|
+
|
15
|
+
Or install it yourself:
|
16
|
+
|
17
|
+
$ gem install webhookr-vero
|
18
|
+
|
19
|
+
[webhookr](https://github.com/zoocasa/webhookr) is installed as a dependency of webhookr-vero. If you have not [setup Webhookr](https://github.com/zoocasa/webhookr#usage--setup), do so now:
|
20
|
+
|
21
|
+
```console
|
22
|
+
rails g webhookr:add_route
|
23
|
+
```
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
Once you have the gem installed run the generator to add the code to your initializer.
|
28
|
+
An initializer will be created if you do not have one.
|
29
|
+
|
30
|
+
```console
|
31
|
+
rails g webhookr:vero:init *initializer_name* -s
|
32
|
+
```
|
33
|
+
|
34
|
+
Run the generator to create an example file to handle vero webhooks.
|
35
|
+
|
36
|
+
```console
|
37
|
+
rails g webhookr:vero:example_hooks
|
38
|
+
```
|
39
|
+
|
40
|
+
Or create a vero handler class for any event that you want to handle. For example
|
41
|
+
to handle unsubscribes you would create a class as follows:
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
class VeroHooks
|
45
|
+
def on_unsubscribed(incoming)
|
46
|
+
# Your custom logic goes here.
|
47
|
+
user = incoming.payload.user
|
48
|
+
puts("User unsubscribed: (#{user.email})")
|
49
|
+
end
|
50
|
+
end
|
51
|
+
```
|
52
|
+
|
53
|
+
For a complete list of events, and the payload format, see below.
|
54
|
+
|
55
|
+
Edit config/initializers/*initializer_name* and change the commented line to point to
|
56
|
+
your custom vero event handling class. If your class was called *VeroHooks*
|
57
|
+
the configuration line would look like this:
|
58
|
+
|
59
|
+
```ruby
|
60
|
+
Webhookr::Vero::Adapter.config.callback = VeroHooks
|
61
|
+
```
|
62
|
+
|
63
|
+
To see the list of vero URLs your application can use when you configure
|
64
|
+
vero webhooks,
|
65
|
+
run the provided webhookr rake task:
|
66
|
+
|
67
|
+
```console
|
68
|
+
rake webhookr:services
|
69
|
+
```
|
70
|
+
|
71
|
+
Example output:
|
72
|
+
|
73
|
+
```console
|
74
|
+
vero:
|
75
|
+
GET /webhooks/events/vero/19xl64emxvn
|
76
|
+
POST /webhooks/events/vero/19xl64emxvn
|
77
|
+
```
|
78
|
+
|
79
|
+
## vero Events & Payload
|
80
|
+
|
81
|
+
### Events
|
82
|
+
|
83
|
+
All webhook events are supported. For further information on these events, see the
|
84
|
+
[vero documentation](http://www.getvero.com/help/reporting/setting-up-veros-webhooks/).
|
85
|
+
|
86
|
+
<table>
|
87
|
+
<tr>
|
88
|
+
<th>Vero Event</th>
|
89
|
+
<th>Event Handler</th>
|
90
|
+
</tr>
|
91
|
+
<tr>
|
92
|
+
<td>Email Sent</td>
|
93
|
+
<td>on_sent(incoming)</td>
|
94
|
+
</tr>
|
95
|
+
<tr>
|
96
|
+
<td>Email Delivered</td>
|
97
|
+
<td>on_delivered(incoming)</td>
|
98
|
+
</tr>
|
99
|
+
<tr>
|
100
|
+
<td>Email Opened</td>
|
101
|
+
<td>on_opened(incoming)</td>
|
102
|
+
</tr>
|
103
|
+
<tr>
|
104
|
+
<td>Email Clicked</td>
|
105
|
+
<td>on_clicked(incoming)</td>
|
106
|
+
</tr>
|
107
|
+
<tr>
|
108
|
+
<td>Email Bounced</td>
|
109
|
+
<td>on_bounced(incoming)</td>
|
110
|
+
</tr>
|
111
|
+
<tr>
|
112
|
+
<td>User Unsubscribed</td>
|
113
|
+
<td>on_unsubscribed(incoming)</td>
|
114
|
+
</tr>
|
115
|
+
<tr>
|
116
|
+
<td>User Updated</td>
|
117
|
+
<td>on_user_updated(incoming)</td>
|
118
|
+
</tr>
|
119
|
+
</table>
|
120
|
+
|
121
|
+
### Payload
|
122
|
+
|
123
|
+
The payload is the full payload data from as per the
|
124
|
+
[vero documentation](http://www.getvero.com/help/reporting/setting-up-veros-webhooks/), converted to an OpenStruct
|
125
|
+
for ease of access. Examples can be found in the example hook file.
|
126
|
+
|
127
|
+
### <a name="supported_services"></a>Supported Service - vero
|
128
|
+
|
129
|
+
* [http://www.getvero.com/help/reporting/setting-up-veros-webhooks/](vero - version: 2015-09-29)
|
130
|
+
|
131
|
+
## <a name="works_with"></a>Works with:
|
132
|
+
|
133
|
+
webhookr-vero works with Rails 3.1, 3.2 and 4.0
|
134
|
+
|
135
|
+
### Versioning
|
136
|
+
This library aims to adhere to [Semantic Versioning 2.0.0](http://semver.org/). Violations of this scheme should be reported as
|
137
|
+
bugs. Specifically, if a minor or patch version is released that breaks backward compatibility, that
|
138
|
+
version should be immediately yanked and/or a new version should be immediately released that restores
|
139
|
+
compatibility. Breaking changes to the public API will only be introduced with new major versions. As a
|
140
|
+
result of this policy, once this gem reaches a 1.0 release, you can (and should) specify a dependency on
|
141
|
+
this gem using the [Pessimistic Version Constraint](http://docs.rubygems.org/read/chapter/16#page74) with
|
142
|
+
two digits of precision. For example:
|
143
|
+
|
144
|
+
spec.add_dependency 'webhookr-vero', '~> 1.0'
|
145
|
+
|
146
|
+
While this gem is currently a 0.x release, suggestion is to require the exact version that works for your code:
|
147
|
+
|
148
|
+
spec.add_dependency 'webhookr-vero', '0.0.1'
|
149
|
+
|
150
|
+
## License
|
151
|
+
|
152
|
+
webhookr-vero is released under the [MIT license](http://www.opensource.org/licenses/MIT).
|
153
|
+
|
154
|
+
## About Tailor Brands
|
155
|
+
|
156
|
+
[Check us out!](https://www.tailorbrands.com)
|
data/Rakefile
ADDED
@@ -0,0 +1,37 @@
|
|
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
|
+
if RUBY_VERSION >= '1.9'
|
11
|
+
begin
|
12
|
+
gem 'psych'
|
13
|
+
rescue Exception => e
|
14
|
+
# it's okay, fall back on the bundled psych
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
$:.push 'lib'
|
19
|
+
|
20
|
+
version = Webhookr::Vero::VERSION
|
21
|
+
|
22
|
+
desc 'Test Webhookr vero'
|
23
|
+
Rake::TestTask.new(:test) do |t|
|
24
|
+
t.test_files = FileList['test/**/*_tests.rb']
|
25
|
+
t.verbose = !!ENV['VERBOSE_TESTS']
|
26
|
+
t.warning = !!ENV['WARNINGS']
|
27
|
+
end
|
28
|
+
|
29
|
+
desc 'Build docs'
|
30
|
+
Rake::RDocTask.new do |t|
|
31
|
+
t.main = 'README.md'
|
32
|
+
t.title = "Webhookr vero #{version}"
|
33
|
+
t.rdoc_dir = 'doc'
|
34
|
+
t.rdoc_files.include('README.md', 'MIT-LICENSE', 'lib/**/*.rb')
|
35
|
+
end
|
36
|
+
|
37
|
+
task :default => :test
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Webhookr
|
2
|
+
module Vero
|
3
|
+
module Generators
|
4
|
+
|
5
|
+
class ExampleHooksGenerator < Rails::Generators::Base
|
6
|
+
EXAMPLE_HOOK_FILE = 'app/models/vero_hooks.rb'
|
7
|
+
source_root File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
|
8
|
+
|
9
|
+
desc "Creates an example vero hook file: '#{EXAMPLE_HOOK_FILE}'"
|
10
|
+
def example_hooks
|
11
|
+
copy_file( "vero_hooks.rb", EXAMPLE_HOOK_FILE)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'generators/webhookr/init_generator'
|
2
|
+
|
3
|
+
module Webhookr
|
4
|
+
module Vero
|
5
|
+
module Generators
|
6
|
+
class InitGenerator < Webhookr::Generators::InitGenerator
|
7
|
+
|
8
|
+
desc "This generator updates the named initializer with vero 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::Vero::Adapter.config.security_token = '#{generate_security_token}'" +
|
18
|
+
"\n# Uncomment the next line to include your custom vero handler\n" +
|
19
|
+
"# <-- Webhookr::Vero::Adapter.config.callback = your_custom_class --> \n"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
class VeroHooks
|
2
|
+
|
3
|
+
# All 'on_' handlers are optional. Omit any you do not require.
|
4
|
+
# Details on the payload structure: http://www.getvero.com/help/reporting/setting-up-veros-webhooks/
|
5
|
+
#
|
6
|
+
|
7
|
+
def on_sent(incoming)
|
8
|
+
user = incoming.payload.user
|
9
|
+
puts("Email sent: (#{user})")
|
10
|
+
end
|
11
|
+
|
12
|
+
def on_delivered(incoming)
|
13
|
+
user = incoming.payload.user
|
14
|
+
puts("Email deliverd: (#{user})")
|
15
|
+
end
|
16
|
+
|
17
|
+
def on_opened(incoming)
|
18
|
+
user = incoming.payload.user
|
19
|
+
puts("Email opened: (#{user})")
|
20
|
+
end
|
21
|
+
|
22
|
+
def on_clicked(incoming)
|
23
|
+
user = incoming.payload.user
|
24
|
+
puts("Email clicked: (#{user})")
|
25
|
+
end
|
26
|
+
|
27
|
+
def on_bounced(incoming)
|
28
|
+
user = incoming.payload.user
|
29
|
+
puts("Email bounced: (#{user})")
|
30
|
+
end
|
31
|
+
|
32
|
+
def on_unsubscribed(incoming)
|
33
|
+
user = incoming.payload.user
|
34
|
+
puts("User unsubscribed: (#{user})")
|
35
|
+
end
|
36
|
+
|
37
|
+
def on_user_updated(incoming)
|
38
|
+
user = incoming.payload.user
|
39
|
+
puts("User updated: (#{user})")
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require "webhookr"
|
2
|
+
require "webhookr-vero/version"
|
3
|
+
require "webhookr/ostruct_utils"
|
4
|
+
|
5
|
+
module Webhookr
|
6
|
+
module Vero
|
7
|
+
class Adapter
|
8
|
+
SERVICE_NAME = "vero"
|
9
|
+
EVENT_KEY = "type"
|
10
|
+
USER_KEY = "user"
|
11
|
+
|
12
|
+
include Webhookr::Services::Adapter::Base
|
13
|
+
|
14
|
+
def self.process(raw_response)
|
15
|
+
new.process(raw_response)
|
16
|
+
end
|
17
|
+
|
18
|
+
def process(raw_response)
|
19
|
+
Array.wrap(parse(raw_response)).collect do |p|
|
20
|
+
Webhookr::AdapterResponse.new(
|
21
|
+
SERVICE_NAME,
|
22
|
+
p.fetch(EVENT_KEY),
|
23
|
+
OstructUtils.to_ostruct(p.except(EVENT_KEY))
|
24
|
+
) if assert_valid_packet(p)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def parse(raw_response)
|
31
|
+
begin
|
32
|
+
ActiveSupport::JSON.decode(
|
33
|
+
CGI.unescape(raw_response)
|
34
|
+
)
|
35
|
+
rescue Exception => e
|
36
|
+
raise InvalidPayloadError.new(e)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def assert_valid_packet(packet)
|
41
|
+
raise(Webhookr::InvalidPayloadError, "Unknown event #{packet[EVENT_KEY]}") unless packet[EVENT_KEY]
|
42
|
+
raise(Webhookr::InvalidPayloadError, "No user data in the response") unless packet[USER_KEY]
|
43
|
+
true
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
|
2
|
+
$: << File.join(File.dirname(__FILE__), %w{ .. .. .. })
|
3
|
+
require 'test_helper'
|
4
|
+
require 'generators/webhookr/vero/init_generator'
|
5
|
+
|
6
|
+
class InitGeneratorTests < Rails::Generators::TestCase
|
7
|
+
tests Webhookr::Vero::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::Vero::Adapter\.config\.security_token}, content)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
require 'coveralls'
|
3
|
+
|
4
|
+
SimpleCov.start
|
5
|
+
Coveralls.wear!
|
6
|
+
|
7
|
+
require 'minitest/autorun'
|
8
|
+
require 'minitest/reporters'
|
9
|
+
require 'rails'
|
10
|
+
require "rails/generators/test_case"
|
11
|
+
require File.expand_path('../../lib/webhookr-vero.rb', __FILE__)
|
12
|
+
|
13
|
+
if RUBY_VERSION >= "1.9"
|
14
|
+
MiniTest::Reporters.use!(MiniTest::Reporters::SpecReporter.new)
|
15
|
+
end
|
@@ -0,0 +1,148 @@
|
|
1
|
+
|
2
|
+
$: << File.join(File.dirname(__FILE__), "..")
|
3
|
+
require 'test_helper'
|
4
|
+
|
5
|
+
describe Webhookr::Vero::Adapter do
|
6
|
+
|
7
|
+
before do
|
8
|
+
@event_type = "sent"
|
9
|
+
end
|
10
|
+
|
11
|
+
def valid_response
|
12
|
+
'{
|
13
|
+
"type": "sent",
|
14
|
+
"user": {
|
15
|
+
"id": 12345,
|
16
|
+
"email": "kevin@tailorbrands.com"
|
17
|
+
},
|
18
|
+
"campaign": {
|
19
|
+
"id": 1235666234572456,
|
20
|
+
"type": "transactional",
|
21
|
+
"name": "Cart Abandonment Followup",
|
22
|
+
"subject": "You have items in your shopping bag",
|
23
|
+
"trigger-event": "Abandoned cart",
|
24
|
+
"permalink": "http://app.getvero.com/view/1/9c8c3ac6ac65736926a6da5aefbf852d"
|
25
|
+
},
|
26
|
+
"sent_at": 1435016238,
|
27
|
+
"user_agent":"Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)"
|
28
|
+
}'
|
29
|
+
end
|
30
|
+
|
31
|
+
def no_user_response
|
32
|
+
'{
|
33
|
+
"type": "sent",
|
34
|
+
"campaign": {
|
35
|
+
"id": 1235666234572456,
|
36
|
+
"type": "transactional",
|
37
|
+
"name": "Cart Abandonment Followup",
|
38
|
+
"subject": "You have items in your shopping bag",
|
39
|
+
"trigger-event": "Abandoned cart",
|
40
|
+
"permalink": "http://app.getvero.com/view/1/9c8c3ac6ac65736926a6da5aefbf852d"
|
41
|
+
},
|
42
|
+
"sent_at": 1435016238,
|
43
|
+
"user_agent":"Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)"
|
44
|
+
}'
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "the class" do
|
48
|
+
|
49
|
+
subject { Webhookr::Vero::Adapter }
|
50
|
+
|
51
|
+
it "must support process" do
|
52
|
+
subject.must_respond_to(:process)
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should not return an error for a valid packet" do
|
56
|
+
lambda {
|
57
|
+
subject.process(valid_response)
|
58
|
+
}.must_be_silent
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
describe "the instance" do
|
64
|
+
|
65
|
+
subject { Webhookr::Vero::Adapter.new }
|
66
|
+
|
67
|
+
it "should not return an error for a valid packet" do
|
68
|
+
lambda {
|
69
|
+
subject.process(valid_response)
|
70
|
+
}.must_be_silent
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should raise Webhookr::InvalidPayloadError for no packet" do
|
74
|
+
lambda {
|
75
|
+
subject.process("")
|
76
|
+
}.must_raise(Webhookr::InvalidPayloadError)
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should raise Webhookr::InvalidPayloadError for a missing user" do
|
80
|
+
lambda {
|
81
|
+
subject.process(no_user_response)
|
82
|
+
}.must_raise(Webhookr::InvalidPayloadError)
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
86
|
+
|
87
|
+
describe "it's response" do
|
88
|
+
before do
|
89
|
+
@adapter = Webhookr::Vero::Adapter.new
|
90
|
+
end
|
91
|
+
|
92
|
+
subject { @adapter.process(valid_response).first }
|
93
|
+
|
94
|
+
it "must respond to service_name" do
|
95
|
+
subject.must_respond_to(:service_name)
|
96
|
+
end
|
97
|
+
|
98
|
+
it "should return the correct service name" do
|
99
|
+
assert_equal(Webhookr::Vero::Adapter::SERVICE_NAME, subject.service_name)
|
100
|
+
end
|
101
|
+
|
102
|
+
it "must respond to event_type" do
|
103
|
+
subject.must_respond_to(:event_type)
|
104
|
+
end
|
105
|
+
|
106
|
+
it "should return the correct event type" do
|
107
|
+
assert_equal(@event_type, subject.event_type)
|
108
|
+
end
|
109
|
+
|
110
|
+
it "must respond to payload" do
|
111
|
+
subject.must_respond_to(:payload)
|
112
|
+
end
|
113
|
+
|
114
|
+
it "must respond to payload.sent_at" do
|
115
|
+
subject.payload.must_respond_to(:sent_at)
|
116
|
+
end
|
117
|
+
|
118
|
+
it "should return the correct data packet for sent_at" do
|
119
|
+
assert_equal(1435016238, subject.payload.sent_at)
|
120
|
+
end
|
121
|
+
|
122
|
+
it "must respond to payload.user_agent" do
|
123
|
+
subject.payload.must_respond_to(:user_agent)
|
124
|
+
end
|
125
|
+
|
126
|
+
it "should return the correct data packet for user_agent" do
|
127
|
+
assert_equal("Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)", subject.payload.user_agent)
|
128
|
+
end
|
129
|
+
|
130
|
+
it "must respond to payload.campaign" do
|
131
|
+
subject.payload.must_respond_to(:campaign)
|
132
|
+
end
|
133
|
+
|
134
|
+
it "should return the correct type for campaign" do
|
135
|
+
assert_equal("transactional", subject.payload.campaign.type)
|
136
|
+
end
|
137
|
+
|
138
|
+
it "must respond to payload.user" do
|
139
|
+
subject.payload.must_respond_to(:user)
|
140
|
+
end
|
141
|
+
|
142
|
+
it "should return the correct email for user" do
|
143
|
+
assert_equal("kevin@tailorbrands.com", subject.payload.user.email)
|
144
|
+
end
|
145
|
+
|
146
|
+
end
|
147
|
+
|
148
|
+
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-vero/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "webhookr-vero"
|
8
|
+
gem.version = Webhookr::Vero::VERSION
|
9
|
+
gem.authors = ["Kevin Smyth"]
|
10
|
+
gem.email = ["kevin@tailorbrands.com"]
|
11
|
+
gem.description = "A webhookr extension to support vero webhooks."
|
12
|
+
gem.summary = gem.description
|
13
|
+
gem.homepage = "http://github.com/TailorBrands/webhookr-vero"
|
14
|
+
gem.license = "MIT"
|
15
|
+
|
16
|
+
gem.files = `git ls-files`.split($/)
|
17
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
18
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
19
|
+
gem.require_paths = ["lib"]
|
20
|
+
|
21
|
+
gem.add_dependency("webhookr")
|
22
|
+
gem.add_dependency("activesupport", [">= 3.1"])
|
23
|
+
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: webhookr-vero
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kevin Smyth
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-09-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: webhookr
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activesupport
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.1'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.1'
|
41
|
+
description: A webhookr extension to support vero webhooks.
|
42
|
+
email:
|
43
|
+
- kevin@tailorbrands.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- .gitignore
|
49
|
+
- Gemfile
|
50
|
+
- Guardfile
|
51
|
+
- LICENSE
|
52
|
+
- README.md
|
53
|
+
- Rakefile
|
54
|
+
- lib/generators/webhookr/vero/example_hooks_generator.rb
|
55
|
+
- lib/generators/webhookr/vero/init_generator.rb
|
56
|
+
- lib/generators/webhookr/vero/templates/vero_hooks.rb
|
57
|
+
- lib/webhookr-vero.rb
|
58
|
+
- lib/webhookr-vero/version.rb
|
59
|
+
- test/generators/webhookr/vero_plugin/init_generator_tests.rb
|
60
|
+
- test/test_helper.rb
|
61
|
+
- test/unit/webhookr-vero/version_tests.rb
|
62
|
+
- test/unit/webhookr-vero_tests.rb
|
63
|
+
- webhookr-vero.gemspec
|
64
|
+
homepage: http://github.com/TailorBrands/webhookr-vero
|
65
|
+
licenses:
|
66
|
+
- MIT
|
67
|
+
metadata: {}
|
68
|
+
post_install_message:
|
69
|
+
rdoc_options: []
|
70
|
+
require_paths:
|
71
|
+
- lib
|
72
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - '>='
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
requirements: []
|
83
|
+
rubyforge_project:
|
84
|
+
rubygems_version: 2.0.14
|
85
|
+
signing_key:
|
86
|
+
specification_version: 4
|
87
|
+
summary: A webhookr extension to support vero webhooks.
|
88
|
+
test_files:
|
89
|
+
- test/generators/webhookr/vero_plugin/init_generator_tests.rb
|
90
|
+
- test/test_helper.rb
|
91
|
+
- test/unit/webhookr-vero/version_tests.rb
|
92
|
+
- test/unit/webhookr-vero_tests.rb
|