nasa-neo 1.3.1 → 1.3.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e27ce374fa0c996d1c8ab7f8b9c3737c9ec74fe09739131ea94182d4a29a3fb8
4
- data.tar.gz: '043791aa288feee62d4950e260257dfeaaaeb48e8c9b21e110ca671b45ce6471'
3
+ metadata.gz: 39c3b2f4dcea89280298b2742156c13eb30d249558d7e86ab46475ec458149c4
4
+ data.tar.gz: 3e4211e5ecea32b7c40962d7858529287917f923f80b819c19136f704c0d4dce
5
5
  SHA512:
6
- metadata.gz: 8e486bd7667154fac645622eb1ee25800c3accf76bd25d8bb2d3a0a2d7cd909c7e1969df615d7ebdd2a15a838e33844495aa41e2f291661f1f72ffc32c7be0dc
7
- data.tar.gz: 6c84a545498950d3296caa425c561756ec61f60c98a9cc1a39ed5d66ec4d389ef5f59bfc9f6b9733f5971c182221c3ccea99d024e250d2155d50ca5b9c752a64
6
+ metadata.gz: 9b886908d2c30577bfd60365a89bf0881da783ca45c10d2974ccfeaddab6ceb10b7e797a9e40d84bf43a092a129a5b57b9fbb665514cade185e202fb6f00748e
7
+ data.tar.gz: 6dec97d322e25a330539b1a57006a4a4d549cd1ec8602b8bd29d679763df019b21104b9361e509ab48d8ceca0ec8fed1154275eeb88328d5303cb804b39005eb
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- nasa-neo (1.3.1)
4
+ nasa-neo (1.3.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -209,6 +209,16 @@ Returns:
209
209
  ```
210
210
  nil
211
211
  ```
212
+ ---
213
+ Example of return if numbered information not present outside year range, eg. if selected miss distance in miles of Near Earth Object is not present (applicable to #miss_distance and #velocity with valid arguments):
214
+ ```
215
+ client.date = "2400-01-01"
216
+ client.miss_distance("miles")
217
+ ```
218
+ Returns:
219
+ ```
220
+ 0.0
221
+ ```
212
222
 
213
223
 
214
224
  ### Testing
@@ -7,6 +7,16 @@ module NasaNeo
7
7
  module CloseObj
8
8
  class Client
9
9
 
10
+ ESTIMATED_DIAMETER_OPTIONS = ["kilometers", "meters", "miles", "feet"]
11
+ MISS_DISTANCE_OPTIONS = ["astronomical", "lunar", "kilometers", "miles"]
12
+ VELOCITY_OPTIONS = ["kilometers_per_second", "kilometers_per_hour", "miles_per_hour"]
13
+
14
+ NEO_NAME_KEYS = ["name"]
15
+ HAZARDOUS_KEYS = ["is_potentially_hazardous_asteroid"]
16
+ ESTIMATED_DIAMETER_KEYS = ["estimated_diameter"]
17
+ MISS_DISTANCE_KEYS = ["close_approach_data", 0, "miss_distance"]
18
+ VELOCITY_KEYS = ["close_approach_data", 0, "relative_velocity"]
19
+
10
20
  attr_accessor :date, :key
11
21
 
12
22
  def initialize(config)
@@ -16,40 +26,37 @@ module NasaNeo
16
26
  @full_url = nil
17
27
  @result = nil
18
28
  @neo_position = 0
19
- @estimated_diameter_options = ["kilometers", "meters", "miles", "feet"]
20
- @miss_distance_options = ["astronomical", "lunar", "kilometers", "miles"]
21
- @velocity_options = ["kilometers_per_second", "kilometers_per_hour", "miles_per_hour"]
22
29
  end
23
30
 
24
31
  def estimated_diameter(measurement = nil, min_max = nil)
25
- if @estimated_diameter_options.include? measurement
32
+ if ESTIMATED_DIAMETER_OPTIONS.include? measurement
26
33
  if ["min", "max"].include? min_max
27
- call_and_rescue { estimated_diameter_data[measurement]["estimated_diameter_#{min_max}"] }
34
+ call_and_rescue { retrieve_neo(ESTIMATED_DIAMETER_KEYS + ["#{measurement}", "estimated_diameter_#{min_max}"]) }
28
35
  else
29
- min_max == nil ? call_and_rescue { estimated_diameter_data[measurement] }
36
+ min_max == nil ? call_and_rescue { retrieve_neo(ESTIMATED_DIAMETER_KEYS + ["#{measurement}"]) }
30
37
  : error_feedback(['min_max', 'check arguments'])
31
38
  end
32
39
  else
33
- measurement == nil ? call_and_rescue { estimated_diameter_data }
40
+ measurement == nil ? call_and_rescue { retrieve_neo(ESTIMATED_DIAMETER_KEYS) }
34
41
  : error_feedback(['measurement', 'check arguments'])
35
42
  end
36
43
  end
37
44
 
38
45
  def hazardous?
39
- call_and_rescue { hazardous_data }
46
+ call_and_rescue { retrieve_neo(HAZARDOUS_KEYS) }
40
47
  end
41
48
 
42
49
  def miss_distance(measurement = nil)
43
- if @miss_distance_options.include? measurement
44
- call_and_rescue { miss_distance_data[measurement].to_f }
50
+ if MISS_DISTANCE_OPTIONS.include? measurement
51
+ call_and_rescue { retrieve_neo(MISS_DISTANCE_KEYS + ["#{measurement}"]).to_f }
45
52
  else
46
- measurement == nil ? call_and_rescue { miss_distance_data }
53
+ measurement == nil ? call_and_rescue { retrieve_neo(MISS_DISTANCE_KEYS) }
47
54
  : error_feedback(['measurement', 'check arguments'])
48
55
  end
49
56
  end
50
57
 
51
58
  def neo_name
52
- call_and_rescue { neo_name_data }
59
+ call_and_rescue { retrieve_neo(NEO_NAME_KEYS) }
53
60
  end
54
61
 
55
62
  def neo_data
@@ -62,7 +69,6 @@ module NasaNeo
62
69
  else
63
70
  @result["element_count"]
64
71
  end
65
-
66
72
  end
67
73
 
68
74
  def update
@@ -74,10 +80,10 @@ module NasaNeo
74
80
  end
75
81
 
76
82
  def velocity(measurement = nil)
77
- if @velocity_options.include? measurement
78
- call_and_rescue { velocity_data[measurement].to_f }
83
+ if VELOCITY_OPTIONS.include? measurement
84
+ call_and_rescue { retrieve_neo(VELOCITY_KEYS + ["#{measurement}"]).to_f }
79
85
  else
80
- measurement == nil ? call_and_rescue { velocity_data }
86
+ measurement == nil ? call_and_rescue { retrieve_neo(VELOCITY_KEYS) }
81
87
  : error_feedback(['measurement', 'check arguments'])
82
88
  end
83
89
  end
@@ -97,6 +103,7 @@ module NasaNeo
97
103
 
98
104
  def get_api_data
99
105
  @full_url = set_full_url
106
+ @neo_position = 0
100
107
  buffer = JSON.parse(buffer_url)
101
108
  @result = buffer
102
109
  end
@@ -105,40 +112,16 @@ module NasaNeo
105
112
  Time.now.strftime("%Y-%m-%d")
106
113
  end
107
114
 
108
- def retrieve_neo
115
+ def retrieve_neo(keys = [])
109
116
  get_api_data if @full_url != set_full_url
110
- @result.dig("near_earth_objects", "#{@date}", @neo_position)
111
- end
112
-
113
- def estimated_diameter_data
114
- data = retrieve_neo
115
- data == nil ? nil : data["estimated_diameter"]
117
+ root_keys = ["near_earth_objects", "#{@date}", @neo_position]
118
+ @result.dig(*root_keys + keys)
116
119
  end
117
120
 
118
121
  def error_feedback(error_info)
119
122
  { 'error': error_info }
120
123
  end
121
124
 
122
- def hazardous_data
123
- data = retrieve_neo
124
- data == nil ? nil : data["is_potentially_hazardous_asteroid"]
125
- end
126
-
127
- def miss_distance_data
128
- data = retrieve_neo
129
- data == nil ? nil : data["close_approach_data"][0]["miss_distance"]
130
- end
131
-
132
- def neo_name_data
133
- data = retrieve_neo
134
- data == nil ? nil : data["name"]
135
- end
136
-
137
- def velocity_data
138
- data = retrieve_neo
139
- data == nil ? nil : data["close_approach_data"][0]["relative_velocity"]
140
- end
141
-
142
125
  def set_full_url
143
126
  "#{@config.host}?start_date=#{@date}&end_date=#{@date}&detailed=false&api_key=#{@key}"
144
127
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module NasaNeo
4
- VERSION = "1.3.1".freeze
4
+ VERSION = "1.3.2".freeze
5
5
  end
@@ -4,10 +4,10 @@ require "nasa-neo/version"
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = 'nasa-neo'
7
- s.version = '1.3.1'
7
+ s.version = '1.3.2'
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
- s.description = "Retrieve information about the closest near earth object on any given day using the NASA NEO API. "
10
+ s.description = "Retrieve information about the closest near earth objects on any given day using the NASA NEO API. "
11
11
  s.authors = ["James Sutherland"]
12
12
  s.email = 'jrsutherland78@googlemail.com'
13
13
  s.homepage = 'https://github.com/LondonJim/NASA-NEO-API-Wrapper'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nasa-neo
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1
4
+ version: 1.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Sutherland
@@ -78,7 +78,7 @@ dependencies:
78
78
  - - ">="
79
79
  - !ruby/object:Gem::Version
80
80
  version: 3.5.1
81
- description: 'Retrieve information about the closest near earth object on any given
81
+ description: 'Retrieve information about the closest near earth objects on any given
82
82
  day using the NASA NEO API. '
83
83
  email: jrsutherland78@googlemail.com
84
84
  executables: []