Class: NeoWs

Inherits:
Object
  • Object
show all
Extended by:
Rest
Defined in:
lib/nasa/api/neo_ws.rb

Overview

NeoWs (Near Earth Object Web Service) With NeoWs a user can: search for Asteroids based on their closest approach date to Earth, lookup a specific Asteroid with its NASA JPL small body id, as well as browse the overall data-set.

Constant Summary collapse

ENDPOINT =

Base API Endpoint for this service

'https://api.nasa.gov/neo/rest/v1/'

Class Method Summary collapse

Methods included from Rest

delete, get, post, put, request

Class Method Details

.browse(page: nil, size: nil) ⇒ NASA::RestResponse

Browse the overall Asteroid data-set

Parameters:

  • page (Integer)

    which page to request

  • size (Integer)

    amount of objects per page, the api defaults to 20

Returns:

  • (NASA::RestResponse)


46
47
48
# File 'lib/nasa/api/neo_ws.rb', line 46

def self.browse(page: nil, size: nil)
  get("#{ENDPOINT}/neo/browse", params: { page: page, size: size })
end

.feed(start_date, end_date = nil) ⇒ NASA::RestResponse

Retrieve a list of Asteroids based on their closest approach date to Earth.

Parameters:

  • start_date (String)

    formatted as YYYY-MM-DD defaults to today

  • end_date (String) (defaults to: nil)

    formatted as YYYY-MM-DD defaults to 7 days after start_date (serverside)

Returns:

  • (NASA::RestResponse)

Raises:

  • (ArgumentError)

    if incorrect date format provided



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/nasa/api/neo_ws.rb', line 20

def self.feed(start_date, end_date = nil)
  start_date ||= Time.new.strftime('%F')
  date_check = ->(date) { date.match(/\d{4}-\d{2}-\d{2}/) }

  raise ArgumentError, 'Incorrect date format' unless date_check.call(start_date)

  raise ArgumentError, 'Incorrect date format' unless end_date && date_check.call(end_date)

  params = { start_date: start_date, end_date: end_date }

  get("#{ENDPOINT}/feed", params: params)
end

.lookup(asteroid_id) ⇒ NASA::RestResponse

Lookup a specific Asteroid based on its NASA JPL small body (SPK-ID) ID

Parameters:

  • asteroid_id (Integer)

    Asteroid SPK-ID

Returns:

  • (NASA::RestResponse)


37
38
39
# File 'lib/nasa/api/neo_ws.rb', line 37

def self.lookup(asteroid_id)
  get("#{ENDPOINT}/neo/#{asteroid_id}")
end