Class: NasaApod::Client

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



20
21
22
23
24
# File 'lib/nasa_apod/client.rb', line 20

def initialize(options={})
  @api_key = options[:api_key] || "DEMO_KEY"
  self.date = options[:date]
  self.list_concepts = options[:list_concepts]
end

Instance Attribute Details

#api_keyObject (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

#dateObject

Returns the value of attribute date.



6
7
8
# File 'lib/nasa_apod/client.rb', line 6

def date
  @date
end

#list_conceptsObject

Returns the value of attribute list_concepts.



6
7
8
# File 'lib/nasa_apod/client.rb', line 6

def list_concepts
  @list_concepts
end

Instance Method Details

#search(options = {}) ⇒ NasaApod::SearchResults

Returns APOD info for specified day.

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :api_key (String)

    Optional. Uses DEMO_KEY as default.

  • :date (String)

    Optional. Returns the APOD results for the given date. Date should be formatted as YYYY-MM-DD. Defaults as today.

  • :concept_tags (Boolean)

    Optional. Returns an array of concept tags if available. Defaults to False.

Returns:

See Also:



36
37
38
39
40
41
# File 'lib/nasa_apod/client.rb', line 36

def search(options={})
  self.date = options[:date] || date
  @list_concepts = options[:list_concepts] || list_concepts
  response = HTTParty.get("https://api.nasa.gov/planetary/apod?api_key=#{api_key}&date=#{date}&concept_tags=#{list_concepts}")
  handle_response(response)
end