Skip to content

Commit

Permalink
FIXED: Register multiple notification causes error.
Browse files Browse the repository at this point in the history
  • Loading branch information
snaka committed Feb 1, 2010
1 parent ec51b5d commit 43f5e34
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 28 deletions.
48 changes: 26 additions & 22 deletions ChangeLog
@@ -1,37 +1,41 @@
= ruby_gntp change log

== Version 0.0.0
* Create public Git repository

== Version 0.0.1
* Initial version
== Version 0.3.4 - 2010/02/02
* FIXED: Register doesn't work with multiple notifications.
* Modify ChangeLog order.

== Version 0.0.2
* Fixed Japanese translated MIT License page URL.
== Version 0.3.3 - 2010/01/26
* Temporary patchwork fix - The code was commented out that recognize version
of the OS causes some defects -

== Version 0.1.0 - 2009/4/17
* Add GNTP.notify method for instant notification.
* Add ruby script examples.
== Version 0.3.1 - yyyy/mm/dd

== Version 0.1.1 - 2009/4/17
* Add NOTE to example directory.
== Version 0.3.0 - yyyy/mm/dd

== Version 0.1.2 - 2009/08/15
* Enabled password authentication mainly for sending notifications to a network machine.
== Version 0.2.0 - 2009/11/03
* Merge spidahman's commits. Lot of thanks, spidahman!
* Add some test(spec).

== Version 0.1.3 - 2009/08/19
* Added notification icon sending.
* Now sends out Origin-X headers.
* Use \r\n instead of \n in the header lines.

== Version 0.2.0 - 2009/11/03
* Merge spidahman's commits. Lot of thanks, spidahman!
* Add some test(spec).
== Version 0.1.2 - 2009/08/15
* Enabled password authentication mainly for sending notifications to a network machine.

== Version 0.3.0 - yyyy/mm/dd
== Version 0.1.1 - 2009/4/17
* Add NOTE to example directory.

== Version 0.3.1 - yyyy/mm/dd
== Version 0.1.0 - 2009/4/17
* Add GNTP.notify method for instant notification.
* Add ruby script examples.

== Version 0.3.2 - 2010/01/26
* Temporary patchwork fix - The code was commented out that recognize version
of the OS causes some defects -
== Version 0.0.2
* Fixed Japanese translated MIT License page URL.

== Version 0.0.1
* Initial version

== Version 0.0.0
* Create public Git repository
8 changes: 8 additions & 0 deletions example/NOTE
@@ -0,0 +1,8 @@
Attention when twitter_notifier.rb is used
Following gem is necessary to operate this script.
- json_pure
- pit

Please ensure that an appropriate value to environment variable EDITOR is set if you start and use Pit.
Pit starts executing the editor command set to EDITOR for the edit of account information, and the script will not operate correctly when this variable is not appropriately set.

Binary file added gems/ruby_gntp-0.1.0.gem
Binary file not shown.
Binary file added gems/ruby_gntp-0.3.4.gem
Binary file not shown.
9 changes: 5 additions & 4 deletions lib/ruby_gntp.rb
Expand Up @@ -42,7 +42,7 @@ class GNTP
attr_reader :message if $DEBUG

RUBY_GNTP_NAME = 'ruby_gntp'
RUBY_GNTP_VERSION = '0.3.3'
RUBY_GNTP_VERSION = '0.3.4'

def initialize(app_name = 'Ruby/GNTP', host = 'localhost', password = '', port = 23053)
@app_name = app_name
Expand Down Expand Up @@ -75,16 +75,17 @@ def register(params)
icon = notification[:icon]

message << "Notification-Name: #{name}\r\n"
message << "Notification-Enabled: #{enabled ? 'True' : 'False'}\r\n"
message << "Notification-Display-Name: #{disp_name}\r\n"
message << "Notification-Enabled: #{enabled ? 'True' : 'False'}\r\n"
message << "#{handle_icon(icon, 'Notification')}\r\n" if icon
message << "\r\n"
end

@binaries.each {|binary|
message << output_binary(binary)
message << "\r\n"
}

message << "\r\n"

unless (ret = send_and_recieve(message))
raise "Register failed"
Expand Down Expand Up @@ -238,7 +239,7 @@ def output_origin_headers
# platformname, platformversion = `uname -s`, `uname -r`
#end
platformname = "Windows"
platformname = "0.0"
platformversion = "0.0"

message << "Origin-Platform-Name: #{platformname.strip}\r\n"
message << "Origin-Platform-Version: #{platformversion.strip}\r\n"
Expand Down
29 changes: 29 additions & 0 deletions test/many_notifications.rb
@@ -0,0 +1,29 @@
require '../lib/ruby_gntp'

g = GNTP.new("test")

g.register( :notifications => [
{ :name => "notify", :enabled => true },
{ :name => "warning", :enabled => true },
{ :name => "error", :enabled => true },
])

g.notify(
:name => "notify",
:title => "Test",
:text => "hoge fuga"
)

g.notify(
:name => "warning",
:title => "warning",
:text => "Warn!"
)

g.notify(
:name => "error",
:title => "error",
:text => "ERROR"
)


36 changes: 34 additions & 2 deletions test/ruby_gntp_spec.rb
Expand Up @@ -11,15 +11,17 @@
include GNTPExampleHelperMethods

DEFAULT_APP_NAME = "Ruby/GNTP"
NOTIFICATION_NAME = "TestApp"
NOTIFICATION_NAME = "Notify"
NOTIFICATION_NAME2 = "Notify2"
NOTIFICATION_NAME3 = "Notify3"

before do
@sended_messages = []
@ok_response = StringIO.new(["GNTP/1.0 -OK NONE\r\n", "\r\n"].join)
@opened_socket = create_stub_socket(@ok_response, @sended_messages)
end

it "can register notifications with minimum params" do
it "can register notification with minimum params" do
@gntp = GNTP.new
@gntp.register :notifications => [{:name => NOTIFICATION_NAME}]

Expand All @@ -37,6 +39,36 @@

end

#
it "can register many notifications" do
@gntp = GNTP.new
@gntp.register :notifications => [
{:name => NOTIFICATION_NAME},
{:name => NOTIFICATION_NAME2},
]

@sended_messages.first.should == [
"GNTP/1.0 REGISTER NONE\r\n",
"Application-Name: #{DEFAULT_APP_NAME}\r\n",
"Origin-Machine-Name: #{Socket.gethostname}\r\n",
"Origin-Software-Name: #{GNTP::RUBY_GNTP_NAME}\r\n",
"Origin-Software-Version: #{GNTP::RUBY_GNTP_VERSION}\r\n",
"Origin-Platform-Name: Windows\r\n",
"Origin-Platform-Version: 0.0\r\n",
"Notifications-Count: 2\r\n",
"\r\n",
"Notification-Name: #{NOTIFICATION_NAME}\r\n",
"Notification-Display-Name: #{NOTIFICATION_NAME}\r\n",
"Notification-Enabled: True\r\n",
"\r\n",
"Notification-Name: #{NOTIFICATION_NAME2}\r\n",
"Notification-Display-Name: #{NOTIFICATION_NAME2}\r\n",
"Notification-Enabled: True\r\n",
"\r\n",
]

end

it "can register notifications to remote host" do
@gntp = GNTP.new "TestApp", "1.2.3.4", "password", 12345
@gntp.register :notifications => [{:name => NOTIFICATION_NAME}]
Expand Down

0 comments on commit 43f5e34

Please sign in to comment.