Class: Libgss::AsyncActionRequest

Inherits:
ActionRequest show all
Defined in:
lib/libgss/async_action_request.rb

Constant Summary

Constants inherited from ActionRequest

Libgss::ActionRequest::STATUS_ERROR, Libgss::ActionRequest::STATUS_PREPARING, Libgss::ActionRequest::STATUS_RECEIVED, Libgss::ActionRequest::STATUS_SENDING, Libgss::ActionRequest::STATUS_SUCCESS, Libgss::ActionRequest::STATUS_TIMEOUT, Libgss::ActionRequest::STATUS_WAITING

Instance Attribute Summary collapse

Attributes inherited from ActionRequest

#action_url, #network, #outputs, #req_headers, #response_hook, #status

Instance Method Summary collapse

Methods inherited from ActionRequest

#add_action, #apply, #approve, #block, #breakoff, #count, #create, #dice, #execute, #find_all, #find_first, #get_by_dictionary, #get_by_game_data, #get_by_int_range, #get_by_player, #get_by_probability, #get_by_schedule, #inspect, #master_diffs, #next_action_id, #paginate, #server_date, #server_time, #unblock, #update, #verify_signature

Constructor Details

#initialize(httpclient, action_url, result_url, req_headers) ⇒ AsyncActionRequest

コンストラクタ



17
18
19
20
# File 'lib/libgss/async_action_request.rb', line 17

def initialize(httpclient, action_url, result_url, req_headers)
  super(httpclient, action_url, req_headers)
  @result_url = result_url
end

Instance Attribute Details

#action_idObject

Returns the value of attribute action_id.



12
13
14
# File 'lib/libgss/async_action_request.rb', line 12

def action_id
  @action_id
end

#idsObject (readonly)

Returns the value of attribute ids.



11
12
13
# File 'lib/libgss/async_action_request.rb', line 11

def ids
  @ids
end

#result_urlObject

Returns the value of attribute result_url.



13
14
15
# File 'lib/libgss/async_action_request.rb', line 13

def result_url
  @result_url
end

Instance Method Details

#async_status(ids = nil) ⇒ Object Also known as: async_results

Raises:



32
33
34
35
36
37
38
39
40
41
# File 'lib/libgss/async_action_request.rb', line 32

def async_status(ids=nil)
  ids ||= @ids
  ids = [ids] unless ids.is_a?(::Array)
  raise Error, "failed to get response. please exec send_request before call." unless ids

  res = network.httpclient_for_action.post(result_url, {'input_ids' => ids}.to_json, req_headers)
  response_hook.call(res) if response_hook # テストでレスポンスを改ざんを再現するために使います
  r = process_response(res, :aync_results_request)
  @outputs = Outputs.new(r["outputs"]) # Outputsを使うことでidによるアクセスを可能に
end

#send_requestObject

アクション群を実行するために実際にHTTPリクエストを送信します。



23
24
25
26
27
28
29
30
# File 'lib/libgss/async_action_request.rb', line 23

def send_request
  res = network.httpclient_for_action.post(action_url, {"inputs" => @actions.map(&:to_hash)}.to_json, req_headers)
  response_hook.call(res) if response_hook # テストでレスポンスを改ざんを再現するために使います
  r = process_response(res, :async_action_request)
  @outputs = Outputs.new(r["outputs"])
  @ids = @outputs.map{|output| output['id'] }
  @outputs
end