Class: Jimson::ClientHelper
- Inherits:
-
Object
- Object
- Jimson::ClientHelper
- Defined in:
- lib/syncano/jimson_client.rb
Overview
Overwritten helper from Jimson gem
Instance Method Summary collapse
-
#send_batch ⇒ Array
Overwritten send_batch method, so it now returns collection of responses.
-
#send_batch_request(batch) ⇒ Array
Overwritten send_batch_request method, so it now adds header with the user agent.
-
#send_single_request(method, args) ⇒ Array
Overwritten send_single_request method, so it now adds header with the user agent.
Instance Method Details
#send_batch ⇒ Array
Overwritten send_batch method, so it now returns collection of responses
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# 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) ⇒ Array
Overwritten send_batch_request method, so it now adds header with the user agent
27 28 29 30 31 32 33 34 35 |
# 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) ⇒ Array
Overwritten send_single_request method, so it now adds header with the user agent
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# 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 |