rushover 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +45 -0
- data/Rakefile +9 -0
- data/lib/rushover.rb +39 -0
- data/lib/rushover/version.rb +3 -0
- data/rushover.gemspec +25 -0
- data/test/rushover_client_test.rb +58 -0
- data/test/rushover_user_test.rb +22 -0
- data/test/test_helper.rb +20 -0
- metadata +120 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Brendon Murphy
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# Rushover
|
2
|
+
|
3
|
+
A simple ruby [Pushover](https://pushover.net/) client. Pushover allows
|
4
|
+
sending simple push notifications to clients on iOS and Android devices.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
gem 'rushover'
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
$ bundle
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
|
18
|
+
$ gem install rushover
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
```ruby
|
23
|
+
require "rushover"
|
24
|
+
|
25
|
+
client = Rushover::Client.new(your_app_token)
|
26
|
+
client.notify(user_key, "some message", :priority => 1, :title => "a title!")
|
27
|
+
|
28
|
+
# Also provides a User class for convenience. Just keeps the user key
|
29
|
+
# around if you want to deal with a User object
|
30
|
+
user = Rushover::User.new(user_key, rushover_client)
|
31
|
+
user.notify("some user message", :title => "another title")
|
32
|
+
```
|
33
|
+
|
34
|
+
Optional params to the Pushover like `priority` or `title` are passed through.
|
35
|
+
|
36
|
+
Calls to `#notify` will return the parsed JSON response body. Pushover app uses
|
37
|
+
:status => 1 for success, 0 for failures.
|
38
|
+
|
39
|
+
## Contributing
|
40
|
+
|
41
|
+
1. Fork it
|
42
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
43
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
44
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
45
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/lib/rushover.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
require "rushover/version"
|
2
|
+
require "rest-client"
|
3
|
+
require "json"
|
4
|
+
|
5
|
+
module Rushover
|
6
|
+
class Client
|
7
|
+
MESSAGES_ENDPOINT = "https://api.pushover.net/1/messages.json".freeze
|
8
|
+
|
9
|
+
attr_accessor :token
|
10
|
+
|
11
|
+
def initialize(token)
|
12
|
+
@token = token
|
13
|
+
end
|
14
|
+
|
15
|
+
def notify(user_key, message, options = {})
|
16
|
+
data = { :token => token, :user => user_key, :message => message }
|
17
|
+
data.merge!(options)
|
18
|
+
begin
|
19
|
+
resp = RestClient.post MESSAGES_ENDPOINT, data.to_json, :content_type => "application/json"
|
20
|
+
JSON.parse(resp)
|
21
|
+
rescue RestClient::Exception => e
|
22
|
+
JSON.parse(e.response)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
class User
|
28
|
+
attr_accessor :key, :client
|
29
|
+
|
30
|
+
def initialize(key, client)
|
31
|
+
@key = key
|
32
|
+
@client = client
|
33
|
+
end
|
34
|
+
|
35
|
+
def notify(message, options = {})
|
36
|
+
client.notify(key, message, options)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/rushover.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/rushover/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Brendon Murphy"]
|
6
|
+
gem.email = ["xternal1+github@gmail.com"]
|
7
|
+
gem.summary = %q{A simple ruby Pushover client}
|
8
|
+
gem.description = gem.summary
|
9
|
+
gem.homepage = ""
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "rushover"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Rushover::VERSION
|
17
|
+
|
18
|
+
gem.add_dependency "json"
|
19
|
+
gem.add_dependency "rest-client"
|
20
|
+
|
21
|
+
gem.add_development_dependency "rake"
|
22
|
+
gem.add_development_dependency "contest"
|
23
|
+
gem.add_development_dependency "fakeweb"
|
24
|
+
end
|
25
|
+
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require File.expand_path("../test_helper", __FILE__)
|
2
|
+
|
3
|
+
class RushoverClientTest < RushoverTest
|
4
|
+
def client
|
5
|
+
Rushover::Client.new("test_api_token")
|
6
|
+
end
|
7
|
+
|
8
|
+
test "it initializes with a token" do
|
9
|
+
subject = Rushover::Client.new("foobar")
|
10
|
+
assert_equal "foobar", subject.token
|
11
|
+
end
|
12
|
+
|
13
|
+
context "with mandatory params" do
|
14
|
+
setup do
|
15
|
+
client.notify("test_user", "test message")
|
16
|
+
end
|
17
|
+
|
18
|
+
test "sending a message hits the messages.json endpoint" do
|
19
|
+
assert_equal "/1/messages.json", FakeWeb.last_request.path
|
20
|
+
end
|
21
|
+
|
22
|
+
test "sending a message uses the token" do
|
23
|
+
assert_equal "test_api_token", last_request_json["token"]
|
24
|
+
end
|
25
|
+
|
26
|
+
test "sending a message to the intended user" do
|
27
|
+
assert_equal "test_user", last_request_json["user"]
|
28
|
+
end
|
29
|
+
|
30
|
+
test "sending a notification includes the message" do
|
31
|
+
assert_equal "test message", last_request_json["message"]
|
32
|
+
end
|
33
|
+
|
34
|
+
test "successful notify" do
|
35
|
+
resp = client.notify("test_user", "test message")
|
36
|
+
assert_equal({"status" => 1}, resp)
|
37
|
+
end
|
38
|
+
|
39
|
+
test "failed notify" do
|
40
|
+
FakeWeb.register_uri(:post, "https://api.pushover.net/1/messages.json",
|
41
|
+
:body => { "message" => "cannot be blank", "status" => 0 }.to_json,
|
42
|
+
:content_type => "application/json", :status => ["400", "Bad request"])
|
43
|
+
resp = client.notify("test_user", nil)
|
44
|
+
assert_equal 0, resp["status"]
|
45
|
+
assert_equal "cannot be blank", resp["message"]
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context "with optional params" do
|
50
|
+
test "basic optional params" do
|
51
|
+
client.notify("test_user", "test message", :device => "test device", :title => "test title", :priority => 1, :timestamp => 123123)
|
52
|
+
assert_equal "test device", last_request_json["device"]
|
53
|
+
assert_equal "test title", last_request_json["title"]
|
54
|
+
assert_equal "1", last_request_json["priority"].to_s
|
55
|
+
assert_equal "123123", last_request_json["timestamp"].to_s
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require File.expand_path("../test_helper", __FILE__)
|
2
|
+
|
3
|
+
class RushoverUserTest < RushoverTest
|
4
|
+
def client
|
5
|
+
Rushover::Client.new("test_api_token")
|
6
|
+
end
|
7
|
+
|
8
|
+
setup do
|
9
|
+
@user = Rushover::User.new("user_key", client)
|
10
|
+
end
|
11
|
+
|
12
|
+
test "it initializes with a user key and client" do
|
13
|
+
assert_equal "user_key", @user.key
|
14
|
+
assert @user.client
|
15
|
+
end
|
16
|
+
|
17
|
+
test "notifying the user via the client" do
|
18
|
+
@user.notify("test user message", :priority => 1)
|
19
|
+
assert_equal "test user message", last_request_json["message"]
|
20
|
+
assert_equal "1", last_request_json["priority"].to_s
|
21
|
+
end
|
22
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require "test/unit"
|
2
|
+
require "contest"
|
3
|
+
require "fakeweb"
|
4
|
+
require "rushover"
|
5
|
+
|
6
|
+
FakeWeb.allow_net_connect = false
|
7
|
+
|
8
|
+
class RushoverTest < Test::Unit::TestCase
|
9
|
+
setup do
|
10
|
+
FakeWeb.register_uri(:post, "https://api.pushover.net/1/messages.json", :body => { :status => 1 }.to_json, :content_type => "application/json")
|
11
|
+
end
|
12
|
+
|
13
|
+
teardown do
|
14
|
+
FakeWeb.clean_registry
|
15
|
+
end
|
16
|
+
|
17
|
+
def last_request_json
|
18
|
+
JSON.parse(FakeWeb.last_request.body)
|
19
|
+
end
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rushover
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Brendon Murphy
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-08-30 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: json
|
16
|
+
requirement: &2164476560 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *2164476560
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rest-client
|
27
|
+
requirement: &2164476140 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *2164476140
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rake
|
38
|
+
requirement: &2164475720 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *2164475720
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: contest
|
49
|
+
requirement: &2164475300 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *2164475300
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: fakeweb
|
60
|
+
requirement: &2164474880 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
type: :development
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *2164474880
|
69
|
+
description: A simple ruby Pushover client
|
70
|
+
email:
|
71
|
+
- xternal1+github@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- .gitignore
|
77
|
+
- Gemfile
|
78
|
+
- LICENSE
|
79
|
+
- README.md
|
80
|
+
- Rakefile
|
81
|
+
- lib/rushover.rb
|
82
|
+
- lib/rushover/version.rb
|
83
|
+
- rushover.gemspec
|
84
|
+
- test/rushover_client_test.rb
|
85
|
+
- test/rushover_user_test.rb
|
86
|
+
- test/test_helper.rb
|
87
|
+
homepage: ''
|
88
|
+
licenses: []
|
89
|
+
post_install_message:
|
90
|
+
rdoc_options: []
|
91
|
+
require_paths:
|
92
|
+
- lib
|
93
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
94
|
+
none: false
|
95
|
+
requirements:
|
96
|
+
- - ! '>='
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
segments:
|
100
|
+
- 0
|
101
|
+
hash: 2170637214120495203
|
102
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
|
+
none: false
|
104
|
+
requirements:
|
105
|
+
- - ! '>='
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
segments:
|
109
|
+
- 0
|
110
|
+
hash: 2170637214120495203
|
111
|
+
requirements: []
|
112
|
+
rubyforge_project:
|
113
|
+
rubygems_version: 1.8.15
|
114
|
+
signing_key:
|
115
|
+
specification_version: 3
|
116
|
+
summary: A simple ruby Pushover client
|
117
|
+
test_files:
|
118
|
+
- test/rushover_client_test.rb
|
119
|
+
- test/rushover_user_test.rb
|
120
|
+
- test/test_helper.rb
|