Class: Gs2::Timer::Client

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

Overview

GS2-Timer クライアント

Author:

  • Game Server Services, Inc.

Constant Summary collapse

@@ENDPOINT =
'timer'

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クライアントシークレット



17
18
19
# File 'lib/gs2/timer/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/timer/Client.rb', line 22

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

Instance Method Details

#create_timer(request) ⇒ Array

タイマーを作成

タイマーを作成すると、指定した時刻に指定したURLに指定したパラメータを持ったアクセスを発生させます。
基本的には指定した時刻以降に60秒以内に呼び出し処理が開始されます。
混雑時には60秒以上かかることがありますので、タイミングがシビアな処理には向きません。

アカウントBANを指定した時刻付近で解除する。など、タイミングがシビアでない処理で利用することをおすすめします。

Parameters:

  • request (Array)
    • callbackMethod => HTTPメソッド

    • callbackUrl => コールバックURL

    • callbackBody => コールバックボディ

    • executeTime => 実行時間

    • retryMax => 最大リトライ回数(OPTIONAL)

Returns:

  • (Array)
    • item

    • timerId => タイマーID

    • timerPoolId => タイマープールID

    • ownerId => オーナーID

    • callbackMethod => HTTPメソッド

    • callbackUrl => コールバックURL

    • callbackBody => コールバックボディ

    • executeTime => 実行時間

    • retryMax => 最大リトライ回数

    • createAt => 作成日時



204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
# File 'lib/gs2/timer/Client.rb', line 204

def create_timer(request)
  if not request; raise ArgumentError.new(); end
  if not request.has_key?('timerPoolName'); raise ArgumentError.new(); end
  if request['timerPoolName'] == nil; raise ArgumentError.new(); end
  body = {};
  if request.has_key?('callbackMethod'); body['callbackMethod'] = request['callbackMethod']; end
  if request.has_key?('callbackUrl'); body['callbackUrl'] = request['callbackUrl']; end
  if request.has_key?('executeTime'); body['executeTime'] = request['executeTime']; end
  if request.has_key?('retryMax'); body['retryMax'] = request['retryMax']; end
  query = {}
  return post(
    'Gs2Timer', 
    'CreateTimer', 
    @@ENDPOINT,
    '/timerPool/' + request['timerPoolName'] + '/timer',
    body,
    query)
end

#create_timer_pool(request) ⇒ Array

タイマープールを作成。

GS2-Timer を利用するには、まずタイマープールを作成する必要があります。
タイマープールには複数のタイマーを格納することができます。

Parameters:

  • request (Array)
    • name => タイマープール名

    • description => 説明文

Returns:

  • (Array)
    • item

      • timerPoolId => タイマープールID

      • ownerId => オーナーID

      • name => タイマープール名

      • description => 説明文

      • createAt => 作成日時



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

def create_timer_pool(request)
  body = {}
  if not request; raise ArgumentError.new() end
  if request.has_key?('name'); body['name'] = request['name'] end
  if request.has_key?('description'); body['description'] = request['description'] end
  return post(
    'Gs2Timer', 
    'CreateTimerPool',
    @@ENDPOINT,
    '/timerPool',
    body)
end

#delete_timer(request) ⇒ Object

タイマーを削除

Parameters:

  • request (Array)
    • timerPoolName => タイマープール名

    • timerId => タイマーID



259
260
261
262
263
264
265
266
267
268
269
270
271
272
# File 'lib/gs2/timer/Client.rb', line 259

def delete_timer(request)
  if not request; raise ArgumentError.new(); end
  if not request.has_key?('timerPoolName'); raise ArgumentError.new(); end
  if request['timerPoolName'] == nil; raise ArgumentError.new(); end
  if not request.has_key?('timerId'); raise ArgumentError.new(); end
  if request['timerId'] == nil; raise ArgumentError.new(); end
  query = {}
  return delete(
    'Gs2Timer', 
    'DeleteTimer', 
    @@ENDPOINT,
    '/timerPool/' + request['timerPoolName'] + '/timer/' + request['timerId'],
    query)
end

#delete_timer_pool(request) ⇒ Object

タイマープールを削除

Parameters:

  • request (Array)
    • timerPoolName => タイマープール名



134
135
136
137
138
139
140
141
142
143
# File 'lib/gs2/timer/Client.rb', line 134

def delete_timer_pool(request)
  if not request; raise ArgumentError.new() end
  if not request.has_key?('timerPoolName'); raise ArgumentError.new() end
  if request['timerPoolName'] == nil; raise ArgumentError.new() end
  return delete(
    'Gs2Timer', 
    'DeleteTimerPool',
    @@ENDPOINT,
    '/timerPool/' + request['timerPoolName'])
end

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

タイマーリストを取得

  • timerPoolName => タイマープール名

Parameters:

  • request (Array)
  • string

    $pageToken ページトークン

  • integer

    $limit 取得件数

Returns:

  • (Array)
    • items

      Array
      • timerId => タイマーID

      • timerPoolId => タイマープールID

      • ownerId => オーナーID

      • callbackMethod => HTTPメソッド

      • callbackUrl => コールバックURL

      • callbackBody => コールバックボディ

      • executeTime => 実行時間

      • retryMax => 最大リトライ回数

      • createAt => 作成日時

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



164
165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'lib/gs2/timer/Client.rb', line 164

def describe_timer(request, pageToken = nil, limit = nil)
  if not request; raise ArgumentError.new(); end
  if not request.has_key?('timerPoolName'); raise ArgumentError.new(); end
  if request['timerPoolName'] == nil; raise ArgumentError.new(); end
  query = {}
  if pageToken; query['pageToken'] = pageToken; end
  if limit; query['limit'] = limit; end
  return get(
    'Gs2Timer', 
    'DescribeTimer', 
    @@ENDPOINT,
    '/timerPool/' + request['timerPoolName'] + '/timer',
    query)
end

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

タイマープールリストを取得。

Parameters:

  • pageToken (String) (defaults to: nil)

    ページトークン

  • limit (Integer) (defaults to: nil)

    取得件数

Returns:

  • (Array)
    • items

      Array
      • timerPoolId => タイマープールID

      • ownerId => オーナーID

      • name => タイマープール名

      • description => 説明文

      • createAt => 作成日時

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



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

def describe_timer_pool(pageToken = nil, limit = nil)
  query = {}
  if pageToken; query['pageToken'] = pageToken end
  if limit; query['limit'] = limit end
  return get(
    'Gs2Timer', 
    'DescribeTimerPool',
    @@ENDPOINT,
    '/timerPool',
    query)
end

#get_timer(request) ⇒ Array

タイマーを取得

  • timerPoolName => タイマープール名

  • timerId => タイマーID

Parameters:

  • request (Array)

Returns:

  • (Array)
    • item

    • timerId => タイマーID

    • timerPoolId => タイマープールID

    • ownerId => オーナーID

    • callbackMethod => HTTPメソッド

    • callbackUrl => コールバックURL

    • callbackBody => コールバックボディ

    • executeTime => 実行時間

    • retryMax => 最大リトライ回数

    • createAt => 作成日時



239
240
241
242
243
244
245
246
247
248
249
250
251
252
# File 'lib/gs2/timer/Client.rb', line 239

def get_timer(request)
  if not request; raise ArgumentError.new(); end
  if not request.has_key?('timerPoolName'); raise ArgumentError.new(); end
  if request['timerPoolName'] == nil; raise ArgumentError.new(); end
  if not request.has_key?('timerId'); raise ArgumentError.new(); end
  if request['timerId'] == nil; raise ArgumentError.new(); end
  query = {}
  return get(
    'Gs2Timer',
    'GetTimer',
    @@ENDPOINT,
    '/timerPool/' + request['timerPoolName'] + '/timer/' + request['timerId'],
    query)
end

#get_timer_pool(request) ⇒ Array

タイマープールを取得

Parameters:

  • request (Array)
    • timerPoolName => タイマープール名

Returns:

  • (Array)
    • item

    • timerPoolId => タイマープールID

    • ownerId => オーナーID

    • name => タイマープール名

    • description => 説明文

    • createAt => 作成日時



119
120
121
122
123
124
125
126
127
128
# File 'lib/gs2/timer/Client.rb', line 119

def get_timer_pool(request)
  if not request; raise ArgumentError.new() end
  if not request.has_key?('timerPoolName'); raise ArgumentError.new() end
  if request['timerPoolName'] == nil; raise ArgumentError.new() end
  return get(
    'Gs2Timer', 
    'GetTimerPool',
    @@ENDPOINT,
    '/timerPool/' + request['timerPoolName'])
end

#update_timer_pool(request) ⇒ Array

タイマープールを更新。

Parameters:

  • request (Array)
    • timerPoolName => タイマープール名

    • description => 説明文

Returns:

  • (Array)
    • item

      • timerPoolId => タイマープールID

      • ownerId => オーナーID

      • name => タイマープール名

      • description => 説明文

      • createAt => 作成日時



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

def update_timer_pool(request)
  body = {}
  if not request; raise ArgumentError.new() end
  if not request.has_key?('timerPoolName'); raise ArgumentError.new() end
  if request.has_key?('description'); body['description'] = request['description'] end
  return put(
    'Gs2Timer', 
    'UpdateTimerPool',
    @@ENDPOINT,
    '/timerPool/' + request['timerPoolName'],
    body)
end