nasa_api 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +16 -0
- data/.rspec +3 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +42 -0
- data/LICENSE.txt +21 -0
- data/README.md +210 -0
- data/Rakefile +8 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/lib/nasa_api.rb +80 -0
- data/lib/nasa_api/mars.rb +32 -0
- data/lib/nasa_api/neo.rb +46 -0
- data/lib/nasa_api/planetary.rb +64 -0
- data/lib/nasa_api/response_handler.rb +169 -0
- data/lib/nasa_api/tech.rb +43 -0
- data/lib/nasa_api/version.rb +5 -0
- data/nasa_api.gemspec +32 -0
- metadata +61 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d1390e7d453bd3b86b927f91b1add210f22ceef01a21fa73ef12d736ecb2506a
|
4
|
+
data.tar.gz: ae8ad46be29686ff459ebf221a2bae64c669fd1f5f6f4fae7f54dd8636221f12
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5bc536978d2d59a91f9978550f4a3f9345b1e909de04c46ff97c2f930c6c6f287f2764d7e1dd0fdea6a86236e650c3e3777cafe78d53e0f481d9762527bcabb4
|
7
|
+
data.tar.gz: 1a5c6f38367bc375b43b057035a5598d26446cafc9aa22879e7090d1781cf6c2e3b191d7ec1399cb05df0cff9970c0f9a1168c6effac6fbc77d97b3c67c6d25f
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
nasa_api (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
diff-lcs (1.4.4)
|
10
|
+
httparty (0.18.1)
|
11
|
+
mime-types (~> 3.0)
|
12
|
+
multi_xml (>= 0.5.2)
|
13
|
+
mime-types (3.3.1)
|
14
|
+
mime-types-data (~> 3.2015)
|
15
|
+
mime-types-data (3.2021.0225)
|
16
|
+
multi_xml (0.6.0)
|
17
|
+
rake (13.0.3)
|
18
|
+
rspec (3.10.0)
|
19
|
+
rspec-core (~> 3.10.0)
|
20
|
+
rspec-expectations (~> 3.10.0)
|
21
|
+
rspec-mocks (~> 3.10.0)
|
22
|
+
rspec-core (3.10.1)
|
23
|
+
rspec-support (~> 3.10.0)
|
24
|
+
rspec-expectations (3.10.1)
|
25
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
26
|
+
rspec-support (~> 3.10.0)
|
27
|
+
rspec-mocks (3.10.2)
|
28
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
29
|
+
rspec-support (~> 3.10.0)
|
30
|
+
rspec-support (3.10.2)
|
31
|
+
|
32
|
+
PLATFORMS
|
33
|
+
x86_64-linux
|
34
|
+
|
35
|
+
DEPENDENCIES
|
36
|
+
httparty
|
37
|
+
nasa_api!
|
38
|
+
rake (~> 13.0)
|
39
|
+
rspec (~> 3.0)
|
40
|
+
|
41
|
+
BUNDLED WITH
|
42
|
+
2.2.3
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2021 chr0x6d
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,210 @@
|
|
1
|
+
# NasaApi
|
2
|
+
|
3
|
+
An easy to use Ruby wrapper around the [NASA Open APIs](https://api.nasa.gov/)
|
4
|
+
|
5
|
+
Currently supports: APOD, EPIC, Earth, Neo, Insight, Mars Rover Photos, TechTransfer and TechPort
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'nasa_api'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle install
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install nasa_api
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
### Creating API clients
|
26
|
+
|
27
|
+
Similar APIs are grouped into clients, as seen below
|
28
|
+
This means that `planetary_client = NasaApi::Planetary.new()` can be used for APOD, Earth and EPIC calls
|
29
|
+
|
30
|
+
- Planetary: APOD, Earth, EPIC
|
31
|
+
- Mars: Insight, Mars Rover Photos
|
32
|
+
- Tech: TechTransfer, TechPort
|
33
|
+
- Neo: Neo
|
34
|
+
|
35
|
+
If no API key is provided, a default 'DEMO_KEY' is used and is limited to 30 calls an hour from an IP
|
36
|
+
|
37
|
+
Visit [NASA Open APIs](https://api.nasa.gov/) to register for your own API key.
|
38
|
+
Once you have your key, pass it in when creating clients: `mars_client = NasaApi::Mars.new(api_key: 'YOUR_KEY')`
|
39
|
+
|
40
|
+
### Using Clients
|
41
|
+
|
42
|
+
All parameters for every API call are supported and matches the parameters from [NASA Open APIs](https://api.nasa.gov/)
|
43
|
+
Don't pass api_key directly to a method call, only pass it when creating a client
|
44
|
+
|
45
|
+
Ruby Date and Time objects can be passed and will be converted to the 'YYYY-MM-DD' format that the API expects
|
46
|
+
|
47
|
+
These 2 calls are identical:
|
48
|
+
`planetary_client.apod(date: '2021-01-01')`
|
49
|
+
`planetary_client.apod(date: Date.new(2021, 1, 1))`
|
50
|
+
|
51
|
+
### Planetary
|
52
|
+
|
53
|
+
Create a client: `planetary_client = NasaApi::Planetary.new(api_key: 'YOUR_KEY')`
|
54
|
+
|
55
|
+
#### APOD (Astronomy Picture of the Day)
|
56
|
+
|
57
|
+
Get the APOD for today
|
58
|
+
```
|
59
|
+
apod_today = planetary_client.apod()
|
60
|
+
apod_today.url # image url
|
61
|
+
apod_today.hd_url
|
62
|
+
apod_today.explanation
|
63
|
+
|
64
|
+
# get the entire response, useful if you want to parse it directly
|
65
|
+
# every api call returns the entire response through call.response
|
66
|
+
apod_today.response
|
67
|
+
```
|
68
|
+
|
69
|
+
Get a range of APOD's
|
70
|
+
```
|
71
|
+
apod_range = planetary_client.apod(start_date: Date.new(2021, 1, 1), end_date: Date.new(2021, 1, 5))
|
72
|
+
apod_today.url # array of image urls for these dates
|
73
|
+
apod_today.date # array of dates
|
74
|
+
```
|
75
|
+
|
76
|
+
Note: There are other parameters available, check the docs and pass them as `parameter: value` to the `apod` method
|
77
|
+
|
78
|
+
#### Earth Imagery
|
79
|
+
|
80
|
+
Get Satellite image URL of place at this latitude/longitude on this date
|
81
|
+
```
|
82
|
+
image = planetary_client.earth_imagery(lon: 100.75, lat: 1.5, date: '2014-02-01')
|
83
|
+
image.url
|
84
|
+
image.response # To view the entire response
|
85
|
+
```
|
86
|
+
|
87
|
+
#### Earth Assets
|
88
|
+
|
89
|
+
Get date-times and closest available imagery for a supplied location and date
|
90
|
+
```
|
91
|
+
assets = planetary_client.earth_assets(lon: 100.75, lat: 1.5, date: Time.new(2014, 02, 01))
|
92
|
+
assets.date
|
93
|
+
assets.url
|
94
|
+
```
|
95
|
+
|
96
|
+
Note: There are more results available like `assets.resource`, not all options are listed here, check ResponseHandler::EarthAssets if looking for all possible results
|
97
|
+
|
98
|
+
#### EPIC (Earth Polychromatic Imaging Camera)
|
99
|
+
|
100
|
+
|
101
|
+
Often when no date is passed the Nasa API will default to today
|
102
|
+
|
103
|
+
Get a range of pictures and information for today
|
104
|
+
```
|
105
|
+
epic = planetary_client.epic()
|
106
|
+
epic.date # array of date+time when images taken
|
107
|
+
epic.image_url # array of all images taken today
|
108
|
+
# much more availabe, use epic.response or check ResponseHandler::Epic to see more
|
109
|
+
```
|
110
|
+
|
111
|
+
### Mars
|
112
|
+
|
113
|
+
Create a client: `mars_client = NasaApi::Mars.new(api_key 'YOUR_KEY')`
|
114
|
+
|
115
|
+
#### Mars Rover Photos
|
116
|
+
|
117
|
+
Get photos from Mars Rovers
|
118
|
+
```
|
119
|
+
rover_data = mars_client.photos(rover: 'curiosity', sol: 1000, camera: 'fhaz')
|
120
|
+
rover_data.photos # Array of hashes for each photo, dates and extra information
|
121
|
+
```
|
122
|
+
|
123
|
+
#### Mars Weather Insight
|
124
|
+
Nasa Docs state that due to sensor problems on Mars missing data is common
|
125
|
+
|
126
|
+
Get latest weather data from Mars at Elysium Planitia, near Mar's equator
|
127
|
+
```
|
128
|
+
weather_data = mars_client.insight()
|
129
|
+
weather_data.sol_keys
|
130
|
+
weather_data.validity_checks
|
131
|
+
weather_data.response
|
132
|
+
```
|
133
|
+
|
134
|
+
### Tech
|
135
|
+
|
136
|
+
Create a client: `tech_client = NasaApi::Tech.new(api_key: 'YOUR_KEY')`
|
137
|
+
|
138
|
+
#### TechTransfer
|
139
|
+
type and item parameters are required
|
140
|
+
Available types: patent, patent_issued, software and spinoff
|
141
|
+
|
142
|
+
Get technology and development information for Nasa Engines
|
143
|
+
```
|
144
|
+
engine_data = tech_client.transfer(type: 'patent', item: 'engine')
|
145
|
+
engine_data.results
|
146
|
+
engine_data.count
|
147
|
+
```
|
148
|
+
Note:
|
149
|
+
|
150
|
+
#### TechPort
|
151
|
+
|
152
|
+
id parameter is required
|
153
|
+
|
154
|
+
Get data on Nasa project ID 17792
|
155
|
+
```
|
156
|
+
project_data = tech_client.port(id: 17792)
|
157
|
+
project_data.project # for one project
|
158
|
+
```
|
159
|
+
|
160
|
+
Often when providing no parameters Nasa will return everything by default
|
161
|
+
|
162
|
+
Get data on all Nasa projects through TechPort
|
163
|
+
```
|
164
|
+
projects_data = tech_client.port()
|
165
|
+
projects_data.projects # for an array of projects
|
166
|
+
```
|
167
|
+
|
168
|
+
### Neo (Near Earth Object)
|
169
|
+
|
170
|
+
Create a client: `neo_client = NasaApi::Neo.new(api_key: 'YOUR_KEY')`
|
171
|
+
|
172
|
+
#### NeoLookup
|
173
|
+
|
174
|
+
Lookup a specific asteroid (asteroid_id required)
|
175
|
+
```
|
176
|
+
asteroid_data = neo_client.lookup(asteroid_id: 3542519)
|
177
|
+
asteroid_data.name
|
178
|
+
asteroid_data.is_potentially_hazardous_asteroid
|
179
|
+
# check ResponseHandler::NeoLookup for more output data
|
180
|
+
```
|
181
|
+
|
182
|
+
#### NeoFeed
|
183
|
+
|
184
|
+
Get data on Neo's over a range of dates
|
185
|
+
```
|
186
|
+
neo_data = neo_client.feed(start_date: Date.new(2021, 1, 1), end_date: '2021-01-05')
|
187
|
+
neo_data.near_earth_objects
|
188
|
+
neo_data.element_count
|
189
|
+
neo_data.links
|
190
|
+
```
|
191
|
+
|
192
|
+
#### NeoBrowse
|
193
|
+
|
194
|
+
Browse the overall asteroid data-set
|
195
|
+
```
|
196
|
+
neo_data = neo_client.browse()
|
197
|
+
neo_data.near_earth_objects
|
198
|
+
neo_data.response
|
199
|
+
```
|
200
|
+
|
201
|
+
## Development
|
202
|
+
|
203
|
+
To run the specs first visit `lib/nasa_api.rb` and provide your API key as the default, as described in the comment
|
204
|
+
This is due to the specs rate-limiting 'DEMO_KEY' quickly while testing API calls
|
205
|
+
|
206
|
+
Issue reports and pull requests are highly appreciated, this gem is in early development and has a lot of room for improvement
|
207
|
+
|
208
|
+
## License
|
209
|
+
|
210
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "bundler/setup"
|
5
|
+
require "nasa_api"
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require "irb"
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/nasa_api.rb
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'date'
|
2
|
+
require 'httparty'
|
3
|
+
|
4
|
+
module NasaApi
|
5
|
+
BASE_URL = 'https://api.nasa.gov/'
|
6
|
+
|
7
|
+
class Error < StandardError
|
8
|
+
attr_reader :http_code, :http_msg, :message
|
9
|
+
|
10
|
+
def initialize(response)
|
11
|
+
@http_code = response.code
|
12
|
+
@http_msg = response.message
|
13
|
+
@message = response['error']['message'] if response['error']
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class NasaInit
|
18
|
+
attr_accessor :api_key, :high_definition, :date, :options
|
19
|
+
|
20
|
+
def initialize(options = {})
|
21
|
+
@api_key = options[:api_key] || 'DEMO_KEY'
|
22
|
+
|
23
|
+
# When testing with RSpec, uncomment the below line with your actual API key as default
|
24
|
+
# Specs will use the default API key, e.g. the string to the right of ||
|
25
|
+
# by default this is 'DEMO_KEY', and will cause specs to fail as DEMO_KEY is rate-limited quickly
|
26
|
+
#
|
27
|
+
# @api_key = options[:api_key] || 'ACTUAL_API_KEY'
|
28
|
+
|
29
|
+
options[:api_key] = @api_key
|
30
|
+
@options = options
|
31
|
+
end
|
32
|
+
|
33
|
+
def parse_date(date)
|
34
|
+
# Allow Ruby Date/Time objects to be used
|
35
|
+
# by changing them to the Nasa API's expected YYYY-MM-DD format
|
36
|
+
case date
|
37
|
+
when Time
|
38
|
+
date.strftime("%Y-%m-%d")
|
39
|
+
when Date
|
40
|
+
date.to_s
|
41
|
+
when String
|
42
|
+
date
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def params_dates(params = {})
|
47
|
+
# If date provided, parse it
|
48
|
+
# If start/end date provided, parse them
|
49
|
+
# If {:random = true} in params, use a random date
|
50
|
+
# otherwise use no date, most Nasa API's will then default to Today's date
|
51
|
+
if params[:date]
|
52
|
+
params[:date] = parse_date(params[:date])
|
53
|
+
return params
|
54
|
+
end
|
55
|
+
|
56
|
+
if params[:start_date]
|
57
|
+
params[:start_date] = parse_date(params[:start_date])
|
58
|
+
if params[:end_date]
|
59
|
+
params[:end_date] = parse_date(params[:end_date])
|
60
|
+
end
|
61
|
+
return params
|
62
|
+
end
|
63
|
+
|
64
|
+
if params[:random]
|
65
|
+
params[:date] = rand(Date.parse('2000-01-01')..Date.today)
|
66
|
+
params.delete(:random)
|
67
|
+
end
|
68
|
+
params
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
require_relative "nasa_api/version"
|
74
|
+
require_relative "nasa_api/response_handler"
|
75
|
+
|
76
|
+
require_relative "nasa_api/planetary"
|
77
|
+
require_relative "nasa_api/neo"
|
78
|
+
require_relative "nasa_api/tech"
|
79
|
+
require_relative "nasa_api/mars"
|
80
|
+
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module NasaApi
|
2
|
+
class Mars < NasaInit
|
3
|
+
INSIGHT_URL = BASE_URL + 'insight_weather/'
|
4
|
+
PHOTOS_URL = BASE_URL + 'mars-photos/api/v1/rovers/'
|
5
|
+
|
6
|
+
def insight(params = {})
|
7
|
+
params[:feedtype] ||= 'json'
|
8
|
+
params[:ver] ||= '1.0'
|
9
|
+
params.merge!(@options)
|
10
|
+
|
11
|
+
response = HTTParty.get(INSIGHT_URL, query: params)
|
12
|
+
if response.code == 200
|
13
|
+
ResponseHandler::MarsInsight.new(response)
|
14
|
+
else
|
15
|
+
Error.new(response)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def photos(params = {})
|
20
|
+
params[:rover] ||= 'curiosity'
|
21
|
+
photo_rover_url = PHOTOS_URL + params[:rover].to_s + '/photos'
|
22
|
+
params.merge!(@options)
|
23
|
+
response = HTTParty.get(photo_rover_url, query: params)
|
24
|
+
if response.code == 200
|
25
|
+
ResponseHandler::MarsPhotos.new(response)
|
26
|
+
else
|
27
|
+
Error.new(response)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
data/lib/nasa_api/neo.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
module NasaApi
|
2
|
+
class Neo < NasaInit
|
3
|
+
NEO_URL = BASE_URL + 'neo/rest/v1/'
|
4
|
+
LOOKUP_URL = NEO_URL + 'neo/'
|
5
|
+
FEED_URL = NEO_URL + 'feed'
|
6
|
+
BROWSE_URL = NEO_URL + 'neo/browse'
|
7
|
+
|
8
|
+
def lookup(params = {})
|
9
|
+
# requires customised URL as it only takes one parameter which doesn't respond to ?asteroid_id=
|
10
|
+
|
11
|
+
params[:asteroid_id] ||= 0
|
12
|
+
asteroid_id = params[:asteroid_id].to_s
|
13
|
+
params.delete(:asteroid_id)
|
14
|
+
params.merge!(@options)
|
15
|
+
response = HTTParty.get(LOOKUP_URL + asteroid_id, query: params)
|
16
|
+
if response.code == 200
|
17
|
+
ResponseHandler::NeoLookup.new(response)
|
18
|
+
else
|
19
|
+
Error.new(response)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def feed(params = {})
|
24
|
+
params = params_dates(params)
|
25
|
+
params.merge!(@options)
|
26
|
+
|
27
|
+
response = HTTParty.get(FEED_URL, query: params)
|
28
|
+
if response.code == 200
|
29
|
+
ResponseHandler::NeoFeed.new(response)
|
30
|
+
else
|
31
|
+
Error.new(response)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def browse(params = {})
|
36
|
+
params.merge!(@options)
|
37
|
+
|
38
|
+
response = HTTParty.get(BROWSE_URL, query: params)
|
39
|
+
if response.code == 200
|
40
|
+
ResponseHandler::NeoBrowse.new(response)
|
41
|
+
else
|
42
|
+
Error.new(response)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
module NasaApi
|
2
|
+
class Planetary < NasaInit
|
3
|
+
PLANETARY_URL = BASE_URL + 'planetary/'
|
4
|
+
APOD_URL = PLANETARY_URL + 'apod'
|
5
|
+
EARTH_URL = PLANETARY_URL + 'earth/'
|
6
|
+
|
7
|
+
EARTH_IMAGERY_URL = EARTH_URL + 'imagery'
|
8
|
+
EARTH_ASSETS_URL = EARTH_URL + 'assets'
|
9
|
+
|
10
|
+
EPIC_URL = BASE_URL + 'EPIC/api/natural'
|
11
|
+
|
12
|
+
def apod(params = {})
|
13
|
+
params = params_dates(params)
|
14
|
+
|
15
|
+
# @options contains global information for all api calls, like api_key
|
16
|
+
# merge it with the specific params for APOD calls to create full request
|
17
|
+
params.merge!(@options)
|
18
|
+
|
19
|
+
response = HTTParty.get(APOD_URL, query: params)
|
20
|
+
if response.code == 200
|
21
|
+
ResponseHandler::Apod.new(response)
|
22
|
+
else
|
23
|
+
Error.new(response)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def earth_imagery(params = {})
|
28
|
+
params = params_dates(params)
|
29
|
+
params.merge!(@options)
|
30
|
+
|
31
|
+
response_head = HTTParty.head(EARTH_IMAGERY_URL, query: params)
|
32
|
+
if response_head.code == 200
|
33
|
+
ResponseHandler::EarthImagery.new(response_head)
|
34
|
+
else
|
35
|
+
Error.new(response_head)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def earth_assets(params = {})
|
40
|
+
params = params_dates(params)
|
41
|
+
params.merge!(@options)
|
42
|
+
|
43
|
+
response = HTTParty.get(EARTH_ASSETS_URL, query: params)
|
44
|
+
if response.code == 200
|
45
|
+
ResponseHandler::EarthAssets.new(response)
|
46
|
+
else
|
47
|
+
Error.new(response)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def epic(params = {})
|
52
|
+
params = params_dates(params)
|
53
|
+
params.merge!(@options)
|
54
|
+
|
55
|
+
response = HTTParty.get(EPIC_URL, query: params)
|
56
|
+
if response.code == 200
|
57
|
+
ResponseHandler::Epic.new(response)
|
58
|
+
else
|
59
|
+
Error.new(response)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
@@ -0,0 +1,169 @@
|
|
1
|
+
module NasaApi
|
2
|
+
module ResponseHandler
|
3
|
+
class Apod
|
4
|
+
attr_accessor :response, :url, :media_type, :title, :explanation, :hd_url, :date, :copyright
|
5
|
+
|
6
|
+
def initialize(response = {})
|
7
|
+
@response = response
|
8
|
+
if response.parsed_response.is_a?(::Hash)
|
9
|
+
@url = response['url']
|
10
|
+
@hd_url = response['hdurl']
|
11
|
+
@media_type = response['media_type']
|
12
|
+
@title = response['title']
|
13
|
+
@explanation = response['explanation']
|
14
|
+
@date = response['date']
|
15
|
+
@copyright = response['copyright']
|
16
|
+
@service_version = response['service_version']
|
17
|
+
else
|
18
|
+
# If start_date->end_date is used an array of hashes is returned
|
19
|
+
# Go through every hash and append its response to an array
|
20
|
+
response.each do |values|
|
21
|
+
(@url ||= []) << values['url']
|
22
|
+
(@hd_url ||= []) << values['hdurl']
|
23
|
+
(@media_type ||= []) << values['media_type']
|
24
|
+
(@title ||= []) << values['title']
|
25
|
+
(@explanation ||= []) << values['explanation']
|
26
|
+
(@date ||= []) << values['date']
|
27
|
+
(@copyright ||= []) << values['copyright']
|
28
|
+
(@service_version ||= []) << values['service_version']
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
class EarthImagery
|
35
|
+
attr_accessor :response, :url
|
36
|
+
|
37
|
+
def initialize(response_head)
|
38
|
+
@response = response_head
|
39
|
+
@url = response_head.request.last_uri.to_s
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
class EarthAssets
|
44
|
+
attr_accessor :response, :url, :date, :id, :resource
|
45
|
+
|
46
|
+
def initialize(response = {})
|
47
|
+
@response = response
|
48
|
+
@url = response['head']
|
49
|
+
@date = response['date']
|
50
|
+
@id = response['id']
|
51
|
+
@resource = response['resource']
|
52
|
+
@service_version = response['service_version']
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
class NeoLookup
|
57
|
+
attr_accessor :response, :links, :id, :neo_reference_id, :name, :designation, :nasa_jpl_url, :absolute_magnitude_h, :estimated_diameter, :is_potentially_hazardous_asteroid, :close_approach_data, :orbital_data, :is_sentry_object
|
58
|
+
|
59
|
+
def initialize(response = {})
|
60
|
+
@response = response
|
61
|
+
@links = response['links']
|
62
|
+
@id = response['id']
|
63
|
+
@neo_reference_id = response['neo_reference_id']
|
64
|
+
@name = response['name']
|
65
|
+
@designation = response['designation']
|
66
|
+
@nasa_jpl_url = response['nasa_jpl_url']
|
67
|
+
@absolute_magnitude_h = response['absolute_magnitude_h']
|
68
|
+
@estimated_diameter = response['estimated_diameter']
|
69
|
+
@is_potentially_hazardous_asteroid = response['is_potentially_hazardous_asteroid']
|
70
|
+
@close_approach_data = response['close_approach_data']
|
71
|
+
@orbital_data = response['orbital_data']
|
72
|
+
@is_sentry_object = response['is_sentry_object']
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
class NeoFeed
|
77
|
+
attr_accessor :response, :links, :element_count, :near_earth_objects
|
78
|
+
|
79
|
+
def initialize(response = {})
|
80
|
+
@response = response
|
81
|
+
@links = response['links']
|
82
|
+
@element_count = response['element_count']
|
83
|
+
@near_earth_objects = response['near_earth_objects']
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
class NeoBrowse
|
88
|
+
attr_accessor :response, :links, :page, :near_earth_objects
|
89
|
+
|
90
|
+
def initialize(response = {})
|
91
|
+
@response = response
|
92
|
+
@links = response['links']
|
93
|
+
@page = response['page']
|
94
|
+
@near_earth_objects = response['near_earth_objects']
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
class Epic
|
99
|
+
attr_accessor :response, :identifier, :caption, :image, :image_url, :version, :centroid_coordinates, :dscovr_j2000_position, :lunar_j2000_position, :sun_j2000_position, :attitude_quaternions, :date, :coords
|
100
|
+
|
101
|
+
def initialize(response = {})
|
102
|
+
@response = response
|
103
|
+
response.each do |values|
|
104
|
+
(@identifier ||= []) << values['identifier']
|
105
|
+
(@caption ||= []) << values['caption']
|
106
|
+
(@image ||= []) << values['image']
|
107
|
+
(@version ||= []) << values['version']
|
108
|
+
(@centroid_coordinates ||= []) << values['centroid_coordinates']
|
109
|
+
(@dscovr_j2000_position ||= []) << values['dscovr_j2000_position']
|
110
|
+
(@lunar_j2000_position ||= []) << values['lunar_j2000_position']
|
111
|
+
(@sun_j2000_position ||= []) << values['sun_j2000_position']
|
112
|
+
(@attitude_quaternions ||= []) << values['attitude_quaternions']
|
113
|
+
(@date ||= []) << values['date']
|
114
|
+
(@coords ||= []) << values['coords']
|
115
|
+
|
116
|
+
# Images are stored in an archive by YYYY/DD/MM url
|
117
|
+
# Requires a little extra logic to retrieve image_url
|
118
|
+
date_parsed = @date[-1].split(' ')[0]
|
119
|
+
parts = date_parsed.split('-')
|
120
|
+
(@image_url ||= []) << "https://epic.gsfc.nasa.gov/archive/natural/#{parts[0]}/#{parts[1]}/#{parts[2]}/png/#{@image[-1].to_s}.png"
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
class TechTransfer
|
126
|
+
attr_accessor :response, :results, :count, :total, :perpage, :page
|
127
|
+
|
128
|
+
def initialize(response = {})
|
129
|
+
@response = response
|
130
|
+
@results = response['results']
|
131
|
+
@count = response['count']
|
132
|
+
@total = response['total']
|
133
|
+
@perpage = response['perpage']
|
134
|
+
@page = response['page']
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
class TechPort
|
139
|
+
attr_accessor :response, :totalCount, :project, :projects
|
140
|
+
|
141
|
+
def initialize(response = {})
|
142
|
+
@response = response
|
143
|
+
@totalCount = response['totalCount'] if response['totalCount']
|
144
|
+
@project = response['project'] if response['project']
|
145
|
+
@projects = response['projects'] if response['projects']
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
class MarsInsight
|
150
|
+
attr_accessor :response, :sol_keys, :validity_checks
|
151
|
+
|
152
|
+
def initialize(response = {})
|
153
|
+
@response = response
|
154
|
+
@sol_keys = response['sol_keys']
|
155
|
+
@validity_checks = response['validity_checks']
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
class MarsPhotos
|
160
|
+
attr_accessor :response, :photos
|
161
|
+
|
162
|
+
def initialize(response = {})
|
163
|
+
@response = response
|
164
|
+
@photos = response['photos']
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module NasaApi
|
2
|
+
class Tech < NasaInit
|
3
|
+
TRANSFER_URL = 'https://api.nasa.gov/techtransfer/'
|
4
|
+
PORT_URL = 'https://api.nasa.gov/techport/api/projects/'
|
5
|
+
|
6
|
+
def transfer(params = {})
|
7
|
+
# Query type must be appended to url like type/ instead of as parameter
|
8
|
+
# if type is not passed, assume a patent type is requested
|
9
|
+
params[:type] ||= 'patent'
|
10
|
+
type = params[:type].to_s
|
11
|
+
params.delete(:type)
|
12
|
+
|
13
|
+
# If item is not passed, default to '', returning all items
|
14
|
+
params[:item] ||= ''
|
15
|
+
item = params[:item].to_s
|
16
|
+
params.delete(:item)
|
17
|
+
params.merge!(@options)
|
18
|
+
|
19
|
+
response = HTTParty.get(TRANSFER_URL + type + '/?' + item, query: params)
|
20
|
+
if response.code == 200
|
21
|
+
ResponseHandler::TechTransfer.new(response)
|
22
|
+
else
|
23
|
+
Error.new(response)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def port(params = {})
|
28
|
+
# If id not passed, default to '', returning all projects
|
29
|
+
params[:id] ||= ''
|
30
|
+
id = params[:id].to_s
|
31
|
+
params.delete(:id)
|
32
|
+
params.merge!(@options)
|
33
|
+
|
34
|
+
response = HTTParty.get(PORT_URL + id, query: params)
|
35
|
+
if response.code == 200
|
36
|
+
ResponseHandler::TechPort.new(response)
|
37
|
+
else
|
38
|
+
Error.new(response)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
data/nasa_api.gemspec
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/nasa_api/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "nasa_api"
|
7
|
+
spec.version = NasaApi::VERSION
|
8
|
+
spec.authors = ["mark-ruddy"]
|
9
|
+
spec.email = ["1markruddy@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = "Ruby wrapper of the Nasa APIs"
|
12
|
+
spec.license = "MIT"
|
13
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
14
|
+
|
15
|
+
# spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
|
16
|
+
spec.metadata["source_code_uri"] = "https://github.com/mark-ruddy/nasa_api"
|
17
|
+
|
18
|
+
# Specify which files should be added to the gem when it is released.
|
19
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
20
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
21
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
|
22
|
+
end
|
23
|
+
spec.bindir = "exe"
|
24
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
25
|
+
spec.require_paths = ["lib"]
|
26
|
+
|
27
|
+
# Uncomment to register a new dependency of your gem
|
28
|
+
# spec.add_dependency "example-gem", "~> 1.0"
|
29
|
+
|
30
|
+
# For more information and examples about making a new gem, checkout our
|
31
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
32
|
+
end
|
metadata
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nasa_api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- mark-ruddy
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-05-09 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description:
|
14
|
+
email:
|
15
|
+
- 1markruddy@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- ".gitignore"
|
21
|
+
- ".rspec"
|
22
|
+
- Gemfile
|
23
|
+
- Gemfile.lock
|
24
|
+
- LICENSE.txt
|
25
|
+
- README.md
|
26
|
+
- Rakefile
|
27
|
+
- bin/console
|
28
|
+
- bin/setup
|
29
|
+
- lib/nasa_api.rb
|
30
|
+
- lib/nasa_api/mars.rb
|
31
|
+
- lib/nasa_api/neo.rb
|
32
|
+
- lib/nasa_api/planetary.rb
|
33
|
+
- lib/nasa_api/response_handler.rb
|
34
|
+
- lib/nasa_api/tech.rb
|
35
|
+
- lib/nasa_api/version.rb
|
36
|
+
- nasa_api.gemspec
|
37
|
+
homepage:
|
38
|
+
licenses:
|
39
|
+
- MIT
|
40
|
+
metadata:
|
41
|
+
source_code_uri: https://github.com/mark-ruddy/nasa_api
|
42
|
+
post_install_message:
|
43
|
+
rdoc_options: []
|
44
|
+
require_paths:
|
45
|
+
- lib
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: 2.3.0
|
51
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
requirements: []
|
57
|
+
rubygems_version: 3.2.3
|
58
|
+
signing_key:
|
59
|
+
specification_version: 4
|
60
|
+
summary: Ruby wrapper of the Nasa APIs
|
61
|
+
test_files: []
|