Sha256: 62f364c126c60a4691f03fc9a6fc9ed61db458054cd994c27e331422ca2de4e9
Contents?: true
Size: 1.18 KB
Versions: 14
Compression:
Stored size: 1.18 KB
Contents
require 'open-uri' require 'yajl' require 'cgi' module Cinch module Plugins class Rubygems include Cinch::Plugin match /r (.*)$/ set :plugin_name, 'rubygems' set :help, <<EOT Rubygems queries http://rubygems.org for finding gems EOT def query(query) url = "https://rubygems.org/api/v1/search.json?query=#{CGI.escape(query)}" back = "Requesting ... \n" begin file = open(url) if file.class == StringIO json = Yajl::Parser.parse(file) if json.empty? return "Nothing matches '#{query}'" end else json = Yajl::Parser.parse(File.read(file)) end all = json.count > 4 ? 4 : json.count all.times do |it| back += "#{json[it]['name']} : #{json[it]['homepage_uri']}\n" end rescue Exception => e p file.class back = "*** #{e.class}\n" back += e.backtrace.join("\n") back += e.to_s end return back end def new(bot) @bot = bot end def execute(m,words) m.reply(query(words.strip)) end end end end
Version data entries
14 entries across 14 versions & 1 rubygems