Class: Lazybird::Tasks::Quote

Inherits:
Object
  • Object
show all
Defined in:
lib/lazybird/tasks/quote.rb

Instance Method Summary collapse

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_quoteObject

TODO create a generic way to call diff apis (this should be on its own subclass)

Raises:

  • (Lazybird::QuoteMaxRetriesException)


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