Skip to content

Commit

Permalink
Merge pull request nervosnetwork#16 from nervosnetwork/fix-http-post
Browse files Browse the repository at this point in the history
fix: http post request for ruby 2.3 and below
  • Loading branch information
xxuejie authored Dec 17, 2018
2 parents 560810c + a075070 commit eb4403e
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 eb4403e

Please sign in to comment.