Skip to content

Commit

Permalink
fix: http post request for ruby 2.3 and below
Browse files Browse the repository at this point in the history
  • Loading branch information
ashchan committed Dec 17, 2018
1 parent 560810c commit a075070
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lib/ckb/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ def initialize(host: URL)
end

def rpc_request(method, params: nil)
response = Net::HTTP.post(
uri,
"{\"id\": 1, \"jsonrpc\": \"2.0\", \"method\": \"#{method}\", \"params\": #{params.to_json}}",
"Content-Type" => "application/json")
http = Net::HTTP.new(uri.host, uri.port)
request = Net::HTTP::Post.new(uri.request_uri)
request.body = { id: 1, jsonrpc: "2.0", method: "#{method}", params: params }.to_json
request["Content-Type"] = "application/json"
response = http.request(request)
result = JSON.parse(response.body, symbolize_names: true)
if result[:error]
raise "jsonrpc error: #{result[:error]}"
Expand Down

0 comments on commit a075070

Please sign in to comment.