Class: Commands::Search

Inherits:
Object
  • Object
show all
Defined in:
lib/commands/plugin/commands.rb

Instance Method Summary collapse

Constructor Details

#initialize(base_command) ⇒ Search

Returns a new instance of Search.



552
553
554
555
# File 'lib/commands/plugin/commands.rb', line 552

def initialize(base_command)
  @base_command = base_command
  @directory = "http://agilewebdevelopment.com/plugins/search?search=%s"
end

Instance Method Details

#optionsObject



557
558
559
560
561
562
563
564
565
# File 'lib/commands/plugin/commands.rb', line 557

def options
  OptionParser.new do |o|
    o.set_summary_indent('  ')
    o.banner =    "Usage: #{@base_command.script_name} search \"search string\""
    o.on(         "-d DIRECTORY", "--directory DIRECTORY",
                  "Queries the URL specified by DIRECTORY.") { |v| @directory = v }
    o.define_head "Search plugins."
  end
end

#parse!(args) ⇒ Object



567
568
569
570
571
572
573
574
575
576
577
578
579
# File 'lib/commands/plugin/commands.rb', line 567

def parse!(args)
  options.parse!(args)
  uri = URI.parse(@directory % URI.escape(args.first))
  request = Net::HTTP.new(uri.host, uri.port)
  root = REXML::Document.new(request.send_request('GET', uri.request_uri, nil, 'Accept' => 'application/xml').body).root 
  root.elements.each('plugin') do |p|
    puts p.elements['name'].text
    puts "  Info: #{p.elements['link'].text}"
    puts "  Install: #{p.elements['repository'].text}"
  end
rescue
  nil
end