Class: NeoWs
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
-
.browse(page: nil, size: nil) ⇒ NASA::RestResponse
Browse the overall Asteroid data-set.
-
.feed(start_date, end_date = nil) ⇒ NASA::RestResponse
Retrieve a list of Asteroids based on their closest approach date to Earth.
-
.lookup(asteroid_id) ⇒ NASA::RestResponse
Lookup a specific Asteroid based on its NASA JPL small body (SPK-ID) ID.
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
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.
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
37 38 39 |
# File 'lib/nasa/api/neo_ws.rb', line 37 def self.lookup(asteroid_id) get("#{ENDPOINT}/neo/#{asteroid_id}") end |