class Jimson::ClientHelper
Overwritten helper from Jimson
gem
Public Instance Methods
send_batch()
click to toggle source
Overwritten send_batch
method, so it now returns collection of responses @return [Array] collection of responses
# File lib/syncano/jimson_client.rb, line 39 def send_batch batch = @batch.map(&:first) # get the requests response = send_batch_request(batch) begin responses = JSON.parse(response) rescue raise Jimson::ClientError::InvalidJSON.new(json) end process_batch_response(responses) responses = @batch @batch = [] responses end
send_batch_request(batch)
click to toggle source
Overwritten send_batch_request
method, so it now adds header with the user agent @return [Array] collection of responses
# File lib/syncano/jimson_client.rb, line 27 def send_batch_request(batch) post_data = batch.to_json resp = RestClient.post(@url, post_data, content_type: 'application/json', user_agent: "syncano-ruby-#{Syncano::VERSION}") if resp.nil? || resp.body.nil? || resp.body.empty? raise Jimson::ClientError::InvalidResponse.new end return resp.body end
send_single_request(method, args)
click to toggle source
Overwritten send_single_request
method, so it now adds header with the user agent @return [Array] collection of responses
# File lib/syncano/jimson_client.rb, line 7 def send_single_request(method, args) post_data = { 'jsonrpc' => JSON_RPC_VERSION, 'method' => method, 'params' => args, 'id' => self.class.make_id }.to_json resp = RestClient.post(@url, post_data, content_type: 'application/json', user_agent: "syncano-ruby-#{Syncano::VERSION}") if resp.nil? || resp.body.nil? || resp.body.empty? raise Jimson::ClientError::InvalidResponse.new end return resp.body rescue Exception, StandardError raise Jimson::ClientError::InternalError.new($!) end