zero_push 1.3.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.travis.yml +0 -7
- data/Gemfile.lock +1 -1
- data/README.md +19 -0
- data/lib/zero_push/client.rb +86 -13
- data/lib/zero_push/version.rb +1 -1
- data/lib/zero_push.rb +9 -37
- data/spec/fixtures/broadcast.yml +57 -0
- data/spec/fixtures/subscribe.yml +46 -0
- data/spec/fixtures/unsubscribe.yml +44 -0
- data/spec/generator_spec.rb +1 -1
- data/spec/zero_push_client_spec.rb +90 -51
- data/spec/zero_push_spec.rb +4 -125
- data/zero_push.gemspec +2 -1
- metadata +13 -27
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
NjA2Zjk0NTY1M2Q1NWU1NzVhMGRhZDQ3ZDNhNTQyZDM1MjBiNTM2Mg==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
MzU5OTI3NWVjODFkNjAzZjUxZTlmZDVlMGJjZDM1MjNkMmZiNWJkZQ==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
OWRlZTk1MjJhYmU4MDBlZjlkOThkZjgzYjlhMmQ2YmE2OTQ1MTk0Mzk2NjVk
|
10
|
+
MGRiNzg2YjhmYWJlZjc4ZGNlMzQ1M2FlNDIzZmJmMWIyNWYwZmJkMjNlYjBl
|
11
|
+
OGE4NjExYmEwNjU3YTdmMjkxNzE4MTVmYjFjMzE5NTNkNGNiZjE=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
NWI0YjZmMmI4NDVmNTZjNDgyNDhjYmM1ZWQwNWNkMTcxMzg5MGIwMTlhOGZl
|
14
|
+
NGFkYTRhZDM1ZmRlMmRmMzM3NDc2NmE1MTE0NTFmOTI3M2YxNmM3YjJkNzM5
|
15
|
+
OGRkZmYxNmQ5MTFlZGM2MDJjYWJjMmU0MzUzZTU2MDNmZmNiOTM=
|
data/.travis.yml
CHANGED
@@ -9,10 +9,3 @@ notifications:
|
|
9
9
|
email:
|
10
10
|
- adam.v.duke@gmail.com
|
11
11
|
- stefan.natchev@gmail.com
|
12
|
-
env:
|
13
|
-
global:
|
14
|
-
- secure: ! 'ILUUZU0RUJoOGipo5mpWFGz9rvherA9WBpEdrkQMQBXgGYz0BqqO3hVvdt6l
|
15
|
-
|
16
|
-
2A7p4RxNNxXlOaQ+XUs0s+5WU7O0ni4+QmGrqEWxDdatdd1rSmet7YWUj+H5
|
17
|
-
|
18
|
-
hIJmFtPYbk/ik89NCTYe+XW/RZrTTaUgfPSsYFifl/JanFRa/bE='
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -18,10 +18,29 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
21
|
+
### Rails Generator
|
21
22
|
Generate the ZeroPush initializer if you are using Ruby on Rails.
|
22
23
|
|
23
24
|
$ rails g zero_push:install
|
24
25
|
|
26
|
+
### API Client
|
27
|
+
|
28
|
+
The easiest way to use the API client is to set the auth token at the module level and call methods on the ZeroPush module.
|
29
|
+
|
30
|
+
ZeroPush.auth_token = 'your-auth-token'
|
31
|
+
ZeroPush.verify_credentials
|
32
|
+
=> true
|
33
|
+
|
34
|
+
If your application requires multiple API client instances, that can be achieved as well.
|
35
|
+
|
36
|
+
client_1 = ZeroPush.client('auth-token-1')
|
37
|
+
client_1.verify_credentials
|
38
|
+
=> true
|
39
|
+
|
40
|
+
client_2 = ZeroPush.client('auth-token-2')
|
41
|
+
client_2.verify_credentials
|
42
|
+
=> true
|
43
|
+
|
25
44
|
For more documentation, check our [Getting Started Guide with ZeroPush](https://zeropush.com/documentation)
|
26
45
|
|
27
46
|
## Contributing
|
data/lib/zero_push/client.rb
CHANGED
@@ -2,38 +2,111 @@ require 'faraday_middleware'
|
|
2
2
|
|
3
3
|
module ZeroPush
|
4
4
|
class Client
|
5
|
+
URL = 'https://api.zeropush.com'.freeze
|
6
|
+
|
7
|
+
attr_accessor :auth_token
|
5
8
|
|
6
9
|
def initialize(auth_token)
|
7
|
-
|
8
|
-
c.token_auth auth_token # Set the Authorization header
|
9
|
-
c.request :url_encoded # form-encode POST params
|
10
|
-
c.response :json, :content_type => /\bjson$/ # parse responses to JSON
|
11
|
-
c.adapter Faraday.default_adapter # Net::HTTP
|
12
|
-
end
|
10
|
+
self.auth_token = auth_token
|
13
11
|
end
|
14
12
|
|
13
|
+
# verifies credentials
|
14
|
+
#
|
15
|
+
# @return [Boolean]
|
15
16
|
def verify_credentials
|
16
|
-
response =
|
17
|
+
response = client.get('/verify_credentials')
|
17
18
|
response.status == 200
|
18
19
|
end
|
19
20
|
|
21
|
+
# Sends a notification to the list of devices
|
22
|
+
#
|
23
|
+
# @param params [Hash]
|
24
|
+
#
|
25
|
+
# Ex.
|
26
|
+
# {"sent_count":10,"inactive_tokens":[],"unregistered_tokens":["abc"]}
|
20
27
|
def notify(params)
|
21
|
-
|
28
|
+
client.post('/notify', params)
|
29
|
+
end
|
30
|
+
|
31
|
+
# Sends a notification to all of the devices registered with the ZeroPush backend
|
32
|
+
#
|
33
|
+
# @param params [Hash]
|
34
|
+
#
|
35
|
+
# Ex.
|
36
|
+
# {"sent_count":10}
|
37
|
+
def broadcast(params)
|
38
|
+
client.post('/broadcast', params)
|
39
|
+
end
|
40
|
+
|
41
|
+
# Subscribes a device to a particular notification channel
|
42
|
+
#
|
43
|
+
# @param device_token [String]
|
44
|
+
# @param channel [String]
|
45
|
+
#
|
46
|
+
# Ex.
|
47
|
+
# {"device_token":"abc", "channels":["foo"]}
|
48
|
+
def subscribe(device_token, channel)
|
49
|
+
client.post("/subscribe/#{channel}", device_token:device_token)
|
50
|
+
end
|
51
|
+
|
52
|
+
# Unsubscribes a device from a particular notification channel
|
53
|
+
#
|
54
|
+
# @param device_token [String]
|
55
|
+
# @param channel [String]
|
56
|
+
#
|
57
|
+
# Ex.
|
58
|
+
# {"device_token":"abc", "channels":[]}
|
59
|
+
def unsubscribe(device_token, channel)
|
60
|
+
client.delete("/subscribe/#{channel}", device_token:device_token)
|
22
61
|
end
|
23
62
|
|
63
|
+
# Registers a device token with the ZeroPush backend
|
64
|
+
#
|
65
|
+
# @param device_token
|
66
|
+
#
|
67
|
+
# Ex.
|
68
|
+
# {"message":"ok"}
|
24
69
|
def register(device_token)
|
25
|
-
|
70
|
+
client.post('/register', device_token: device_token)
|
26
71
|
end
|
27
72
|
|
73
|
+
# Sets the badge for a particular device
|
74
|
+
#
|
75
|
+
# @param device_token
|
76
|
+
# @param badge
|
77
|
+
#
|
78
|
+
# Ex.
|
79
|
+
# {"message":"ok"}
|
28
80
|
def set_badge(device_token, badge)
|
29
|
-
|
81
|
+
client.post('/set_badge', device_token: device_token, badge: badge)
|
30
82
|
end
|
31
83
|
|
84
|
+
# Returns a list of tokens that have been marked inactive
|
85
|
+
#
|
86
|
+
# Ex.
|
87
|
+
# [
|
88
|
+
# {
|
89
|
+
# "device_token":"238b8cb09011850cb4bd544dfe0c8f5eeab73d7eeaae9bdca59076db4ae49947",
|
90
|
+
# "marked_inactive_at":"2013-07-17T01:27:53-04:00"
|
91
|
+
# },
|
92
|
+
# {
|
93
|
+
# "device_token":"8c97be6643eea2143322005bc4c44a1aee5e549bce5e2bb2116114f45484ddaf",
|
94
|
+
# "marked_inactive_at":"2013-07-17T01:27:50-04:00"
|
95
|
+
# }
|
96
|
+
# ]
|
32
97
|
def inactive_tokens
|
33
|
-
|
98
|
+
client.get('/inactive_tokens')
|
34
99
|
end
|
35
100
|
|
36
|
-
|
37
|
-
|
101
|
+
# the HTTP client configured for API requests
|
102
|
+
#
|
103
|
+
def client
|
104
|
+
Faraday.new(url: URL) do |c|
|
105
|
+
c.token_auth self.auth_token
|
106
|
+
c.request :url_encoded # form-encode POST params
|
107
|
+
c.response :json, :content_type => /\bjson$/ # parse responses to JSON
|
108
|
+
c.adapter Faraday.default_adapter # Net::HTTP
|
109
|
+
end
|
110
|
+
end
|
38
111
|
end
|
39
112
|
end
|
data/lib/zero_push/version.rb
CHANGED
data/lib/zero_push.rb
CHANGED
@@ -1,61 +1,33 @@
|
|
1
|
-
require 'faraday'
|
2
|
-
require 'zero_push/client'
|
3
1
|
require 'zero_push/version'
|
2
|
+
require 'zero_push/client'
|
3
|
+
require 'faraday'
|
4
4
|
|
5
5
|
module ZeroPush
|
6
|
-
URL = "https://api.zeropush.com"
|
7
|
-
|
8
6
|
class << self
|
9
7
|
attr_accessor :auth_token
|
10
8
|
|
11
|
-
# verifies credentials
|
12
|
-
#
|
13
|
-
# @return [Boolean]
|
14
9
|
def verify_credentials
|
15
|
-
|
16
|
-
response.status == 200
|
10
|
+
client.verify_credentials
|
17
11
|
end
|
18
12
|
|
19
|
-
# Sends a notification to the list of devices
|
20
|
-
#
|
21
|
-
# @param params [Hash]
|
22
|
-
# @return response
|
23
13
|
def notify(params)
|
24
|
-
client.
|
14
|
+
client.notify(params)
|
25
15
|
end
|
26
16
|
|
27
|
-
# Registers a device token with the ZeroPush backend
|
28
|
-
#
|
29
|
-
# @param device_token
|
30
|
-
# @return response
|
31
17
|
def register(device_token)
|
32
|
-
client.
|
18
|
+
client.register(device_token)
|
33
19
|
end
|
34
20
|
|
35
|
-
# Sets the badge for a particular device
|
36
|
-
#
|
37
|
-
# @param device_token
|
38
|
-
# @param badge
|
39
|
-
# @return response
|
40
21
|
def set_badge(device_token, badge)
|
41
|
-
client.
|
22
|
+
client.set_badge(device_token, badge)
|
42
23
|
end
|
43
24
|
|
44
|
-
# Returns a list of tokens that have been marked inactive
|
45
|
-
#
|
46
|
-
# @returns array
|
47
25
|
def inactive_tokens
|
48
|
-
client.
|
26
|
+
client.inactive_tokens
|
49
27
|
end
|
50
28
|
|
51
|
-
|
52
|
-
|
53
|
-
def client
|
54
|
-
Faraday.new(url: URL) do |c|
|
55
|
-
c.token_auth self.auth_token
|
56
|
-
c.request :url_encoded # form-encode POST params
|
57
|
-
c.adapter Faraday.default_adapter # Net::HTTP
|
58
|
-
end
|
29
|
+
def client(auth_token = self.auth_token)
|
30
|
+
ZeroPush::Client.new(auth_token)
|
59
31
|
end
|
60
32
|
end
|
61
33
|
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: https://api.zeropush.com/broadcast
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: alert=hi
|
9
|
+
headers:
|
10
|
+
Authorization:
|
11
|
+
- Token token="test_token"
|
12
|
+
User-Agent:
|
13
|
+
- Faraday v0.8.8
|
14
|
+
Content-Type:
|
15
|
+
- application/x-www-form-urlencoded
|
16
|
+
response:
|
17
|
+
status:
|
18
|
+
code: 200
|
19
|
+
message:
|
20
|
+
headers:
|
21
|
+
server:
|
22
|
+
- nginx/1.2.6
|
23
|
+
date:
|
24
|
+
- Thu, 06 Jun 2013 20:13:18 GMT
|
25
|
+
content-type:
|
26
|
+
- application/json; charset=utf-8
|
27
|
+
transfer-encoding:
|
28
|
+
- chunked
|
29
|
+
connection:
|
30
|
+
- close
|
31
|
+
status:
|
32
|
+
- 200 OK
|
33
|
+
strict-transport-security:
|
34
|
+
- max-age=31536000
|
35
|
+
x-ua-compatible:
|
36
|
+
- IE=Edge,chrome=1
|
37
|
+
etag:
|
38
|
+
- ! '"58f271cd44a149e655e5c75c6ac3d588"'
|
39
|
+
cache-control:
|
40
|
+
- max-age=0, private, must-revalidate
|
41
|
+
set-cookie:
|
42
|
+
- _zero-push-session=BAh7BkkiD3Nlc3Npb25faWQGOgZFRkkiJTAyN2ZlNmZiYmE2NDAwZTAwNDhkZjljMDhjOTk5MDMzBjsAVA%3D%3D--123a1dc1afeac26db5bea15eea8574e82e0d91b2;
|
43
|
+
path=/; secure; HttpOnly
|
44
|
+
x-request-id:
|
45
|
+
- cb7a26e273628f7f0c9f3c4bbcfb5007
|
46
|
+
x-runtime:
|
47
|
+
- '0.045243'
|
48
|
+
x-rack-cache:
|
49
|
+
- invalidate, pass
|
50
|
+
x-powered-by:
|
51
|
+
- Phusion Passenger 4.0.2
|
52
|
+
body:
|
53
|
+
encoding: US-ASCII
|
54
|
+
string: ! '{"sent_count":10}'
|
55
|
+
http_version:
|
56
|
+
recorded_at: Thu, 06 Jun 2013 20:13:18 GMT
|
57
|
+
recorded_with: VCR 2.4.0
|
@@ -0,0 +1,46 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: https://api.zeropush.com/subscribe/foo_channel
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: device_token=abc
|
9
|
+
headers:
|
10
|
+
Authorization:
|
11
|
+
- Token token="test_token"
|
12
|
+
User-Agent:
|
13
|
+
- Faraday v0.8.8
|
14
|
+
Content-Type:
|
15
|
+
- application/x-www-form-urlencoded
|
16
|
+
response:
|
17
|
+
status:
|
18
|
+
code: 200
|
19
|
+
message:
|
20
|
+
headers:
|
21
|
+
server:
|
22
|
+
- nginx/1.2.6
|
23
|
+
date:
|
24
|
+
- Tue, 24 Sep 2013 21:04:42 GMT
|
25
|
+
content-type:
|
26
|
+
- application/json; charset=utf-8
|
27
|
+
transfer-encoding:
|
28
|
+
- chunked
|
29
|
+
connection:
|
30
|
+
- close
|
31
|
+
status:
|
32
|
+
- 200 OK
|
33
|
+
strict-transport-security:
|
34
|
+
- max-age=31536000
|
35
|
+
etag:
|
36
|
+
- "\"87bf21d9412e1d8611e6bdbe67ee3701\""
|
37
|
+
cache-control:
|
38
|
+
- max-age=0, private, must-revalidate
|
39
|
+
x-request-id:
|
40
|
+
- 79f5fe32-7d1e-4ffd-b90f-d17eaa7547da
|
41
|
+
body:
|
42
|
+
encoding: US-ASCII
|
43
|
+
string: "{\"device_token\":\"abc\",\"channels\":[\"foo_channel\"]}"
|
44
|
+
http_version:
|
45
|
+
recorded_at: Tue, 24 Sep 2013 21:04:42 GMT
|
46
|
+
recorded_with: VCR 2.4.0
|
@@ -0,0 +1,44 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: delete
|
5
|
+
uri: https://api.zeropush.com/subscribe/foo_channel?device_token=abc
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ""
|
9
|
+
headers:
|
10
|
+
Authorization:
|
11
|
+
- Token token="test_token"
|
12
|
+
User-Agent:
|
13
|
+
- Faraday v0.8.8
|
14
|
+
response:
|
15
|
+
status:
|
16
|
+
code: 200
|
17
|
+
message:
|
18
|
+
headers:
|
19
|
+
server:
|
20
|
+
- nginx/1.2.6
|
21
|
+
date:
|
22
|
+
- Tue, 24 Sep 2013 21:04:42 GMT
|
23
|
+
content-type:
|
24
|
+
- application/json; charset=utf-8
|
25
|
+
transfer-encoding:
|
26
|
+
- chunked
|
27
|
+
connection:
|
28
|
+
- close
|
29
|
+
status:
|
30
|
+
- 200 OK
|
31
|
+
strict-transport-security:
|
32
|
+
- max-age=31536000
|
33
|
+
etag:
|
34
|
+
- "\"87bf21d9412e1d8611e6bdbe67ee3701\""
|
35
|
+
cache-control:
|
36
|
+
- max-age=0, private, must-revalidate
|
37
|
+
x-request-id:
|
38
|
+
- 79f5fe32-7d1e-4ffd-b90f-d17eaa7547da
|
39
|
+
body:
|
40
|
+
encoding: US-ASCII
|
41
|
+
string: "{\"device_token\":\"abc\",\"channels\":[]}"
|
42
|
+
http_version:
|
43
|
+
recorded_at: Tue, 24 Sep 2013 21:04:42 GMT
|
44
|
+
recorded_with: VCR 2.4.0
|
data/spec/generator_spec.rb
CHANGED
@@ -15,7 +15,7 @@ class ZeroPush::GeneratorTest < Rails::Generators::TestCase
|
|
15
15
|
production_config = %Q|ZeroPush.auth_token = '#{production_token}'|
|
16
16
|
assert(initializer.include?(production_config), "The initializer doesn't include the production configuration")
|
17
17
|
|
18
|
-
development_config = %Q|ZeroPush.auth_token = '#{development_token}|
|
18
|
+
development_config = %Q|ZeroPush.auth_token = '#{development_token}'|
|
19
19
|
assert(initializer.include?(development_config), "The initializer doesn't include the development configuration")
|
20
20
|
end
|
21
21
|
end
|
@@ -2,129 +2,168 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe ZeroPush::Client do
|
4
4
|
|
5
|
-
let(:auth_token){ENV[
|
6
|
-
let(:
|
7
|
-
let(:unverified_client){ZeroPush::Client.new("not a valid token")}
|
5
|
+
let(:auth_token){ENV['AUTH_TOKEN'] || 'test_token'}
|
6
|
+
let(:client){ZeroPush.client(auth_token)}
|
8
7
|
|
9
|
-
describe
|
8
|
+
describe '#verify_credentials' do
|
10
9
|
before do
|
11
|
-
VCR.insert_cassette
|
10
|
+
VCR.insert_cassette 'verify_credentials'
|
12
11
|
end
|
13
12
|
|
14
13
|
after do
|
15
14
|
VCR.eject_cassette
|
16
15
|
end
|
17
16
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
it "should verify credentials successfully" do
|
22
|
-
response.must_equal true
|
23
|
-
end
|
17
|
+
it 'should verify credentials successfully' do
|
18
|
+
client.verify_credentials.must_equal true
|
24
19
|
end
|
25
20
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
it "should fail to verify credentials" do
|
30
|
-
response.must_equal false
|
31
|
-
end
|
21
|
+
it 'should fail to verify credentials' do
|
22
|
+
client = ZeroPush.client('not a valid token')
|
23
|
+
client.verify_credentials.must_equal false
|
32
24
|
end
|
33
25
|
end
|
34
26
|
|
35
|
-
describe
|
27
|
+
describe '#notify' do
|
36
28
|
before do
|
37
|
-
VCR.insert_cassette
|
29
|
+
VCR.insert_cassette 'notify'
|
38
30
|
end
|
39
31
|
|
40
32
|
after do
|
41
33
|
VCR.eject_cassette
|
42
34
|
end
|
43
35
|
|
44
|
-
let(:response){
|
36
|
+
let(:response){client.notify(device_tokens: ['abc'], alert: 'hi')}
|
45
37
|
|
46
|
-
it
|
47
|
-
response.class.must_equal Faraday::Response
|
48
|
-
end
|
49
|
-
|
50
|
-
it "should return a Hash for a response body" do
|
38
|
+
it 'should return a hash' do
|
51
39
|
response.body.class.must_equal Hash
|
52
40
|
end
|
53
41
|
|
54
|
-
it
|
55
|
-
response.
|
42
|
+
it 'should construct the request' do
|
43
|
+
response.body['sent_count'].must_equal 0
|
44
|
+
response.body['inactive_tokens'].must_equal []
|
56
45
|
end
|
57
46
|
end
|
58
47
|
|
59
|
-
describe
|
48
|
+
describe '#register' do
|
60
49
|
before do
|
61
|
-
VCR.insert_cassette
|
50
|
+
VCR.insert_cassette 'register'
|
62
51
|
end
|
63
52
|
|
64
53
|
after do
|
65
54
|
VCR.eject_cassette
|
66
55
|
end
|
67
56
|
|
68
|
-
let(:response){
|
57
|
+
let(:response){client.register('abc')}
|
58
|
+
|
59
|
+
it 'should return a hash' do
|
60
|
+
response.body.class.must_equal Hash
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'should register the device' do
|
64
|
+
response.body['message'].must_equal 'ok'
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe '#subscribe' do
|
69
|
+
before do
|
70
|
+
VCR.insert_cassette 'subscribe'
|
71
|
+
end
|
69
72
|
|
70
|
-
|
71
|
-
|
73
|
+
after do
|
74
|
+
VCR.eject_cassette
|
72
75
|
end
|
73
76
|
|
74
|
-
|
77
|
+
let(:response){client.subscribe('abc', 'foo_channel')}
|
78
|
+
|
79
|
+
it 'should return a hash' do
|
75
80
|
response.body.class.must_equal Hash
|
76
81
|
end
|
77
82
|
|
78
|
-
it
|
79
|
-
response.
|
83
|
+
it 'should subscribe a device to a channel' do
|
84
|
+
response.body['device_token'].must_equal 'abc'
|
85
|
+
response.body['channels'].must_equal ['foo_channel']
|
80
86
|
end
|
81
87
|
end
|
82
88
|
|
83
|
-
describe
|
89
|
+
describe '#unsubscribe' do
|
84
90
|
before do
|
85
|
-
VCR.insert_cassette
|
91
|
+
VCR.insert_cassette 'unsubscribe'
|
86
92
|
end
|
87
93
|
|
88
94
|
after do
|
89
95
|
VCR.eject_cassette
|
90
96
|
end
|
91
97
|
|
92
|
-
let(:response){
|
98
|
+
let(:response){client.unsubscribe('abc', 'foo_channel')}
|
99
|
+
|
100
|
+
it 'should return a hash' do
|
101
|
+
response.body.class.must_equal Hash
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'should subscribe a device to a channel' do
|
105
|
+
response.body['device_token'].must_equal 'abc'
|
106
|
+
response.body['channels'].must_equal []
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
describe '#broadcast' do
|
111
|
+
before do
|
112
|
+
VCR.insert_cassette 'broadcast'
|
113
|
+
end
|
93
114
|
|
94
|
-
|
95
|
-
|
115
|
+
after do
|
116
|
+
VCR.eject_cassette
|
96
117
|
end
|
97
118
|
|
98
|
-
|
119
|
+
let(:response){client.broadcast(alert:'hi')}
|
120
|
+
|
121
|
+
it 'should return a hash' do
|
99
122
|
response.body.class.must_equal Hash
|
100
123
|
end
|
101
124
|
|
102
|
-
it
|
103
|
-
response.
|
125
|
+
it 'should broadcast a notification to all the devices' do
|
126
|
+
response.body['sent_count'].must_equal 10
|
104
127
|
end
|
105
128
|
end
|
106
129
|
|
107
|
-
describe
|
130
|
+
describe '#set_badge' do
|
108
131
|
before do
|
109
|
-
VCR.insert_cassette
|
132
|
+
VCR.insert_cassette 'set_badge'
|
110
133
|
end
|
111
134
|
|
112
135
|
after do
|
113
136
|
VCR.eject_cassette
|
114
137
|
end
|
115
138
|
|
116
|
-
let(:response){
|
139
|
+
let(:response){client.set_badge('abc', 10)}
|
140
|
+
|
141
|
+
it 'should return a hash' do
|
142
|
+
response.body.class.must_equal Hash
|
143
|
+
end
|
144
|
+
|
145
|
+
it 'should set the device\'s badge' do
|
146
|
+
response.body['message'].must_equal 'ok'
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
describe '#inactive_tokens' do
|
151
|
+
before do
|
152
|
+
VCR.insert_cassette 'inactive_tokens'
|
153
|
+
end
|
117
154
|
|
118
|
-
|
119
|
-
|
155
|
+
after do
|
156
|
+
VCR.eject_cassette
|
120
157
|
end
|
121
158
|
|
122
|
-
|
159
|
+
let(:response){client.inactive_tokens}
|
160
|
+
|
161
|
+
it 'should return an array' do
|
123
162
|
response.body.class.must_equal Array
|
124
163
|
end
|
125
164
|
|
126
|
-
it
|
127
|
-
response.
|
165
|
+
it 'should get a list of inactive tokens' do
|
166
|
+
response.body.count.must_equal 2
|
128
167
|
end
|
129
168
|
end
|
130
169
|
end
|
data/spec/zero_push_spec.rb
CHANGED
@@ -1,134 +1,13 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require 'json'
|
3
2
|
|
4
3
|
describe ZeroPush do
|
5
4
|
before do
|
6
|
-
ZeroPush.auth_token = ENV[
|
5
|
+
ZeroPush.auth_token = ENV['AUTH_TOKEN'] || 'test_token'
|
7
6
|
end
|
8
7
|
|
9
|
-
describe
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
it "should return a Faraday client" do
|
14
|
-
client.class.must_equal Faraday::Connection
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
describe ".verify_credentials" do
|
19
|
-
before do
|
20
|
-
VCR.insert_cassette "verify_credentials"
|
21
|
-
end
|
22
|
-
|
23
|
-
after do
|
24
|
-
VCR.eject_cassette
|
25
|
-
end
|
26
|
-
|
27
|
-
let(:response){ZeroPush.verify_credentials}
|
28
|
-
|
29
|
-
it "should verify credentials successfully" do
|
30
|
-
response.must_equal true
|
31
|
-
end
|
32
|
-
|
33
|
-
it "should fail to verify credentials" do
|
34
|
-
ZeroPush.auth_token = "not a valid token"
|
35
|
-
response.must_equal false
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
describe ".notify" do
|
40
|
-
before do
|
41
|
-
VCR.insert_cassette "notify"
|
42
|
-
end
|
43
|
-
|
44
|
-
after do
|
45
|
-
VCR.eject_cassette
|
46
|
-
end
|
47
|
-
|
48
|
-
let(:response){ZeroPush.notify(device_tokens: ['abc'], alert: 'hi')}
|
49
|
-
|
50
|
-
it "should return a Faraday::Response" do
|
51
|
-
response.class.must_equal Faraday::Response
|
52
|
-
end
|
53
|
-
|
54
|
-
it "should return a response with a body that can be parsed into a Hash" do
|
55
|
-
JSON.parse(response.body).class.must_equal Hash
|
56
|
-
end
|
57
|
-
|
58
|
-
it "should be successful" do
|
59
|
-
response.status.must_equal 200
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
describe ".register" do
|
64
|
-
before do
|
65
|
-
VCR.insert_cassette "register"
|
66
|
-
end
|
67
|
-
|
68
|
-
after do
|
69
|
-
VCR.eject_cassette
|
70
|
-
end
|
71
|
-
|
72
|
-
let(:response){ZeroPush.register('abc')}
|
73
|
-
|
74
|
-
it "should return a Faraday::Response" do
|
75
|
-
response.class.must_equal Faraday::Response
|
76
|
-
end
|
77
|
-
|
78
|
-
it "should return a response with a body that can be parsed into a Hash" do
|
79
|
-
JSON.parse(response.body).class.must_equal Hash
|
80
|
-
end
|
81
|
-
|
82
|
-
it "should register the device" do
|
83
|
-
response.status.must_equal 200
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
describe ".set_badge" do
|
88
|
-
before do
|
89
|
-
VCR.insert_cassette "set_badge"
|
90
|
-
end
|
91
|
-
|
92
|
-
after do
|
93
|
-
VCR.eject_cassette
|
94
|
-
end
|
95
|
-
|
96
|
-
let(:response){ZeroPush.set_badge('abc', 10)}
|
97
|
-
|
98
|
-
it "should return a Faraday::Response" do
|
99
|
-
response.class.must_equal Faraday::Response
|
100
|
-
end
|
101
|
-
|
102
|
-
it "should return a response with a body that can be parsed into a Hash" do
|
103
|
-
JSON.parse(response.body).class.must_equal Hash
|
104
|
-
end
|
105
|
-
|
106
|
-
it "should set the device's badge" do
|
107
|
-
response.status.must_equal 200
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
describe ".inactive_tokens" do
|
112
|
-
before do
|
113
|
-
VCR.insert_cassette "inactive_tokens"
|
114
|
-
end
|
115
|
-
|
116
|
-
after do
|
117
|
-
VCR.eject_cassette
|
118
|
-
end
|
119
|
-
|
120
|
-
let(:response){ZeroPush.inactive_tokens}
|
121
|
-
|
122
|
-
it "should return a Faraday::Response" do
|
123
|
-
response.class.must_equal Faraday::Response
|
124
|
-
end
|
125
|
-
|
126
|
-
it "should return a response with a body that can be parsed into an Array" do
|
127
|
-
JSON.parse(response.body).class.must_equal Array
|
128
|
-
end
|
129
|
-
|
130
|
-
it "should get a list of inactive tokens" do
|
131
|
-
response.status.must_equal 200
|
8
|
+
describe '.client' do
|
9
|
+
it 'should return a client instance' do
|
10
|
+
ZeroPush.client.class.must_equal ZeroPush::Client
|
132
11
|
end
|
133
12
|
end
|
134
13
|
end
|
data/zero_push.gemspec
CHANGED
@@ -11,6 +11,7 @@ Gem::Specification.new do |gem|
|
|
11
11
|
gem.summary = %q{A gem for interacting with the ZeroPush API. (http://zeropush.com)}
|
12
12
|
gem.description = %q{ZeroPush is a simple service for sending iOS push notifications. (http://zeropush.com)}
|
13
13
|
gem.homepage = "https://zeropush.com"
|
14
|
+
gem.license = 'MIT'
|
14
15
|
|
15
16
|
gem.files = `git ls-files`.split($/)
|
16
17
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
@@ -19,7 +20,7 @@ Gem::Specification.new do |gem|
|
|
19
20
|
gem.required_ruby_version = '>= 1.9'
|
20
21
|
|
21
22
|
gem.add_dependency "faraday", "~> 0.8.5"
|
22
|
-
gem.add_dependency
|
23
|
+
gem.add_dependency "faraday_middleware", "~> 0.9.0"
|
23
24
|
|
24
25
|
gem.add_development_dependency 'actionpack', '~> 3.2.11'
|
25
26
|
gem.add_development_dependency 'activesupport', '~> 3.2.11'
|
metadata
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zero_push
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
5
|
-
prerelease:
|
4
|
+
version: 2.0.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Stefan Natchev
|
@@ -10,12 +9,11 @@ authors:
|
|
10
9
|
autorequire:
|
11
10
|
bindir: bin
|
12
11
|
cert_chain: []
|
13
|
-
date: 2013-
|
12
|
+
date: 2013-09-24 00:00:00.000000000 Z
|
14
13
|
dependencies:
|
15
14
|
- !ruby/object:Gem::Dependency
|
16
15
|
name: faraday
|
17
16
|
requirement: !ruby/object:Gem::Requirement
|
18
|
-
none: false
|
19
17
|
requirements:
|
20
18
|
- - ~>
|
21
19
|
- !ruby/object:Gem::Version
|
@@ -23,7 +21,6 @@ dependencies:
|
|
23
21
|
type: :runtime
|
24
22
|
prerelease: false
|
25
23
|
version_requirements: !ruby/object:Gem::Requirement
|
26
|
-
none: false
|
27
24
|
requirements:
|
28
25
|
- - ~>
|
29
26
|
- !ruby/object:Gem::Version
|
@@ -31,7 +28,6 @@ dependencies:
|
|
31
28
|
- !ruby/object:Gem::Dependency
|
32
29
|
name: faraday_middleware
|
33
30
|
requirement: !ruby/object:Gem::Requirement
|
34
|
-
none: false
|
35
31
|
requirements:
|
36
32
|
- - ~>
|
37
33
|
- !ruby/object:Gem::Version
|
@@ -39,7 +35,6 @@ dependencies:
|
|
39
35
|
type: :runtime
|
40
36
|
prerelease: false
|
41
37
|
version_requirements: !ruby/object:Gem::Requirement
|
42
|
-
none: false
|
43
38
|
requirements:
|
44
39
|
- - ~>
|
45
40
|
- !ruby/object:Gem::Version
|
@@ -47,7 +42,6 @@ dependencies:
|
|
47
42
|
- !ruby/object:Gem::Dependency
|
48
43
|
name: actionpack
|
49
44
|
requirement: !ruby/object:Gem::Requirement
|
50
|
-
none: false
|
51
45
|
requirements:
|
52
46
|
- - ~>
|
53
47
|
- !ruby/object:Gem::Version
|
@@ -55,7 +49,6 @@ dependencies:
|
|
55
49
|
type: :development
|
56
50
|
prerelease: false
|
57
51
|
version_requirements: !ruby/object:Gem::Requirement
|
58
|
-
none: false
|
59
52
|
requirements:
|
60
53
|
- - ~>
|
61
54
|
- !ruby/object:Gem::Version
|
@@ -63,7 +56,6 @@ dependencies:
|
|
63
56
|
- !ruby/object:Gem::Dependency
|
64
57
|
name: activesupport
|
65
58
|
requirement: !ruby/object:Gem::Requirement
|
66
|
-
none: false
|
67
59
|
requirements:
|
68
60
|
- - ~>
|
69
61
|
- !ruby/object:Gem::Version
|
@@ -71,7 +63,6 @@ dependencies:
|
|
71
63
|
type: :development
|
72
64
|
prerelease: false
|
73
65
|
version_requirements: !ruby/object:Gem::Requirement
|
74
|
-
none: false
|
75
66
|
requirements:
|
76
67
|
- - ~>
|
77
68
|
- !ruby/object:Gem::Version
|
@@ -79,7 +70,6 @@ dependencies:
|
|
79
70
|
- !ruby/object:Gem::Dependency
|
80
71
|
name: minitest
|
81
72
|
requirement: !ruby/object:Gem::Requirement
|
82
|
-
none: false
|
83
73
|
requirements:
|
84
74
|
- - ~>
|
85
75
|
- !ruby/object:Gem::Version
|
@@ -87,7 +77,6 @@ dependencies:
|
|
87
77
|
type: :development
|
88
78
|
prerelease: false
|
89
79
|
version_requirements: !ruby/object:Gem::Requirement
|
90
|
-
none: false
|
91
80
|
requirements:
|
92
81
|
- - ~>
|
93
82
|
- !ruby/object:Gem::Version
|
@@ -95,7 +84,6 @@ dependencies:
|
|
95
84
|
- !ruby/object:Gem::Dependency
|
96
85
|
name: mocha
|
97
86
|
requirement: !ruby/object:Gem::Requirement
|
98
|
-
none: false
|
99
87
|
requirements:
|
100
88
|
- - ~>
|
101
89
|
- !ruby/object:Gem::Version
|
@@ -103,7 +91,6 @@ dependencies:
|
|
103
91
|
type: :development
|
104
92
|
prerelease: false
|
105
93
|
version_requirements: !ruby/object:Gem::Requirement
|
106
|
-
none: false
|
107
94
|
requirements:
|
108
95
|
- - ~>
|
109
96
|
- !ruby/object:Gem::Version
|
@@ -111,7 +98,6 @@ dependencies:
|
|
111
98
|
- !ruby/object:Gem::Dependency
|
112
99
|
name: rake
|
113
100
|
requirement: !ruby/object:Gem::Requirement
|
114
|
-
none: false
|
115
101
|
requirements:
|
116
102
|
- - ~>
|
117
103
|
- !ruby/object:Gem::Version
|
@@ -119,7 +105,6 @@ dependencies:
|
|
119
105
|
type: :development
|
120
106
|
prerelease: false
|
121
107
|
version_requirements: !ruby/object:Gem::Requirement
|
122
|
-
none: false
|
123
108
|
requirements:
|
124
109
|
- - ~>
|
125
110
|
- !ruby/object:Gem::Version
|
@@ -127,7 +112,6 @@ dependencies:
|
|
127
112
|
- !ruby/object:Gem::Dependency
|
128
113
|
name: railties
|
129
114
|
requirement: !ruby/object:Gem::Requirement
|
130
|
-
none: false
|
131
115
|
requirements:
|
132
116
|
- - ~>
|
133
117
|
- !ruby/object:Gem::Version
|
@@ -135,7 +119,6 @@ dependencies:
|
|
135
119
|
type: :development
|
136
120
|
prerelease: false
|
137
121
|
version_requirements: !ruby/object:Gem::Requirement
|
138
|
-
none: false
|
139
122
|
requirements:
|
140
123
|
- - ~>
|
141
124
|
- !ruby/object:Gem::Version
|
@@ -143,7 +126,6 @@ dependencies:
|
|
143
126
|
- !ruby/object:Gem::Dependency
|
144
127
|
name: vcr
|
145
128
|
requirement: !ruby/object:Gem::Requirement
|
146
|
-
none: false
|
147
129
|
requirements:
|
148
130
|
- - ~>
|
149
131
|
- !ruby/object:Gem::Version
|
@@ -151,7 +133,6 @@ dependencies:
|
|
151
133
|
type: :development
|
152
134
|
prerelease: false
|
153
135
|
version_requirements: !ruby/object:Gem::Requirement
|
154
|
-
none: false
|
155
136
|
requirements:
|
156
137
|
- - ~>
|
157
138
|
- !ruby/object:Gem::Version
|
@@ -176,10 +157,13 @@ files:
|
|
176
157
|
- lib/zero_push.rb
|
177
158
|
- lib/zero_push/client.rb
|
178
159
|
- lib/zero_push/version.rb
|
160
|
+
- spec/fixtures/broadcast.yml
|
179
161
|
- spec/fixtures/inactive_tokens.yml
|
180
162
|
- spec/fixtures/notify.yml
|
181
163
|
- spec/fixtures/register.yml
|
182
164
|
- spec/fixtures/set_badge.yml
|
165
|
+
- spec/fixtures/subscribe.yml
|
166
|
+
- spec/fixtures/unsubscribe.yml
|
183
167
|
- spec/fixtures/verify_credentials.yml
|
184
168
|
- spec/generator_spec.rb
|
185
169
|
- spec/spec_helper.rb
|
@@ -188,37 +172,39 @@ files:
|
|
188
172
|
- zero_push.gemspec
|
189
173
|
- zeropush-header.png
|
190
174
|
homepage: https://zeropush.com
|
191
|
-
licenses:
|
175
|
+
licenses:
|
176
|
+
- MIT
|
177
|
+
metadata: {}
|
192
178
|
post_install_message:
|
193
179
|
rdoc_options: []
|
194
180
|
require_paths:
|
195
181
|
- lib
|
196
182
|
required_ruby_version: !ruby/object:Gem::Requirement
|
197
|
-
none: false
|
198
183
|
requirements:
|
199
184
|
- - ! '>='
|
200
185
|
- !ruby/object:Gem::Version
|
201
186
|
version: '1.9'
|
202
187
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
203
|
-
none: false
|
204
188
|
requirements:
|
205
189
|
- - ! '>='
|
206
190
|
- !ruby/object:Gem::Version
|
207
191
|
version: '0'
|
208
192
|
requirements: []
|
209
193
|
rubyforge_project:
|
210
|
-
rubygems_version: 1.
|
194
|
+
rubygems_version: 2.1.0
|
211
195
|
signing_key:
|
212
|
-
specification_version:
|
196
|
+
specification_version: 4
|
213
197
|
summary: A gem for interacting with the ZeroPush API. (http://zeropush.com)
|
214
198
|
test_files:
|
199
|
+
- spec/fixtures/broadcast.yml
|
215
200
|
- spec/fixtures/inactive_tokens.yml
|
216
201
|
- spec/fixtures/notify.yml
|
217
202
|
- spec/fixtures/register.yml
|
218
203
|
- spec/fixtures/set_badge.yml
|
204
|
+
- spec/fixtures/subscribe.yml
|
205
|
+
- spec/fixtures/unsubscribe.yml
|
219
206
|
- spec/fixtures/verify_credentials.yml
|
220
207
|
- spec/generator_spec.rb
|
221
208
|
- spec/spec_helper.rb
|
222
209
|
- spec/zero_push_client_spec.rb
|
223
210
|
- spec/zero_push_spec.rb
|
224
|
-
has_rdoc:
|