class UrbanDict::UrbanResponse
Attributes
uri[RW]
Public Class Methods
new(url)
click to toggle source
# File lib/urban_dict.rb, line 11 def initialize(url) @uri = URI.parse(url) end
Public Instance Methods
get_response()
click to toggle source
# File lib/urban_dict.rb, line 15 def get_response response = Net::HTTP.get_response(@uri) unless response.code == "200" return { error: "There was a problem using the urban dictionary endpoint. Response code = #{ response.code }" } end body = JSON.parse(response.body) definitions = body["list"] unless definitions.count > 0 return { error: "No definition found for '#{ word }'." } end entry = definitions.first #puts entry["definition"] #puts "Example: #{ entry["example"]}" end