Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby:Thor和Httparty_Ruby_Httparty_Thor - Fatal编程技术网

Ruby:Thor和Httparty

Ruby:Thor和Httparty,ruby,httparty,thor,Ruby,Httparty,Thor,我试图在我的类FindXYZ扩展Thor中使用HttpParty,但它不起作用。我只想使用HTTPartyget在我的方法中查询couchdbxyz 当我尝试运行时,我看到错误无法找到get require 'json' require 'httparty' require 'thor' class FindXyz < Thor include Thor::Actions include HTTParty headers 'Accept' => 'applicat

我试图在我的类FindXYZ扩展Thor中使用HttpParty,但它不起作用。我只想使用HTTPartyget在我的方法中查询couchdbxyz

当我尝试运行时,我看到错误无法找到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
require'json'
需要“httparty”
需要“雷神”
类FindXyz“应用程序/json”
服务器='192.168.5.50:5984'
用户='uname'
密码='passo'
couchdb_url=“http://{user}:{password}@{server}”
基本身份验证用户、密码
基本uri地址
默认参数:输出=>'json'
格式:json
描述“xyz”,“查找包含SSL的方案”
方法_选项:name,:alias=>“-t”,:required=>true
方法_选项:位置,:别名=>“-s”,:必需=>true
def xyz
名称=选项[:名称]
loc=选项[:位置]
file_path=file.join(loc,name)
t_json=json.parse(File.read(File_路径))
t_json[“ID”]。每个都有|
path_to_doc=“/test123/#{temp}”
响应=获取(路径到文档)
如果response.to_.include?('Birdy'),则将“Found=>{temp}”放入
结束#结束循环
结束#关闭方法xyz
结束#结束课堂

在课外尝试这种方法

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

并且
HTTParty.get(…)
在FinXyz类内部从类外部尝试这种方法

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

HTTParty.get(…)
FinXyz类内部

非常感谢您的快速响应,但**一端是类**一端是方法xyz,**一端是该方法的一端。。。。抱歉,索引不好非常感谢您的快速响应,但**一端是类**一端是方法xyz**一端是该方法的端。。。。对不起,误会了