ruby-libnio 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +7 -8
- data/VERSION +1 -1
- data/examples/simple.rb +8 -16
- data/lib/ruby-libnio.rb +4 -38
- data/spec/libnio_spec.rb +9 -32
- metadata +2 -2
data/README.rdoc
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
Library for writing Notify.io(http://notify.io) applications
|
4
4
|
|
5
5
|
== Note
|
6
|
-
|
6
|
+
No longer accepting block initialization on LibNio module.
|
7
7
|
|
8
8
|
== Dependencies
|
9
9
|
|
@@ -25,12 +25,11 @@ base_uri to 'http://notify.io'
|
|
25
25
|
To set up your notifier you'll want to set defaults for some of the
|
26
26
|
parameters that the Notify.io is expecting:
|
27
27
|
|
28
|
-
n = Notifier.new
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
end
|
28
|
+
n = Notifier.new
|
29
|
+
n.title = "GHNotify Message"
|
30
|
+
n.link = "http://ghnotiy.com"
|
31
|
+
n.sticky = true
|
32
|
+
n.icon = "http://a3.twimg.com/profile_images/517037601/notifyio-icon.png"
|
34
33
|
|
35
34
|
Note that you can override these defaults on a per notification basis if you
|
36
35
|
would like later.
|
@@ -68,7 +67,7 @@ This will return an array of the responses codes from the Notify.io API.
|
|
68
67
|
|
69
68
|
== Shoutouts
|
70
69
|
|
71
|
-
Thanks to Rob Olson for
|
70
|
+
Thanks to Rob Olson for advice.
|
72
71
|
|
73
72
|
|
74
73
|
== Note on Patches/Pull Requests
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
data/examples/simple.rb
CHANGED
@@ -8,34 +8,26 @@ class Notifier
|
|
8
8
|
notify_api_key 'p8m5zlpfwj6fqigrff'
|
9
9
|
end
|
10
10
|
|
11
|
-
|
11
|
+
n = Notifier.new
|
12
12
|
# set the defaults for notifications
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
# or initialize your notifier with a block
|
19
|
-
n2 = Notifier.new do |n|
|
20
|
-
n.title = "GHNotify Message"
|
21
|
-
n.link = "http://ghnotiy.com"
|
22
|
-
n.sticky = true
|
23
|
-
n.icon = "http://a3.twimg.com/profile_images/517037601/notifyio-icon.png"
|
24
|
-
end
|
13
|
+
n.title = "GHNotify Message"
|
14
|
+
n.link = "http://ghnotiy.com"
|
15
|
+
n.sticky = true
|
16
|
+
n.icon = "http://a3.twimg.com/profile_images/517037601/notifyio-icon.png"
|
25
17
|
|
26
18
|
# you'll need the MD5 hash of the gmail address of the user you want to notify
|
27
19
|
userhash_1 = "a9d9e4fd104a3ae26793ca155c6ee872"
|
28
20
|
|
29
21
|
# to use the default options
|
30
22
|
# :text is required
|
31
|
-
puts
|
23
|
+
puts n.notify(userhash_1, :text => "some text")
|
32
24
|
|
33
25
|
# overwrite some default options
|
34
|
-
puts
|
26
|
+
puts n.notify(userhash_1, :text => "message text", :title => "New Title", :sticky => false)
|
35
27
|
|
36
28
|
|
37
29
|
# you can also notify multiple users with the same message
|
38
30
|
userhash_2 = "5add5f77c09f4c639293e7254a1faf77"
|
39
31
|
users = [userhash_1, userhash_2]
|
40
32
|
|
41
|
-
|
33
|
+
n.notify_all(users, :text => "Tell everyone")
|
data/lib/ruby-libnio.rb
CHANGED
@@ -8,33 +8,10 @@ module LibNio
|
|
8
8
|
def self.included(base)
|
9
9
|
base.send(:include, HTTParty)
|
10
10
|
base.send(:base_uri, 'api.notify.io')
|
11
|
-
base.
|
12
|
-
base.extend ClassMethods
|
13
|
-
|
14
|
-
__overwrite_initialize__
|
15
|
-
|
16
|
-
def self.method_added(name)
|
17
|
-
return if name != :initialize || @_overwrote_initialize
|
18
|
-
|
19
|
-
@_overwrote_initialize = true
|
20
|
-
__overwrite_initialize__
|
21
|
-
end
|
22
|
-
|
23
|
-
end
|
11
|
+
base.extend ClassMethods
|
24
12
|
end
|
25
13
|
|
26
14
|
module ClassMethods
|
27
|
-
def __overwrite_initialize__
|
28
|
-
class_eval do
|
29
|
-
alias_method :original_initialize, :initialize
|
30
|
-
|
31
|
-
def initialize(*args)
|
32
|
-
yield(self) if block_given?
|
33
|
-
original_initialize(*args)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
15
|
def notify_api_key(key = nil)
|
39
16
|
return @api_key if key.nil?
|
40
17
|
@api_key = key
|
@@ -44,26 +21,15 @@ module LibNio
|
|
44
21
|
def api_key
|
45
22
|
self.class.notify_api_key
|
46
23
|
end
|
47
|
-
|
48
|
-
def default_options
|
49
|
-
{:title => title,
|
50
|
-
:icon => icon,
|
51
|
-
:link => link,
|
52
|
-
:sticky => sticky }
|
53
|
-
end
|
54
|
-
|
24
|
+
|
55
25
|
def notify(userhash, opts = {})
|
56
|
-
|
57
|
-
|
58
|
-
# TODO: handle api key not being set
|
59
|
-
self.class.post("/v1/notify/#{userhash}?api_key=#{api_key}", :body => options)
|
26
|
+
self.class.post("/v1/notify/#{userhash}?api_key=#{api_key}", :body => opts)
|
60
27
|
end
|
61
28
|
|
62
29
|
def notify_all(userhashes, opts = {})
|
63
|
-
options = default_options.merge(opts)
|
64
30
|
responses = []
|
65
31
|
userhashes.each do |user|
|
66
|
-
responses << self.class.post("/v1/notify/#{user}?api_key=#{api_key}", :body =>
|
32
|
+
responses << self.class.post("/v1/notify/#{user}?api_key=#{api_key}", :body => opts)
|
67
33
|
end
|
68
34
|
responses
|
69
35
|
end
|
data/spec/libnio_spec.rb
CHANGED
@@ -3,45 +3,22 @@ require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
|
|
3
3
|
describe LibNio do
|
4
4
|
before(:each) do
|
5
5
|
@klass = Class.new
|
6
|
-
@klass.instance_eval { include LibNio }
|
6
|
+
@klass.instance_eval { include LibNio; notify_api_key '1234' }
|
7
7
|
end
|
8
8
|
|
9
9
|
it "should mix in HTTParty" do
|
10
10
|
@klass.include?(HTTParty).should == true
|
11
11
|
end
|
12
12
|
|
13
|
-
it "should
|
14
|
-
@klass.
|
13
|
+
it "should have a method to return the API key" do
|
14
|
+
@klass.respond_to?(:notify_api_key).should == true
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should store the API key" do
|
18
|
+
@klass.notify_api_key.should == "1234"
|
15
19
|
end
|
16
20
|
|
17
|
-
|
18
|
-
|
19
|
-
class C
|
20
|
-
include LibNio
|
21
|
-
|
22
|
-
attr_accessor :name, :val
|
23
|
-
|
24
|
-
def initialize(n, v)
|
25
|
-
@name = n
|
26
|
-
@val = v
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
@c = C.new("joe", 4) do |c|
|
31
|
-
c.title = "test"
|
32
|
-
c.link = "http://test.net"
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
it "should handle the block initialization" do
|
37
|
-
@c.title.should == "test"
|
38
|
-
@c.link.should == "http://test.net"
|
39
|
-
end
|
40
|
-
|
41
|
-
it "should call the mixing class' initialize with the correct parameters" do
|
42
|
-
@c.name.should == "joe"
|
43
|
-
@c.val.should == 4
|
44
|
-
end
|
21
|
+
it "should set the base uri" do
|
22
|
+
@klass.base_uri.should == 'http://api.notify.io'
|
45
23
|
end
|
46
|
-
|
47
24
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-libnio
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hunter Gillane
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-02-
|
12
|
+
date: 2010-02-18 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|