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

@@ENDPOINT =
'timer'
@@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/timer/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/timer/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/timer/Client.rb', line 32

def self.VARIATION(v = nil)
  if v
    @@VARIATION = v
  else
    return @@VARIATION
  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 => 作成日時



189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
# File 'lib/gs2/timer/Client.rb', line 189

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,
    @@VARIATION,
    @@ENDPOINT_BASE + '/timerPool/' + request['timerPoolName'] + '/timer',
    body,
    query)
end

#create_timer_pool(request) ⇒ Array

タイマープールを作成。

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

Parameters:

  • request (Array)
    • name => スタミナプール名

Returns:

  • (Array)
    • item

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

      • ownerId => オーナーID

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

      • createAt => 作成日時



78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/gs2/timer/Client.rb', line 78

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

#delete_timer(request) ⇒ Object

タイマーを削除

Parameters:

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

    • timerId => タイマーID



246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
# File 'lib/gs2/timer/Client.rb', line 246

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,
    @@VARIATION,
    @@ENDPOINT_BASE + '/timerPool/' + request['timerPoolName'] + '/timer/' + request['timerId'],
    query)
end

#delete_timer_pool(request) ⇒ Object

タイマープールを削除

Parameters:

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



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

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,
    @@VARIATION,
    @@ENDPOINT_BASE + '/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 => 次ページトークン



148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/gs2/timer/Client.rb', line 148

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,
    @@VARIATION,
    @@ENDPOINT_BASE + '/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 => タイマープール名

      • createAt => 作成日時

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



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

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,
    @@VARIATION,
    @@ENDPOINT_BASE + '/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 => 作成日時



225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
# File 'lib/gs2/timer/Client.rb', line 225

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,
    @@VARIATION,
    @@ENDPOINT_BASE + '/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 => タイマープール名

    • createAt => 作成日時



101
102
103
104
105
106
107
108
109
110
111
# File 'lib/gs2/timer/Client.rb', line 101

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,
    @@VARIATION,
    @@ENDPOINT_BASE + '/timerPool/' + request['timerPoolName'])
end