Class: Chuck::Request
Instance Attribute Summary collapse
-
#first_name ⇒ Object
readonly
Returns the value of attribute first_name.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#jokes ⇒ Object
readonly
Returns the value of attribute jokes.
-
#last_name ⇒ Object
readonly
Returns the value of attribute last_name.
-
#raw_response ⇒ Object
readonly
Returns the value of attribute raw_response.
Class Method Summary collapse
-
.categories ⇒ Object
Class methods =============================================================.
- .retrieve(options = {}) ⇒ Object
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Request
constructor
Instance methods ==========================================================.
- #success ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Request
Instance methods ==========================================================
18 19 20 |
# File 'lib/chuck.rb', line 18 def initialize( = {}) .each{|k, v| self.instance_variable_set(:"@#{k}", v) if self.respond_to?(k)} end |
Instance Attribute Details
#first_name ⇒ Object (readonly)
Returns the value of attribute first_name.
14 15 16 |
# File 'lib/chuck.rb', line 14 def first_name @first_name end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
14 15 16 |
# File 'lib/chuck.rb', line 14 def id @id end |
#jokes ⇒ Object (readonly)
Returns the value of attribute jokes.
14 15 16 |
# File 'lib/chuck.rb', line 14 def jokes @jokes end |
#last_name ⇒ Object (readonly)
Returns the value of attribute last_name.
14 15 16 |
# File 'lib/chuck.rb', line 14 def last_name @last_name end |
#raw_response ⇒ Object (readonly)
Returns the value of attribute raw_response.
14 15 16 |
# File 'lib/chuck.rb', line 14 def raw_response @raw_response end |
Class Method Details
.categories ⇒ Object
Class methods =============================================================
28 29 30 |
# File 'lib/chuck.rb', line 28 def self.categories get("/categories").parsed_response end |
.retrieve(options = {}) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/chuck.rb', line 32 def self.retrieve( = {}) url = "/jokes/random/#{[:quantity] or 1}" query = Hash.new query[:firstName] = [:first_name] if [:first_name] query[:lastName] = [:last_name] if [:last_name] query[:limitTo] = "[#{[:only].join(',')}]" if [:only] query[:exclude] = "[#{[:exclude].join(',')}]" if [:except] result = JSON.parse(get(url, query).parsed_response) Chuck::Request.new jokes: Chuck::Joke.jokes_from_result(result['value']), first_name: query[:firstName], last_name: query[:lastName], raw_response: result end |
Instance Method Details
#success ⇒ Object
22 23 24 |
# File 'lib/chuck.rb', line 22 def success @raw_response['type'] == 'success' end |