发送带有httparty的GET请求,URL中的查询不作为参数

时间:2018-11-02 06:48:12

标签: ruby httparty

我正尝试通过httpart发送GET请求,如下所示:

GET /transactions/info/{id}

以下是我的实现:

require 'httparty'

class TransactionsRPC
  include HTTParty
  base_uri ENV['API_URL']

  def initialize(txid)
    @options = {id: txid}
  end

 def transaction
        new_url = "/transactions/info/" + @options[:id]
     self.class.get(""+new_url)
  end
end

txinfo =  TransactionsRPC.new("44XVpeGohyAt4uAJW2WLkjYcKgYyNWQGrATgD3H35dsu")
pp txinfo.transaction

但是,当我运行它时,出现以下错误:

Traceback (most recent call last):
    11: from test.rb:19:in `<main>'
    10: from test.rb:14:in `transaction'
     9: from /home/deploy/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/httparty-0.16.2/lib/httparty.rb:489:in `get'
     8: from /home/deploy/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/httparty-0.16.2/lib/httparty.rb:563:in `perform_request'
     7: from /home/deploy/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/httparty-0.16.2/lib/httparty/request.rb:143:in `perform'
     6: from /home/deploy/.rbenv/versions/2.5.1/lib/ruby/2.5.0/net/http.rb:1455:in `request'
     5: from /home/deploy/.rbenv/versions/2.5.1/lib/ruby/2.5.0/net/http.rb:910:in `start'
     4: from /home/deploy/.rbenv/versions/2.5.1/lib/ruby/2.5.0/net/http.rb:1457:in `block in request'
     3: from /home/deploy/.rbenv/versions/2.5.1/lib/ruby/2.5.0/net/http.rb:1464:in `request'
     2: from /home/deploy/.rbenv/versions/2.5.1/lib/ruby/2.5.0/net/http.rb:1490:in `transport_request'
     1: from /home/deploy/.rbenv/versions/2.5.1/lib/ruby/2.5.0/net/http.rb:1551:in `begin_transport'
/home/deploy/.rbenv/versions/2.5.1/lib/ruby/2.5.0/net/http.rb:1616:in `addr_port': undefined method `include?' for nil:NilClass (NoMethodError)

知道我在做什么错或如何修正我的代码吗?

0 个答案:

没有答案