2012-05-30 27 views
1

我正在嘗試在我的課程中使用HTTParty FindXYZ擴展了Thor,但它不起作用。我所希望做的是使用HTTParty 得到查詢CouchDB的在我的方法XYZRuby:Thor和Httparty

當我嘗試運行我看到錯誤找不到得到

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 

回答

1

這樣試試吧來自課外

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

and HTTParty.get(...)裏面的FinXyz類

+0

非常感謝您的快速反應,但**一端是類**一個是方法xyz和**一個是在該方法的結尾 ....對不良的indendation –