class Urban::Web
Constants
- Response
Public Instance Methods
random()
click to toggle source
# File lib/urban/web.rb, line 12 def random build_response fetch :random end
search(phrase)
click to toggle source
# File lib/urban/web.rb, line 8 def search(phrase) build_response fetch :define, :term => phrase end
Private Instance Methods
build_query(parameters)
click to toggle source
# File lib/urban/web.rb, line 31 def build_query(parameters) "?" + parameters.map { |k,v| "#{k}=#{v}" }.join("&") end
build_response(response)
click to toggle source
# File lib/urban/web.rb, line 22 def build_response(response) Response.new response.base_uri.to_s, response end
build_uri(page, params = nil)
click to toggle source
# File lib/urban/web.rb, line 26 def build_uri(page, params = nil) query = build_query(params) unless params.nil? escape_uri "#{url}/#{page}.php#{query}" end
escape_uri(uri)
click to toggle source
# File lib/urban/web.rb, line 35 def escape_uri(uri) if RUBY_VERSION > '1.9' URI::Parser.new.escape uri else URI.escape uri end end
fetch(*args)
click to toggle source
# File lib/urban/web.rb, line 18 def fetch(*args) open build_uri(*args) end
url()
click to toggle source
# File lib/urban/web.rb, line 43 def url "http://www.urbandictionary.com" end