lib/urban_dictionary.rb in urban_dictionary-0.0.2 vs lib/urban_dictionary.rb in urban_dictionary-1.0.0

- old
+ new

@@ -1,11 +1,13 @@ require 'uri' require 'net/http' -require 'urban_dictionary/version' -require 'urban_dictionary/word' -require 'urban_dictionary/entry' +require_relative 'urban_dictionary/version' +require_relative 'urban_dictionary/cli' +require_relative 'urban_dictionary/entry' +require_relative 'urban_dictionary/formatters' +require_relative 'urban_dictionary/word' module UrbanDictionary DEFINE_URL = 'http://www.urbandictionary.com/define.php' RANDOM_URL = 'http://www.urbandictionary.com/random.php' @@ -14,12 +16,15 @@ end def self.random_word url = URI.parse(RANDOM_URL) req = Net::HTTP::Get.new(url.path) - rsp = Net::HTTP.start(url.host, url.port) {|http| + rsp = Net::HTTP.start(url.host, url.port) do |http| http.request(req) - } + end - define(rsp['location']) + Word.from_url(rsp['location']) end -end \ No newline at end of file +end + +UrbanDictionary::Formatter.register(:json, UrbanDictionary::JsonFormatter) +UrbanDictionary::Formatter.register(:plain, UrbanDictionary::PlainFormatter)