one_signal 0.0.10 → 0.0.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.txt +10 -0
- data/example.rb +79 -1
- data/lib/one_signal/player.rb +54 -0
- data/lib/one_signal/version.rb +1 -1
- data/test/player_test.rb +30 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 81a534565c3f0919da7c7250150de3760e4e9a96
|
4
|
+
data.tar.gz: 98c50f60a4ff5f37c9f6175a239c4d1fd2b77d1b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b9b559c8e42e11958e3b644d6283e61436d881edbb5fd9deae8bcfe95af77a3635ba628f3f1ee6d68d2ebf5245bc5b9015c3fe40562efa65138f28e0799b4625
|
7
|
+
data.tar.gz: 2051ac191f169aa17b2f0f8a378ab64e3b5c7ec037c53fd92d627fbf05bcf5712f8be4b48a9836fac49af2f00e6763d0122fcd977a658277393435153083586c
|
data/CHANGELOG.txt
CHANGED
data/example.rb
CHANGED
@@ -5,6 +5,7 @@ Dotenv.load
|
|
5
5
|
api_key = ENV['ONESIGNAL_API_KEY']
|
6
6
|
@app_id = ENV['ONESIGNAL_APP_ID']
|
7
7
|
@device_token = "abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabc3"
|
8
|
+
@example_player_id = ENV['EXAMPLE_PLAYER_ID']
|
8
9
|
|
9
10
|
OneSignal::OneSignal.api_key = api_key
|
10
11
|
|
@@ -33,6 +34,73 @@ def create_player
|
|
33
34
|
end
|
34
35
|
end
|
35
36
|
|
37
|
+
def create_player_session(id:)
|
38
|
+
params = {
|
39
|
+
# app_id: @app_id,
|
40
|
+
# device_type: 0,
|
41
|
+
# identifier: @device_token,
|
42
|
+
# tags: {
|
43
|
+
# user_id: 'test2',
|
44
|
+
# device_type: 'chrome'
|
45
|
+
# }
|
46
|
+
device_os: 'iPhone5,1',
|
47
|
+
game_version: '1.0.6',
|
48
|
+
timezone: -28800
|
49
|
+
}
|
50
|
+
|
51
|
+
begin
|
52
|
+
response = OneSignal::Player.create_session(id: id, params: params)
|
53
|
+
puts "code : #{response.code}"
|
54
|
+
puts "message : #{response.message}"
|
55
|
+
puts "body : #{response.body}"
|
56
|
+
rescue OneSignal::OneSignalError => e
|
57
|
+
puts "-- message : #{e.message}"
|
58
|
+
puts "-- status : #{e.http_status}"
|
59
|
+
puts "-- body : #{e.http_body}"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def create_player_purchase(id:)
|
64
|
+
params = {
|
65
|
+
purchases: [
|
66
|
+
{
|
67
|
+
sku: 'SKU123',
|
68
|
+
iso: 'USD',
|
69
|
+
amount: '0.99'
|
70
|
+
}
|
71
|
+
]
|
72
|
+
}
|
73
|
+
|
74
|
+
begin
|
75
|
+
response = OneSignal::Player.create_purchase(id: id, params: params)
|
76
|
+
puts "code : #{response.code}"
|
77
|
+
puts "message : #{response.message}"
|
78
|
+
puts "body : #{response.body}"
|
79
|
+
rescue OneSignal::OneSignalError => e
|
80
|
+
puts "-- message : #{e.message}"
|
81
|
+
puts "-- status : #{e.http_status}"
|
82
|
+
puts "-- body : #{e.http_body}"
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def create_player_focus(id:)
|
87
|
+
params = {
|
88
|
+
state: 'ping',
|
89
|
+
active_time: 60
|
90
|
+
}
|
91
|
+
|
92
|
+
begin
|
93
|
+
response = OneSignal::Player.create_focus(id: id, params: params)
|
94
|
+
puts "code : #{response.code}"
|
95
|
+
puts "message : #{response.message}"
|
96
|
+
puts "body : #{response.body}"
|
97
|
+
rescue OneSignal::OneSignalError => e
|
98
|
+
puts "-- message : #{e.message}"
|
99
|
+
puts "-- status : #{e.http_status}"
|
100
|
+
puts "-- body : #{e.http_body}"
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
36
104
|
def update_player(id:)
|
37
105
|
params = {
|
38
106
|
app_id: @app_id,
|
@@ -108,8 +176,18 @@ def all_players
|
|
108
176
|
puts response.body
|
109
177
|
end
|
110
178
|
|
179
|
+
def get_player(id:)
|
180
|
+
response = OneSignal::Player.get(id: id)
|
181
|
+
puts response.body
|
182
|
+
end
|
183
|
+
|
111
184
|
# player_id = create_player
|
112
185
|
# update_player(id: player_id)
|
186
|
+
player_id = '9c9a3fb4-62e0-455d-865b-670ccea594a1'
|
187
|
+
# create_player_session(id: player_id)
|
188
|
+
# create_player_purchase(id: player_id)
|
189
|
+
create_player_focus(id: player_id)
|
113
190
|
# notify
|
114
191
|
# csv_export
|
115
|
-
all_players
|
192
|
+
# all_players
|
193
|
+
get_player(id: player_id)
|
data/lib/one_signal/player.rb
CHANGED
@@ -67,6 +67,60 @@ module OneSignal
|
|
67
67
|
return response
|
68
68
|
end
|
69
69
|
|
70
|
+
def self.create_session(id:, params: {})
|
71
|
+
uri_string = @@base_uri
|
72
|
+
uri_string += "/players"
|
73
|
+
uri_string += "/#{id}"
|
74
|
+
uri_string += "/on_session"
|
75
|
+
uri = URI.parse(uri_string)
|
76
|
+
|
77
|
+
response = send_post_request(uri: uri, body: params)
|
78
|
+
|
79
|
+
ensure_http_status(response: response,
|
80
|
+
status: '200',
|
81
|
+
method_name: 'Create Session',
|
82
|
+
uri: uri,
|
83
|
+
params: params)
|
84
|
+
|
85
|
+
return response
|
86
|
+
end
|
87
|
+
|
88
|
+
def self.create_purchase(id:, params: {})
|
89
|
+
uri_string = @@base_uri
|
90
|
+
uri_string += "/players"
|
91
|
+
uri_string += "/#{id}"
|
92
|
+
uri_string += "/on_purchase"
|
93
|
+
uri = URI.parse(uri_string)
|
94
|
+
|
95
|
+
response = send_post_request(uri: uri, body: params)
|
96
|
+
|
97
|
+
ensure_http_status(response: response,
|
98
|
+
status: '200',
|
99
|
+
method_name: 'Create Purchase',
|
100
|
+
uri: uri,
|
101
|
+
params: params)
|
102
|
+
|
103
|
+
return response
|
104
|
+
end
|
105
|
+
|
106
|
+
def self.create_focus(id:, params: {})
|
107
|
+
uri_string = @@base_uri
|
108
|
+
uri_string += "/players"
|
109
|
+
uri_string += "/#{id}"
|
110
|
+
uri_string += "/on_focus"
|
111
|
+
uri = URI.parse(uri_string)
|
112
|
+
|
113
|
+
response = send_post_request(uri: uri, body: params)
|
114
|
+
|
115
|
+
ensure_http_status(response: response,
|
116
|
+
status: '200',
|
117
|
+
method_name: 'Create Focus',
|
118
|
+
uri: uri,
|
119
|
+
params: params)
|
120
|
+
|
121
|
+
return response
|
122
|
+
end
|
123
|
+
|
70
124
|
def self.update(id:, params: {})
|
71
125
|
uri_string = @@base_uri
|
72
126
|
uri_string += "/players"
|
data/lib/one_signal/version.rb
CHANGED
data/test/player_test.rb
CHANGED
@@ -9,8 +9,10 @@ class PlayerTest < MiniTest::Test
|
|
9
9
|
@all_uri = URI.parse(base_url)
|
10
10
|
@player_id = "fake-id-123"
|
11
11
|
@get_uri = URI.parse(base_url + "/#{@player_id}")
|
12
|
-
|
13
12
|
@update_uri = URI.parse(base_url + "/#{@player_id}")
|
13
|
+
@create_session_uri = URI.parse(base_url + "/#{@player_id}/on_session")
|
14
|
+
@create_purchase_uri = URI.parse(base_url + "/#{@player_id}/on_purchase")
|
15
|
+
@create_focus_uri = URI.parse(base_url + "/#{@player_id}/on_focus")
|
14
16
|
|
15
17
|
@params = {
|
16
18
|
foo: "bar",
|
@@ -81,4 +83,31 @@ class PlayerTest < MiniTest::Test
|
|
81
83
|
assert_equal response, OneSignal::Player.update(id: @player_id, params: @params)
|
82
84
|
end
|
83
85
|
|
86
|
+
def test_create_session
|
87
|
+
response = mock_response_ok
|
88
|
+
OneSignal::OneSignal.expects(:send_post_request)
|
89
|
+
.with(uri: @create_session_uri, body: @params)
|
90
|
+
.returns(response)
|
91
|
+
assert_equal response, OneSignal::Player.create_session(id: @player_id,
|
92
|
+
params: @params)
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_create_purchase
|
96
|
+
response = mock_response_ok
|
97
|
+
OneSignal::OneSignal.expects(:send_post_request)
|
98
|
+
.with(uri: @create_purchase_uri, body: @params)
|
99
|
+
.returns(response)
|
100
|
+
assert_equal response, OneSignal::Player.create_purchase(id: @player_id,
|
101
|
+
params: @params)
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_create_focus
|
105
|
+
response = mock_response_ok
|
106
|
+
OneSignal::OneSignal.expects(:send_post_request)
|
107
|
+
.with(uri: @create_focus_uri, body: @params)
|
108
|
+
.returns(response)
|
109
|
+
assert_equal response, OneSignal::Player.create_focus(id: @player_id,
|
110
|
+
params: @params)
|
111
|
+
end
|
112
|
+
|
84
113
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: one_signal
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.11
|
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-
|
11
|
+
date: 2016-02-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|