messenger 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION.yml +1 -1
- data/bin/messenger +3 -3
- data/lib/messenger.rb +1 -0
- data/lib/messenger/campfire.rb +1 -1
- data/lib/messenger/email.rb +1 -1
- data/lib/messenger/jabber.rb +1 -1
- data/lib/messenger/result.rb +18 -0
- data/lib/messenger/web.rb +1 -1
- data/test/test_campfire.rb +4 -2
- data/test/test_jabber.rb +6 -3
- data/test/test_result.rb +25 -0
- data/test/test_web.rb +4 -2
- metadata +4 -1
data/VERSION.yml
CHANGED
data/bin/messenger
CHANGED
@@ -89,13 +89,13 @@ end
|
|
89
89
|
#
|
90
90
|
puts "# Sending message to #{ARGV[0]}"
|
91
91
|
begin
|
92
|
-
|
93
|
-
if
|
92
|
+
result = Messenger.send(ARGV[0], ARGV[1], options)
|
93
|
+
if result.success?
|
94
94
|
puts "# Message sent successfully"
|
95
95
|
else
|
96
96
|
puts "# Message not sent"
|
97
97
|
puts "# Details:"
|
98
|
-
puts
|
98
|
+
puts result.response
|
99
99
|
end
|
100
100
|
rescue => e
|
101
101
|
puts "# **Error** #{e}"
|
data/lib/messenger.rb
CHANGED
data/lib/messenger/campfire.rb
CHANGED
data/lib/messenger/email.rb
CHANGED
data/lib/messenger/jabber.rb
CHANGED
data/lib/messenger/web.rb
CHANGED
@@ -18,7 +18,7 @@ module Messenger
|
|
18
18
|
def self.send(url, body, options={})
|
19
19
|
raise URLError, "The URL provided is invalid" unless self.valid_url?(url)
|
20
20
|
response = HTTParty.post(url, options.merge(:body => body))
|
21
|
-
|
21
|
+
Result.new(success?(response), response)
|
22
22
|
end
|
23
23
|
|
24
24
|
def self.obfuscate(url)
|
data/test/test_campfire.rb
CHANGED
@@ -14,13 +14,15 @@ module Messenger
|
|
14
14
|
should "post a successful message" do
|
15
15
|
HTTParty.expects(:post).with("http://subdomain.campfirenow.com/room/room/speak.json", :basic_auth => { :username => 'api', :password => 'x' }, :body => '{"message":{"body":"content"}}', :headers => { "Content-Type" => "application/json" }).returns(@success_response)
|
16
16
|
result = Campfire.send("campfire://api:room@subdomain.campfirenow.com", 'content')
|
17
|
-
|
17
|
+
assert result.success?
|
18
|
+
assert_equal @success_response, result.response
|
18
19
|
end
|
19
20
|
|
20
21
|
should "post a failed message" do
|
21
22
|
HTTParty.expects(:post).with("http://subdomain.campfirenow.com/room/room/speak.json", :basic_auth => { :username => 'api', :password => 'x' }, :body => '{"message":{"body":"content"}}', :headers => { "Content-Type" => "application/json" }).returns(@failure_response)
|
22
23
|
result = Campfire.send("campfire://api:room@subdomain.campfirenow.com", 'content')
|
23
|
-
assert_equal
|
24
|
+
assert_equal false, result.success?
|
25
|
+
assert_equal @failure_response, result.response
|
24
26
|
end
|
25
27
|
|
26
28
|
should "raise when sending to an invalid URL" do
|
data/test/test_jabber.rb
CHANGED
@@ -14,19 +14,22 @@ module Messenger
|
|
14
14
|
should "send a successful jabber message" do
|
15
15
|
::Jabber::Simple.expects(:new).with("notifier@zencoder.com", "asdfasdf", nil).returns(@successful_jabber)
|
16
16
|
result = Jabber.send("jabber://brandon@zencoder.com", "Test message", :jabber_id => "notifier@zencoder.com", :jabber_password => "asdfasdf")
|
17
|
-
|
17
|
+
assert result.success?
|
18
|
+
assert_nil result.response
|
18
19
|
end
|
19
20
|
|
20
21
|
should "determine and set the jabber host" do
|
21
22
|
::Jabber::Simple.expects(:new).with("notifier@zencoder.com", "asdfasdf", "host.com").returns(@successful_jabber)
|
22
23
|
result = Jabber.send("jabber://brandon@zencoder.com/host.com", "Test message", :jabber_id => "notifier@zencoder.com", :jabber_password => "asdfasdf")
|
23
|
-
|
24
|
+
assert result.success?
|
25
|
+
assert_nil result.response
|
24
26
|
end
|
25
27
|
|
26
28
|
should "fail if the recipient is not subscribed" do
|
27
29
|
::Jabber::Simple.expects(:new).with("notifier@zencoder.com", "asdfasdf", nil).returns(@failed_jabber)
|
28
30
|
result = Jabber.send("jabber://brandon@zencoder.com", "Test message", :jabber_id => "notifier@zencoder.com", :jabber_password => "asdfasdf")
|
29
|
-
assert_equal
|
31
|
+
assert_equal false, result.success?
|
32
|
+
assert_equal "Not yet authorized", result.response
|
30
33
|
end
|
31
34
|
|
32
35
|
should "raise when sending to an invalid URL" do
|
data/test/test_result.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require "#{File.dirname(__FILE__)}/test_helper"
|
2
|
+
|
3
|
+
module Messenger
|
4
|
+
|
5
|
+
class ResultTest < Test::Unit::TestCase
|
6
|
+
|
7
|
+
context "A result" do
|
8
|
+
|
9
|
+
should "return success as a boolean" do
|
10
|
+
result = Result.new(true, "Response")
|
11
|
+
assert result.success?
|
12
|
+
result = Result.new(false, "Response")
|
13
|
+
assert_equal false, result.success?
|
14
|
+
end
|
15
|
+
|
16
|
+
should "give access to the raw response" do
|
17
|
+
result = Result.new(true, "Response")
|
18
|
+
assert_equal "Response", result.response
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
data/test/test_web.rb
CHANGED
@@ -14,13 +14,15 @@ module Messenger
|
|
14
14
|
should "post a successful message" do
|
15
15
|
HTTParty.expects(:post).with("http://example.com", :body => '{ "key": "value" }', :headers => { "Content-Type" => "application/json" }).returns(@success_response)
|
16
16
|
result = Web.send("http://example.com", '{ "key": "value" }', :headers => { "Content-Type" => "application/json" })
|
17
|
-
|
17
|
+
assert result.success?
|
18
|
+
assert_equal @success_response, result.response
|
18
19
|
end
|
19
20
|
|
20
21
|
should "post a failed message" do
|
21
22
|
HTTParty.expects(:post).with("http://example.com", :body => '{ "key": "value" }', :headers => { "Content-Type" => "application/json" }).returns(@failure_response)
|
22
23
|
result = Web.send("http://example.com", '{ "key": "value" }', :headers => { "Content-Type" => "application/json" })
|
23
|
-
assert_equal
|
24
|
+
assert_equal false, result.success?
|
25
|
+
assert_equal @failure_response, result.response
|
24
26
|
end
|
25
27
|
|
26
28
|
should "raise if trying to send to an invalid URL" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: messenger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brandon Arbini
|
@@ -109,12 +109,14 @@ files:
|
|
109
109
|
- lib/messenger/email.rb
|
110
110
|
- lib/messenger/errors.rb
|
111
111
|
- lib/messenger/jabber.rb
|
112
|
+
- lib/messenger/result.rb
|
112
113
|
- lib/messenger/web.rb
|
113
114
|
- test/test_campfire.rb
|
114
115
|
- test/test_email.rb
|
115
116
|
- test/test_helper.rb
|
116
117
|
- test/test_jabber.rb
|
117
118
|
- test/test_messenger.rb
|
119
|
+
- test/test_result.rb
|
118
120
|
- test/test_web.rb
|
119
121
|
- LICENSE
|
120
122
|
has_rdoc: true
|
@@ -151,4 +153,5 @@ test_files:
|
|
151
153
|
- test/test_helper.rb
|
152
154
|
- test/test_jabber.rb
|
153
155
|
- test/test_messenger.rb
|
156
|
+
- test/test_result.rb
|
154
157
|
- test/test_web.rb
|