【问题标题】:Ruby: Thor and Httparty红宝石:雷神和 Httparty
【发布时间】:2012-05-30 03:03:40
【问题描述】:

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

当我尝试运行时,我看到错误找不到 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

【问题讨论】:

    标签: ruby httparty thor


    【解决方案1】:

    在课外试试这个方法

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

    HTTParty.get(...) 在 FinXyz 类中

    【讨论】:

    • 非常感谢您的快速响应,但**一个用于类 **一个用于 xyz 方法,**一个用于该方法的结尾...。对不起缩进
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-09
    相关资源
    最近更新 更多