flox 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.yardopts +2 -1
- data/lib/flox/rest_service.rb +28 -9
- data/lib/flox/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7994c4b7087c3bbdd2202eb9078e9a3d718059a1
|
4
|
+
data.tar.gz: 84ca494ed9b601e7a4b5287b9075a6af6ef452cf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 866c2b3e215e19adf4751313b126e792efdb747b93fc76bbe6c809373682a000e3be344152587ffee7ba966a03253d70dac67eca4264b88491698232cf1444d2
|
7
|
+
data.tar.gz: 0f9e469c3487c31b559675d24a893c34260742d24f265733e926f9c4fd91c714560807740209221bd0f4d55174a05d23027c10faf244a5d99511105713cb8674
|
data/.yardopts
CHANGED
data/lib/flox/rest_service.rb
CHANGED
@@ -3,6 +3,8 @@
|
|
3
3
|
## License: Simplified BSD
|
4
4
|
|
5
5
|
require 'json'
|
6
|
+
require 'zlib'
|
7
|
+
require 'base64'
|
6
8
|
require 'net/http'
|
7
9
|
|
8
10
|
# A class that makes it easy to communicate with the Flox server via a REST protocol.
|
@@ -61,17 +63,20 @@ class Flox::RestService
|
|
61
63
|
# @return the server response.
|
62
64
|
def login(auth_type, auth_id=nil, auth_token=nil)
|
63
65
|
auth_data = {
|
64
|
-
|
65
|
-
|
66
|
-
|
66
|
+
:authType => auth_type,
|
67
|
+
:authId => auth_id,
|
68
|
+
:authToken => auth_token
|
67
69
|
}
|
68
70
|
|
69
71
|
if (auth_type.to_sym == :guest)
|
70
72
|
response = auth_data
|
71
|
-
auth_data[
|
73
|
+
auth_data[:id] = String.random_uid
|
72
74
|
else
|
75
|
+
if @authentication[:authType] == :guest
|
76
|
+
auth_data[:id] = @authentication[:id]
|
77
|
+
end
|
73
78
|
response = post("authenticate", auth_data)
|
74
|
-
auth_data[
|
79
|
+
auth_data[:id] = response["id"]
|
75
80
|
end
|
76
81
|
|
77
82
|
@authentication = auth_data
|
@@ -90,12 +95,13 @@ class Flox::RestService
|
|
90
95
|
"sdk" => { "type" => "ruby", "version" => Flox::VERSION },
|
91
96
|
"gameKey" => @game_key,
|
92
97
|
"dispatchTime" => Time.now.utc.to_xs_datetime,
|
98
|
+
"bodyCompression" => "zlib",
|
93
99
|
"player" => @authentication
|
94
100
|
}
|
95
101
|
|
96
102
|
request["Content-Type"] = "application/json"
|
97
103
|
request["X-Flox"] = flox_header.to_json
|
98
|
-
request.body = data.to_json if data
|
104
|
+
request.body = encode(data.to_json) if data
|
99
105
|
|
100
106
|
uri = URI.parse(@base_url)
|
101
107
|
http = Net::HTTP::new(uri.host, uri.port)
|
@@ -107,19 +113,32 @@ class Flox::RestService
|
|
107
113
|
|
108
114
|
http.start do |session|
|
109
115
|
response = session.request(request)
|
116
|
+
body = response.body
|
117
|
+
body = decode(body) if response['x-content-encoding'] == 'zlib'
|
118
|
+
|
110
119
|
if (response.is_a? Net::HTTPSuccess)
|
111
|
-
return JSON.parse(
|
120
|
+
return JSON.parse(body || '{}')
|
112
121
|
else
|
113
122
|
message = begin
|
114
|
-
JSON.parse(
|
123
|
+
JSON.parse(body)['message']
|
115
124
|
rescue
|
116
|
-
|
125
|
+
body
|
117
126
|
end
|
118
127
|
raise Flox::Error, message
|
119
128
|
end
|
120
129
|
end
|
121
130
|
end
|
122
131
|
|
132
|
+
def decode(string)
|
133
|
+
return nil if string.nil? or string.empty?
|
134
|
+
Zlib::Inflate.inflate(Base64.decode64(string))
|
135
|
+
end
|
136
|
+
|
137
|
+
def encode(string)
|
138
|
+
return nil if string.nil?
|
139
|
+
Base64.encode64(Zlib::Deflate.deflate(string))
|
140
|
+
end
|
141
|
+
|
123
142
|
def full_path(path)
|
124
143
|
"/api/games/#{@game_id}/#{path}"
|
125
144
|
end
|
data/lib/flox/version.rb
CHANGED