pushio 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +20 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +48 -0
- data/Rakefile +2 -0
- data/lib/push_io.rb +10 -0
- data/lib/push_io/client.rb +45 -0
- data/lib/push_io/configuration.rb +17 -0
- data/lib/push_io/errors.rb +4 -0
- data/lib/push_io/version.rb +3 -0
- data/pushio.gemspec +22 -0
- data/spec/push_io_spec.rb +39 -0
- metadata +94 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Push IO LLC
|
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,48 @@
|
|
1
|
+
# PushIoClient
|
2
|
+
|
3
|
+
An easy to use client for integrating push notifications into Ruby-based applications. This gem uses the Push IO API to trigger notification delivery to whatever audience you specify. In order to get full use of this gem you will need to have an active account on https://manage.push.io and have recipient devices registered to receive notifications. Learn more at http://push.io
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'pushio'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install pushio
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Configure the client:
|
22
|
+
|
23
|
+
```
|
24
|
+
PushIo::Client.configure do |config|
|
25
|
+
config.app_guid = [your app guid from https://manage.push.io]
|
26
|
+
config.sender_secret = [for your app on https://manage.push.io]
|
27
|
+
end
|
28
|
+
```
|
29
|
+
|
30
|
+
Send a broadcast push to everyone registered for your app:
|
31
|
+
```
|
32
|
+
push_client = PushIo::Client.new
|
33
|
+
notification_id = push_client.broadcast :message => "Hello everyone!"
|
34
|
+
```
|
35
|
+
|
36
|
+
Send a push to an audience:
|
37
|
+
```
|
38
|
+
push_client.deliver_to_audience "friends", :message => "Howdy friends", :count => 8
|
39
|
+
```
|
40
|
+
|
41
|
+
|
42
|
+
## Contributing
|
43
|
+
|
44
|
+
1. Fork it
|
45
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
46
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
47
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
48
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/lib/push_io.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
module PushIo
|
2
|
+
class Client
|
3
|
+
attr_reader :config
|
4
|
+
def initialize(attributes = {})
|
5
|
+
@config = PushIo::Client.config.dup
|
6
|
+
attributes.each do |name, value|
|
7
|
+
@config.send("#{name}=", value) if @config.respond_to?("#{name}=")
|
8
|
+
end
|
9
|
+
if (@config.app_guid.nil? || @config.app_guid == '' || @config.sender_secret.nil? || @config.sender_secret == '')
|
10
|
+
raise UnconfiguredClientError, "You must specify a Push IO service app_guid and sender_secret either in an initializer or when creating your PushIo::Client instance"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class << self
|
15
|
+
attr_accessor :configuration
|
16
|
+
|
17
|
+
def config
|
18
|
+
self.configuration ||= Configuration.new
|
19
|
+
end
|
20
|
+
|
21
|
+
def configure
|
22
|
+
yield(config)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def broadcast(*payload)
|
27
|
+
send_post(payload, {:audience => "broadcast"})
|
28
|
+
end
|
29
|
+
|
30
|
+
def deliver_to_audience(audience, *payload)
|
31
|
+
send_post(payload, {:audience => audience})
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
def send_url
|
36
|
+
"#{@config.endpoint_url}#{PushIo::NOTIFY_APP_PATH}#{@config.app_guid}/#{@config.sender_secret}"
|
37
|
+
end
|
38
|
+
def send_post(payload, args)
|
39
|
+
response = HTTPClient.new.post(send_url, {:body => build_post(args, payload)})
|
40
|
+
end
|
41
|
+
def build_post(args, payload)
|
42
|
+
args.merge({:payload => MultiJson.dump(payload)})
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module PushIo
|
2
|
+
class Configuration
|
3
|
+
|
4
|
+
attr_accessor :app_guid
|
5
|
+
attr_accessor :sender_secret
|
6
|
+
attr_writer :endpoint_url
|
7
|
+
|
8
|
+
def endpoint_url
|
9
|
+
@endpoint_url || PushIo::ENDPOINT_URL
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
module PushIo
|
15
|
+
ENDPOINT_URL = "https://manage.push.io"
|
16
|
+
NOTIFY_APP_PATH = "/api/v1/notify_app/"
|
17
|
+
end
|
data/pushio.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/push_io/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Push IO LLC", "Sean McKibben"]
|
6
|
+
gem.email = ["sean@push.io"]
|
7
|
+
gem.description = %q{Ruby client library to send push notifications via the Push IO API. See: http://push.io for more information and to set up your account.}
|
8
|
+
gem.summary = %q{This gem enables developers to easily create new notifications and send them via the Push IO API from Ruby apps.}
|
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 = "pushio"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = PushIo::VERSION
|
17
|
+
|
18
|
+
gem.add_dependency("httpclient", '>= 2.2.7')
|
19
|
+
gem.add_dependency("multi_json", '>= 1.3.0')
|
20
|
+
|
21
|
+
gem.add_development_dependency("rspec", '>= 2.11.0')
|
22
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require "rspec"
|
2
|
+
require 'push_io'
|
3
|
+
|
4
|
+
describe PushIo do
|
5
|
+
context "unconfigured" do
|
6
|
+
it "should tell you how to configure" do
|
7
|
+
expect{PushIo::Client.new}.to raise_error(PushIo::UnconfiguredClientError)
|
8
|
+
|
9
|
+
end
|
10
|
+
end
|
11
|
+
context "configured" do
|
12
|
+
before :each do
|
13
|
+
PushIo::Client.configure do |config|
|
14
|
+
config.app_guid = "1234"
|
15
|
+
config.sender_secret = "5678"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
it "should allow configuration" do
|
19
|
+
client = PushIo::Client.new
|
20
|
+
client.config.app_guid.should == "1234"
|
21
|
+
client.config.sender_secret.should == "5678"
|
22
|
+
end
|
23
|
+
it "should allow configuration override" do
|
24
|
+
client = PushIo::Client.new(:app_guid => "aaaa", :sender_secret => "qqqq")
|
25
|
+
client.config.app_guid.should == "aaaa"
|
26
|
+
client.config.sender_secret.should == "qqqq"
|
27
|
+
end
|
28
|
+
it "makes a send url" do
|
29
|
+
client = PushIo::Client.new
|
30
|
+
client.send(:send_url).should == "https://manage.push.io/api/v1/notify_app/1234/5678"
|
31
|
+
client = PushIo::Client.new(:app_guid => "aaaa", :sender_secret => "qqqq")
|
32
|
+
client.send(:send_url).should == "https://manage.push.io/api/v1/notify_app/aaaa/qqqq"
|
33
|
+
client = PushIo::Client.new(:endpoint_url => "http://somewhere.else.entirely.org")
|
34
|
+
client.send(:send_url).should == "http://somewhere.else.entirely.org/api/v1/notify_app/1234/5678"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
end
|
metadata
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pushio
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Push IO LLC
|
9
|
+
- Sean McKibben
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2012-09-19 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: httpclient
|
17
|
+
requirement: &70259231551220 !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 2.2.7
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: *70259231551220
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: multi_json
|
28
|
+
requirement: &70259231550500 !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.3.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: *70259231550500
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: rspec
|
39
|
+
requirement: &70259231549820 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ! '>='
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: 2.11.0
|
45
|
+
type: :development
|
46
|
+
prerelease: false
|
47
|
+
version_requirements: *70259231549820
|
48
|
+
description: ! 'Ruby client library to send push notifications via the Push IO API.
|
49
|
+
See: http://push.io for more information and to set up your account.'
|
50
|
+
email:
|
51
|
+
- sean@push.io
|
52
|
+
executables: []
|
53
|
+
extensions: []
|
54
|
+
extra_rdoc_files: []
|
55
|
+
files:
|
56
|
+
- .gitignore
|
57
|
+
- Gemfile
|
58
|
+
- LICENSE
|
59
|
+
- README.md
|
60
|
+
- Rakefile
|
61
|
+
- lib/push_io.rb
|
62
|
+
- lib/push_io/client.rb
|
63
|
+
- lib/push_io/configuration.rb
|
64
|
+
- lib/push_io/errors.rb
|
65
|
+
- lib/push_io/version.rb
|
66
|
+
- pushio.gemspec
|
67
|
+
- spec/push_io_spec.rb
|
68
|
+
homepage: ''
|
69
|
+
licenses: []
|
70
|
+
post_install_message:
|
71
|
+
rdoc_options: []
|
72
|
+
require_paths:
|
73
|
+
- lib
|
74
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
75
|
+
none: false
|
76
|
+
requirements:
|
77
|
+
- - ! '>='
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
requirements: []
|
87
|
+
rubyforge_project:
|
88
|
+
rubygems_version: 1.8.15
|
89
|
+
signing_key:
|
90
|
+
specification_version: 3
|
91
|
+
summary: This gem enables developers to easily create new notifications and send them
|
92
|
+
via the Push IO API from Ruby apps.
|
93
|
+
test_files:
|
94
|
+
- spec/push_io_spec.rb
|