Class: Gs2::Realtime::Client

Inherits:
Core::AbstractClient
  • Object
show all
Defined in:
lib/gs2/realtime/Client.rb

Overview

GS2-Realtime クライアント

Author:

  • Game Server Services, Inc.

Constant Summary

@@ENDPOINT =
'realtime'
@@VARIATION =
'a'

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(region, gs2_client_id, gs2_client_secret) ⇒ Client

コンストラクタ

Parameters:

  • region (String)

    リージョン名

  • gs2_client_id (String)

    GSIクライアントID

  • gs2_client_secret (String)

    GSIクライアントシークレット



18
19
20
# File 'lib/gs2/realtime/Client.rb', line 18

def initialize(region, gs2_client_id, gs2_client_secret)
  super(region, gs2_client_id, gs2_client_secret)
end

Class Method Details

.ENDPOINT(v = nil) ⇒ Object

デバッグ用。通常利用する必要はありません。



23
24
25
26
27
28
29
# File 'lib/gs2/realtime/Client.rb', line 23

def self.ENDPOINT(v = nil)
  if v
    @@ENDPOINT = v
  else
    return @@ENDPOINT
  end
end

.VARIATION(v = nil) ⇒ Object

デバッグ用。通常利用する必要はありません。



32
33
34
35
36
37
38
# File 'lib/gs2/realtime/Client.rb', line 32

def self.VARIATION(v = nil)
  if v
    @@VARIATION = v
  else
    return @@VARIATION
  end
end

Instance Method Details

#create_gathering(request) ⇒ Array

ギャザリングを作成

ギャザリングを作成すると、ゲームサーバが起動します。
ゲームサーバはWebSocketで接続することができ、同じゲームサーバに接続しているユーザ間でメッセージをやり取りすることができます。
ゲームサーバとの通信プロトコルの説明については別途ドキュメントを確認してください。

userIds にユーザIDを指定することで、ギャザリングに参加できるユーザのIDを制限することができます。
ギャザリング作成時に参加するユーザが確定している場合は指定してください。
省略すると、暗号鍵を知っていれば誰でも参加することができます。

Parameters:

  • request (Array)
    • gatheringPoolName => ギャザリングプール名

    • name => ギャザリング名

    • userIds => 参加ユーザIDリスト

Returns:

  • (Array)
    • item

      • gatheringId => ギャザリングID

      • ownerId => オーナーID

      • name => ギャザリング名

      • hostId => ホストID

      • ipAddress => IPアドレス

      • port => 待ち受けポート

      • secret => 暗号鍵

      • userIds => 参加ユーザIDリスト

      • createAt => 作成日時



229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
# File 'lib/gs2/realtime/Client.rb', line 229

def create_gathering(request)
  if not request; raise ArgumentError.new(); end
  if not request.has_key?('gatheringPoolName'); raise ArgumentError.new(); end
  if not request['gatheringPoolName']; raise ArgumentError.new(); end
  body = {}
  if request.has_key?('name'); body['name'] = request['name']; end
  if request.has_key?('userIds')
    body['userIds'] = request['userIds']
    if not body['userIds'].is_a?(Array); body['userIds'] = body['userIds'].split(','); end
  end
  query = {}
  return post(
        'Gs2Realtime', 
        'CreateGathering', 
        @@ENDPOINT, 
        @@VARIATION,
        '/gatheringPool/' + request['gatheringPoolName'] + '/gathering',
        body,
        query);
end

#create_gathering_pool(request) ⇒ Array

ギャザリングプールを作成

GS2-Realtime を利用するには、まずギャザリングプールを作成する必要があります。
ギャザリングプールには複数のギャザリングを紐付けることができます。

Parameters:

  • request (Array)
    • name => マッチメイキング名

    • description => 説明文

Returns:

  • (Array)
    • item

      • gatheringPoolId => ギャザリングプールID

      • ownerId => オーナーID

      • name => ギャザリングプール名

      • description => 説明文

      • createAt => 作成日時



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/gs2/realtime/Client.rb', line 81

def create_gathering_pool(request)
  if not request; raise ArgumentError.new(); end
  body = {}
  if request.has_key?('name'); body['name'] = request['name']; end
  if request.has_key?('description'); body['description'] = request['description']; end
  query = {}
  return post(
        'Gs2Realtime', 
        'CreateGatheringPool', 
        @@ENDPOINT, 
        @@VARIATION,
        '/gatheringPool',
        body,
        query);
end

#delete_gathering(request) ⇒ Object

ギャザリングを削除

Parameters:

  • request (Array)
    • gatheringPoolName => ギャザリングプール名

    • gatheringName => ギャザリング名



287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
# File 'lib/gs2/realtime/Client.rb', line 287

def delete_gathering(request)
  if not request; raise ArgumentError.new(); end
  if not request.has_key?('gatheringPoolName'); raise ArgumentError.new(); end
  if not request['gatheringPoolName']; raise ArgumentError.new(); end
  if not request.has_key?('gatheringName'); raise ArgumentError.new(); end
  if not request['gatheringName']; raise ArgumentError.new(); end
  query = {}
  return delete(
        'Gs2Realtime', 
        'DeleteGathering', 
        @@ENDPOINT, 
        @@VARIATION,
        '/gatheringPool/' + request['gatheringPoolName'] + '/gathering/' + request['gatheringName'],
        query);
end

#delete_gathering_pool(request) ⇒ Object

ギャザリングプールを削除

Parameters:

  • request (Array)
    • gatheringPoolName => ギャザリングプール名



155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/gs2/realtime/Client.rb', line 155

def delete_gathering_pool(request)
  if not request; raise ArgumentError.new(); end
  if not request.has_key?('gatheringPoolName'); raise ArgumentError.new(); end
  if not request['gatheringPoolName']; raise ArgumentError.new(); end
  query = {}
  return delete(
        'Gs2Realtime', 
        'DeleteGatheringPool', 
        @@ENDPOINT, 
        @@VARIATION,
        '/gatheringPool/' + request['gatheringPoolName'],
        query);
end

#describe_gathering(request, pageToken = NULL, limit = NULL) ⇒ Array

ギャザリングリストを取得

Parameters:

  • request (Array)
    • gatheringPoolName => ギャザリングプール名

  • pageToken (String) (defaults to: NULL)

    ページトークン

  • limit (Integer) (defaults to: NULL)

    取得件数

Returns:

  • (Array)
    • items

      Array
      • gatheringId => ギャザリングID

      • ownerId => オーナーID

      • name => ギャザリング名

      • hostId => ホストID

      • ipAddress => IPアドレス

      • port => 待ち受けポート

      • secret => 暗号鍵

      • userIds => 参加ユーザIDリスト

      • createAt => 作成日時

    • nextPageToken => 次ページトークン



188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# File 'lib/gs2/realtime/Client.rb', line 188

def describe_gathering(request, pageToken = NULL, limit = NULL)
  if not request; raise ArgumentError.new(); end
  if not request.has_key?('gatheringPoolName'); raise ArgumentError.new(); end
  if not request['gatheringPoolName']; raise ArgumentError.new(); end
  query = {}
  if pageToken; query['pageToken'] = pageToken; end
  if limit; query['limit'] = limit; end
  return get(
        'Gs2Realtime', 
        'DescribeGathering', 
        @@ENDPOINT, 
        @@VARIATION,
        '/gatheringPool/' + request['gatheringPoolName'] + '/gathering',
        query);
end

#describe_gathering_pool(pageToken = NULL, limit = NULL) ⇒ Array

ギャザリングプールリストを取得

Parameters:

  • pageToken (String) (defaults to: NULL)

    ページトークン

  • limit (Integer) (defaults to: NULL)

    取得件数

Returns:

  • (Array)
    • items

      Array
      • gatheringPoolId => ギャザリングプールID

      • ownerId => オーナーID

      • name => ギャザリングプール名

      • description => 説明文

      • createAt => 作成日時

    • nextPageToken => 次ページトークン



53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/gs2/realtime/Client.rb', line 53

def describe_gathering_pool(pageToken = NULL, limit = NULL)
  query = {}
  if pageToken; query['pageToken'] = pageToken; end
  if limit; query['limit'] = limit; end
  return get(
        'Gs2Realtime', 
        'DescribeGatheringPool', 
        @@ENDPOINT, 
        @@VARIATION,
        '/gatheringPool',
        query);
end

#get_gathering(request) ⇒ Array

ギャザリングを取得

Parameters:

  • request (Array)
    • gatheringPoolName => ギャザリングプール名

    • gatheringName => ギャザリング名

Returns:

  • (Array)
    • item

      • gatheringId => ギャザリングID

      • ownerId => オーナーID

      • name => ギャザリング名

      • hostId => ホストID

      • ipAddress => IPアドレス

      • port => 待ち受けポート

      • secret => 暗号鍵

      • userIds => 参加ユーザIDリスト

      • createAt => 作成日時



266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
# File 'lib/gs2/realtime/Client.rb', line 266

def get_gathering(request)
  if not request; raise ArgumentError.new(); end
  if not request.has_key?('gatheringPoolName'); raise ArgumentError.new(); end
  if not request['gatheringPoolName']; raise ArgumentError.new(); end
  if not request.has_key?('gatheringName'); raise ArgumentError.new(); end
  if not request['gatheringName']; raise ArgumentError.new(); end
  query = {}
  return get(
      'Gs2Realtime',
      'GetGathering',
      @@ENDPOINT,
      @@VARIATION,
      '/gatheringPool/' + request['gatheringPoolName'] + '/gathering/' + request['gatheringName'],
      query);
end

#get_gathering_pool(request) ⇒ Array

ギャザリングプールを取得

Parameters:

  • request (Array)
    • gatheringPoolName => ギャザリングプール名

Returns:

  • (Array)
    • item

      • gatheringPoolId => ギャザリングプールID

      • ownerId => オーナーID

      • name => ギャザリングプール名

      • description => 説明文

      • createAt => 作成日時



108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/gs2/realtime/Client.rb', line 108

def get_gathering_pool(request)
  if not request; raise ArgumentError.new(); end
  if not request.has_key?('gatheringPoolName'); raise ArgumentError.new(); end
  if not request['gatheringPoolName']; raise ArgumentError.new(); end
  query = {}
  return get(
      'Gs2Realtime',
      'GetGatheringPool',
      @@ENDPOINT,
      @@VARIATION,
      '/gatheringPool/' + request['gatheringPoolName'],
      query);
end

#update_gathering_pool(request) ⇒ Array

ギャザリングプールを更新

Parameters:

  • request (Array)
    • gatheringPoolName => ギャザリングプール名

    • description => 説明文

Returns:

  • (Array)
    • item

      • gatheringPoolId => ギャザリングプールID

      • ownerId => オーナーID

      • name => ギャザリングプール名

      • description => 説明文

      • createAt => 作成日時



134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/gs2/realtime/Client.rb', line 134

def update_gathering_pool(request)
  if not request; raise ArgumentError.new(); end
  if not request.has_key?('gatheringPoolName'); raise ArgumentError.new(); end
  if not request['gatheringPoolName']; raise ArgumentError.new(); end
  body = {}
  if request.has_key?('description'); body['description'] = request['description']; end
  query = {}
  return put(
      'Gs2Realtime',
      'UpdateGatheringPool',
      @@ENDPOINT,
      @@VARIATION,
      '/gatheringPool/' + request['gatheringPoolName'],
      body,
      query);
end