nasa-neo 1.1.2 → 1.2.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 +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +48 -3
- data/lib/nasa-neo/client.rb +46 -7
- data/lib/nasa-neo/version.rb +1 -1
- data/nasa-neo.gemspec +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 05daf1bedded0b0e75c38f2904a5a0e2cf991d1e4dc0f1a0ed0c0da246564508
|
|
4
|
+
data.tar.gz: d1e4a20ff50b5642cb2bf62e0d0cb6ec2ec3915c84e582763d0378f3affecfd8
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2381142f3cf7f95b81b56d968b4c85d61b3089d33fae7ea2d507beac8ec82d2cfda384c9d4ee4836f5af1c6728c64cf306b508a9227525339eb77c23fefdc7d7
|
|
7
|
+
data.tar.gz: 2e571042bb5248f03cfcc9fa587e819efa6304666359e23d4595a98497ba095084da700fecf9e6f0d7070f3c69c7991ccf0a1c069ef13599b0036660fa071ed7
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
|
@@ -73,7 +73,24 @@ Example return:
|
|
|
73
73
|
```
|
|
74
74
|
{"kilometers"=>{"estimated_diameter_min"=>0.1838886721, "estimated_diameter_max"=>0.411187571}, "meters"=>{"estimated_diameter_min"=>183.8886720703, "estimated_diameter_max"=>411.1875710413}, "miles"=>{"estimated_diameter_min"=>0.1142630881, "estimated_diameter_max"=>0.2555000322}, "feet"=>{"estimated_diameter_min"=>603.309310875, "estimated_diameter_max"=>1349.040630575}}
|
|
75
75
|
```
|
|
76
|
-
|
|
76
|
+
---
|
|
77
|
+
Current valid arguments: "kilometers", "meters", "miles", "feet"
|
|
78
|
+
```
|
|
79
|
+
client.estimated_diameter("meters")
|
|
80
|
+
```
|
|
81
|
+
Example return:
|
|
82
|
+
```
|
|
83
|
+
{"estimated_diameter_min"=>183.8886720703, "estimated_diameter_max"=>411.1875710413}
|
|
84
|
+
```
|
|
85
|
+
---
|
|
86
|
+
Current valid arguments: "min", "max"
|
|
87
|
+
```
|
|
88
|
+
client.estimated_diameter("meters", "min")
|
|
89
|
+
```
|
|
90
|
+
Example return:
|
|
91
|
+
```
|
|
92
|
+
183.8886720703
|
|
93
|
+
```
|
|
77
94
|
|
|
78
95
|
#### Miss distance to earth
|
|
79
96
|
|
|
@@ -84,6 +101,15 @@ Example return:
|
|
|
84
101
|
```
|
|
85
102
|
{"astronomical"=>"0.1915058335", "lunar"=>"74.4957733154", "kilometers"=>"28648866", "miles"=>"17801580"}
|
|
86
103
|
```
|
|
104
|
+
---
|
|
105
|
+
Current valid arguments: "astronomical", "lunar", "kilometers", "miles"
|
|
106
|
+
```
|
|
107
|
+
client.miss_distance("miles")
|
|
108
|
+
```
|
|
109
|
+
Example return (converts string to float):
|
|
110
|
+
```
|
|
111
|
+
17801580
|
|
112
|
+
```
|
|
87
113
|
|
|
88
114
|
|
|
89
115
|
#### Velocity
|
|
@@ -95,6 +121,15 @@ Example return:
|
|
|
95
121
|
```
|
|
96
122
|
{"kilometers_per_second"=>"14.488889894", "kilometers_per_hour"=>"52160.0036184644", "miles_per_hour"=>"32410.1978039286"}
|
|
97
123
|
```
|
|
124
|
+
---
|
|
125
|
+
Current valid arguments: "kilometers_per_second", "kilometers_per_hour", "miles_per_hour"
|
|
126
|
+
```
|
|
127
|
+
client.velocity("miles_per_hour")
|
|
128
|
+
```
|
|
129
|
+
Example return (converts string to float)
|
|
130
|
+
```
|
|
131
|
+
32410.1978039286
|
|
132
|
+
```
|
|
98
133
|
|
|
99
134
|
|
|
100
135
|
#### All data on closest object
|
|
@@ -103,7 +138,7 @@ Example return:
|
|
|
103
138
|
client.neo_data
|
|
104
139
|
```
|
|
105
140
|
|
|
106
|
-
Example return:
|
|
141
|
+
Example return (all raw data on closest object):
|
|
107
142
|
```
|
|
108
143
|
{"links"=>{"self"=>"https://api.nasa.gov/neo/rest/v1/neo/3840869?api_key=DEMO_KEY"}, "id"=>"3840869", "neo_reference_id"=>"3840869", "name"=>"(2019 GK4)", "nasa_jpl_url"=>"http://ssd.jpl.nasa.gov/sbdb.cgi?sstr=3840869", "absolute_magnitude_h"=>23.83, "estimated_diameter"=>{"kilometers"=>{"estimated_diameter_min"=>0.0455569852, "estimated_diameter_max"=>0.1018685158}, "meters"=>{"estimated_diameter_min"=>45.5569852336, "estimated_diameter_max"=>101.8685158322}, "miles"=>{"estimated_diameter_min"=>0.0283077895, "estimated_diameter_max"=>0.0632981416}, "feet"=>{"estimated_diameter_min"=>149.4651794337, "estimated_diameter_max"=>334.214301483}}, "is_potentially_hazardous_asteroid"=>false, "close_approach_data"=>[{"close_approach_date"=>"2019-04-10", "epoch_date_close_approach"=>1554879600000, "relative_velocity"=>{"kilometers_per_second"=>"14.9701946153", "kilometers_per_hour"=>"53892.7006150984", "miles_per_hour"=>"33486.828334976"}, "miss_distance"=>{"astronomical"=>"0.089370038", "lunar"=>"34.7649421692", "kilometers"=>"13369567", "miles"=>"8307464"}, "orbiting_body"=>"Earth"}], "is_sentry_object"=>false}
|
|
109
144
|
```
|
|
@@ -120,7 +155,17 @@ Returns (on next API call method):
|
|
|
120
155
|
```
|
|
121
156
|
{:error=>["400", "Forbidden"]}
|
|
122
157
|
```
|
|
123
|
-
If
|
|
158
|
+
If a status error is returned the next method request for information will make an API call
|
|
159
|
+
|
|
160
|
+
---
|
|
161
|
+
Example of unrecognised argument on method:
|
|
162
|
+
```
|
|
163
|
+
client.estimated_diameter("wrong measurement unit")
|
|
164
|
+
```
|
|
165
|
+
Returns:
|
|
166
|
+
```
|
|
167
|
+
{:error=>["measurement", "check argument"]}
|
|
168
|
+
```
|
|
124
169
|
|
|
125
170
|
|
|
126
171
|
### Testing
|
data/lib/nasa-neo/client.rb
CHANGED
|
@@ -15,18 +15,36 @@ module NasaNeo
|
|
|
15
15
|
@date = parsed_date
|
|
16
16
|
@full_url = nil
|
|
17
17
|
@result = nil
|
|
18
|
+
@estimated_diameter_options = ["kilometers", "meters", "miles", "feet"]
|
|
19
|
+
@miss_distance_options = ["astronomical", "lunar", "kilometers", "miles"]
|
|
20
|
+
@velocity_options = ["kilometers_per_second", "kilometers_per_hour", "miles_per_hour"]
|
|
18
21
|
end
|
|
19
22
|
|
|
20
|
-
def estimated_diameter
|
|
21
|
-
|
|
23
|
+
def estimated_diameter(measurement = nil, min_max = nil)
|
|
24
|
+
if @estimated_diameter_options.include? measurement
|
|
25
|
+
if ["min", "max"].include? min_max
|
|
26
|
+
call_and_rescue { estimated_diameter_data[measurement]["estimated_diameter_#{min_max}"] }
|
|
27
|
+
else
|
|
28
|
+
min_max == nil ? call_and_rescue { estimated_diameter_data[measurement] }
|
|
29
|
+
: error_feedback(['min_max', 'check arguments'])
|
|
30
|
+
end
|
|
31
|
+
else
|
|
32
|
+
measurement == nil ? call_and_rescue { estimated_diameter_data }
|
|
33
|
+
: error_feedback(['measurement', 'check arguments'])
|
|
34
|
+
end
|
|
22
35
|
end
|
|
23
36
|
|
|
24
37
|
def hazardous?
|
|
25
38
|
call_and_rescue { retrieve_neo["is_potentially_hazardous_asteroid"]}
|
|
26
39
|
end
|
|
27
40
|
|
|
28
|
-
def miss_distance
|
|
29
|
-
|
|
41
|
+
def miss_distance(measurement = nil)
|
|
42
|
+
if @miss_distance_options.include? measurement
|
|
43
|
+
call_and_rescue { miss_distance_data[measurement].to_f }
|
|
44
|
+
else
|
|
45
|
+
measurement == nil ? call_and_rescue { miss_distance_data }
|
|
46
|
+
: error_feedback(['measurement', 'check arguments'])
|
|
47
|
+
end
|
|
30
48
|
end
|
|
31
49
|
|
|
32
50
|
def neo_name
|
|
@@ -37,8 +55,13 @@ module NasaNeo
|
|
|
37
55
|
call_and_rescue { retrieve_neo }
|
|
38
56
|
end
|
|
39
57
|
|
|
40
|
-
def velocity
|
|
41
|
-
|
|
58
|
+
def velocity(measurement = nil)
|
|
59
|
+
if @velocity_options.include? measurement
|
|
60
|
+
call_and_rescue { velocity_data[measurement].to_f }
|
|
61
|
+
else
|
|
62
|
+
measurement == nil ? call_and_rescue { velocity_data }
|
|
63
|
+
: error_feedback(['measurement', 'check arguments'])
|
|
64
|
+
end
|
|
42
65
|
end
|
|
43
66
|
|
|
44
67
|
private
|
|
@@ -51,7 +74,7 @@ module NasaNeo
|
|
|
51
74
|
yield if block_given?
|
|
52
75
|
rescue OpenURI::HTTPError => e
|
|
53
76
|
@full_url = nil
|
|
54
|
-
|
|
77
|
+
error_feedback(e.io.status)
|
|
55
78
|
end
|
|
56
79
|
|
|
57
80
|
def get_api_data
|
|
@@ -69,6 +92,22 @@ module NasaNeo
|
|
|
69
92
|
@result["near_earth_objects"]["#{@date}"][0]
|
|
70
93
|
end
|
|
71
94
|
|
|
95
|
+
def estimated_diameter_data
|
|
96
|
+
retrieve_neo["estimated_diameter"]
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def error_feedback(error_info)
|
|
100
|
+
{ 'error': error_info }
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def miss_distance_data
|
|
104
|
+
retrieve_neo["close_approach_data"][0]["miss_distance"]
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def velocity_data
|
|
108
|
+
retrieve_neo["close_approach_data"][0]["relative_velocity"]
|
|
109
|
+
end
|
|
110
|
+
|
|
72
111
|
def set_full_url
|
|
73
112
|
"#{@config.host}?start_date=#{@date}&end_date=#{@date}&detailed=false&api_key=#{@key}"
|
|
74
113
|
end
|
data/lib/nasa-neo/version.rb
CHANGED
data/nasa-neo.gemspec
CHANGED
|
@@ -4,7 +4,7 @@ require "nasa-neo/version"
|
|
|
4
4
|
|
|
5
5
|
Gem::Specification.new do |s|
|
|
6
6
|
s.name = 'nasa-neo'
|
|
7
|
-
s.version = '1.
|
|
7
|
+
s.version = '1.2.0'
|
|
8
8
|
s.date = '2019-04-09'
|
|
9
9
|
s.summary = "This gem provides a simple wrapper for https://api.nasa.gov/api.html#NeoWS API"
|
|
10
10
|
s.description = "Retrieve information about the closest near earth object on any given day using the NASA NEO API. "
|