Class: NasaApod::Client
- Inherits:
-
Object
- Object
- NasaApod::Client
- Defined in:
- lib/nasa_apod/client.rb
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#concept_tags ⇒ Object
Returns the value of attribute concept_tags.
-
#date ⇒ Object
Returns the value of attribute date.
-
#hd ⇒ Object
Returns the value of attribute hd.
Instance Method Summary collapse
- #attributes ⇒ Object
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #random_post(options = {}) ⇒ Object (also: #wormhole)
-
#search(options = {}) ⇒ NasaApod::SearchResults
Returns APOD info for specified day.
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
28 29 30 31 32 33 |
# File 'lib/nasa_apod/client.rb', line 28 def initialize(={}) @api_key = [:api_key] || "DEMO_KEY" self.date = [:date] self. = [:concept_tags] self.hd = [:hd] end |
Instance Attribute Details
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
6 7 8 |
# File 'lib/nasa_apod/client.rb', line 6 def api_key @api_key end |
#concept_tags ⇒ Object
Returns the value of attribute concept_tags.
6 7 8 |
# File 'lib/nasa_apod/client.rb', line 6 def end |
#date ⇒ Object
Returns the value of attribute date.
6 7 8 |
# File 'lib/nasa_apod/client.rb', line 6 def date @date end |
#hd ⇒ Object
Returns the value of attribute hd.
6 7 8 |
# File 'lib/nasa_apod/client.rb', line 6 def hd @hd end |
Instance Method Details
#attributes ⇒ Object
60 61 62 63 64 |
# File 'lib/nasa_apod/client.rb', line 60 def attributes instance_variables.each_with_object(Hash.new) do |var,hash| hash[var.to_s.delete("@")] = instance_variable_get(var) end end |
#random_post(options = {}) ⇒ Object Also known as: wormhole
53 54 55 56 |
# File 'lib/nasa_apod/client.rb', line 53 def random_post(={}) date = rand(Date.parse("1995-06-16")..Date.today) search(date: date) end |
#search(options = {}) ⇒ NasaApod::SearchResults
Returns APOD info for specified day.
45 46 47 48 49 50 51 |
# File 'lib/nasa_apod/client.rb', line 45 def search(={}) self.date = [:date] || date = [:concept_tags] || @hd = [:hd] || hd response = HTTParty.get(DEFAULT_URL, { query: attributes }) handle_response(response) end |