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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0bfcc3ed174c17361a262d7634fe46f422b68305
4
- data.tar.gz: 8c9a1c957fe98e7b0e557212e5cea525db3a8be7
3
+ metadata.gz: 7994c4b7087c3bbdd2202eb9078e9a3d718059a1
4
+ data.tar.gz: 84ca494ed9b601e7a4b5287b9075a6af6ef452cf
5
5
  SHA512:
6
- metadata.gz: 6f5bdb3a1b5391172b3ae9ee2b338e12df39589c8374934aaf17ec026978d1b8206d4d07b7a2f7a4dfbdc419dde912caf83aee9ff4044684391e6d89b5c4e4b4
7
- data.tar.gz: dc46222be994747ca4a6e6b4b0dd6cdb7e5364902d7c7eb1587dd596319fc8db9b254abd4ef9138c3270762e80aa359039b34a2718c7099ed5edf68c4b9dfbe8
6
+ metadata.gz: 866c2b3e215e19adf4751313b126e792efdb747b93fc76bbe6c809373682a000e3be344152587ffee7ba966a03253d70dac67eca4264b88491698232cf1444d2
7
+ data.tar.gz: 0f9e469c3487c31b559675d24a893c34260742d24f265733e926f9c4fd91c714560807740209221bd0f4d55174a05d23027c10faf244a5d99511105713cb8674
data/.yardopts CHANGED
@@ -1,3 +1,4 @@
1
1
  --readme README.md
2
2
  --title 'Flox-Ruby API Documentation'
3
- --markup markdown
3
+ --markup markdown
4
+ --no-private
@@ -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
- "authType" => auth_type,
65
- "authId" => auth_id,
66
- "authToken" => auth_token
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["id"] = String.random_uid
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["id"] = response["id"]
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(response.body || '{}')
120
+ return JSON.parse(body || '{}')
112
121
  else
113
122
  message = begin
114
- JSON.parse(response.body)['message']
123
+ JSON.parse(body)['message']
115
124
  rescue
116
- response.body
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
@@ -9,6 +9,6 @@
9
9
  class Flox
10
10
 
11
11
  # The current version of the Flox SDK.
12
- VERSION = '0.1.1'
12
+ VERSION = '0.1.2'
13
13
 
14
14
  end
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.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Sperl