Class: Gs2::Notification::Client

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

Overview

GS2-Notification クライアント

Author:

  • Game Server Services, Inc.

Constant Summary

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

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

Instance Method Details

#createNotification(request) ⇒ Array

通知を作成

通知はGS2内で発生したイベントを受け取る手段を提供します。
例えば、GS2-Watch の監視データが一定の閾値を超えた時に通知する。といった用途に利用できます。

GS2 のサービスの多くはクオータを買い、その範囲内でサービスを利用する形式が多く取られていますが、
現在の消費クオータが GS2-Watch で取れますので、クオータの消費量が予約量の80%を超えたら通知をだす。というような使い方ができます。

Parameters:

  • request (Array)
    • name => 通知名

    • description => 説明文

Returns:

  • (Array)
    • item

      • notificationId => 通知ID

      • ownerId => オーナーID

      • name => 通知名

      • description => 説明文

      • createAt => 作成日時

      • updateAt => 更新日時



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/gs2/notification/Client.rb', line 86

def createNotification(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(
        'Gs2Notification', 
        'CreateNotification', 
        @@ENDPOINT, 
        @@VARIATION,
        '/notification',
        body,
        query);
end

#createSubscribe(request) ⇒ Array

通知先を作成

E-Mail, HTTP/HTTPS 通信を指定して通知先を登録できます。
通知先は1つの通知に対して複数登録することもできます。

そのため、メールとSlackに通知する。といった利用ができます。

type に指定できるパラメータ

  • email

  • http/https


endpoint には type に指定したプロトコルによって指定する内容が変わります。
email を選択した場合には メールアドレスを、
http/https を選択した場合には URL を指定してください。

http/https を選択した場合には登録時に疎通確認を行います。
指定したURLでPOSTリクエストを受け付けられる状態で登録してください。
疎通確認の通信は通常の通知とは異なり、body パラメータがからの通信が発生します。ご注意ください。

Parameters:

  • request (Array)
    • notificationName => 通知名

    • name => 通知先名

    • type => 通知プロトコル

    • endpoint => 通知先

Returns:

  • (Array)
    • item

      • subscribeId => 通知先ID

      • notificationId => 通知ID

      • type => 通知プロトコル

      • endpoint => 通知先

      • createAt => 作成日時



240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
# File 'lib/gs2/notification/Client.rb', line 240

def createSubscribe(request)
  if not request; raise ArgumentError.new(); end
  if not request.has_key?('notificationName'); raise ArgumentError.new(); end
  if not request['notificationName']; raise ArgumentError.new(); end
  body = {}
  if request.has_key?('name'); body['name'] = request['name']; end
  if request.has_key?('type'); body['type'] = request['type']; end
  if request.has_key?('endpoint'); body['endpoint'] = request['endpoint']; end
  query = {}
  return post(
      'Gs2Notification',
      'CreateSubscribe',
      @@ENDPOINT,
      @@VARIATION,
      '/notification/' + request['notificationName'] + '/subscribe',
      body,
      query);
end

#deleteNotification(request) ⇒ Object

通知を削除

Parameters:

  • request (Array)
    • notificationName => 通知名



162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'lib/gs2/notification/Client.rb', line 162

def deleteNotification(request)
  if not request; raise ArgumentError.new(); end
  if not request.has_key?('notificationName'); raise ArgumentError.new(); end
  if not request['notificationName']; raise ArgumentError.new(); end
  query = {}
  return delete(
        'Gs2Notification', 
        'DeleteNotification', 
        @@ENDPOINT, 
        @@VARIATION,
        '/notification/' + request['notificationName'],
        query);
end

#deleteSubscribe(request) ⇒ Object

通知先を削除

Parameters:

  • request (Array)
    • notificationName => 通知名

    • subscribeId => 通知先ID



292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
# File 'lib/gs2/notification/Client.rb', line 292

def deleteSubscribe(request)
  if not request; raise ArgumentError.new(); end
  if not request.has_key?('notificationName'); raise ArgumentError.new(); end
  if not request['notificationName']; raise ArgumentError.new(); end
  if not request.has_key?('subscribeId'); raise ArgumentError.new(); end
  if not request['subscribeId']; raise ArgumentError.new(); end
  query = {}
  return delete(
      'Gs2Notification',
      'DeleteSubscribe',
      @@ENDPOINT,
      @@VARIATION,
      '/notification/' + request['notificationName'] + '/subscribe/' + request['subscribeId'],
      query);
end

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

通知リストを取得

Parameters:

  • pageToken (String) (defaults to: NULL)

    ページトークン

  • limit (Integer) (defaults to: NULL)

    取得件数

Returns:

  • (Array)
    • items

      Array
      • notificationId => 通知ID

      • ownerId => オーナーID

      • name => 通知名

      • description => 説明文

      • createAt => 作成日時

      • updateAt => 更新日時

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



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

def describeNotification(pageToken = NULL, limit = NULL)
  query = {}
  if pageToken; query['pageToken'] = pageToken; end
  if limit; query['limit'] = limit; end
  return get(
        'Gs2Notification', 
        'DescribeNotification', 
        @@ENDPOINT, 
        @@VARIATION,
        '/notification',
        query);
end

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

通知先リストを取得

Parameters:

  • request (Array)
    • notificationName => 通知名

  • pageToken (String) (defaults to: NULL)

    ページトークン

  • limit (Integer) (defaults to: NULL)

    取得件数

Returns:

  • (Array)
    • items

      Array
      • subscribeId => 通知先ID

      • notificationId => 通知ID

      • type => 通知プロトコル

      • endpoint => 通知先

      • createAt => 作成日時

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



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

def describeSubscribe(request, pageToken = NULL, limit = NULL)
  if not request; raise ArgumentError.new(); end
  if not request.has_key?('notificationName'); raise ArgumentError.new(); end
  if not request['notificationName']; raise ArgumentError.new(); end
  query = {}
  if pageToken; query['pageToken'] = pageToken; end
  if limit; query['limit'] = limit; end
  return get(
      'Gs2Notification',
      'DescribeSubscribe',
      @@ENDPOINT,
      @@VARIATION,
      '/notification/' + request['notificationName'] + '/subscribe',
      query);
end

#getNotification(request) ⇒ Array

通知を取得

Parameters:

  • request (Array)
    • notificationName => 通知名

Returns:

  • (Array)
    • item

      • notificationId => 通知ID

      • ownerId => オーナーID

      • name => 通知名

      • description => 説明文

      • createAt => 作成日時

      • updateAt => 更新日時



114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/gs2/notification/Client.rb', line 114

def getNotification(request)
  if not request; raise ArgumentError.new(); end
  if not request.has_key?('notificationName'); raise ArgumentError.new(); end
  if not request['notificationName']; raise ArgumentError.new(); end
  query = {}
  return get(
      'Gs2Notification',
      'GetNotification',
      @@ENDPOINT,
      @@VARIATION,
      '/notification/' + request['notificationName'],
      query);
end

#getSubscribe(request) ⇒ Array

通知先を取得

Parameters:

  • request (Array)
    • notificationName => 通知名

    • subscribeId => 通知先ID

Returns:

  • (Array)
    • item

      • subscribeId => 通知先ID

      • notificationId => 通知ID

      • type => 通知プロトコル

      • endpoint => 通知先

      • createAt => 作成日時



271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
# File 'lib/gs2/notification/Client.rb', line 271

def getSubscribe(request)
  if not request; raise ArgumentError.new(); end
  if not request.has_key?('notificationName'); raise ArgumentError.new(); end
  if not request['notificationName']; raise ArgumentError.new(); end
  if not request.has_key?('subscribeId'); raise ArgumentError.new(); end
  if not request['subscribeId']; raise ArgumentError.new(); end
  query = {}
  return get(
      'Gs2Notification',
      'GetSubscribe',
      @@ENDPOINT,
      @@VARIATION,
      '/notification/' + request['notificationName'] + '/subscribe/' + request['subscribeId'],
      query);
end

#updateNotification(request) ⇒ Array

通知を更新

Parameters:

  • request (Array)
    • notificationName => 通知名

    • description => 説明文

Returns:

  • (Array)
    • item

      • notificationId => 通知ID

      • ownerId => オーナーID

      • name => 通知名

      • description => 説明文

      • createAt => 作成日時

      • updateAt => 更新日時



141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/gs2/notification/Client.rb', line 141

def updateNotification(request)
  if not request; raise ArgumentError.new(); end
  if not request.has_key?('notificationName'); raise ArgumentError.new(); end
  if not request['notificationName']; raise ArgumentError.new(); end
  body = {}
  if request.has_key?('description'); body['description'] = request['description']; end
  query = {}
  return put(
      'Gs2Notification',
      'UpdateNotification',
      @@ENDPOINT,
      @@VARIATION,
      '/notification/' + request['notificationName'],
      body,
      query);
end