Sha256: aed637ff624d8bd44ed343fdec3262f973bcbfb7080662d57ca49404382a4926
Contents?: true
Size: 1.39 KB
Versions: 3
Compression:
Stored size: 1.39 KB
Contents
# -*- coding: utf-8 -*- require 'libgss' require 'net/http' require 'uri' module Libgss class AsyncActionRequest < ActionRequest attr_reader :ids attr_accessor :action_id attr_accessor :result_url # コンストラクタ def initialize(httpclient, action_url, result_url, req_headers) super(httpclient, action_url, req_headers) @result_url = result_url end # アクション群を実行するために実際にHTTPリクエストを送信します。 def send_request(&callback) res = @httpclient.post(action_url, {"inputs" => @actions.map(&:to_hash)}.to_json, req_headers) case res.code.to_i when 200..299 then # OK else raise Error, "failed to send action request: [#{res.code}] #{res.body}" end r = JSON.parse(res.body) # puts res.body @outputs = Outputs.new(r["outputs"]) callback.call(@outputs) if callback @ids = @outputs.map do |output| output['id'] end @outputs end def async_status() raise Error, "failed to get response. please exec send_request before call." unless @ids res = @httpclient.get(result_url, {input_ids: @ids.join(',')}, req_headers) case res.code.to_i when 200..299 then # OK else raise Error, "failed to send action request: [#{res.code}] #{res.body}" end r = JSON.parse(res.body) end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
libgss-0.7.3 | lib/libgss/async_action_request.rb |
libgss-0.7.2 | lib/libgss/async_action_request.rb |
libgss-0.7.1 | lib/libgss/async_action_request.rb |