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 collapse

@@ENDPOINT =
'realtime'

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(region, gs2_client_id, gs2_client_secret) ⇒ Client

コンストラクタ

Parameters:

  • リージョン名

  • GSIクライアントID

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



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

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

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



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

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

Instance Method Details

#create_gathering(request) ⇒ Array

ギャザリングを作成

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

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

Parameters:

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

    • name => ギャザリング名

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

Returns:

    • item

      • gatheringId => ギャザリングID

      • ownerId => オーナーID

      • name => ギャザリング名

      • hostId => ホストID

      • ipAddress => IPアドレス

      • port => 待ち受けポート

      • secret => 暗号鍵

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

      • createAt => 作成日時



213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
# File 'lib/gs2/realtime/Client.rb', line 213

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 body['userIds'].is_a?(Array); body['userIds'] = body['userIds'].join(','); end
  end
  query = {}
  return post(
        'Gs2Realtime', 
        'CreateGathering', 
        @@ENDPOINT, 
        '/gatheringPool/' + request['gatheringPoolName'] + '/gathering',
        body,
        query);
end

#create_gathering_pool(request) ⇒ Array

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

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

Parameters:

    • name => マッチメイキング名

    • description => 説明文

Returns:

    • item

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

      • ownerId => オーナーID

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

      • description => 説明文

      • createAt => 作成日時



70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/gs2/realtime/Client.rb', line 70

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, 
        '/gatheringPool',
        body,
        query);
end

#delete_gathering(request) ⇒ Object

ギャザリングを削除

Parameters:

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

    • gatheringName => ギャザリング名



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

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, 
        '/gatheringPool/' + request['gatheringPoolName'] + '/gathering/' + request['gatheringName'],
        query);
end

#delete_gathering_pool(request) ⇒ Object

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

Parameters:

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



141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/gs2/realtime/Client.rb', line 141

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, 
        '/gatheringPool/' + request['gatheringPoolName'],
        query);
end

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

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

Parameters:

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

  • (defaults to: nil)

    ページトークン

  • (defaults to: nil)

    取得件数

Returns:

    • items

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

      • ownerId => オーナーID

      • name => ギャザリング名

      • hostId => ホストID

      • ipAddress => IPアドレス

      • port => 待ち受けポート

      • secret => 暗号鍵

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

      • createAt => 作成日時

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



173
174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'lib/gs2/realtime/Client.rb', line 173

def describe_gathering(request, pageToken = nil, limit = nil)
  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, 
        '/gatheringPool/' + request['gatheringPoolName'] + '/gathering',
        query);
end

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

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

Parameters:

  • (defaults to: nil)

    ページトークン

  • (defaults to: nil)

    取得件数

Returns:

    • items

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

      • ownerId => オーナーID

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

      • description => 説明文

      • createAt => 作成日時

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



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/gs2/realtime/Client.rb', line 43

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

#get_gathering(request) ⇒ Array

ギャザリングを取得

Parameters:

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

    • gatheringName => ギャザリング名

Returns:

    • item

      • gatheringId => ギャザリングID

      • ownerId => オーナーID

      • name => ギャザリング名

      • hostId => ホストID

      • ipAddress => IPアドレス

      • port => 待ち受けポート

      • secret => 暗号鍵

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

      • createAt => 作成日時



249
250
251
252
253
254
255
256
257
258
259
260
261
262
# File 'lib/gs2/realtime/Client.rb', line 249

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,
      '/gatheringPool/' + request['gatheringPoolName'] + '/gathering/' + request['gatheringName'],
      query);
end

#get_gathering_pool(request) ⇒ Array

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

Parameters:

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

Returns:

    • item

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

      • ownerId => オーナーID

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

      • description => 説明文

      • createAt => 作成日時



96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/gs2/realtime/Client.rb', line 96

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,
      '/gatheringPool/' + request['gatheringPoolName'],
      query);
end

#update_gathering_pool(request) ⇒ Array

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

Parameters:

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

    • description => 説明文

Returns:

    • item

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

      • ownerId => オーナーID

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

      • description => 説明文

      • createAt => 作成日時



121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/gs2/realtime/Client.rb', line 121

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,
      '/gatheringPool/' + request['gatheringPoolName'],
      body,
      query);
end