Class: Liblab::Quote::GuessTheQuote
- Inherits:
-
Object
- Object
- Liblab::Quote::GuessTheQuote
- Defined in:
- lib/liblab/quote/guess_the_quote.rb
Class Method Summary collapse
-
.call ⇒ Object
Example returns bodyguard?”, :movie_name=>“The Two Towers”.
Class Method Details
.call ⇒ Object
Example returns bodyguard?”, :movie_name=>“The Two Towers”
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/liblab/quote/guess_the_quote.rb', line 7 def self.call() page = rand(1..2) _path = "quote?page=#{page}" # Get a random page of quotes quote_result = ::Liblab::Client::Base.new.get(_path) if quote_result.code == 200 # Get a random quote from returned quotes index = rand(1..999) quote = JSON.parse(quote_result.body)["docs"][index] movie_result = ::Liblab::Movie::Get.call(quote["movie"]) if movie_result.code == 200 # Get movie name for the selected quote movie = JSON.parse(movie_result.body)["docs"][0] return { quote: quote["dialog"], movie_name: movie["name"] } else return movie_result end else return quote_result end end |