ruby-libnio 0.0.1 → 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/README.rdoc CHANGED
@@ -2,6 +2,68 @@
2
2
 
3
3
  Library for writing Notify.io(http://notify.io) applications
4
4
 
5
+ == Dependencies
6
+
7
+ You'll need the HTTParty gem
8
+
9
+ == Setting up Notifiers
10
+
11
+ To use ruby-libnio, include the LibNio module in the class you want to
12
+ send notifications from and set your Notify.io API key:
13
+
14
+ class Notifier
15
+ include LibNio
16
+ notify_api_key '[key]'
17
+ end
18
+
19
+ LibNio will include HTTParty in the Notification class and set the
20
+ base_uri to 'http://notify.io'
21
+
22
+ To set up your notifier you'll want to set defaults for some of the
23
+ parameters that the Notify.io is expecting:
24
+
25
+ n = Notifier.new do |n|
26
+ n.title = "GHNotify Message"
27
+ n.link = "http://ghnotiy.com"
28
+ n.sticky = true
29
+ n.icon = "http://a3.twimg.com/profile_images/517037601/notifyio-icon.png"
30
+ end
31
+
32
+ Note that you can override these defaults on a per notification basis if you
33
+ would like later.
34
+
35
+ == Sending Notifications
36
+
37
+ To send notifications to users using Notify.io you will need the md5 hash of
38
+ the Gmail address that they signed up with Notify.io with.
39
+
40
+ Note that the md5 hash of me@example.com and Me@example.com will be different,
41
+ so it is important that you use the correct casing. In the future, the Notify.io
42
+ API may include a method to verify user hashes, but for now you might need to
43
+ explicitly ask for them to ensure notifications are sent.
44
+
45
+ With that in mind, here is how we might send a message to someone, given we know
46
+ their userhash:
47
+ userhash_1 = "a9d9e4fd104a3ae26793ca155c6ee872"
48
+ n1.notify(userhash_1, :text => "some text")
49
+
50
+ This will POST to the Notify.io API, and send the default parameters you set earlier,
51
+ as well as the +text+ parameter you send in the method call. Notify's API will return
52
+ 'OK' if the POST is successful.
53
+
54
+ As mentioned, you can override the defaults on a per-notification basis if you want:
55
+ userhash_1 = "a9d9e4fd104a3ae26793ca155c6ee872"
56
+ n1.notify(userhash_1, :text => "some text", :title => "new title", :sticky => false)
57
+
58
+ Lastly, it is possible to send the same notification to a number of users:
59
+ userhash_1 = "a9d9e4fd104a3ae26793ca155c6ee872"
60
+ userhash_2 = "5add5f77c09f4c639293e7254a1faf77"
61
+ users = [userhash_1, userhash_2]
62
+ n2.notify_all(users, :text => "Tell everyone")
63
+
64
+ This will return an array of the responses codes from the Notify.io API.
65
+
66
+
5
67
  == Note on Patches/Pull Requests
6
68
 
7
69
  * Fork the project.
data/Rakefile CHANGED
@@ -5,13 +5,12 @@ begin
5
5
  require 'jeweler'
6
6
  Jeweler::Tasks.new do |gem|
7
7
  gem.name = "ruby-libnio"
8
- gem.summary = %Q{Library to assist in writing Notify.io application}
9
- gem.description = %Q{Library to assist in writing Notify.io application}
8
+ gem.summary = %Q{helps you write applications that can send notifications to Notify.io}
9
+ gem.description = %Q{helps you write applications that can send notifications to Notify.io}
10
10
  gem.email = "hunter.gillane@gmail.com"
11
11
  gem.homepage = "http://github.com/pinecon3/ruby-libnio"
12
12
  gem.authors = ["Hunter Gillane"]
13
13
  gem.add_dependency('httparty', '>= 0.4.5')
14
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
14
  end
16
15
  Jeweler::GemcutterTasks.new
17
16
  rescue LoadError
@@ -50,4 +49,4 @@ Rake::RDocTask.new do |rdoc|
50
49
  rdoc.title = "ruby-libnio #{version}"
51
50
  rdoc.rdoc_files.include('README*')
52
51
  rdoc.rdoc_files.include('lib/**/*.rb')
53
- end
52
+ end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.1.0
@@ -0,0 +1,41 @@
1
+ require 'rubygems'
2
+ require '../lib/ruby-libnio'
3
+
4
+ class Notifier
5
+ include LibNio
6
+ # you'll receive an api key when you create an account with Notify.io
7
+ # http://notify.io
8
+ notify_api_key 'p8m5zlpfwj6fqigrff'
9
+ end
10
+
11
+ n1 = Notifier.new
12
+ # set the defaults for notifications
13
+ n1.title = "GHNotify Message"
14
+ n1.link = "http://ghnotiy.com"
15
+ n1.sticky = true
16
+ n1.icon = "http://a3.twimg.com/profile_images/517037601/notifyio-icon.png"
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
25
+
26
+ # you'll need the MD5 hash of the gmail address of the user you want to notify
27
+ userhash_1 = "a9d9e4fd104a3ae26793ca155c6ee872"
28
+
29
+ # to use the default options
30
+ # :text is required
31
+ puts n1.notify(userhash_1, :text => "some text")
32
+
33
+ # overwrite some default options
34
+ puts n2.notify(userhash_1, :text => "message text", :title => "New Title", :sticky => false)
35
+
36
+
37
+ # you can also notify multiple users with the same message
38
+ userhash_2 = "5add5f77c09f4c639293e7254a1faf77"
39
+ users = [userhash_1, userhash_2]
40
+
41
+ puts n2.notify_all(users, :text => "Tell everyone").each {|resp| puts resp }
data/lib/ruby-libnio.rb CHANGED
@@ -1,26 +1,52 @@
1
1
  require 'httparty'
2
2
 
3
- class LibNio
4
- include HTTParty
5
- base_uri "api.notify.io"
3
+ module LibNio
6
4
 
7
- def initialize(key)
8
- @api_key = key
5
+ attr_accessor :title, :icon, :link, :sticky
6
+
7
+ def self.included(base)
8
+ base.extend ClassMethods
9
+ base.send(:include, HTTParty)
10
+ base.send(:base_uri, 'api.notify.io')
11
+ end
12
+
13
+ module ClassMethods
14
+ def notify_api_key(key=nil)
15
+ return @@api_key unless key
16
+ @@api_key = key
17
+ end
18
+
19
+ def initialize
20
+ yield self if block_given?
21
+ end
9
22
  end
10
23
 
11
- def t_get
12
- self.class.get('/')
24
+ def api_key
25
+ self.class.notify_api_key
13
26
  end
14
27
 
15
- def notify(userhash, message, title, icon, link, sticky)
16
- options = { :body =>
17
- {:text => message,
18
- :title => title,
19
- :icon => icon,
20
- :link => link,
21
- :sticky => sticky }
22
- }
23
-
24
- self.class.post("/v1/notify/#{userhash}?api_key=#{@api_key}", options)
28
+ def default_options
29
+ {:title => title,
30
+ :icon => icon,
31
+ :link => link,
32
+ :sticky => sticky }
25
33
  end
34
+
35
+ def notify(userhash, opts = {})
36
+ options = default_options.merge(opts)
37
+
38
+ # TODO: handle api key not being set
39
+ self.class.post("/v1/notify/#{userhash}?api_key=#{api_key}", :body => options)
40
+ end
41
+
42
+ def notify_all(userhashes, opts = {})
43
+ options = default_options.merge(opts)
44
+ responses = []
45
+ userhashes.each do |user|
46
+ responses << self.class.post("/v1/notify/#{user}?api_key=#{api_key}", :body => options)
47
+ end
48
+ responses
49
+ end
50
+
51
+ private :api_key
26
52
  end
data/ruby-libnio.gemspec CHANGED
@@ -5,12 +5,12 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{ruby-libnio}
8
- s.version = "0.0.1"
8
+ s.version = "0.1.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Hunter Gillane"]
12
- s.date = %q{2010-01-25}
13
- s.description = %q{Library to assist in writing Notify.io application}
12
+ s.date = %q{2010-01-31}
13
+ s.description = %q{helps you write applications that can send notifications to Notify.io}
14
14
  s.email = %q{hunter.gillane@gmail.com}
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE",
@@ -23,8 +23,11 @@ Gem::Specification.new do |s|
23
23
  "README.rdoc",
24
24
  "Rakefile",
25
25
  "VERSION",
26
+ "examples/simple.rb",
26
27
  "lib/ruby-libnio.rb",
27
28
  "ruby-libnio.gemspec",
29
+ "spec/libnio-spec.rb",
30
+ "spec/spec_helper.rb",
28
31
  "test/helper.rb",
29
32
  "test/test_ruby-libnio.rb"
30
33
  ]
@@ -32,10 +35,13 @@ Gem::Specification.new do |s|
32
35
  s.rdoc_options = ["--charset=UTF-8"]
33
36
  s.require_paths = ["lib"]
34
37
  s.rubygems_version = %q{1.3.5}
35
- s.summary = %q{Library to assist in writing Notify.io application}
38
+ s.summary = %q{helps you write applications that can send notifications to Notify.io}
36
39
  s.test_files = [
37
- "test/helper.rb",
38
- "test/test_ruby-libnio.rb"
40
+ "spec/libnio-spec.rb",
41
+ "spec/spec_helper.rb",
42
+ "test/helper.rb",
43
+ "test/test_ruby-libnio.rb",
44
+ "examples/simple.rb"
39
45
  ]
40
46
 
41
47
  if s.respond_to? :specification_version then
@@ -0,0 +1,16 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
2
+
3
+ describe LibNio do
4
+ before(:each) do
5
+ @klass = Class.new
6
+ @klass.instance_eval { include LibNio }
7
+ end
8
+ c
9
+ it "should mix in HTTParty" do
10
+ @klass.include?(HTTParty).should == true
11
+ end
12
+
13
+ it "should set the base uri" do
14
+ @klass.base_uri.should == 'http://api.notify.io'
15
+ end
16
+ end
@@ -0,0 +1,3 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'ruby-libnio')
2
+ gem 'rspec'
3
+ require 'spec/autorun'
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.0.1
4
+ version: 0.1.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-01-25 00:00:00 -08:00
12
+ date: 2010-01-31 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -22,7 +22,7 @@ dependencies:
22
22
  - !ruby/object:Gem::Version
23
23
  version: 0.4.5
24
24
  version:
25
- description: Library to assist in writing Notify.io application
25
+ description: helps you write applications that can send notifications to Notify.io
26
26
  email: hunter.gillane@gmail.com
27
27
  executables: []
28
28
 
@@ -38,8 +38,11 @@ files:
38
38
  - README.rdoc
39
39
  - Rakefile
40
40
  - VERSION
41
+ - examples/simple.rb
41
42
  - lib/ruby-libnio.rb
42
43
  - ruby-libnio.gemspec
44
+ - spec/libnio-spec.rb
45
+ - spec/spec_helper.rb
43
46
  - test/helper.rb
44
47
  - test/test_ruby-libnio.rb
45
48
  has_rdoc: true
@@ -69,7 +72,10 @@ rubyforge_project:
69
72
  rubygems_version: 1.3.5
70
73
  signing_key:
71
74
  specification_version: 3
72
- summary: Library to assist in writing Notify.io application
75
+ summary: helps you write applications that can send notifications to Notify.io
73
76
  test_files:
77
+ - spec/libnio-spec.rb
78
+ - spec/spec_helper.rb
74
79
  - test/helper.rb
75
80
  - test/test_ruby-libnio.rb
81
+ - examples/simple.rb