playlyfe 0.8.1 → 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.
- data/lib/playlyfe.rb +30 -35
- data/test/test.rb +37 -41
- metadata +1 -17
data/lib/playlyfe.rb
CHANGED
@@ -103,52 +103,48 @@ class Playlyfe
|
|
103
103
|
end
|
104
104
|
end
|
105
105
|
|
106
|
-
def check_token(
|
106
|
+
def check_token(query)
|
107
107
|
access_token = @load.call
|
108
108
|
if access_token['expires_at'] < Time.now.to_i
|
109
109
|
puts 'Access Token Expired'
|
110
110
|
get_access_token()
|
111
111
|
access_token = @load.call
|
112
112
|
end
|
113
|
-
|
113
|
+
query[:access_token] = access_token['access_token']
|
114
114
|
end
|
115
115
|
|
116
|
-
def api(
|
117
|
-
|
118
|
-
options[:query] ||= {}
|
119
|
-
options[:body] ||= {}
|
120
|
-
options[:raw] ||= false
|
121
|
-
check_token(options)
|
116
|
+
def api(method, route, query = {}, body = {}, raw = false)
|
117
|
+
check_token(query)
|
122
118
|
begin
|
123
|
-
case
|
119
|
+
case method
|
124
120
|
when 'GET'
|
125
|
-
res = RestClient.get("https://api.playlyfe.com/#{@version}#{
|
126
|
-
{:params =>
|
121
|
+
res = RestClient.get("https://api.playlyfe.com/#{@version}#{route}",
|
122
|
+
{:params => query }
|
127
123
|
)
|
128
124
|
when 'POST'
|
129
|
-
res = RestClient.post("https://api.playlyfe.com/#{@version}#{
|
130
|
-
|
125
|
+
res = RestClient.post("https://api.playlyfe.com/#{@version}#{route}?#{hash_to_query(query)}",
|
126
|
+
body.to_json,
|
131
127
|
:content_type => :json,
|
132
128
|
:accept => :json
|
133
129
|
)
|
134
130
|
when 'PUT'
|
135
|
-
res = RestClient.put("https://api.playlyfe.com/#{@version}#{
|
136
|
-
|
131
|
+
res = RestClient.put("https://api.playlyfe.com/#{@version}#{route}?#{hash_to_query(query)}",
|
132
|
+
body.to_json,
|
137
133
|
:content_type => :json,
|
138
134
|
:accept => :json
|
139
135
|
)
|
140
136
|
when 'PATCH'
|
141
|
-
res = RestClient.patch("https://api.playlyfe.com/#{@version}#{
|
142
|
-
|
137
|
+
res = RestClient.patch("https://api.playlyfe.com/#{@version}#{route}?#{hash_to_query(query)}",
|
138
|
+
body.to_json,
|
143
139
|
:content_type => :json,
|
144
140
|
:accept => :json
|
145
141
|
)
|
146
142
|
when 'DELETE'
|
147
|
-
res = RestClient.delete("https://api.playlyfe.com/#{@version}#{
|
148
|
-
{:params =>
|
143
|
+
res = RestClient.delete("https://api.playlyfe.com/#{@version}#{route}",
|
144
|
+
{:params => query }
|
149
145
|
)
|
150
146
|
end
|
151
|
-
if
|
147
|
+
if raw == true
|
152
148
|
return res.body
|
153
149
|
else
|
154
150
|
if res.body == 'null'
|
@@ -162,29 +158,28 @@ class Playlyfe
|
|
162
158
|
end
|
163
159
|
end
|
164
160
|
|
165
|
-
def get(
|
166
|
-
|
167
|
-
api(options)
|
161
|
+
def get(route, query = {})
|
162
|
+
api("GET", route, query, {}, false)
|
168
163
|
end
|
169
164
|
|
170
|
-
def
|
171
|
-
|
172
|
-
api(options)
|
165
|
+
def get_raw(route, query = {})
|
166
|
+
api("GET", route, query, {}, true)
|
173
167
|
end
|
174
168
|
|
175
|
-
def
|
176
|
-
|
177
|
-
api(options)
|
169
|
+
def post(route, query = {}, body = {})
|
170
|
+
api("POST", route, query, body, false)
|
178
171
|
end
|
179
172
|
|
180
|
-
def
|
181
|
-
|
182
|
-
api(options)
|
173
|
+
def put(route, query = {}, body = {})
|
174
|
+
api("PUT", route, query, body, false)
|
183
175
|
end
|
184
176
|
|
185
|
-
def
|
186
|
-
|
187
|
-
|
177
|
+
def patch(route, query = {}, body = {})
|
178
|
+
api("PATCH", route, query, body, false)
|
179
|
+
end
|
180
|
+
|
181
|
+
def delete(route, query = {})
|
182
|
+
api("DELETE", route, query, {}, false)
|
188
183
|
end
|
189
184
|
|
190
185
|
def hash_to_query(hash)
|
data/test/test.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'test/unit'
|
2
|
-
require 'redis'
|
3
2
|
require 'playlyfe'
|
4
3
|
|
5
4
|
class PlaylyfeTest < Test::Unit::TestCase
|
@@ -39,61 +38,58 @@ class PlaylyfeTest < Test::Unit::TestCase
|
|
39
38
|
)
|
40
39
|
|
41
40
|
begin
|
42
|
-
pl.get(
|
41
|
+
pl.get('/gege', { player_id: 'student1' })
|
43
42
|
rescue PlaylyfeError => e
|
44
43
|
assert_equal e.name,'route_not_found'
|
45
44
|
assert_equal e.message, 'This route does not exist'
|
46
45
|
end
|
47
46
|
|
48
|
-
players = pl.api(
|
47
|
+
players = pl.api('GET', '/players', { player_id: 'student1', limit: 1 })
|
49
48
|
assert_not_nil players["data"]
|
50
49
|
assert_not_nil players["data"][0]
|
51
50
|
|
52
|
-
players = pl.get(
|
51
|
+
players = pl.get('/players', { player_id: 'student1', limit: 1 })
|
53
52
|
assert_not_nil players["data"]
|
54
53
|
assert_not_nil players["data"][0]
|
55
54
|
|
56
55
|
begin
|
57
|
-
pl.get(
|
56
|
+
pl.get('/player')
|
58
57
|
rescue PlaylyfeError => e
|
59
58
|
assert_equal e.message, "The 'player_id' parameter should be specified in the query"
|
60
59
|
end
|
61
60
|
|
62
61
|
player_id = 'student1'
|
63
|
-
player = pl.get(
|
62
|
+
player = pl.get('/player', { player_id: player_id } )
|
64
63
|
assert_equal player["id"], "student1"
|
65
64
|
assert_equal player["alias"], "Student1"
|
66
65
|
assert_equal player["enabled"], true
|
67
66
|
|
68
|
-
pl.get(
|
69
|
-
pl.get(
|
70
|
-
pl.get(
|
71
|
-
pl.get(
|
67
|
+
pl.get('/definitions/processes', { player_id: player_id } )
|
68
|
+
pl.get('/definitions/teams', { player_id: player_id } )
|
69
|
+
pl.get('/processes', { player_id: player_id } )
|
70
|
+
pl.get('/teams', { player_id: player_id } )
|
72
71
|
|
73
|
-
processes = pl.get(
|
72
|
+
processes = pl.get('/processes', { player_id: 'student1', limit: 1, skip: 4 })
|
74
73
|
assert_equal processes["data"][0]["definition"], "module1"
|
75
74
|
assert_equal processes["data"].size, 1
|
76
75
|
|
77
|
-
new_process = pl.post(
|
76
|
+
new_process = pl.post('/definitions/processes/module1', { player_id: player_id })
|
78
77
|
assert_equal new_process["definition"], "module1"
|
79
78
|
assert_equal new_process["state"], "ACTIVE"
|
80
79
|
|
81
80
|
patched_process = pl.patch(
|
82
|
-
|
83
|
-
|
84
|
-
|
81
|
+
"/processes/#{new_process['id']}",
|
82
|
+
{ player_id: player_id },
|
83
|
+
{ name: 'patched_process', access: 'PUBLIC' }
|
85
84
|
)
|
86
85
|
|
87
86
|
assert_equal patched_process['name'], 'patched_process'
|
88
87
|
assert_equal patched_process['access'], 'PUBLIC'
|
89
88
|
|
90
|
-
deleted_process = pl.delete(
|
89
|
+
deleted_process = pl.delete("/processes/#{new_process['id']}", { player_id: player_id })
|
91
90
|
assert_not_nil deleted_process['message']
|
92
91
|
|
93
|
-
|
94
|
-
#puts data
|
95
|
-
|
96
|
-
raw_data = pl.get(route: '/player', query: { player_id: player_id }, raw: true)
|
92
|
+
raw_data = pl.get_raw('/player', { player_id: player_id })
|
97
93
|
assert_equal raw_data.class, String
|
98
94
|
end
|
99
95
|
|
@@ -105,64 +101,64 @@ class PlaylyfeTest < Test::Unit::TestCase
|
|
105
101
|
)
|
106
102
|
|
107
103
|
begin
|
108
|
-
pl.get(
|
104
|
+
pl.get('/gege', { player_id: 'student1' })
|
109
105
|
rescue PlaylyfeError => e
|
110
106
|
assert_equal e.name,'route_not_found'
|
111
107
|
assert_equal e.message, 'This route does not exist'
|
112
108
|
end
|
113
109
|
|
114
|
-
players = pl.api(
|
110
|
+
players = pl.api('GET', '/runtime/players', { player_id: 'student1', limit: 1 })
|
115
111
|
assert_not_nil players["data"]
|
116
112
|
assert_not_nil players["data"][0]
|
117
113
|
|
118
|
-
players = pl.get(
|
114
|
+
players = pl.get('/runtime/players', { player_id: 'student1', limit: 1 })
|
119
115
|
assert_not_nil players["data"]
|
120
116
|
assert_not_nil players["data"][0]
|
121
117
|
|
122
118
|
begin
|
123
|
-
pl.get(
|
119
|
+
pl.get('/runtime/player')
|
124
120
|
rescue PlaylyfeError => e
|
125
121
|
assert_equal e.message, "The 'player_id' parameter should be specified in the query"
|
126
122
|
end
|
127
123
|
|
128
124
|
player_id = 'student1'
|
129
|
-
player = pl.get(
|
125
|
+
player = pl.get('/runtime/player', { player_id: player_id } )
|
130
126
|
assert_equal player["id"], "student1"
|
131
127
|
assert_equal player["alias"], "Student1"
|
132
128
|
assert_equal player["enabled"], true
|
133
129
|
|
134
|
-
pl.get(
|
135
|
-
pl.get(
|
136
|
-
pl.get(
|
137
|
-
pl.get(
|
130
|
+
pl.get('/runtime/definitions/processes', { player_id: player_id } )
|
131
|
+
pl.get('/runtime/definitions/teams', { player_id: player_id } )
|
132
|
+
pl.get('/runtime/processes', { player_id: player_id } )
|
133
|
+
pl.get('/runtime/teams', { player_id: player_id } )
|
138
134
|
|
139
|
-
processes = pl.get(
|
135
|
+
processes = pl.get('/runtime/processes', { player_id: 'student1', limit: 1, skip: 4 })
|
140
136
|
assert_equal processes["data"][0]["definition"], "module1"
|
141
137
|
assert_equal processes["data"].size, 1
|
142
138
|
|
143
|
-
new_process = pl.post(
|
139
|
+
new_process = pl.post('/runtime/processes', { player_id: player_id }, { definition: 'module1' })
|
144
140
|
assert_equal new_process["definition"]["id"], "module1"
|
145
141
|
assert_equal new_process["state"], "ACTIVE"
|
146
142
|
|
147
143
|
patched_process = pl.patch(
|
148
|
-
|
149
|
-
|
150
|
-
|
144
|
+
"/runtime/processes/#{new_process['id']}",
|
145
|
+
{ player_id: player_id },
|
146
|
+
{ name: 'patched_process', access: 'PUBLIC' }
|
151
147
|
)
|
152
148
|
|
153
149
|
assert_equal patched_process['name'], 'patched_process'
|
154
150
|
assert_equal patched_process['access'], 'PUBLIC'
|
155
151
|
|
156
|
-
deleted_process = pl.delete(
|
152
|
+
deleted_process = pl.delete("/runtime/processes/#{new_process['id']}", { player_id: player_id })
|
157
153
|
assert_not_nil deleted_process['message']
|
158
154
|
|
159
|
-
#data = pl.put(
|
155
|
+
#data = pl.put("/players/#{player_id}/reset", { player_id: player_id })
|
160
156
|
#puts data
|
161
157
|
|
162
|
-
raw_data = pl.
|
158
|
+
raw_data = pl.get_raw('/runtime/player', { player_id: player_id })
|
163
159
|
assert_equal raw_data.class, String
|
164
160
|
|
165
|
-
new_metric = pl.post(
|
161
|
+
new_metric = pl.post('/design/versions/latest/metrics', {}, {
|
166
162
|
id: 'apple',
|
167
163
|
name: 'apple',
|
168
164
|
type: 'point',
|
@@ -175,7 +171,7 @@ class PlaylyfeTest < Test::Unit::TestCase
|
|
175
171
|
}
|
176
172
|
});
|
177
173
|
assert_equal new_metric['id'], 'apple'
|
178
|
-
deleted_metric = pl.delete(
|
174
|
+
deleted_metric = pl.delete('/design/versions/latest/metrics/apple')
|
179
175
|
assert_equal deleted_metric['message'], "The metric 'apple' has been deleted successfully"
|
180
176
|
end
|
181
177
|
|
@@ -186,7 +182,7 @@ class PlaylyfeTest < Test::Unit::TestCase
|
|
186
182
|
client_secret: "NDc3NTA0NmItMjBkZi00MjI2LWFhMjUtOTI0N2I1YTkxYjc2M2U3ZGI0MDAtNGQ1Mi0xMWU0LWJmZmUtMzkyZTdiOTYxYmMx",
|
187
183
|
type: 'client'
|
188
184
|
)
|
189
|
-
pl.get(
|
185
|
+
pl.get('/game/players', { limit: 1 })
|
190
186
|
end
|
191
187
|
|
192
188
|
def test_store
|
@@ -199,7 +195,7 @@ class PlaylyfeTest < Test::Unit::TestCase
|
|
199
195
|
store: lambda { |token| access_token = token },
|
200
196
|
load: lambda { return access_token }
|
201
197
|
)
|
202
|
-
players = pl.get(
|
198
|
+
players = pl.get('/players', { player_id: 'student1', limit: 1 })
|
203
199
|
assert_not_nil players["data"]
|
204
200
|
assert_not_nil players["data"][0]
|
205
201
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: playlyfe
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -75,22 +75,6 @@ dependencies:
|
|
75
75
|
- - ! '>='
|
76
76
|
- !ruby/object:Gem::Version
|
77
77
|
version: '0'
|
78
|
-
- !ruby/object:Gem::Dependency
|
79
|
-
name: redis
|
80
|
-
requirement: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
|
-
requirements:
|
83
|
-
- - ! '>='
|
84
|
-
- !ruby/object:Gem::Version
|
85
|
-
version: '0'
|
86
|
-
type: :development
|
87
|
-
prerelease: false
|
88
|
-
version_requirements: !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
|
-
requirements:
|
91
|
-
- - ! '>='
|
92
|
-
- !ruby/object:Gem::Version
|
93
|
-
version: '0'
|
94
78
|
description: This gem can be used to interact with the playlyfe gamification platform
|
95
79
|
using oauth 2.0
|
96
80
|
email: peter@playlyfe.com
|