1

我试图在我的类FindXYZ中使用 HTTParty 来扩展 Thor,但它不起作用。我想做的就是在我的方法xyz中使用 HTTParty get来查询 couchdb

当我尝试运行时,我看到错误找不到get

require 'json'
require 'httparty'
require 'thor'

class FindXyz < Thor
  include Thor::Actions

  include HTTParty
    headers 'Accept' => 'application/json'
    server = '192.168.5.50:5984'
    user = 'uname'
    password = 'passo'

    couchdb_url = "http://#{user}:#{password}@#{server}"
    basic_auth user, password
    base_uri couchdb_url
    default_params :output => 'json'
    format :json

    desc "xyz", "Find scenarios that contains SSL"
    method_option :name, :aliases => "-t", :required => true
    method_option :location, :aliases => "-s",:required => true

    def xyz
      name = options[:name]
      loc = options[:location]
      file_path = File.join(loc, name)

      t_json = JSON.parse(File.read(file_path))

     t_json["ids"].each do |temp|
       path_to_doc = "/test123/#{temp}"
       response = get(path_to_doc)
       puts "Found => #{temp}" if response.to_s.include?('Birdy')
    end #close the loop
  end #close the method xyz
end #close class
4

1 回答 1

1

从课外尝试这种方式

puts FindXyz.get('....').inspect

HTTParty.get(...)在 FinXyz 类里面

于 2012-05-30T03:22:15.243 回答