moogle 0.1.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.
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +35 -0
- data/Gemfile.lock +148 -0
- data/LICENSE.txt +202 -0
- data/NOTICE.txt +4 -0
- data/README.md +33 -0
- data/Rakefile +44 -0
- data/fixtures/vcr_cassettes/push_blog_entry.yml +48 -0
- data/fixtures/vcr_cassettes/push_webhook_ping.yml +41 -0
- data/lib/moogle/commands/create_link.rb +45 -0
- data/lib/moogle/commands/create_target.rb +46 -0
- data/lib/moogle/commands/destroy_link.rb +37 -0
- data/lib/moogle/commands/destroy_target.rb +37 -0
- data/lib/moogle/commands/find_targets.rb +31 -0
- data/lib/moogle/commands/push_blog_entry.rb +54 -0
- data/lib/moogle/commands/push_email.rb +60 -0
- data/lib/moogle/commands/push_webhook_ping.rb +58 -0
- data/lib/moogle/commands/update_target.rb +44 -0
- data/lib/moogle/commands.rb +9 -0
- data/lib/moogle/error.rb +6 -0
- data/lib/moogle/events/blog_entry_pushed.rb +34 -0
- data/lib/moogle/events/email_pushed.rb +36 -0
- data/lib/moogle/events/error.rb +24 -0
- data/lib/moogle/events/link_created.rb +21 -0
- data/lib/moogle/events/link_destroyed.rb +21 -0
- data/lib/moogle/events/target_created.rb +21 -0
- data/lib/moogle/events/target_destroyed.rb +21 -0
- data/lib/moogle/events/target_updated.rb +21 -0
- data/lib/moogle/events/webhook_ping_pushed.rb +34 -0
- data/lib/moogle/handlers/accept_notification.rb +96 -0
- data/lib/moogle/messages/notification.rb +34 -0
- data/lib/moogle/models/blog_target.rb +29 -0
- data/lib/moogle/models/email_target.rb +16 -0
- data/lib/moogle/models/facebook_target.rb +14 -0
- data/lib/moogle/models/link.rb +20 -0
- data/lib/moogle/models/post_log.rb +21 -0
- data/lib/moogle/models/target.rb +22 -0
- data/lib/moogle/models/twitter_target.rb +14 -0
- data/lib/moogle/models/webhook_target.rb +18 -0
- data/lib/moogle/models.rb +9 -0
- data/lib/moogle/representers/link_representer.rb +23 -0
- data/lib/moogle/representers/target_representer.rb +34 -0
- data/lib/moogle/requests/create_link.rb +24 -0
- data/lib/moogle/requests/create_target.rb +40 -0
- data/lib/moogle/requests/destroy_link.rb +22 -0
- data/lib/moogle/requests/destroy_target.rb +22 -0
- data/lib/moogle/requests/find_targets.rb +21 -0
- data/lib/moogle/requests/push_blog_entry.rb +67 -0
- data/lib/moogle/requests/push_email.rb +46 -0
- data/lib/moogle/requests/push_webhook_ping.rb +49 -0
- data/lib/moogle/requests/update_target.rb +22 -0
- data/lib/moogle/requests.rb +6 -0
- data/lib/moogle/version.rb +11 -0
- data/lib/moogle.rb +5 -0
- data/moogle.gemspec +160 -0
- data/spec/commands/find_targets_spec.rb +32 -0
- data/spec/commands/links_spec.rb +92 -0
- data/spec/commands/push_blog_entry_spec.rb +33 -0
- data/spec/commands/push_email_spec.rb +44 -0
- data/spec/commands/push_webhook_ping_spec.rb +30 -0
- data/spec/commands/targets_spec.rb +165 -0
- data/spec/handlers/accept_notification_spec.rb +55 -0
- data/spec/moogle_spec.rb +1 -0
- data/spec/spec_helper.rb +12 -0
- data/spec/support/dependencies.rb +10 -0
- data/spec/support/vcr.rb +6 -0
- metadata +326 -0
data/moogle.gemspec
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
# Generated by jeweler
|
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
|
4
|
+
# -*- encoding: utf-8 -*-
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |s|
|
|
7
|
+
s.name = "moogle"
|
|
8
|
+
s.version = "0.1.0"
|
|
9
|
+
|
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
|
11
|
+
s.authors = ["Benjamin Yu"]
|
|
12
|
+
s.date = "2012-05-02"
|
|
13
|
+
s.description = "Notification pushing to 3rd parties"
|
|
14
|
+
s.email = "benjaminlyu@gmail.com"
|
|
15
|
+
s.extra_rdoc_files = [
|
|
16
|
+
"LICENSE.txt",
|
|
17
|
+
"README.md"
|
|
18
|
+
]
|
|
19
|
+
s.files = [
|
|
20
|
+
".document",
|
|
21
|
+
".rspec",
|
|
22
|
+
"Gemfile",
|
|
23
|
+
"Gemfile.lock",
|
|
24
|
+
"LICENSE.txt",
|
|
25
|
+
"NOTICE.txt",
|
|
26
|
+
"README.md",
|
|
27
|
+
"Rakefile",
|
|
28
|
+
"fixtures/vcr_cassettes/push_blog_entry.yml",
|
|
29
|
+
"fixtures/vcr_cassettes/push_webhook_ping.yml",
|
|
30
|
+
"lib/moogle.rb",
|
|
31
|
+
"lib/moogle/commands.rb",
|
|
32
|
+
"lib/moogle/commands/create_link.rb",
|
|
33
|
+
"lib/moogle/commands/create_target.rb",
|
|
34
|
+
"lib/moogle/commands/destroy_link.rb",
|
|
35
|
+
"lib/moogle/commands/destroy_target.rb",
|
|
36
|
+
"lib/moogle/commands/find_targets.rb",
|
|
37
|
+
"lib/moogle/commands/push_blog_entry.rb",
|
|
38
|
+
"lib/moogle/commands/push_email.rb",
|
|
39
|
+
"lib/moogle/commands/push_webhook_ping.rb",
|
|
40
|
+
"lib/moogle/commands/update_target.rb",
|
|
41
|
+
"lib/moogle/error.rb",
|
|
42
|
+
"lib/moogle/events/blog_entry_pushed.rb",
|
|
43
|
+
"lib/moogle/events/email_pushed.rb",
|
|
44
|
+
"lib/moogle/events/error.rb",
|
|
45
|
+
"lib/moogle/events/link_created.rb",
|
|
46
|
+
"lib/moogle/events/link_destroyed.rb",
|
|
47
|
+
"lib/moogle/events/target_created.rb",
|
|
48
|
+
"lib/moogle/events/target_destroyed.rb",
|
|
49
|
+
"lib/moogle/events/target_updated.rb",
|
|
50
|
+
"lib/moogle/events/webhook_ping_pushed.rb",
|
|
51
|
+
"lib/moogle/handlers/accept_notification.rb",
|
|
52
|
+
"lib/moogle/messages/notification.rb",
|
|
53
|
+
"lib/moogle/models.rb",
|
|
54
|
+
"lib/moogle/models/blog_target.rb",
|
|
55
|
+
"lib/moogle/models/email_target.rb",
|
|
56
|
+
"lib/moogle/models/facebook_target.rb",
|
|
57
|
+
"lib/moogle/models/link.rb",
|
|
58
|
+
"lib/moogle/models/post_log.rb",
|
|
59
|
+
"lib/moogle/models/target.rb",
|
|
60
|
+
"lib/moogle/models/twitter_target.rb",
|
|
61
|
+
"lib/moogle/models/webhook_target.rb",
|
|
62
|
+
"lib/moogle/representers/link_representer.rb",
|
|
63
|
+
"lib/moogle/representers/target_representer.rb",
|
|
64
|
+
"lib/moogle/requests.rb",
|
|
65
|
+
"lib/moogle/requests/create_link.rb",
|
|
66
|
+
"lib/moogle/requests/create_target.rb",
|
|
67
|
+
"lib/moogle/requests/destroy_link.rb",
|
|
68
|
+
"lib/moogle/requests/destroy_target.rb",
|
|
69
|
+
"lib/moogle/requests/find_targets.rb",
|
|
70
|
+
"lib/moogle/requests/push_blog_entry.rb",
|
|
71
|
+
"lib/moogle/requests/push_email.rb",
|
|
72
|
+
"lib/moogle/requests/push_webhook_ping.rb",
|
|
73
|
+
"lib/moogle/requests/update_target.rb",
|
|
74
|
+
"lib/moogle/version.rb",
|
|
75
|
+
"moogle.gemspec",
|
|
76
|
+
"spec/commands/find_targets_spec.rb",
|
|
77
|
+
"spec/commands/links_spec.rb",
|
|
78
|
+
"spec/commands/push_blog_entry_spec.rb",
|
|
79
|
+
"spec/commands/push_email_spec.rb",
|
|
80
|
+
"spec/commands/push_webhook_ping_spec.rb",
|
|
81
|
+
"spec/commands/targets_spec.rb",
|
|
82
|
+
"spec/handlers/accept_notification_spec.rb",
|
|
83
|
+
"spec/moogle_spec.rb",
|
|
84
|
+
"spec/spec_helper.rb",
|
|
85
|
+
"spec/support/dependencies.rb",
|
|
86
|
+
"spec/support/vcr.rb"
|
|
87
|
+
]
|
|
88
|
+
s.homepage = "http://github.com/byu/moogle"
|
|
89
|
+
s.licenses = ["Apache 2.0"]
|
|
90
|
+
s.require_paths = ["lib"]
|
|
91
|
+
s.rubygems_version = "1.8.17"
|
|
92
|
+
s.summary = "Notification pushing to 3rd parties"
|
|
93
|
+
|
|
94
|
+
if s.respond_to? :specification_version then
|
|
95
|
+
s.specification_version = 3
|
|
96
|
+
|
|
97
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
|
98
|
+
s.add_runtime_dependency(%q<addressable>, [">= 2.2.7"])
|
|
99
|
+
s.add_runtime_dependency(%q<aequitas>, [">= 0.0.2"])
|
|
100
|
+
s.add_runtime_dependency(%q<data_mapper>, [">= 1.2.0"])
|
|
101
|
+
s.add_runtime_dependency(%q<mail>, [">= 2.4.3"])
|
|
102
|
+
s.add_runtime_dependency(%q<faraday>, [">= 0.7.6"])
|
|
103
|
+
s.add_runtime_dependency(%q<rafaday>, [">= 0.1.0"])
|
|
104
|
+
s.add_runtime_dependency(%q<roar>, [">= 0.9.2"])
|
|
105
|
+
s.add_runtime_dependency(%q<serf>, [">= 0.8.0"])
|
|
106
|
+
s.add_runtime_dependency(%q<uuidtools>, [">= 2.1.2"])
|
|
107
|
+
s.add_runtime_dependency(%q<virtus>, [">= 0.3.0"])
|
|
108
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.8.0"])
|
|
109
|
+
s.add_development_dependency(%q<yard>, ["~> 0.7.5"])
|
|
110
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.1.3"])
|
|
111
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.8.3"])
|
|
112
|
+
s.add_development_dependency(%q<simplecov>, [">= 0"])
|
|
113
|
+
s.add_development_dependency(%q<vcr>, ["~> 2.0.0"])
|
|
114
|
+
s.add_development_dependency(%q<webmock>, ["~> 1.8.1"])
|
|
115
|
+
s.add_development_dependency(%q<dm-sqlite-adapter>, [">= 0"])
|
|
116
|
+
s.add_development_dependency(%q<dm-mysql-adapter>, [">= 0"])
|
|
117
|
+
else
|
|
118
|
+
s.add_dependency(%q<addressable>, [">= 2.2.7"])
|
|
119
|
+
s.add_dependency(%q<aequitas>, [">= 0.0.2"])
|
|
120
|
+
s.add_dependency(%q<data_mapper>, [">= 1.2.0"])
|
|
121
|
+
s.add_dependency(%q<mail>, [">= 2.4.3"])
|
|
122
|
+
s.add_dependency(%q<faraday>, [">= 0.7.6"])
|
|
123
|
+
s.add_dependency(%q<rafaday>, [">= 0.1.0"])
|
|
124
|
+
s.add_dependency(%q<roar>, [">= 0.9.2"])
|
|
125
|
+
s.add_dependency(%q<serf>, [">= 0.8.0"])
|
|
126
|
+
s.add_dependency(%q<uuidtools>, [">= 2.1.2"])
|
|
127
|
+
s.add_dependency(%q<virtus>, [">= 0.3.0"])
|
|
128
|
+
s.add_dependency(%q<rspec>, ["~> 2.8.0"])
|
|
129
|
+
s.add_dependency(%q<yard>, ["~> 0.7.5"])
|
|
130
|
+
s.add_dependency(%q<bundler>, ["~> 1.1.3"])
|
|
131
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
|
|
132
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
|
133
|
+
s.add_dependency(%q<vcr>, ["~> 2.0.0"])
|
|
134
|
+
s.add_dependency(%q<webmock>, ["~> 1.8.1"])
|
|
135
|
+
s.add_dependency(%q<dm-sqlite-adapter>, [">= 0"])
|
|
136
|
+
s.add_dependency(%q<dm-mysql-adapter>, [">= 0"])
|
|
137
|
+
end
|
|
138
|
+
else
|
|
139
|
+
s.add_dependency(%q<addressable>, [">= 2.2.7"])
|
|
140
|
+
s.add_dependency(%q<aequitas>, [">= 0.0.2"])
|
|
141
|
+
s.add_dependency(%q<data_mapper>, [">= 1.2.0"])
|
|
142
|
+
s.add_dependency(%q<mail>, [">= 2.4.3"])
|
|
143
|
+
s.add_dependency(%q<faraday>, [">= 0.7.6"])
|
|
144
|
+
s.add_dependency(%q<rafaday>, [">= 0.1.0"])
|
|
145
|
+
s.add_dependency(%q<roar>, [">= 0.9.2"])
|
|
146
|
+
s.add_dependency(%q<serf>, [">= 0.8.0"])
|
|
147
|
+
s.add_dependency(%q<uuidtools>, [">= 2.1.2"])
|
|
148
|
+
s.add_dependency(%q<virtus>, [">= 0.3.0"])
|
|
149
|
+
s.add_dependency(%q<rspec>, ["~> 2.8.0"])
|
|
150
|
+
s.add_dependency(%q<yard>, ["~> 0.7.5"])
|
|
151
|
+
s.add_dependency(%q<bundler>, ["~> 1.1.3"])
|
|
152
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
|
|
153
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
|
154
|
+
s.add_dependency(%q<vcr>, ["~> 2.0.0"])
|
|
155
|
+
s.add_dependency(%q<webmock>, ["~> 1.8.1"])
|
|
156
|
+
s.add_dependency(%q<dm-sqlite-adapter>, [">= 0"])
|
|
157
|
+
s.add_dependency(%q<dm-mysql-adapter>, [">= 0"])
|
|
158
|
+
end
|
|
159
|
+
end
|
|
160
|
+
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
|
2
|
+
|
|
3
|
+
describe 'Moogle::Commands::FindTargets' do
|
|
4
|
+
before {
|
|
5
|
+
Moogle::WebhookTarget.create(
|
|
6
|
+
owner_ref: 'System:1a',
|
|
7
|
+
options: {
|
|
8
|
+
'webhook_uri' => 'http://example.com/target'
|
|
9
|
+
},
|
|
10
|
+
links: [
|
|
11
|
+
Moogle::Link.new
|
|
12
|
+
])
|
|
13
|
+
}
|
|
14
|
+
let(:request_hash) {{
|
|
15
|
+
owner_ref: 'System:1a'
|
|
16
|
+
}}
|
|
17
|
+
let(:request) {
|
|
18
|
+
Moogle::Requests::FindTargets.new request_hash
|
|
19
|
+
}
|
|
20
|
+
let(:command) {
|
|
21
|
+
Moogle::Commands::FindTargets
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
it 'should find the target with link' do
|
|
25
|
+
result = command.call request
|
|
26
|
+
result.size.should == 1
|
|
27
|
+
result.first.kind.should == 'moogle/domain/target'
|
|
28
|
+
result.first.owner_ref.should == 'System:1a'
|
|
29
|
+
result.first.options['webhook_uri'].should == 'http://example.com/target'
|
|
30
|
+
result.first.links.size.should == 1
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
|
2
|
+
|
|
3
|
+
describe 'Moogle::Commands::CreateLink' do
|
|
4
|
+
let(:existing_target) {
|
|
5
|
+
Moogle::WebhookTarget.create(
|
|
6
|
+
owner_ref: 'System:1a',
|
|
7
|
+
options: {
|
|
8
|
+
'webhook_uri' => 'http://example.com/target'
|
|
9
|
+
})
|
|
10
|
+
}
|
|
11
|
+
let(:request_hash) {{
|
|
12
|
+
target_id: existing_target.id,
|
|
13
|
+
receiver_ref: 'Gym:1',
|
|
14
|
+
message_kind: 'my_message_kind'
|
|
15
|
+
}}
|
|
16
|
+
let(:request) {
|
|
17
|
+
Moogle::Requests::CreateLink.new request_hash
|
|
18
|
+
}
|
|
19
|
+
let(:command) {
|
|
20
|
+
Moogle::Commands::CreateLink
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
it 'should create a link' do
|
|
24
|
+
result = command.call request
|
|
25
|
+
result.kind.should == 'moogle/events/link_created'
|
|
26
|
+
result.parent_uuid.should == request.uuid
|
|
27
|
+
result.link.message_kind.should == 'my_message_kind'
|
|
28
|
+
result.link.receiver_ref.should == 'Gym:1'
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it 'should be able to parse a hash as request' do
|
|
32
|
+
result = command.call request
|
|
33
|
+
result.kind.should == 'moogle/events/link_created'
|
|
34
|
+
result.link.message_kind.should == 'my_message_kind'
|
|
35
|
+
result.link.receiver_ref.should == 'Gym:1'
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
describe 'Moogle::Commands::DestroyLink' do
|
|
40
|
+
let(:request_hash) {{
|
|
41
|
+
link_id: 12345
|
|
42
|
+
}}
|
|
43
|
+
let(:command) {
|
|
44
|
+
Moogle::Commands::DestroyLink
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
describe 'with non-existent link' do
|
|
48
|
+
let(:request) {
|
|
49
|
+
Moogle::Requests::DestroyLink.new request_hash
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
it 'should succeed' do
|
|
53
|
+
result = command.call request
|
|
54
|
+
result.kind.should == 'moogle/events/link_destroyed'
|
|
55
|
+
result.link_id.should == 12345
|
|
56
|
+
result.parent_uuid.should == request.uuid
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
describe 'with existing link' do
|
|
61
|
+
let(:existing_target) {
|
|
62
|
+
Moogle::WebhookTarget.create(
|
|
63
|
+
owner_ref: 'System:1a',
|
|
64
|
+
options: {
|
|
65
|
+
'webhook_uri' => 'http://example.com/target'
|
|
66
|
+
})
|
|
67
|
+
}
|
|
68
|
+
let(:existing_link) {
|
|
69
|
+
Moogle::Commands::CreateLink.call(
|
|
70
|
+
Moogle::Requests::CreateLink.new(
|
|
71
|
+
target_id: existing_target.id,
|
|
72
|
+
receiver_ref: 'Gym:1',
|
|
73
|
+
message_kind: 'my_message_kind')).link
|
|
74
|
+
}
|
|
75
|
+
let(:request) {
|
|
76
|
+
Moogle::Requests::DestroyLink.new link_id: existing_link.id
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
it 'should succeed' do
|
|
80
|
+
result = command.call request
|
|
81
|
+
result.kind.should == 'moogle/events/link_destroyed'
|
|
82
|
+
result.link_id.should == existing_link.id
|
|
83
|
+
result.parent_uuid.should == request.uuid
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
it 'should be able to parse a hash as request' do
|
|
88
|
+
result = command.call request_hash
|
|
89
|
+
result.kind.should == 'moogle/events/link_destroyed'
|
|
90
|
+
result.link_id.should == 12345
|
|
91
|
+
end
|
|
92
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
|
2
|
+
|
|
3
|
+
describe 'Moogle::Commands::PushBlogEntry' do
|
|
4
|
+
let(:request) {{
|
|
5
|
+
target_id: 1,
|
|
6
|
+
message_origin: 'btwb/events/workout_session_created',
|
|
7
|
+
subject: 'My Test Title',
|
|
8
|
+
html_body: 'Body of the blog post',
|
|
9
|
+
categories: ['tag1', 'tag2'],
|
|
10
|
+
rpc_uri: 'http://example.wordpress.com/xmlrpc.php',
|
|
11
|
+
blog_uri: 'http://example.wordpress.com/',
|
|
12
|
+
blog_id: 'my_blog_id',
|
|
13
|
+
username: 'user@example.com',
|
|
14
|
+
password: 'password',
|
|
15
|
+
publish_immediately: true,
|
|
16
|
+
uuid: '85d9e997-6dcd-499e-9a5d-09dc0dc8c3b4'
|
|
17
|
+
}}
|
|
18
|
+
let(:command) {
|
|
19
|
+
Moogle::Commands::PushBlogEntry
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
it 'should push a blog entry' do
|
|
23
|
+
VCR.use_cassette('push_blog_entry') do
|
|
24
|
+
result = command.call request
|
|
25
|
+
result.kind.should == 'moogle/events/blog_entry_pushed'
|
|
26
|
+
result.post_ref.should == '61'
|
|
27
|
+
result.target_id.should == request[:target_id]
|
|
28
|
+
result.message_origin == request[:message_origin]
|
|
29
|
+
result.parent_uuid.should == request[:uuid]
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
end
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
|
2
|
+
|
|
3
|
+
describe 'Moogle::Commands::PushEmail' do
|
|
4
|
+
before(:each) do
|
|
5
|
+
Mail.defaults do
|
|
6
|
+
delivery_method :test
|
|
7
|
+
end
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
let(:request) {{
|
|
11
|
+
uuid: '85d9e997-6dcd-499e-9a5d-09dc0dc8c3b4',
|
|
12
|
+
target_id: 1,
|
|
13
|
+
message_origin: 'btwb/events/daily_wod_created',
|
|
14
|
+
subject: 'My Test Subject',
|
|
15
|
+
text_body: 'This is a text email',
|
|
16
|
+
html_body: 'This is an html body email',
|
|
17
|
+
categories: ['tag1'],
|
|
18
|
+
to: 'user@example.com',
|
|
19
|
+
from: 'from_user@example.com'
|
|
20
|
+
}}
|
|
21
|
+
let(:command) {
|
|
22
|
+
Moogle::Commands::PushEmail
|
|
23
|
+
}
|
|
24
|
+
let(:options) {{
|
|
25
|
+
}}
|
|
26
|
+
|
|
27
|
+
it 'should push an email' do
|
|
28
|
+
result = command.call request, options
|
|
29
|
+
result.kind.should == 'moogle/events/email_pushed'
|
|
30
|
+
|
|
31
|
+
result.target_id.should == request[:target_id]
|
|
32
|
+
result.message_origin == request[:message_origin]
|
|
33
|
+
result.parent_uuid.should == request[:uuid]
|
|
34
|
+
result.request.should_not be_nil
|
|
35
|
+
|
|
36
|
+
deliveries = Mail.delivery_method.class.deliveries
|
|
37
|
+
deliveries.size.should == 1
|
|
38
|
+
sent_mail = deliveries.first
|
|
39
|
+
sent_mail.to.should == [request[:to]]
|
|
40
|
+
sent_mail.from.should == [request[:from]]
|
|
41
|
+
sent_mail.subject.should == request[:subject]
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
|
2
|
+
|
|
3
|
+
describe 'Moogle::Commands::PushWebhookPing' do
|
|
4
|
+
let(:request) {{
|
|
5
|
+
uuid: '85d9e997-6dcd-499e-9a5d-09dc0dc8c3b4',
|
|
6
|
+
target_id: 1,
|
|
7
|
+
message_origin: 'btwb/events/daily_wod_created',
|
|
8
|
+
data: '{}',
|
|
9
|
+
webhook_uri: 'http://www.example.com/',
|
|
10
|
+
secret: 'secretpassword'
|
|
11
|
+
}}
|
|
12
|
+
let(:command) {
|
|
13
|
+
Moogle::Commands::PushWebhookPing
|
|
14
|
+
}
|
|
15
|
+
let(:options) {{
|
|
16
|
+
}}
|
|
17
|
+
|
|
18
|
+
it 'should push a ping' do
|
|
19
|
+
VCR.use_cassette('push_webhook_ping') do
|
|
20
|
+
result = command.call request, options
|
|
21
|
+
result.kind.should == 'moogle/events/webhook_ping_pushed'
|
|
22
|
+
|
|
23
|
+
result.webhook_uri.should == request[:webhook_uri]
|
|
24
|
+
result.target_id.should == request[:target_id]
|
|
25
|
+
result.message_origin == request[:message_origin]
|
|
26
|
+
result.parent_uuid.should == request[:uuid]
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
end
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
|
2
|
+
|
|
3
|
+
describe 'Moogle::Commands::CreateTarget' do
|
|
4
|
+
let(:request_hash) {{
|
|
5
|
+
type: :blog,
|
|
6
|
+
owner_ref: 'System:1',
|
|
7
|
+
options: {
|
|
8
|
+
'rpc_uri' => 'http://example.com/target',
|
|
9
|
+
'blog_uri' => 'http://example.com/',
|
|
10
|
+
'blog_id' => 'example_blog_name',
|
|
11
|
+
'username' => 'username',
|
|
12
|
+
'password' => 'password',
|
|
13
|
+
'publish_immediately' => true
|
|
14
|
+
}
|
|
15
|
+
}}
|
|
16
|
+
let(:request) {
|
|
17
|
+
Moogle::Requests::CreateTarget.new request_hash
|
|
18
|
+
}
|
|
19
|
+
let(:command) {
|
|
20
|
+
Moogle::Commands::CreateTarget
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
it 'should create a target' do
|
|
24
|
+
result = command.call request
|
|
25
|
+
result.kind.should == 'moogle/events/target_created'
|
|
26
|
+
result.parent_uuid.should == request.uuid
|
|
27
|
+
result.target.type.should == Moogle::BlogTarget
|
|
28
|
+
result.target.owner_ref.should == 'System:1'
|
|
29
|
+
result.target.options.should == {
|
|
30
|
+
'rpc_uri' => 'http://example.com/target',
|
|
31
|
+
'blog_uri' => 'http://example.com/',
|
|
32
|
+
'blog_id' => 'example_blog_name',
|
|
33
|
+
'username' => 'username',
|
|
34
|
+
'password' => 'password',
|
|
35
|
+
'publish_immediately' => true
|
|
36
|
+
}
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
it 'should be able to parse a hash as request' do
|
|
40
|
+
result = command.call request_hash
|
|
41
|
+
result.kind.should == 'moogle/events/target_created'
|
|
42
|
+
result.target.type.should == Moogle::BlogTarget
|
|
43
|
+
result.target.owner_ref.should == 'System:1'
|
|
44
|
+
result.target.options.should == {
|
|
45
|
+
'rpc_uri' => 'http://example.com/target',
|
|
46
|
+
'blog_uri' => 'http://example.com/',
|
|
47
|
+
'blog_id' => 'example_blog_name',
|
|
48
|
+
'username' => 'username',
|
|
49
|
+
'password' => 'password',
|
|
50
|
+
'publish_immediately' => true
|
|
51
|
+
}
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
describe 'Moogle::Commands::DestroyTarget' do
|
|
56
|
+
let(:request_hash) {{
|
|
57
|
+
target_id: 12345
|
|
58
|
+
}}
|
|
59
|
+
let(:command) {
|
|
60
|
+
Moogle::Commands::DestroyTarget
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
describe 'with non-existent target' do
|
|
64
|
+
let(:request) {
|
|
65
|
+
Moogle::Requests::DestroyTarget.new request_hash
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
it 'should succeed' do
|
|
69
|
+
result = command.call request
|
|
70
|
+
result.kind.should == 'moogle/events/target_destroyed'
|
|
71
|
+
result.parent_uuid.should == request.uuid
|
|
72
|
+
result.target_id.should == 12345
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
describe 'with existing target' do
|
|
77
|
+
let(:existing_target) {
|
|
78
|
+
Moogle::BlogTarget.create(
|
|
79
|
+
owner_ref: 'System:1a',
|
|
80
|
+
options: {
|
|
81
|
+
'rpc_uri' => 'http://example.com/target',
|
|
82
|
+
'blog_uri' => 'http://example.com/',
|
|
83
|
+
'blog_id' => 'example_blog_name',
|
|
84
|
+
'username' => 'username',
|
|
85
|
+
'password' => 'password',
|
|
86
|
+
'publish_immediately' => true
|
|
87
|
+
})
|
|
88
|
+
}
|
|
89
|
+
let(:request) {
|
|
90
|
+
Moogle::Requests::DestroyTarget.new target_id: existing_target.id
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
it 'should succeed' do
|
|
94
|
+
result = command.call request
|
|
95
|
+
result.kind.should == 'moogle/events/target_destroyed'
|
|
96
|
+
result.parent_uuid.should == request.uuid
|
|
97
|
+
result.target_id.should == existing_target.id
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
it 'should be able to parse a hash as request' do
|
|
102
|
+
result = command.call request_hash
|
|
103
|
+
result.kind.should == 'moogle/events/target_destroyed'
|
|
104
|
+
result.target_id.should == 12345
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
describe 'Moogle::Commands::UpdateTarget' do
|
|
109
|
+
let(:existing_target) {
|
|
110
|
+
Moogle::BlogTarget.create(
|
|
111
|
+
owner_ref: 'System:1a',
|
|
112
|
+
options: {
|
|
113
|
+
'rpc_uri' => 'http://example.com/target',
|
|
114
|
+
'blog_uri' => 'http://example.com/',
|
|
115
|
+
'blog_id' => 'example_blog_name',
|
|
116
|
+
'username' => 'username',
|
|
117
|
+
'password' => 'password',
|
|
118
|
+
'publish_immediately' => true
|
|
119
|
+
})
|
|
120
|
+
}
|
|
121
|
+
let(:request_hash) {{
|
|
122
|
+
target_id: existing_target.id,
|
|
123
|
+
options: {
|
|
124
|
+
'rpc_uri' => 'http://example.com/target',
|
|
125
|
+
'blog_uri' => 'http://example.com/',
|
|
126
|
+
'blog_id' => 'example_blog_name',
|
|
127
|
+
'username' => 'username',
|
|
128
|
+
'password' => 'password',
|
|
129
|
+
'publish_immediately' => false
|
|
130
|
+
}
|
|
131
|
+
}}
|
|
132
|
+
let(:request) {
|
|
133
|
+
Moogle::Requests::UpdateTarget.new request_hash
|
|
134
|
+
}
|
|
135
|
+
let(:command) {
|
|
136
|
+
Moogle::Commands::UpdateTarget
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
it 'should update existing target' do
|
|
140
|
+
result = command.call request
|
|
141
|
+
result.kind.should == 'moogle/events/target_updated'
|
|
142
|
+
result.parent_uuid.should == request.uuid
|
|
143
|
+
result.target.options.should == {
|
|
144
|
+
'rpc_uri' => 'http://example.com/target',
|
|
145
|
+
'blog_uri' => 'http://example.com/',
|
|
146
|
+
'blog_id' => 'example_blog_name',
|
|
147
|
+
'username' => 'username',
|
|
148
|
+
'password' => 'password',
|
|
149
|
+
'publish_immediately' => false
|
|
150
|
+
}
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
it 'should be able to parse a hash as request' do
|
|
154
|
+
result = command.call request
|
|
155
|
+
result.kind.should == 'moogle/events/target_updated'
|
|
156
|
+
result.target.options.should == {
|
|
157
|
+
'rpc_uri' => 'http://example.com/target',
|
|
158
|
+
'blog_uri' => 'http://example.com/',
|
|
159
|
+
'blog_id' => 'example_blog_name',
|
|
160
|
+
'username' => 'username',
|
|
161
|
+
'password' => 'password',
|
|
162
|
+
'publish_immediately' => false
|
|
163
|
+
}
|
|
164
|
+
end
|
|
165
|
+
end
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
|
2
|
+
|
|
3
|
+
describe 'Moogle::Handlers::AcceptNotification' do
|
|
4
|
+
let(:target) {
|
|
5
|
+
Moogle::EmailTarget.create(
|
|
6
|
+
owner_ref: 'member:1',
|
|
7
|
+
options: {
|
|
8
|
+
'to' => 'target@example.com',
|
|
9
|
+
'from' => 'source@example.com'
|
|
10
|
+
},
|
|
11
|
+
links: [
|
|
12
|
+
{
|
|
13
|
+
receiver_ref: 'member:1',
|
|
14
|
+
message_kind: 'some_application/my_notification'
|
|
15
|
+
}
|
|
16
|
+
]
|
|
17
|
+
)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
before(:each) do
|
|
21
|
+
target
|
|
22
|
+
end
|
|
23
|
+
after(:each) do
|
|
24
|
+
target.destroy
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
let(:message) {{
|
|
28
|
+
message_kind: 'some_application/my_notification',
|
|
29
|
+
receiver_refs: ['member:1', 'gym:1'],
|
|
30
|
+
subject: 'Subject',
|
|
31
|
+
html_body: 'My Html Body',
|
|
32
|
+
text_body: 'Text Body'
|
|
33
|
+
}}
|
|
34
|
+
let(:handler) {
|
|
35
|
+
Moogle::Handlers::AcceptNotification
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
it 'should accept a notification' do
|
|
39
|
+
pusher_queue = []
|
|
40
|
+
error_channel = []
|
|
41
|
+
results = handler.call(
|
|
42
|
+
message,
|
|
43
|
+
pusher_queue: pusher_queue,
|
|
44
|
+
error_channel: error_channel)
|
|
45
|
+
results.should be_nil
|
|
46
|
+
pusher_queue.first.class.should == Hash
|
|
47
|
+
pusher_queue.first[:subject].should == 'Subject'
|
|
48
|
+
pusher_queue.first[:html_body].should == 'My Html Body'
|
|
49
|
+
pusher_queue.first[:text_body].should == 'Text Body'
|
|
50
|
+
pusher_queue.first[:to].should == 'target@example.com'
|
|
51
|
+
pusher_queue.first[:from].should == 'source@example.com'
|
|
52
|
+
error_channel.should == []
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
end
|
data/spec/moogle_spec.rb
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
data/spec/spec_helper.rb
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
|
3
|
+
require 'rspec'
|
|
4
|
+
require 'moogle'
|
|
5
|
+
|
|
6
|
+
# Requires supporting files with custom matchers and macros, etc,
|
|
7
|
+
# in ./support/ and its subdirectories.
|
|
8
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
|
9
|
+
|
|
10
|
+
RSpec.configure do |config|
|
|
11
|
+
|
|
12
|
+
end
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
require 'moogle/commands'
|
|
2
|
+
require 'moogle/handlers/accept_notification'
|
|
3
|
+
require 'moogle/requests'
|
|
4
|
+
|
|
5
|
+
Aequitas::Violation.default_transformer =
|
|
6
|
+
Aequitas::MessageTransformer::DefaultStatic.new
|
|
7
|
+
|
|
8
|
+
DataMapper::Logger.new($stdout, :debug)
|
|
9
|
+
DataMapper.setup(:moogle_db, 'sqlite::memory:')
|
|
10
|
+
DataMapper.auto_migrate!
|