Class: QuoteFetcher
- Inherits:
-
Object
- Object
- QuoteFetcher
- Defined in:
- lib/theysaidsocli.rb
Constant Summary collapse
- QOD_URL =
"http://quotes.rest/qod.json"
- QOD_URL_WITH_CATEGORY =
"http://quotes.rest/qod.json?category="
- CATEGORIES_URL =
"http://quotes.rest/qod/categories.json"
Instance Method Summary collapse
Instance Method Details
#categories ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# 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) ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# 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 |