Class: RubyJoke

Inherits:
Object
  • Object
show all
Defined in:
lib/rubyjokes.rb

Instance Method Summary collapse

Instance Method Details

#get_joke(parameters) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/rubyjokes.rb', line 12

def get_joke(parameters)
  if parameters.class == Hash
    response = query_with_params parameters
    if response.body["type"] == "success" 
      return response.body["value"]["joke"]
    else
      return response.body 
    end
  else
    return "Sorry, Chuck Norris only responds to Hashes. Hashes are as badass as Chuck Norris"  
  end         
end

#get_single_jokeObject



7
8
9
10
# File 'lib/rubyjokes.rb', line 7

def get_single_joke
  response = query
  return response.body["value"]["joke"]            
end

#queryObject



32
33
34
35
36
# File 'lib/rubyjokes.rb', line 32

def query
  response = Unirest.get JokeDefinitions.get_end_point,
                         headers: {accept: "json/application"}
  return response
end

#query_with_params(parameters) ⇒ Object



25
26
27
28
29
30
# File 'lib/rubyjokes.rb', line 25

def query_with_params(parameters)
  response = Unirest.get JokeDefinitions.get_end_point,
                         headers: {accept: "json/application"},
                         parameters: parameters
  return response
end