Class: Lazybird::Tasks::Quote
- Inherits:
-
Object
- Object
- Lazybird::Tasks::Quote
- Defined in:
- lib/lazybird/tasks/quote.rb
Instance Method Summary collapse
-
#initialize(url:, retry_attempts: 3) ⇒ Quote
constructor
A new instance of Quote.
- #quote_check(quote) ⇒ Object
-
#random_storm_quote ⇒ Object
TODO create a generic way to call diff apis (this should be on its own subclass).
Constructor Details
#initialize(url:, retry_attempts: 3) ⇒ Quote
Returns a new instance of Quote.
7 8 9 10 11 |
# File 'lib/lazybird/tasks/quote.rb', line 7 def initialize(url:, retry_attempts: 3) @url = url @retry_attempts = retry_attempts @retry_count = 0 end |
Instance Method Details
#quote_check(quote) ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/lazybird/tasks/quote.rb', line 20 def quote_check(quote) if quote.length > 140 @retry_count += 1 yield else @retry_count = 0 quote end end |
#random_storm_quote ⇒ Object
TODO create a generic way to call diff apis (this should be on its own subclass)
14 15 16 17 18 |
# File 'lib/lazybird/tasks/quote.rb', line 14 def random_storm_quote raise Lazybird::QuoteMaxRetriesException if @retry_count > @retry_attempts quote = fetch_json(@url)['quote'] quote_check(quote) { random_storm_quote } end |