Sha256: 66a29117ca9eea1b267e476e2bcdaf823f93eb7b4e1dd7e18362df29657160b4

Contents?: true

Size: 1.41 KB

Versions: 1

Compression:

Stored size: 1.41 KB

Contents

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
nasa-api-client-0.0.1 lib/nasa/client.rb