appush_client 0.2 → 0.3
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/appush_client.gemspec +2 -2
- data/lib/appush_client.rb +0 -4
- data/spec/appush_client_spec.rb +160 -50
- metadata +2 -2
data/appush_client.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = 'appush_client'
|
5
|
-
s.version = '0.
|
5
|
+
s.version = '0.3'
|
6
6
|
|
7
7
|
s.authors = ['Igor Guerrero']
|
8
8
|
s.date = '2010-01-09'
|
@@ -13,5 +13,5 @@ Gem::Specification.new do |s|
|
|
13
13
|
'spec/appush_client_spec.rb']
|
14
14
|
s.summary = "Ruby client library for Appush PUSH service."
|
15
15
|
|
16
|
-
s.add_dependency 'rest-client', '>= 1.
|
16
|
+
s.add_dependency 'rest-client', '>= 1.3.1'
|
17
17
|
end
|
data/lib/appush_client.rb
CHANGED
@@ -139,10 +139,6 @@ class Profile < AppushClient
|
|
139
139
|
def register_device(device_token, tags=[])
|
140
140
|
url = "#{@service_url}/device/#{device_token}"
|
141
141
|
|
142
|
-
if tags.empty?
|
143
|
-
return RestClient.put url, :content_type=>:json, :accept=>:json
|
144
|
-
end
|
145
|
-
|
146
142
|
data = {:tags=>tags}.to_json
|
147
143
|
|
148
144
|
RestClient.put url, data, :content_type=>:json, :accept=>:json
|
data/spec/appush_client_spec.rb
CHANGED
@@ -3,91 +3,201 @@
|
|
3
3
|
require 'appush_client'
|
4
4
|
require 'webmock/rspec'
|
5
5
|
|
6
|
+
require 'json'
|
7
|
+
|
6
8
|
include WebMock
|
7
9
|
|
8
10
|
describe "Using Appush client API" do
|
9
11
|
before(:each) do
|
10
|
-
|
11
|
-
@
|
12
|
-
@
|
13
|
-
@
|
14
|
-
|
15
|
-
@
|
16
|
-
|
17
|
-
|
18
|
-
|
12
|
+
# I used test keys and tokens, but tested them to work
|
13
|
+
@root_key = "09a539a84e32ddbce7c6bcdcedba78f4"
|
14
|
+
@root_secret = "e77694945eff115f4b0cc6d0bcf800ec"
|
15
|
+
@app_key = "38KaiutatmjKWPsbksVco1YeQeE"
|
16
|
+
@app_secret = "5ZulDkmNY230rRyx3v6CaJfkAhP"
|
17
|
+
@profile_key = "GkYwZ5xTV8PXJJZksQDV3POKMCp"
|
18
|
+
@profile_secret = "TqRrqWfnW0Zp4jsxOEQQR6iCcLH"
|
19
|
+
@service_url = "https://appush.com/api"
|
20
|
+
|
21
|
+
# we initialize every object on every test
|
22
|
+
@root_user = RootUser.new @root_key, @root_secret, :service_url=>@service_url
|
23
|
+
@application = Application.new @app_key, @app_secret, :service_url=>@service_url
|
24
|
+
@profile = Profile.new @profile_key, @profile_secret, :service_url=>@service_url
|
19
25
|
end
|
20
26
|
|
21
27
|
it "should not be null" do
|
22
|
-
@
|
23
|
-
@
|
24
|
-
|
28
|
+
@root_user.should_not be nil
|
29
|
+
@root_user.to_s.should == "Server = https://09a539a84e32ddbce7c6bcdcedba78f4:e77694945eff115f4b0cc6d0bcf800ec@appush.com/api"
|
30
|
+
|
31
|
+
@application.should_not be nil
|
32
|
+
@application.to_s.should == "Server = https://38KaiutatmjKWPsbksVco1YeQeE:5ZulDkmNY230rRyx3v6CaJfkAhP@appush.com/api"
|
33
|
+
|
34
|
+
@profile.should_not be nil
|
35
|
+
@profile.to_s.should == "Server = https://GkYwZ5xTV8PXJJZksQDV3POKMCp:TqRrqWfnW0Zp4jsxOEQQR6iCcLH@appush.com/api"
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should create an application" do
|
39
|
+
result = "{\"id\":\"YZgzHWpxdt4emUAYTptovTcfYdW\"}"
|
40
|
+
|
41
|
+
stub_request(:post, "https://#{@root_key}:#{@root_secret}@appush.com/api/application").to_return(:body=>result)
|
42
|
+
|
43
|
+
@root_user.create_application("test").to_s.should == result
|
44
|
+
|
45
|
+
WebMock.should have_requested(:post, "https://#{@root_key}:#{@root_secret}@appush.com/api/application").once
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should modify an application" do
|
49
|
+
result = ""
|
50
|
+
id = "test"
|
51
|
+
|
52
|
+
stub_request(:put, "https://#{@root_key}:#{@root_secret}@appush.com/api/application/#{id}").to_return(:body=>result)
|
53
|
+
|
54
|
+
@root_user.modify_application("test", :name=>"new name").to_s.should == result
|
55
|
+
|
56
|
+
WebMock.should have_requested(:put, "https://#{@root_key}:#{@root_secret}@appush.com/api/application/#{id}").once
|
25
57
|
end
|
26
|
-
|
27
|
-
it "should get device information" do
|
28
|
-
result = {"tags"=>["foo", "waa"], "status"=> 200}
|
29
58
|
|
30
|
-
|
59
|
+
it "should list all applications" do
|
60
|
+
result = "[\"app1\", \"app2\"]"
|
61
|
+
|
62
|
+
stub_request(:get, "https://#{@root_key}:#{@root_secret}@appush.com/api/application").to_return(:body=>result)
|
63
|
+
|
64
|
+
@root_user.list_applications.to_s.should == result
|
65
|
+
|
66
|
+
WebMock.should have_requested(:get, "https://#{@root_key}:#{@root_secret}@appush.com/api/application").once
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should get an application" do
|
70
|
+
result = "{\"name\":\"My New Application\", \"application_token\": \"EVtmyITWMKzDRtawXxubVmfIYWU\", \"application_secret\": \"e52c6cbd232e2111671953d320ff80a2\", \"status\":\"dev\",\"dev_pem\":\"Bag Attributes\", \"active_devices\":0}\""
|
71
|
+
id = "test"
|
72
|
+
|
73
|
+
stub_request(:get, "https://#{@root_key}:#{@root_secret}@appush.com/api/application/#{id}").to_return(:body=>result)
|
74
|
+
|
75
|
+
@root_user.get_application(id).to_s.should == result
|
76
|
+
|
77
|
+
WebMock.should have_requested(:get, "https://#{@root_key}:#{@root_secret}@appush.com/api/application/#{id}").once
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should get an application icon" do
|
81
|
+
result = File.read("#{File.dirname(__FILE__)}/no-icon.png")
|
82
|
+
id = "test"
|
83
|
+
|
84
|
+
stub_request(:get, "https://#{@root_key}:#{@root_secret}@appush.com/api/application/#{id}/icon").to_return(:body=>result)
|
85
|
+
|
86
|
+
@root_user.get_application_icon(id).to_s.should == result
|
87
|
+
|
88
|
+
WebMock.should have_requested(:get, "https://#{@root_key}:#{@root_secret}@appush.com/api/application/#{id}/icon").once
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should save an application icon" do
|
92
|
+
icon = File.read("#{File.dirname(__FILE__)}/no-icon.png")
|
93
|
+
id = "test"
|
94
|
+
|
95
|
+
stub_request(:put, "https://#{@root_key}:#{@root_secret}@appush.com/api/application/#{id}/icon").with(:body=>icon, :headers=>{"Content-Type"=>"image/png"}).to_return(:body=>"")
|
96
|
+
|
97
|
+
@root_user.save_application_icon(id, icon).to_s.should == ""
|
98
|
+
|
99
|
+
WebMock.should have_requested(:put, "https://#{@root_key}:#{@root_secret}@appush.com/api/application/#{id}/icon").once
|
100
|
+
end
|
101
|
+
|
102
|
+
it "should delete an application" do
|
103
|
+
id = "test"
|
104
|
+
|
105
|
+
stub_request(:delete, "https://#{@root_key}:#{@root_secret}@appush.com/api/application/#{id}").to_return(:body=>"")
|
106
|
+
|
107
|
+
@root_user.delete_application(id).to_s.should == ""
|
108
|
+
|
109
|
+
WebMock.should have_requested(:delete, "https://#{@root_key}:#{@root_secret}@appush.com/api/application/#{id}").once
|
110
|
+
end
|
111
|
+
|
112
|
+
it "should send a notification" do
|
113
|
+
id = "test"
|
114
|
+
|
115
|
+
params={:tags=>["one", "two", "three"],
|
116
|
+
:devices=>["lol", "waa"],
|
117
|
+
:exclude=>["do", "not", "exclude", "me"],
|
118
|
+
:alert=>"w00t!",
|
119
|
+
:sound=>"cat.ogg",
|
120
|
+
:badge=>1,
|
121
|
+
:kv=>{:go=>"crazy"}}
|
122
|
+
|
123
|
+
stub_request(:post, "https://#{@root_key}:#{@root_secret}@appush.com/api/application/#{id}/notification").with(:body=>"{\"devices\":[\"lol\",\"waa\"],\"payload\":{\"go\":\"crazy\",\"aps\":{\"badge\":1,\"sound\":\"cat.ogg\",\"alert\":\"w00t!\"}},\"exclude\":[\"do\",\"not\",\"exclude\",\"me\"],\"tags\":[\"one\",\"two\",\"three\"]}", :headers=>{"Content-Type"=>"application/json"}).to_return(:body=>"")
|
124
|
+
|
125
|
+
@root_user.send_notification(id, params).to_s.should == ""
|
126
|
+
|
127
|
+
WebMock.should have_requested(:post, "https://#{@root_key}:#{@root_secret}@appush.com/api/application/#{id}/notification").once
|
128
|
+
end
|
129
|
+
|
130
|
+
it "should get an notification status" do
|
131
|
+
app_id = "test_app"
|
132
|
+
notification_id = "test_notification"
|
133
|
+
|
134
|
+
stub_request(:get, "https://#{@root_key}:#{@root_secret}@appush.com/api/application/#{app_id}/notification/#{notification_id}").to_return(:body=>"")
|
135
|
+
|
136
|
+
@root_user.get_notification_status(app_id, notification_id).to_s.should == ""
|
137
|
+
|
138
|
+
WebMock.should have_requested(:get, "https://#{@root_key}:#{@root_secret}@appush.com/api/application/#{app_id}/notification/#{notification_id}").once
|
139
|
+
end
|
140
|
+
|
141
|
+
it "should get all devices by tag" do
|
142
|
+
app_id = "test"
|
143
|
+
tag = "waa"
|
144
|
+
|
145
|
+
stub_request(:get, "https://#{@root_key}:#{@root_secret}@appush.com/api/application/#{app_id}/tag/#{tag}").to_return(:body=>"")
|
31
146
|
|
32
|
-
@
|
147
|
+
@root_user.get_devices_by_tag(app_id, tag).to_s.should == ""
|
33
148
|
|
34
|
-
WebMock.should have_requested(:get, "
|
149
|
+
WebMock.should have_requested(:get, "https://#{@root_key}:#{@root_secret}@appush.com/api/application/#{app_id}/tag/#{tag}").once
|
35
150
|
end
|
36
151
|
|
37
|
-
it "should
|
38
|
-
|
152
|
+
it "should get a device information" do
|
153
|
+
dev_token = "test_dev"
|
39
154
|
|
40
|
-
stub_request(:
|
155
|
+
stub_request(:get, "https://#{@profile_key}:#{@profile_secret}@appush.com/api/device/#{dev_token}").to_return(:body=>"")
|
41
156
|
|
42
|
-
@
|
157
|
+
@profile.get_device(dev_token).to_s.should == ""
|
43
158
|
|
44
|
-
WebMock.should have_requested(:
|
159
|
+
WebMock.should have_requested(:get, "https://#{@profile_key}:#{@profile_secret}@appush.com/api/device/#{dev_token}").once
|
45
160
|
end
|
46
161
|
|
47
|
-
it "should
|
48
|
-
|
162
|
+
it "should register a device with tags" do
|
163
|
+
dev_token = "test_dev"
|
164
|
+
tags = ["foo", "bar"]
|
49
165
|
|
50
|
-
stub_request(:
|
166
|
+
stub_request(:put, "https://#{@profile_key}:#{@profile_secret}@appush.com/api/device/#{dev_token}").with(:body=>{:tags=>tags}.to_json, :headers=>{"Content-Type"=>"application/json"}).to_return(:body=>"")
|
51
167
|
|
52
|
-
@
|
168
|
+
@profile.register_device(dev_token, tags).to_s.should == ""
|
53
169
|
|
54
|
-
WebMock.should have_requested(:
|
170
|
+
WebMock.should have_requested(:put, "https://#{@profile_key}:#{@profile_secret}@appush.com/api/device/#{dev_token}").once
|
55
171
|
end
|
56
172
|
|
57
|
-
it "should
|
58
|
-
|
173
|
+
it "should register a device without tags" do
|
174
|
+
dev_token = "test_dev"
|
175
|
+
tags = []
|
59
176
|
|
60
|
-
stub_request(:
|
177
|
+
stub_request(:put, "https://#{@profile_key}:#{@profile_secret}@appush.com/api/device/#{dev_token}").with(:body=>{:tags=>tags}.to_json, :headers=>{"Content-Type"=>"application/json"}).to_return(:body=>"")
|
61
178
|
|
62
|
-
@
|
179
|
+
@profile.register_device(dev_token, tags).to_s.should == ""
|
63
180
|
|
64
|
-
WebMock.should have_requested(:
|
181
|
+
WebMock.should have_requested(:put, "https://#{@profile_key}:#{@profile_secret}@appush.com/api/device/#{dev_token}").once
|
65
182
|
end
|
66
183
|
|
67
|
-
it "should
|
68
|
-
|
69
|
-
tags = ["foo", "waa"]
|
70
|
-
devices = ["test_device"]
|
71
|
-
exclude = ["invalid_device"]
|
72
|
-
alert = "hello"
|
73
|
-
sound = "meow.aiff"
|
74
|
-
badge = 1
|
75
|
-
kv = {"spam"=>"foo"}
|
184
|
+
it "should unregister a device" do
|
185
|
+
dev_token = "test_dev"
|
76
186
|
|
77
|
-
stub_request(:
|
187
|
+
stub_request(:delete, "https://#{@profile_key}:#{@profile_secret}@appush.com/api/device/#{dev_token}").to_return(:body=>"")
|
78
188
|
|
79
|
-
@
|
189
|
+
@profile.unregister_device(dev_token).to_s.should == ""
|
80
190
|
|
81
|
-
WebMock.should have_requested(:
|
191
|
+
WebMock.should have_requested(:delete, "https://#{@profile_key}:#{@profile_secret}@appush.com/api/device/#{dev_token}").once
|
82
192
|
end
|
83
193
|
|
84
|
-
it "should
|
85
|
-
result =
|
194
|
+
it "should create a profile" do
|
195
|
+
result = "[\"x\", \"y\"]"
|
86
196
|
|
87
|
-
stub_request(:
|
197
|
+
stub_request(:post, "https://#{@app_key}:#{@app_secret}@appush.com/api/profile").with(:headers=>{"Content-Type"=>"application/json"}).to_return(:body=>result)
|
88
198
|
|
89
|
-
@
|
199
|
+
@application.create_profile.to_s.should == result
|
90
200
|
|
91
|
-
WebMock.should have_requested(:
|
201
|
+
WebMock.should have_requested(:post, "https://#{@app_key}:#{@app_secret}@appush.com/api/profile").once
|
92
202
|
end
|
93
203
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: appush_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: "0.
|
4
|
+
version: "0.3"
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Igor Guerrero
|
@@ -20,7 +20,7 @@ dependencies:
|
|
20
20
|
requirements:
|
21
21
|
- - ">="
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version:
|
23
|
+
version: 1.3.1
|
24
24
|
version:
|
25
25
|
description: Ruby client library for Appush PUSH service.
|
26
26
|
email:
|