one_signal 0.0.14 → 1.0.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 07b611d3394091ab3465667f2d3c3fb2b133a187
4
- data.tar.gz: 79759f5f3e6213d6b7c6118cc4929b6f517e493b
3
+ metadata.gz: ea70b55c5209ae2e1d55b7b24728dbe125031707
4
+ data.tar.gz: e7c77d266e4ea20bc0cc7650925c0fc2a214bc47
5
5
  SHA512:
6
- metadata.gz: 3faac17bb9a87c791984cf5d30c49fada0a1191486cfdfad15a9c86b99929be1f2d219b9857ef0217337744281184f44d2f4d1e3e964366fadf71ae9ad3f7ab4
7
- data.tar.gz: 59e1002563a7111e9574086480fe384eca3a1808f870d0a6f8e0cdadcf78020efa057a285c8bd6502fbe04eebd4883aa6d0ddb0a902df0b235738ba4138ac093
6
+ metadata.gz: f20b6d9543e7c9dd390cd138475ee339ffb5d8eea96a7fd6a932990a80ab789589bbcd77c50bc01d76e15c5280b8725932ef4a22fbc511e375c92d4decc49886
7
+ data.tar.gz: c1f3aef54be919fc7ec8216d5793c8cf1ee4538aa5888e85f340b5953a79a1d93b50dda07c20a4699b83883ded0ad07365258978526ab29686a987d791d1af16
data/.env.example ADDED
@@ -0,0 +1,2 @@
1
+ ONESIGNAL_USER_AUTH_KEY=YOUR_USER_AUTH_KEY_HERE
2
+ ONESIGNAL_API_KEY=YOUR_API_KEY_HERE
data/CHANGELOG.txt CHANGED
@@ -1,3 +1,7 @@
1
+ === 1.0.0 2016-02-23
2
+
3
+ * Update Player#csv_export for API consistency
4
+
1
5
  === 0.0.14 2016-02-22
2
6
 
3
7
  * Change ruby required version from 2.2.0 to 2.1.0
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # OneSignal Ruby bindings
1
+ # OneSignal Ruby bindings [![Build Status](https://travis-ci.org/tbalthazar/onesignal-ruby.svg?branch=master)](https://travis-ci.org/tbalthazar/onesignal-ruby)
2
2
 
3
3
  This gem provides a simple SDK to access the [OneSignal API](https://documentation.onesignal.com/docs/server-api-overview).
4
4
 
@@ -18,7 +18,11 @@ bundle exec rake
18
18
 
19
19
  ## Basic usage
20
20
 
21
- See basic examples in [example.rb](/example.rb)
21
+ See basic examples in [example.rb](/example.rb).
22
+ To run it:
23
+ - rename [.env.example](/.env.example) into `.env`
24
+ - set your `USER_AUTH_KEY` and `API_KEY` in the `.env` file
25
+ - run `ruby example.rb`
22
26
 
23
27
  ## Documentation
24
28
 
data/example.rb CHANGED
@@ -1,309 +1,53 @@
1
1
  require 'one_signal'
2
2
  require 'dotenv'
3
3
 
4
+ # load your keys with https://github.com/bkeepers/dotenv
4
5
  Dotenv.load
5
6
  api_key = ENV['ONESIGNAL_API_KEY']
6
7
  user_auth_key = ENV['ONESIGNAL_USER_AUTH_KEY']
7
- @app_id = ENV['ONESIGNAL_APP_ID']
8
- @device_token = "abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabc3"
9
- @example_player_id = ENV['EXAMPLE_PLAYER_ID']
10
8
 
9
+ # configure OneSignal
11
10
  OneSignal::OneSignal.api_key = api_key
12
11
  OneSignal::OneSignal.user_auth_key = user_auth_key
13
12
 
14
- def create_player
15
- params = {
16
- app_id: @app_id,
17
- device_type: 0,
18
- identifier: @device_token,
19
- tags: {
20
- user_id: 'test2',
21
- device_type: 'chrome'
22
- }
23
- }
24
-
25
- begin
26
- response = OneSignal::Player.create(params: params)
27
- puts "code : #{response.code}"
28
- puts "message : #{response.message}"
29
- puts "body : #{response.body}"
30
- puts "id : #{JSON.parse(response.body).class}"
31
- return JSON.parse(response.body)["id"]
32
- rescue OneSignal::OneSignalError => e
33
- puts "-- message : #{e.message}"
34
- puts "-- status : #{e.http_status}"
35
- puts "-- body : #{e.http_body}"
36
- end
37
- end
38
-
39
- def create_player_session(id:)
40
- params = {
41
- # app_id: @app_id,
42
- # device_type: 0,
43
- # identifier: @device_token,
44
- # tags: {
45
- # user_id: 'test2',
46
- # device_type: 'chrome'
47
- # }
48
- device_os: 'iPhone5,1',
49
- game_version: '1.0.6',
50
- timezone: -28800
51
- }
52
-
53
- begin
54
- response = OneSignal::Player.create_session(id: id, params: params)
55
- puts "code : #{response.code}"
56
- puts "message : #{response.message}"
57
- puts "body : #{response.body}"
58
- rescue OneSignal::OneSignalError => e
59
- puts "-- message : #{e.message}"
60
- puts "-- status : #{e.http_status}"
61
- puts "-- body : #{e.http_body}"
62
- end
63
- end
64
-
65
- def create_player_purchase(id:)
66
- params = {
67
- purchases: [
68
- {
69
- sku: 'SKU123',
70
- iso: 'USD',
71
- amount: '0.99'
72
- }
73
- ]
74
- }
75
-
76
- begin
77
- response = OneSignal::Player.create_purchase(id: id, params: params)
78
- puts "code : #{response.code}"
79
- puts "message : #{response.message}"
80
- puts "body : #{response.body}"
81
- rescue OneSignal::OneSignalError => e
82
- puts "-- message : #{e.message}"
83
- puts "-- status : #{e.http_status}"
84
- puts "-- body : #{e.http_body}"
85
- end
86
- end
87
-
88
- def create_player_focus(id:)
89
- params = {
90
- state: 'ping',
91
- active_time: 60
92
- }
93
-
94
- begin
95
- response = OneSignal::Player.create_focus(id: id, params: params)
96
- puts "code : #{response.code}"
97
- puts "message : #{response.message}"
98
- puts "body : #{response.body}"
99
- rescue OneSignal::OneSignalError => e
100
- puts "-- message : #{e.message}"
101
- puts "-- status : #{e.http_status}"
102
- puts "-- body : #{e.http_body}"
103
- end
104
- end
105
-
106
- def update_player(id:)
107
- params = {
108
- app_id: @app_id,
109
- device_type: 0,
110
- identifier: @device_token,
111
- tags: {
112
- user_id: 'test2updated',
113
- device_type: 'chrome'
114
- }
115
- }
116
-
117
- begin
118
- response = OneSignal::Player.update(id: id, params: params)
119
- puts "code : #{response.code}"
120
- puts "message : #{response.message}"
121
- puts "body : #{response.body}"
122
- puts "id : #{JSON.parse(response.body).class}"
123
- rescue OneSignal::OneSignalError => e
124
- puts "-- message : #{e.message}"
125
- puts "-- status : #{e.http_status}"
126
- puts "-- body : #{e.http_body}"
127
- end
128
- end
129
-
130
- def all_notifs
131
- params = {
132
- app_id: @app_id,
133
- limit: 5,
134
- offset: 0
135
- }
136
-
137
- begin
138
- response = OneSignal::Notification.all(params: params)
139
- puts "code : #{response.code}"
140
- puts "message : #{response.message}"
141
- puts "body : #{response.body}"
142
- puts "id : #{JSON.parse(response.body).class}"
143
- rescue OneSignal::OneSignalError => e
144
- puts "-- message : #{e.message}"
145
- puts "-- status : #{e.http_status}"
146
- puts "-- body : #{e.http_body}"
147
- end
148
- end
149
-
150
- def get_notif(id:)
151
- params = {
152
- app_id: @app_id
153
- }
154
-
155
- begin
156
- response = OneSignal::Notification.get(id: id, params: params)
157
- puts "code : #{response.code}"
158
- puts "message : #{response.message}"
159
- puts "body : #{response.body}"
160
- puts "id : #{JSON.parse(response.body).class}"
161
- rescue OneSignal::OneSignalError => e
162
- puts "-- message : #{e.message}"
163
- puts "-- status : #{e.http_status}"
164
- puts "-- body : #{e.http_body}"
165
- end
166
- end
167
-
168
- def notify
169
- params = {
170
- app_id: @app_id,
171
- contents: {
172
- en: 'hey buddy'
173
- },
174
- ios_badgeType: 'None',
175
- ios_badgeCount: 1,
176
- tags: [
177
- {
178
- key: 'user_id',
179
- relation: '=',
180
- value: "2"
181
- },
182
- { operator: 'AND' },
183
- {
184
- key: 'device_type',
185
- relation: '=',
186
- value: 'ios'
187
- }
188
- ]
189
- }
190
-
191
- begin
192
- response = OneSignal::Notification.create(params: params)
193
- puts "code : #{response.code}"
194
- puts "message : #{response.message}"
195
- puts "body : #{response.body}"
196
- body = JSON.parse(response.body)
197
- return body["id"]
198
- rescue OneSignal::NoRecipientsError => e
199
- puts "--- NoRecipientsError: #{e.inspect}"
200
- puts "-- message : #{e.message}"
201
- puts "-- status : #{e.http_status}"
202
- puts "-- body : #{e.http_body}"
203
- rescue OneSignal::OneSignalError => e
204
- puts "--- OneSignalError : #{e.inspect}"
205
- puts "-- message : #{e.message}"
206
- puts "-- status : #{e.http_status}"
207
- puts "-- body : #{e.http_body}"
208
- end
209
- end
210
-
211
- def csv_export
212
- response = OneSignal::Player.csv_export(app_id: @app_id)
213
- puts response.body
214
- end
215
-
216
- def all_players
217
- response = OneSignal::Player.all(params: {app_id: @app_id, limit: 3})
218
- puts response.body
13
+ # create app
14
+ params = {
15
+ name: 'test-app'
16
+ }
17
+ response = OneSignal::App.create(params: params)
18
+ app_id = JSON.parse(response.body)["id"]
19
+ puts "--- created app id: #{app_id}"
20
+
21
+ # add a player
22
+ device_token = "abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabc1"
23
+ params = {
24
+ app_id: app_id,
25
+ device_type: 0,
26
+ identifier: device_token,
27
+ tags: {
28
+ user_id: '123'
29
+ }
30
+ }
31
+ response = OneSignal::Player.create(params: params)
32
+ player_id = JSON.parse(response.body)["id"]
33
+ puts "--- created player id: #{player_id}"
34
+
35
+ # notify the player (this will fail because we haven't configured the app yet)
36
+ params = {
37
+ app_id: app_id,
38
+ contents: {
39
+ en: 'hello player'
40
+ },
41
+ ios_badgeType: 'None',
42
+ ios_badgeCount: 1,
43
+ include_player_ids: [player_id]
44
+ }
45
+ begin
46
+ response = OneSignal::Notification.create(params: params)
47
+ notification_id = JSON.parse(response.body)["id"]
48
+ rescue OneSignal::OneSignalError => e
49
+ puts "--- OneSignalError :"
50
+ puts "-- message : #{e.message}"
51
+ puts "-- status : #{e.http_status}"
52
+ puts "-- body : #{e.http_body}"
219
53
  end
220
-
221
- def get_player(id:)
222
- response = OneSignal::Player.get(id: id)
223
- puts response.body
224
- end
225
-
226
- def update_notif(id:)
227
- params = {
228
- app_id: @app_id,
229
- opened: true
230
- }
231
- response = OneSignal::Notification.update(id: id, params: params)
232
- puts response.body
233
- end
234
-
235
- def delete_notif(id:)
236
- params = {
237
- app_id: @app_id
238
- }
239
-
240
- begin
241
- response = OneSignal::Notification.delete(id: id, params: params)
242
- puts "code : #{response.code}"
243
- puts "message : #{response.message}"
244
- puts "body : #{response.body}"
245
- puts "id : #{JSON.parse(response.body).class}"
246
- rescue OneSignal::OneSignalError => e
247
- puts "-- message : #{e.message}"
248
- puts "-- status : #{e.http_status}"
249
- puts "-- body : #{e.http_body}"
250
- end
251
- end
252
-
253
- def all_apps
254
- begin
255
- response = OneSignal::App.all(params: nil)
256
- puts "code : #{response.code}"
257
- puts "message : #{response.message}"
258
- puts "body : #{response.body}"
259
- puts "id : #{JSON.parse(response.body).class}"
260
- rescue OneSignal::OneSignalError => e
261
- puts "-- message : #{e.message}"
262
- puts "-- status : #{e.http_status}"
263
- puts "-- body : #{e.http_body}"
264
- end
265
- end
266
-
267
- def get_app(id:)
268
- response = OneSignal::App.get(id: id)
269
- puts response.body
270
- end
271
-
272
- def create_app
273
- params = {
274
- name: 'footest'
275
- }
276
- response = OneSignal::App.create(params: params)
277
- puts response.body
278
- end
279
-
280
- def update_app
281
- params = {
282
- name: 'bartest'
283
- }
284
- response = OneSignal::App.update(id: "29203a07-8f1f-438a-9932-9549c6b28c14",
285
- params: params)
286
- puts response.body
287
- end
288
-
289
- # player_id = create_player
290
- # update_player(id: player_id)
291
- player_id = '9c9a3fb4-62e0-455d-865b-670ccea594a1'
292
- notification_id = 'c6e10bac-af7d-4879-a5e9-439de53e3cff'
293
- # create_player_session(id: player_id)
294
- # create_player_purchase(id: player_id)
295
- # create_player_focus(id: player_id)
296
- # notification_id = notify
297
- # puts "--- notif id: #{notification_id}"
298
- # csv_export
299
- # all_players
300
- # get_player(id: player_id)
301
- # all_notifs
302
- # get_notif(id: notification_id)
303
- # delete_notif(id: notification_id)
304
- # update_notif(id: notification_id)
305
- # get_notif(id: notification_id)
306
- # all_apps
307
- # get_app(id: @app_id)
308
- # create_app
309
- update_app
@@ -2,12 +2,12 @@ module OneSignal
2
2
 
3
3
  class Player < OneSignal
4
4
 
5
- def self.csv_export(app_id:)
5
+ def self.csv_export(params:)
6
6
  uri_string = @@base_uri
7
7
  uri_string += "/players/csv_export"
8
8
  uri = URI.parse(uri_string)
9
9
 
10
- response = send_post_request(uri: uri, body: {app_id: app_id})
10
+ response = send_post_request(uri: uri, body: params)
11
11
 
12
12
  ensure_http_status(response: response,
13
13
  status: '200',
@@ -1,3 +1,3 @@
1
1
  module OneSignal
2
- VERSION = "0.0.14"
2
+ VERSION = "1.0.0"
3
3
  end
data/one_signal.gemspec CHANGED
@@ -2,7 +2,6 @@ require File.expand_path('lib/one_signal/version')
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.required_ruby_version = '>= 2.1.0'
5
- s.add_runtime_dependency 'json', '~> 1.8'
6
5
  s.add_development_dependency 'rake', '~> 10.4'
7
6
  s.add_development_dependency 'mocha', '~> 1.1'
8
7
  s.add_development_dependency 'dotenv', '~> 2.0'
data/test/player_test.rb CHANGED
@@ -33,12 +33,11 @@ class PlayerTest < MiniTest::Test
33
33
  end
34
34
 
35
35
  def test_csv_export
36
- @app_id = "foobar"
37
36
  response = mock_response_ok
38
37
  OneSignal::OneSignal.expects(:send_post_request)
39
- .with(uri: @csv_export_uri, body: {app_id: @app_id})
38
+ .with(uri: @csv_export_uri, body: @params)
40
39
  .returns(response)
41
- assert_equal response, OneSignal::Player.csv_export(app_id: @app_id)
40
+ assert_equal response, OneSignal::Player.csv_export(params: @params)
42
41
  end
43
42
 
44
43
  def test_all
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: one_signal
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.14
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thomas Balthazar
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-22 00:00:00.000000000 Z
11
+ date: 2016-02-23 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: json
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '1.8'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '1.8'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: rake
29
15
  requirement: !ruby/object:Gem::Requirement
@@ -86,6 +72,7 @@ executables: []
86
72
  extensions: []
87
73
  extra_rdoc_files: []
88
74
  files:
75
+ - ".env.example"
89
76
  - ".gitignore"
90
77
  - ".travis.yml"
91
78
  - CHANGELOG.txt