flox 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/flox.rb +37 -19
- data/lib/flox/rest_service.rb +3 -4
- data/lib/flox/version.rb +5 -1
- data/test/test_flox.rb +13 -1
- metadata +15 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9ad9881566390837774beb2f6ba709d533e2cd94
|
4
|
+
data.tar.gz: 25da47a5b5d16804352e2beba5e479b332f38ccf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f39a94d6a7edc427e1b003773f9f44c813a033339a52c13d748cdda5306b63c19c83e012253b2caa31386570c8743707c856b666e2e736cd4adb327e2c47a316
|
7
|
+
data.tar.gz: 539663241fe8bfea69b91f928f052b88fea07029037ed4a56da069db6e080053708be529d972ef48b125fdc761ac2e494980b6bc0fc9798e80201a0e61951590
|
data/lib/flox.rb
CHANGED
@@ -14,7 +14,7 @@ class Flox
|
|
14
14
|
# @private
|
15
15
|
attr_reader :service
|
16
16
|
|
17
|
-
# The player that is currently logged in.
|
17
|
+
# @return [Flox::Player] The player that is currently logged in.
|
18
18
|
attr_reader :current_player
|
19
19
|
|
20
20
|
# Creates a new instance with a certain game ID and key. Per default, a guest
|
@@ -26,12 +26,16 @@ class Flox
|
|
26
26
|
end
|
27
27
|
|
28
28
|
# Makes a key-login on the server. It is recommended to create a 'hero'
|
29
|
-
# player in the web interface and use that for the login.
|
29
|
+
# player in the web interface and use that for the login. After the login,
|
30
|
+
# `current_player` will point to this player.
|
31
|
+
# @return [Flox::Player]
|
30
32
|
def login_with_key(key)
|
31
33
|
login(:key, key)
|
32
34
|
end
|
33
35
|
|
34
|
-
# Creates a new guest player and logs it in.
|
36
|
+
# Creates a new guest player and logs it in. After the login,
|
37
|
+
# `current_player` will point to this player.
|
38
|
+
# @return [Flox::Player]
|
35
39
|
def login_guest()
|
36
40
|
login(:guest)
|
37
41
|
end
|
@@ -47,7 +51,7 @@ class Flox
|
|
47
51
|
|
48
52
|
# Loads an entity with a certain type and id from the server.
|
49
53
|
# Normally, the type is the class name you used for the entity in your game.
|
50
|
-
#
|
54
|
+
# @return [Flox::Entity]
|
51
55
|
def load_entity(type, id)
|
52
56
|
path = entity_path(type, id)
|
53
57
|
data = service.get(path)
|
@@ -58,7 +62,14 @@ class Flox
|
|
58
62
|
end
|
59
63
|
end
|
60
64
|
|
65
|
+
# Loads an entity with type '.player'.
|
66
|
+
# @return [Flox::Player]
|
67
|
+
def load_player(id)
|
68
|
+
load_entity('.player', id)
|
69
|
+
end
|
70
|
+
|
61
71
|
# Stores an entity on the server.
|
72
|
+
# @return [Flox::Entity]
|
62
73
|
def save_entity(entity)
|
63
74
|
result = service.put(entity.path, entity)
|
64
75
|
entity['updatedAt'] = result['updatedAt']
|
@@ -66,11 +77,12 @@ class Flox
|
|
66
77
|
entity
|
67
78
|
end
|
68
79
|
|
69
|
-
# :call-seq:
|
70
|
-
# delete_entity(entity)
|
71
|
-
# delete_entity(type, id)
|
72
|
-
#
|
73
80
|
# Deletes the given entity from the database.
|
81
|
+
# @overload delete_entity(entity)
|
82
|
+
# @param [Flox:Entity] entity the entity to delete
|
83
|
+
# @overload delete_entity(type, id)
|
84
|
+
# @param [String] type the type of the entity
|
85
|
+
# @param [String] id the id of the entity
|
74
86
|
def delete_entity(*entity)
|
75
87
|
if entity.length > 1
|
76
88
|
type, id = entity[0], entity[1]
|
@@ -91,6 +103,7 @@ class Flox
|
|
91
103
|
|
92
104
|
# Loads all scores of a leaderboard, sorted by rank. 'scope' can either be
|
93
105
|
# one of the symbols +:today, :this_week, :all_time+ or an array of player IDs.
|
106
|
+
# @return [Array<Flox::Score>]
|
94
107
|
def load_scores(leaderboard_id, scope)
|
95
108
|
path = leaderboard_path(leaderboard_id)
|
96
109
|
args = {}
|
@@ -106,35 +119,37 @@ class Flox
|
|
106
119
|
end
|
107
120
|
|
108
121
|
# Loads a JSON object from the given path. This works with any resource
|
109
|
-
# e.g. entities, logs, etc.
|
122
|
+
# e.g. entities, logs, etc.
|
123
|
+
# @return [Hash]
|
110
124
|
def load_resource(path, args=nil)
|
111
125
|
service.get(path, args)
|
112
126
|
end
|
113
127
|
|
114
128
|
# Loads a log with a certain ID. A log is a Hash instance.
|
129
|
+
# @return [Hash]
|
115
130
|
def load_log(log_id)
|
116
131
|
log = service.get log_path(log_id)
|
117
132
|
log['id'] = log_id unless log['id']
|
118
133
|
log
|
119
134
|
end
|
120
135
|
|
121
|
-
# Loads logs
|
136
|
+
# Loads logs defined by a certain query.
|
122
137
|
# Here are some sample queries:
|
123
138
|
#
|
124
|
-
# *
|
125
|
-
# *
|
126
|
-
# *
|
127
|
-
# *
|
139
|
+
# * `day:2014-02-20` → all logs of a certain day
|
140
|
+
# * `severity:warning` → all logs of type warning & error
|
141
|
+
# * `severity:error` → all logs of type error
|
142
|
+
# * `day:2014-02-20 severity:error` → all error logs from February 20th.
|
128
143
|
#
|
129
|
-
#
|
130
|
-
# over the logs.
|
144
|
+
# @return [Flox::ResourceEnumerator<Hash>]
|
131
145
|
def load_logs(query=nil, limit=nil)
|
132
146
|
log_ids = load_log_ids(query, limit)
|
133
147
|
paths = log_ids.map { |log_id| log_path(log_id) }
|
134
148
|
ResourceEnumerator.new(service, paths)
|
135
149
|
end
|
136
150
|
|
137
|
-
# Loads just the IDs of the logs,
|
151
|
+
# Loads just the IDs of the logs, defined by a certain query.
|
152
|
+
# @return [Array<String>]
|
138
153
|
def load_log_ids(query=nil, limit=nil)
|
139
154
|
log_ids = []
|
140
155
|
cursor = nil
|
@@ -152,23 +167,26 @@ class Flox
|
|
152
167
|
log_ids
|
153
168
|
end
|
154
169
|
|
155
|
-
# Loads the status of the Flox service
|
156
|
-
# keys 'status' and 'version'.
|
170
|
+
# Loads the status of the Flox service.
|
171
|
+
# @return [Hash] with the keys 'status' and 'version'.
|
157
172
|
def status
|
158
173
|
service.get("")
|
159
174
|
end
|
160
175
|
|
161
176
|
# The ID of the game you are accessing.
|
177
|
+
# @return [String]
|
162
178
|
def game_id
|
163
179
|
service.game_id
|
164
180
|
end
|
165
181
|
|
166
182
|
# The key of the game you are accessing.
|
183
|
+
# @return [String]
|
167
184
|
def game_key
|
168
185
|
service.game_key
|
169
186
|
end
|
170
187
|
|
171
188
|
# The base URL of the Flox service.
|
189
|
+
# @return [String]
|
172
190
|
def base_url
|
173
191
|
service.base_url
|
174
192
|
end
|
data/lib/flox/rest_service.rb
CHANGED
@@ -3,7 +3,6 @@
|
|
3
3
|
## License: Simplified BSD
|
4
4
|
|
5
5
|
require 'json'
|
6
|
-
require 'yaml'
|
7
6
|
require 'net/http'
|
8
7
|
|
9
8
|
# A class that makes it easy to communicate with the Flox server via a REST protocol.
|
@@ -22,7 +21,7 @@ class Flox::RestService
|
|
22
21
|
@game_id = game_id
|
23
22
|
@game_key = game_key
|
24
23
|
@base_url = base_url
|
25
|
-
|
24
|
+
login :guest
|
26
25
|
end
|
27
26
|
|
28
27
|
# Makes a `GET` request at the server. The given data-Hash is URI-encoded
|
@@ -64,12 +63,12 @@ class Flox::RestService
|
|
64
63
|
auth_data = {
|
65
64
|
"authType" => auth_type,
|
66
65
|
"authId" => auth_id,
|
67
|
-
"authToken" => auth_token
|
68
|
-
"id" => auth_id
|
66
|
+
"authToken" => auth_token
|
69
67
|
}
|
70
68
|
|
71
69
|
if (auth_type.to_sym == :guest)
|
72
70
|
response = auth_data
|
71
|
+
auth_data["id"] = String.random_uid
|
73
72
|
else
|
74
73
|
response = post("authenticate", auth_data)
|
75
74
|
auth_data["id"] = response["id"]
|
data/lib/flox/version.rb
CHANGED
@@ -2,9 +2,13 @@
|
|
2
2
|
## Copyright: Copyright 2014 Gamua
|
3
3
|
## License: Simplified BSD
|
4
4
|
|
5
|
+
# The main class used to interact with the Flox cloud service. Create an
|
6
|
+
# instance of Flox using the game ID and key acquired from the web interface,
|
7
|
+
# then login with a "Hero" key. That way, you will be able to access the data
|
8
|
+
# of all players.
|
5
9
|
class Flox
|
6
10
|
|
7
11
|
# The current version of the Flox SDK.
|
8
|
-
VERSION =
|
12
|
+
VERSION = '0.0.2'
|
9
13
|
|
10
14
|
end
|
data/test/test_flox.rb
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
|
5
5
|
require 'flox'
|
6
6
|
require 'test/unit'
|
7
|
-
require 'mocha/
|
7
|
+
require 'mocha/setup'
|
8
8
|
|
9
9
|
class FloxTest < Test::Unit::TestCase
|
10
10
|
|
@@ -79,6 +79,7 @@ class FloxTest < Test::Unit::TestCase
|
|
79
79
|
assert_not_nil(player)
|
80
80
|
assert_equal(:guest, player.auth_type)
|
81
81
|
assert_equal(player, flox.current_player)
|
82
|
+
assert_not_nil(player.id)
|
82
83
|
end
|
83
84
|
|
84
85
|
def test_load_entity
|
@@ -97,6 +98,17 @@ class FloxTest < Test::Unit::TestCase
|
|
97
98
|
assert_equal(data["name"], entity["name"])
|
98
99
|
end
|
99
100
|
|
101
|
+
def test_load_player
|
102
|
+
id = "id"
|
103
|
+
data = { "name" => "Jean-Luc" }
|
104
|
+
flox.service.expects(:get).once.returns(data)
|
105
|
+
player = flox.load_player(id)
|
106
|
+
assert_kind_of(Flox::Player, player)
|
107
|
+
assert_equal(data["name"], player["name"])
|
108
|
+
assert_equal(id, player.id)
|
109
|
+
assert_equal('.player', player.type)
|
110
|
+
end
|
111
|
+
|
100
112
|
def test_save_entity
|
101
113
|
data = { "name" => "Jean-Luc" }
|
102
114
|
entity = Flox::Entity.new("type", "id", data)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flox
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Sperl
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0.8'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
55
69
|
description: |
|
56
70
|
Flox is the no-fuzz backend for game developers. The Ruby SDK allows direct
|
57
71
|
interaction with the Flox servers, e.g. to download log files or update
|