class QuoteFetcher
Constants
- CATEGORIES_URL
- QOD_URL
- QOD_URL_WITH_CATEGORY
Public Instance Methods
categories()
click to toggle source
# File lib/theysaidsocli.rb, line 16 def categories categories_response = HTTParty.get(CATEGORIES_URL) response = Response.new(categories_response) raise RateLimitError if response.rate_limited? raise NotFoundError unless response.success? categories = [] response.content[:categories].each do |key, value| categories << Category.new(key, value) end categories end
qod(category = nil)
click to toggle source
# File lib/theysaidsocli.rb, line 30 def qod(category = nil) sanitized_category = sanitize_input(category) qod_response = HTTParty.get(sanitized_category ? "#{QOD_URL_WITH_CATEGORY}#{sanitized_category}" : QOD_URL) response = Response.new(qod_response) raise RateLimitError if response.rate_limited? raise NotFoundError unless response.success? Quote.new(response.content[:quotes][0]) end
Private Instance Methods
sanitize_input(category)
click to toggle source
# File lib/theysaidsocli.rb, line 43 def sanitize_input(category) return nil if category.nil? category.gsub(/[^0-9A-Za-z]/,'') end