Class: Libgss::ActionRequest
- Inherits:
-
Object
- Object
- Libgss::ActionRequest
- Defined in:
- lib/libgss/action_request.rb
Direct Known Subclasses
Defined Under Namespace
Classes: Error, SignatureError
Constant Summary collapse
- STATUS_PREPARING =
0
- STATUS_SENDING =
1
- STATUS_WAITING =
2
- STATUS_RECEIVED =
3
- STATUS_SUCCESS =
4
- STATUS_ERROR =
5
- STATUS_TIMEOUT =
6
Instance Attribute Summary collapse
-
#action_url ⇒ Object
readonly
Returns the value of attribute action_url.
-
#network ⇒ Object
readonly
読み込みのみ、書き込み不可.
-
#outputs ⇒ Object
readonly
Returns the value of attribute outputs.
-
#req_headers ⇒ Object
readonly
Returns the value of attribute req_headers.
-
#response_hook ⇒ Object
Returns the value of attribute response_hook.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
- #add_action(hash) ⇒ Object
-
#apply(name, target) ⇒ Object
フレンドシップを申請をします。.
-
#approve(name, target) ⇒ Object
フレンドシップの申請を承認します。.
-
#block(name, target) ⇒ Object
フレンドをブロック(ブラックリスト追加)します。.
-
#breakoff(name, target) ⇒ Object
フレンドシップの申請のキャンセル、申請却下、フレンド解除をします。.
-
#count(name, conditions = nil) ⇒ Integer
条件に該当するデータを取得.
-
#create(name, attrs) ⇒ Object
ログあるいは履歴を登録します。.
-
#dice(name, conditions = nil) ⇒ Object
確率テーブルに従って、発生させた乱数から得られた値.
-
#execute(name, key, args = nil) ⇒ Object
ストアドスクリプトを実行します。.
-
#find_all(name, conditions = nil, order = nil) ⇒ Array<Libgss::JsonObject>
(also: #all)
条件に該当するデータを取得.
-
#find_first(name, conditions = nil, order = nil) ⇒ Libgss::JsonObject
(also: #first)
条件に該当するデータを1件だけ取得.
-
#get_by_dictionary(name, input, conditions = nil) ⇒ Object
(also: #get_dictionary)
辞書テーブルからinputに対応するoutputの値を返します。.
-
#get_by_game_data(name = "GameData", player_id = nil) ⇒ Object
(also: #get_game_data)
ゲームデータからplayer_idに対応するゲームデータを返します.
-
#get_by_int_range(name, input, conditions = nil) ⇒ Object
(also: #get_int_range)
整数範囲テーブルからinputに対応するoutputの値を返します。.
-
#get_by_player(name = "Player", player_id = nil) ⇒ Object
(also: #get_player)
プレイヤーからplayer_idに対応するプレイヤーを返します.
-
#get_by_probability(name, value, conditions = nil) ⇒ Object
(also: #get_probability)
確率テーブルからinputに対応するoutputの値を返します。 diceがあるのであまり使われないはず。.
-
#get_by_schedule(name, time = Time.now.to_i, conditions = nil) ⇒ Object
(also: #get_schedule)
期間テーブルからinputに対応するoutputの値を返します。.
-
#initialize(network, action_url, req_headers) ⇒ ActionRequest
constructor
コンストラクタ.
- #inspect ⇒ Object
-
#master_diffs(downloaded_versions) ⇒ Object
マスタの差分を取得します.
- #next_action_id ⇒ Object
-
#paginate(name, page, per_page, conditions = nil, order = nil) ⇒ Array<Libgss::JsonObject>
ページネーション付きで条件に該当するデータを取得.
-
#send_request(&callback) ⇒ Object
アクション群を実行するために実際にHTTPリクエストを送信します。.
-
#server_date(time = nil) ⇒ Date
引数timeに指定された時刻の運用日付を返します。 「運用日付」とは AppGarden ので 設定された時刻を日付の開始時刻とした場合の日付(Ruby ストアドスクリプト内ではDateオブジェクト)を返します。.
-
#server_time ⇒ Time
サーバの現在時刻を返します。.
-
#unblock(name, target) ⇒ Object
フレンドをブロックの解除(ブラックリストから除外)します。.
-
#update(name, attrs, player_id = nil) ⇒ Object
プレイヤー、ゲームデータを更新します。.
-
#verify_signature(res, &block) ⇒ Object
シグネチャの検証を行います.
Constructor Details
#initialize(network, action_url, req_headers) ⇒ ActionRequest
コンストラクタ
34 35 36 37 38 39 40 41 |
# File 'lib/libgss/action_request.rb', line 34 def initialize(network, action_url, req_headers) @network = network @action_url = action_url @req_headers = req_headers @status = STATUS_PREPARING @actions = [] @action_id = 0; end |
Instance Attribute Details
#action_url ⇒ Object (readonly)
Returns the value of attribute action_url.
28 29 30 |
# File 'lib/libgss/action_request.rb', line 28 def action_url @action_url end |
#network ⇒ Object (readonly)
読み込みのみ、書き込み不可
27 28 29 |
# File 'lib/libgss/action_request.rb', line 27 def network @network end |
#outputs ⇒ Object (readonly)
Returns the value of attribute outputs.
29 30 31 |
# File 'lib/libgss/action_request.rb', line 29 def outputs @outputs end |
#req_headers ⇒ Object (readonly)
Returns the value of attribute req_headers.
28 29 30 |
# File 'lib/libgss/action_request.rb', line 28 def req_headers @req_headers end |
#response_hook ⇒ Object
Returns the value of attribute response_hook.
31 32 33 |
# File 'lib/libgss/action_request.rb', line 31 def response_hook @response_hook end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
29 30 31 |
# File 'lib/libgss/action_request.rb', line 29 def status @status end |
Instance Method Details
#add_action(hash) ⇒ Object
53 54 55 56 57 |
# File 'lib/libgss/action_request.rb', line 53 def add_action(hash) action = Action.new(next_action_id, hash) @actions << action action end |
#apply(name, target) ⇒ Object
フレンドシップを申請をします。
378 379 380 381 |
# File 'lib/libgss/action_request.rb', line 378 def apply(name, target) args = {action: "apply", name: name, target: target} add_action(args) end |
#approve(name, target) ⇒ Object
フレンドシップの申請を承認します。
387 388 389 390 |
# File 'lib/libgss/action_request.rb', line 387 def approve(name, target) args = {action: "approve", name: name, target: target} add_action(args) end |
#block(name, target) ⇒ Object
フレンドをブロック(ブラックリスト追加)します。
405 406 407 408 |
# File 'lib/libgss/action_request.rb', line 405 def block(name, target) args = {action: "block", name: name, target: target} add_action(args) end |
#breakoff(name, target) ⇒ Object
フレンドシップの申請のキャンセル、申請却下、フレンド解除をします。
396 397 398 399 |
# File 'lib/libgss/action_request.rb', line 396 def breakoff(name, target) args = {action: "breakoff", name: name, target: target} add_action(args) end |
#count(name, conditions = nil) ⇒ Integer
条件に該当するデータを取得
194 195 196 197 198 |
# File 'lib/libgss/action_request.rb', line 194 def count(name, conditions = nil) args = {action: "count", name: name} args[:conditions] = conditions if conditions add_action(args) end |
#create(name, attrs) ⇒ Object
ログあるいは履歴を登録します。
299 300 301 302 |
# File 'lib/libgss/action_request.rb', line 299 def create(name, attrs) args = {action: "create", name: name, attrs: attrs} add_action(args) end |
#dice(name, conditions = nil) ⇒ Object
確率テーブルに従って、発生させた乱数から得られた値
320 321 322 323 324 |
# File 'lib/libgss/action_request.rb', line 320 def dice(name, conditions = nil) args = {action: "dice", name: name} args[:conditions] = conditions if conditions add_action(args) end |
#execute(name, key, args = nil) ⇒ Object
ストアドスクリプトを実行します。
331 332 333 334 335 |
# File 'lib/libgss/action_request.rb', line 331 def execute(name, key, args = nil) action_args = {action: "execute", name: name, key: key} action_args[:args] = args if args add_action(action_args) end |
#find_all(name, conditions = nil, order = nil) ⇒ Array<Libgss::JsonObject> Also known as: all
条件に該当するデータを取得
168 169 170 171 172 173 |
# File 'lib/libgss/action_request.rb', line 168 def find_all(name, conditions = nil, order = nil) args = {action: "all", name: name} args[:conditions] = conditions if conditions args[:order] = order if order add_action(args) end |
#find_first(name, conditions = nil, order = nil) ⇒ Libgss::JsonObject Also known as: first
条件に該当するデータを1件だけ取得
205 206 207 208 209 210 |
# File 'lib/libgss/action_request.rb', line 205 def find_first(name, conditions = nil, order = nil) args = {action: "first", name: name} args[:conditions] = conditions if conditions args[:order] = order if order add_action(args) end |
#get_by_dictionary(name, input, conditions = nil) ⇒ Object Also known as: get_dictionary
辞書テーブルからinputに対応するoutputの値を返します。
218 219 220 221 222 |
# File 'lib/libgss/action_request.rb', line 218 def get_by_dictionary(name, input, conditions = nil) args = {action: "get", name: name, input: input} args[:conditions] = conditions if conditions add_action(args) end |
#get_by_game_data(name = "GameData", player_id = nil) ⇒ Object Also known as: get_game_data
ゲームデータからplayer_idに対応するゲームデータを返します
283 284 285 286 287 288 |
# File 'lib/libgss/action_request.rb', line 283 def get_by_game_data(name = "GameData", player_id = nil) args = {action: "get"} args[:name] = name if name args[:player_id] = player_id.to_s if player_id add_action(args) end |
#get_by_int_range(name, input, conditions = nil) ⇒ Object Also known as: get_int_range
整数範囲テーブルからinputに対応するoutputの値を返します。
242 243 244 245 246 |
# File 'lib/libgss/action_request.rb', line 242 def get_by_int_range(name, input, conditions = nil) args = {action: "get", name: name, input: input} args[:conditions] = conditions if conditions add_action(args) end |
#get_by_player(name = "Player", player_id = nil) ⇒ Object Also known as: get_player
プレイヤーからplayer_idに対応するプレイヤーを返します
269 270 271 272 273 274 |
# File 'lib/libgss/action_request.rb', line 269 def get_by_player(name = "Player", player_id = nil) args = {action: "get"} args[:name] = name if name args[:player_id] = player_id.to_s if player_id add_action(args) end |
#get_by_probability(name, value, conditions = nil) ⇒ Object Also known as: get_probability
確率テーブルからinputに対応するoutputの値を返します。diceがあるのであまり使われないはず。
256 257 258 259 260 |
# File 'lib/libgss/action_request.rb', line 256 def get_by_probability(name, value, conditions = nil) args = {action: "get", name: name, value: value} args[:conditions] = conditions if conditions add_action(args) end |
#get_by_schedule(name, time = Time.now.to_i, conditions = nil) ⇒ Object Also known as: get_schedule
期間テーブルからinputに対応するoutputの値を返します。
230 231 232 233 234 |
# File 'lib/libgss/action_request.rb', line 230 def get_by_schedule(name, time = Time.now.to_i, conditions = nil) args = {action: "get", name: name, time: time} args[:conditions] = conditions if conditions add_action(args) end |
#inspect ⇒ Object
43 44 45 46 47 |
# File 'lib/libgss/action_request.rb', line 43 def inspect r = "#<#{self.class.name}:#{self.object_id} " fields = (instance_variables - [:@network]).map{|f| "#{f}=#{instance_variable_get(f).inspect}"} r << fields.join(", ") << ">" end |
#master_diffs(downloaded_versions) ⇒ Object
マスタの差分を取得します
423 424 425 426 |
# File 'lib/libgss/action_request.rb', line 423 def master_diffs(downloaded_versions) args = {action: "master_diffs", downloaded_versions: downloaded_versions} add_action(args) end |
#next_action_id ⇒ Object
49 50 51 |
# File 'lib/libgss/action_request.rb', line 49 def next_action_id @action_id += 1 end |
#paginate(name, page, per_page, conditions = nil, order = nil) ⇒ Array<Libgss::JsonObject>
ページネーション付きで条件に該当するデータを取得
183 184 185 186 187 188 |
# File 'lib/libgss/action_request.rb', line 183 def paginate(name, page, per_page, conditions = nil, order = nil) args = {action: "all", name: name, page: page, per_page: per_page} args[:conditions] = conditions if conditions args[:order] = order if order add_action(args) end |
#send_request(&callback) ⇒ Object
アクション群を実行するために実際にHTTPリクエストを送信します。
60 61 62 63 64 65 66 67 68 69 |
# File 'lib/libgss/action_request.rb', line 60 def send_request(&callback) res = Libgss.with_retry("action_request") do network.httpclient_for_action.post(action_url, {"inputs" => @actions.map(&:to_hash)}.to_json, req_headers) end response_hook.call(res) if response_hook # テストでレスポンスを改ざんを再現するために使います r = process_response(res, :action_request) @outputs = Outputs.new(r["outputs"]) callback.call(@outputs) if callback @outputs end |
#server_date(time = nil) ⇒ Date
引数timeに指定された時刻の運用日付を返します。「運用日付」とは AppGarden ので設定された時刻を日付の開始時刻とした場合の日付(Ruby ストアドスクリプト内ではDateオブジェクト)を返します。
352 353 354 355 356 |
# File 'lib/libgss/action_request.rb', line 352 def server_date(time = nil) args = {action: "server_date"} args[:time] = time if time add_action(args) end |
#server_time ⇒ Time
サーバの現在時刻を返します。
341 342 343 |
# File 'lib/libgss/action_request.rb', line 341 def server_time() add_action(action: "server_time") end |
#unblock(name, target) ⇒ Object
フレンドをブロックの解除(ブラックリストから除外)します。
414 415 416 417 |
# File 'lib/libgss/action_request.rb', line 414 def unblock(name, target) args = {action: "unblock", name: name, target: target} add_action(args) end |
#update(name, attrs, player_id = nil) ⇒ Object
プレイヤー、ゲームデータを更新します。
309 310 311 312 313 |
# File 'lib/libgss/action_request.rb', line 309 def update(name, attrs, player_id = nil) args = {action: "update", name: name, attrs: attrs} args[:player_id] = player_id.to_s if player_id add_action(args) end |
#verify_signature(res, &block) ⇒ Object
シグネチャの検証を行います
90 91 92 93 94 95 96 97 |
# File 'lib/libgss/action_request.rb', line 90 def verify_signature(res, &block) case network.api_version when "1.0.0" then verify_signature_on_headers(res, &block) when "1.1.0" then verify_signature_included_body(res, &block) else raise Error, "Unsupported API version: #{network.api_version}" end end |