require 'nasa/client/version' require 'blanket' require 'hashie' module NASA class Client attr_accessor :base_uri, :application_id def initialize(_base_uri, application_id) @base_uri = 'https://api.nasa.gov/' @application_id = application_id end def apod(date = Time.now.strftime('%Y-%m-%d'), concept_tags = true, hd = false) request .planetary('apod') .get(:params => { :api_key => @application_id.dup, :concept_tags => concept_tags.to_s, :date => date, :hd => hd }) .to_h end # end_date is 1 week in seconds def neo_feed(start_date = Time.now.strftime('%Y-%m-%d'), end_date = (Time.now + 604800).strftime('%Y-%m-%d')) request .neo .rest .v1('feed') .get(:params => { :api_key => @application_id.dup, :start_date => start_date, :end_date => end_date }) .to_h end def neo_lookup(asteroid_id) request .neo .rest .v1 .neo(asteroid_id.to_s) .get(:params => { :api_key => @application_id.dup }) .to_h end private def request headers = { 'Content-Type' => 'application/json' } Blanket.wrap(@base_uri.dup, :headers => headers) end end end