smulube-notifo 0.1.1

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/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Jonathan Markwell
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,28 @@
1
+ = notifo
2
+
3
+ A library for using Notifo. Notifo is a way for users to receive mobile notifications for anything, more at http://notifo.com. This gem uses John Nunemaker's awesome HTTParty.
4
+
5
+ == Installing
6
+ $ gem install notifo
7
+
8
+ == Using notifo
9
+
10
+ require 'rubygems'
11
+ require 'notifo'
12
+ notifo = Notifo.new("YOUR_NOTIFO_SERVICE_USERNAME","YOUR_NOTIFO_SERVICE_APISECRET")
13
+ notifo.subscribe_user("A_NOTIFO_USERNAME")
14
+ notifo.send_notification("A_SUBSCRIBED_NOTIFO_USERNAME","A MESSAGE")
15
+ notifo.send_message("A_SUBSCRIBED_NOTIFO_USERNAME", "A MESSAGE")
16
+ notifo.verify_webhook_signature(post_params_hash)
17
+
18
+ == Note on Patches/Pull Requests
19
+
20
+ * Fork the project.
21
+ * Make your feature addition or bug fix.
22
+ * Add tests for it. This is important so I don't break it in a future version unintentionally.
23
+ * Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
24
+ * Send me a pull request. Bonus points for topic branches.
25
+
26
+ == Copyright
27
+
28
+ Copyright (c) 2010 Jonathan Markwell. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,59 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "smulube-notifo"
8
+ gem.summary = "A library for using the Notifo iPhone notifications service."
9
+ gem.description = "A library for using Notifo. Notifo is a way for users to receive mobile notifications for anything, more at http://notifo.com. This gem uses John Nunemaker's awesome HTTParty."
10
+ gem.email = "jonathan.markwell@gmail.com"
11
+ gem.homepage = "http://github.com/jot/notifo"
12
+ gem.authors = ["Jonathan Markwell"]
13
+ gem.add_dependency "httparty", "~>0.4.5"
14
+ gem.add_development_dependency "shoulda"
15
+ gem.add_development_dependency "fakeweb"
16
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
17
+ end
18
+ Jeweler::GemcutterTasks.new
19
+ rescue LoadError
20
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
21
+ end
22
+
23
+ require 'rake/testtask'
24
+ Rake::TestTask.new(:test) do |test|
25
+ test.libs << 'lib' << 'test'
26
+ test.pattern = 'test/**/*_test.rb'
27
+ test.verbose = true
28
+ end
29
+
30
+ begin
31
+ require 'rcov/rcovtask'
32
+ Rcov::RcovTask.new do |test|
33
+ test.libs << 'test'
34
+ test.pattern = 'test/**/*_test.rb'
35
+ test.verbose = true
36
+ end
37
+ rescue LoadError
38
+ task :rcov do
39
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
40
+ end
41
+ end
42
+
43
+ task :test => :check_dependencies
44
+
45
+ task :default => :test
46
+
47
+ require 'rake/rdoctask'
48
+ Rake::RDocTask.new do |rdoc|
49
+ if File.exist?('VERSION')
50
+ version = File.read('VERSION')
51
+ else
52
+ version = ""
53
+ end
54
+
55
+ rdoc.rdoc_dir = 'rdoc'
56
+ rdoc.title = "notifo #{version}"
57
+ rdoc.rdoc_files.include('README*')
58
+ rdoc.rdoc_files.include('lib/**/*.rb')
59
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.1
data/lib/notifo.rb ADDED
@@ -0,0 +1,75 @@
1
+ require 'httparty'
2
+ require 'cgi'
3
+ require 'digest/sha1'
4
+
5
+ # Simple client class for the Notifo API.
6
+ class Notifo
7
+ include HTTParty
8
+ base_uri 'https://api.notifo.com/v1'
9
+
10
+ # Create a new client instance. Must be supplied with the username and
11
+ # api_secret for your service.
12
+ #
13
+ # Required Parameters:
14
+ # username - notifo service username
15
+ # api_secret - notifo service api secret
16
+ def initialize(username, api_secret)
17
+ @auth = { :username => username, :password => api_secret }
18
+ end
19
+
20
+ # Subscribe a user to your service. This sends them a message confirming they
21
+ # want to use the service.
22
+ #
23
+ # Required Parameters:
24
+ # username - notifo username to subscribe to your service
25
+ def subscribe_user(username)
26
+ options = { :body => { :username => username }, :basic_auth => @auth }
27
+ self.class.post("/subscribe_user", options)
28
+ end
29
+
30
+ # Send a notification to the specified user. You will only be allowed to send
31
+ # notifications to users who have previously subscribed to your service.
32
+ #
33
+ # Required Parameters:
34
+ # username - notifo username of recipient
35
+ # message - message being sent; must be url encoded
36
+ #
37
+ # Optional Parameters:
38
+ # title - name of "notification event"
39
+ # uri - the uri that will be loaded when the notification is opened; if specified, must be urlencoded; if a web address, must start with http:// or https://
40
+ # label - label describing the "application" (used only if being sent from a User account; the Service label is automatically applied if being sent from a Service account)
41
+ def send_notification(username, message, title = nil, uri = nil, label = nil)
42
+ options = { :body => {:to => username, :msg => message, :label => title, :title => title, :uri => uri}, :basic_auth => @auth }
43
+ self.class.post('/send_notification', options)
44
+ end
45
+
46
+ def post(username, message, title = nil, uri = nil, label = nil) # :ndoc:
47
+ warn "DEPRECATION WARNING: the 'post' method is deprecated. Use 'send_notification' instead"
48
+ send_notification(username, message, title, uri, label)
49
+ end
50
+
51
+ # Required Parameters:
52
+ # params - the hash of params the webhook passed to you. All keys must be *Strings*, not symbols.
53
+ def verify_webhook_signature(params)
54
+ signature = params['notifo_signature']
55
+ other_notifo_params = params.reject {|key,val| !(key =~ /\Anotifo_/ && key != "notifo_signature")}
56
+ str = other_notifo_params.keys.sort.map do |key|
57
+ params[key]
58
+ end.join
59
+ str << @auth[:password]
60
+
61
+ signature == Digest::SHA1.hexdigest(CGI::escape(str))
62
+ end
63
+
64
+ # Send a message to a specific Notifo user. Messages are slightly different
65
+ # from notifications in that they are permitted to be sent to users who
66
+ # haven't subscribed.
67
+ #
68
+ # Required Parameters:
69
+ # username - notifo username of recipient
70
+ # message - message being sent; must be url encoded
71
+ def send_message(username, message)
72
+ options = { :body => { :to => username, :msg => message }, :basic_auth => @auth }
73
+ self.class.post('/send_message', options)
74
+ end
75
+ end
@@ -0,0 +1,61 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{smulube-notifo}
8
+ s.version = "0.1.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Jonathan Markwell"]
12
+ s.date = %q{2011-02-03}
13
+ s.description = %q{A library for using Notifo. Notifo is a way for users to receive mobile notifications for anything, more at http://notifo.com. This gem uses John Nunemaker's awesome HTTParty.}
14
+ s.email = %q{jonathan.markwell@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "lib/notifo.rb",
27
+ "smulube-notifo.gemspec",
28
+ "test/assets/webhook_params.yaml",
29
+ "test/notifo_test.rb",
30
+ "test/test_helper.rb"
31
+ ]
32
+ s.homepage = %q{http://github.com/jot/notifo}
33
+ s.rdoc_options = ["--charset=UTF-8"]
34
+ s.require_paths = ["lib"]
35
+ s.rubygems_version = %q{1.3.7}
36
+ s.summary = %q{A library for using the Notifo iPhone notifications service.}
37
+ s.test_files = [
38
+ "test/test_helper.rb",
39
+ "test/notifo_test.rb"
40
+ ]
41
+
42
+ if s.respond_to? :specification_version then
43
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
44
+ s.specification_version = 3
45
+
46
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
47
+ s.add_runtime_dependency(%q<httparty>, ["~> 0.4.5"])
48
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
49
+ s.add_development_dependency(%q<fakeweb>, [">= 0"])
50
+ else
51
+ s.add_dependency(%q<httparty>, ["~> 0.4.5"])
52
+ s.add_dependency(%q<shoulda>, [">= 0"])
53
+ s.add_dependency(%q<fakeweb>, [">= 0"])
54
+ end
55
+ else
56
+ s.add_dependency(%q<httparty>, ["~> 0.4.5"])
57
+ s.add_dependency(%q<shoulda>, [">= 0"])
58
+ s.add_dependency(%q<fakeweb>, [">= 0"])
59
+ end
60
+ end
61
+
@@ -0,0 +1,10 @@
1
+ ---
2
+ notifo_service: Message
3
+ notifo_title: ""
4
+ notifo_uri: http://test.com/
5
+ notifo_to_username: testing42
6
+ notifo_signature: 853bbc06ccae3491f3b9e5617f8b2b9dce6f65d5
7
+ notifo_unix_time: "1278988965"
8
+ notifo_message: Test
9
+ notifo_id: "1043960"
10
+ notifo_webhook_url: http://jackowayed-notifo.oncloud.org/
@@ -0,0 +1,61 @@
1
+ require 'test_helper'
2
+
3
+ class NotifoTest < Test::Unit::TestCase
4
+
5
+ context "setup test environment correctly" do
6
+ should "have substituted the username and password into the NOTIFO_BASE_URI constant" do
7
+ assert_equal "https://#{NOTIFO_USERNAME}:#{NOTIFO_API_SECRET}@api.notifo.com/v1", NOTIFO_BASE_URI
8
+ end
9
+ end
10
+
11
+ context "container context" do
12
+ setup do
13
+ @response = '{"status":"success","response_code":2201,"response_message":"OK"}'
14
+ end
15
+
16
+ context "#verify_webhook_sigature" do
17
+ should "return true if given the right API secret" do
18
+ assert NOTIFO.verify_webhook_signature(WEBHOOK)
19
+ end
20
+
21
+ should "return false if given the wrong API secret" do
22
+ bad_notifo = Notifo.new NOTIFO_USERNAME, 'thisisntthesecret'
23
+ assert !bad_notifo.verify_webhook_signature(WEBHOOK)
24
+ end
25
+ end
26
+
27
+ context "#subscribe user successfully" do
28
+ setup do
29
+ FakeWeb.register_uri(:post, "#{NOTIFO_BASE_URI}/subscribe_user", :body => @response)
30
+ end
31
+
32
+ should "subscribe the user" do
33
+ assert_equal @response, NOTIFO.subscribe_user("user")
34
+ end
35
+ end
36
+
37
+ context "#send_message successfully" do
38
+ setup do
39
+ FakeWeb.register_uri(:post, "#{NOTIFO_BASE_URI}/send_message", :body => @response)
40
+ end
41
+
42
+ should "send message to another user via notifo" do
43
+ assert_equal @response, NOTIFO.send_message("user", "message")
44
+ end
45
+ end
46
+
47
+ context "#send_notification successfully" do
48
+ setup do
49
+ FakeWeb.register_uri(:post, "#{NOTIFO_BASE_URI}/send_notification", :body => @response)
50
+ end
51
+
52
+ should "send notification using the new send_notification method" do
53
+ assert_equal @response, NOTIFO.send_notification("user", "message", "title", "http://google.com", "label")
54
+ end
55
+
56
+ should "send notification using the old post method" do
57
+ assert_equal @response, NOTIFO.post("user", "message", "title", "http://google.com", "label")
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,21 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+ require 'fakeweb'
5
+
6
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
7
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
8
+ require 'notifo'
9
+
10
+ class Test::Unit::TestCase
11
+ end
12
+
13
+ NOTIFO_USERNAME = 'testing42'
14
+ NOTIFO_API_SECRET = 'x96cb52807a33bafc8fd741eeba5e40ff89f05896'
15
+
16
+ NOTIFO = Notifo.new NOTIFO_USERNAME, NOTIFO_API_SECRET
17
+ NOTIFO_BASE_URI = Notifo.base_uri.gsub(/(https:\/\/)(.+)/, "\\1#{NOTIFO_USERNAME}:#{NOTIFO_API_SECRET}@\\2")
18
+
19
+ FakeWeb.allow_net_connect = false
20
+
21
+ WEBHOOK = YAML::load(File.read('test/assets/webhook_params.yaml'))
metadata ADDED
@@ -0,0 +1,122 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: smulube-notifo
3
+ version: !ruby/object:Gem::Version
4
+ hash: 25
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 1
10
+ version: 0.1.1
11
+ platform: ruby
12
+ authors:
13
+ - Jonathan Markwell
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-02-03 00:00:00 +00:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: httparty
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ hash: 5
30
+ segments:
31
+ - 0
32
+ - 4
33
+ - 5
34
+ version: 0.4.5
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: shoulda
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 3
46
+ segments:
47
+ - 0
48
+ version: "0"
49
+ type: :development
50
+ version_requirements: *id002
51
+ - !ruby/object:Gem::Dependency
52
+ name: fakeweb
53
+ prerelease: false
54
+ requirement: &id003 !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ hash: 3
60
+ segments:
61
+ - 0
62
+ version: "0"
63
+ type: :development
64
+ version_requirements: *id003
65
+ description: A library for using Notifo. Notifo is a way for users to receive mobile notifications for anything, more at http://notifo.com. This gem uses John Nunemaker's awesome HTTParty.
66
+ email: jonathan.markwell@gmail.com
67
+ executables: []
68
+
69
+ extensions: []
70
+
71
+ extra_rdoc_files:
72
+ - LICENSE
73
+ - README.rdoc
74
+ files:
75
+ - .document
76
+ - .gitignore
77
+ - LICENSE
78
+ - README.rdoc
79
+ - Rakefile
80
+ - VERSION
81
+ - lib/notifo.rb
82
+ - smulube-notifo.gemspec
83
+ - test/assets/webhook_params.yaml
84
+ - test/notifo_test.rb
85
+ - test/test_helper.rb
86
+ has_rdoc: true
87
+ homepage: http://github.com/jot/notifo
88
+ licenses: []
89
+
90
+ post_install_message:
91
+ rdoc_options:
92
+ - --charset=UTF-8
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ none: false
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ hash: 3
101
+ segments:
102
+ - 0
103
+ version: "0"
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ hash: 3
110
+ segments:
111
+ - 0
112
+ version: "0"
113
+ requirements: []
114
+
115
+ rubyforge_project:
116
+ rubygems_version: 1.3.7
117
+ signing_key:
118
+ specification_version: 3
119
+ summary: A library for using the Notifo iPhone notifications service.
120
+ test_files:
121
+ - test/test_helper.rb
122
+ - test/notifo_test.rb