Class: Dadjoke::Joke
- Inherits:
-
Object
- Object
- Dadjoke::Joke
- Defined in:
- lib/dadjoke.rb
Overview
Fetch dad jokes from icanhazdadjoke.com
Class Method Summary collapse
-
.random ⇒ String
Fetch a random joke.
-
.search(term, limit = 3) ⇒ Array<String>
Search for jokes based on a term.
Class Method Details
.random ⇒ String
Fetch a random joke
21 22 23 |
# File 'lib/dadjoke.rb', line 21 def self.random HTTParty.get(@url, headers: @headers)["joke"] end |
.search(term, limit = 3) ⇒ Array<String>
Search for jokes based on a term
30 31 32 33 34 35 36 37 38 |
# File 'lib/dadjoke.rb', line 30 def self.search(term, limit = 3) query = { term:, limit: } response = HTTParty.get( "#{@url}/search", headers: @headers, query: ) response["results"].map { |result| result["joke"] } end |