messenger 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,5 @@
1
1
  ---
2
- :patch: 0
2
+ :patch: 1
3
3
  :major: 0
4
4
  :build:
5
5
  :minor: 1
@@ -89,13 +89,13 @@ end
89
89
  #
90
90
  puts "# Sending message to #{ARGV[0]}"
91
91
  begin
92
- status, details = Messenger.send(ARGV[0], ARGV[1], options)
93
- if !!status
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 details
98
+ puts result.response
99
99
  end
100
100
  rescue => e
101
101
  puts "# **Error** #{e}"
@@ -63,6 +63,7 @@ module Messenger
63
63
  end
64
64
 
65
65
 
66
+ autoload :Result, "messenger/result"
66
67
  autoload :Email, "messenger/email"
67
68
  autoload :Web, "messenger/web"
68
69
  autoload :Campfire, "messenger/campfire"
@@ -22,7 +22,7 @@ module Messenger
22
22
  :headers => { "Content-Type" => "application/json" },
23
23
  :body => { "message" => { "body" => body } }.to_json
24
24
  )
25
- [success?(response), response]
25
+ Result.new(success?(response), response)
26
26
  end
27
27
 
28
28
  def self.obfuscate(url)
@@ -23,7 +23,7 @@ module Messenger
23
23
  body message
24
24
  end
25
25
  mail.deliver!
26
- [true, nil]
26
+ Result.new(true, nil)
27
27
  end
28
28
 
29
29
  def self.obfuscate(url)
@@ -29,7 +29,7 @@ module Messenger
29
29
  sleep 1
30
30
  end
31
31
  status = jabber.subscribed_to?(recipient)
32
- [status, status ? nil : "Not yet authorized"]
32
+ Result.new(status, status ? nil : "Not yet authorized")
33
33
  end
34
34
 
35
35
  def self.obfuscate(url)
@@ -0,0 +1,18 @@
1
+ module Messenger
2
+
3
+ class Result
4
+
5
+ attr_reader :response
6
+
7
+ def initialize(success, response)
8
+ @success = success
9
+ @response = response
10
+ end
11
+
12
+ def success?
13
+ !!@success
14
+ end
15
+
16
+ end
17
+
18
+ end
@@ -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
- [success?(response), response]
21
+ Result.new(success?(response), response)
22
22
  end
23
23
 
24
24
  def self.obfuscate(url)
@@ -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
- assert_equal [true, @success_response], result
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 [false, @failure_response], result
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
@@ -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
- assert_equal [true, nil], result
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
- assert_equal [true, nil], result
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 [false, "Not yet authorized"], result
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
@@ -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
@@ -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
- assert_equal [true, @success_response], result
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 [false, @failure_response], result
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.0
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