class NasaApi::NasaInit
Attributes
api_key[RW]
date[RW]
high_definition[RW]
options[RW]
Public Class Methods
new(options = {})
click to toggle source
# File lib/nasa_api.rb, line 20 def initialize(options = {}) @api_key = options[:api_key] || 'DEMO_KEY' # When testing with RSpec, uncomment the below line with your actual API key as default # Specs will use the default API key, e.g. the string to the right of || # by default this is 'DEMO_KEY', and will cause specs to fail as DEMO_KEY is rate-limited quickly # # @api_key = options[:api_key] || 'ACTUAL_API_KEY' options[:api_key] = @api_key @options = options end
Public Instance Methods
params_dates(params = {})
click to toggle source
# File lib/nasa_api.rb, line 46 def params_dates(params = {}) # If date provided, parse it # If start/end date provided, parse them # If {:random = true} in params, use a random date # otherwise use no date, most Nasa API's will then default to Today's date if params[:date] params[:date] = parse_date(params[:date]) return params end if params[:start_date] params[:start_date] = parse_date(params[:start_date]) if params[:end_date] params[:end_date] = parse_date(params[:end_date]) end return params end if params[:random] params[:date] = rand(Date.parse('2000-01-01')..Date.today) params.delete(:random) end params end
parse_date(date)
click to toggle source
# File lib/nasa_api.rb, line 33 def parse_date(date) # Allow Ruby Date/Time objects to be used # by changing them to the Nasa API's expected YYYY-MM-DD format case date when Time date.strftime("%Y-%m-%d") when Date date.to_s when String date end end