nasa-neo 1.0.1
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 +11 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +47 -0
- data/LICENSE.txt +21 -0
- data/README.md +100 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/nasa-neo.rb +1 -0
- data/lib/nasa-neo/base.rb +14 -0
- data/lib/nasa-neo/client.rb +68 -0
- data/lib/nasa-neo/configuration.rb +16 -0
- data/lib/nasa-neo/version.rb +3 -0
- data/nasa-neo.gemspec +27 -0
- metadata +116 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 599d7a51ce2552ed535efddbd37471ef9c8c8e35289def3bdfa7808044e728d6
|
|
4
|
+
data.tar.gz: 60f31be728aef30756e88df8f1b2cf34ce6550368a0fb9e806b525642da64a1e
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 255b7d3a020408ecbcb3d78fb77783b54b59a645617f692a3883ad908cd6f620448d77d5fc71c122d0c264e690d680c31b801b2814a1035712f9d2f72a8457c2
|
|
7
|
+
data.tar.gz: da9e5e20d38f08d54362d437a1862376842abd413d25b214f00635b155cea223712489b51bb5681eb0fdc4830e4c66f18dfefdc23cccfcf53416eebc73fde584
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
nasa-neo (1.0.1)
|
|
5
|
+
|
|
6
|
+
GEM
|
|
7
|
+
remote: https://rubygems.org/
|
|
8
|
+
specs:
|
|
9
|
+
addressable (2.6.0)
|
|
10
|
+
public_suffix (>= 2.0.2, < 4.0)
|
|
11
|
+
crack (0.4.3)
|
|
12
|
+
safe_yaml (~> 1.0.0)
|
|
13
|
+
diff-lcs (1.3)
|
|
14
|
+
hashdiff (0.3.8)
|
|
15
|
+
public_suffix (3.0.3)
|
|
16
|
+
rake (10.5.0)
|
|
17
|
+
rspec (3.8.0)
|
|
18
|
+
rspec-core (~> 3.8.0)
|
|
19
|
+
rspec-expectations (~> 3.8.0)
|
|
20
|
+
rspec-mocks (~> 3.8.0)
|
|
21
|
+
rspec-core (3.8.0)
|
|
22
|
+
rspec-support (~> 3.8.0)
|
|
23
|
+
rspec-expectations (3.8.2)
|
|
24
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
25
|
+
rspec-support (~> 3.8.0)
|
|
26
|
+
rspec-mocks (3.8.0)
|
|
27
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
28
|
+
rspec-support (~> 3.8.0)
|
|
29
|
+
rspec-support (3.8.0)
|
|
30
|
+
safe_yaml (1.0.5)
|
|
31
|
+
webmock (3.5.1)
|
|
32
|
+
addressable (>= 2.3.6)
|
|
33
|
+
crack (>= 0.3.2)
|
|
34
|
+
hashdiff
|
|
35
|
+
|
|
36
|
+
PLATFORMS
|
|
37
|
+
ruby
|
|
38
|
+
|
|
39
|
+
DEPENDENCIES
|
|
40
|
+
bundler (~> 2.0.1)
|
|
41
|
+
nasa-neo!
|
|
42
|
+
rake (~> 10.0)
|
|
43
|
+
rspec (~> 3.8)
|
|
44
|
+
webmock (~> 3.5.1)
|
|
45
|
+
|
|
46
|
+
BUNDLED WITH
|
|
47
|
+
2.0.1
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019 James Sutherland
|
|
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,100 @@
|
|
|
1
|
+
# Nasa Near Earth Object API Wrapper
|
|
2
|
+
|
|
3
|
+
Gives details on the closest Near Earth Object of the day.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Uses `Ruby 2.6.1`
|
|
8
|
+
|
|
9
|
+
`bundle`
|
|
10
|
+
|
|
11
|
+
Add this line to your application's Gemfile:
|
|
12
|
+
|
|
13
|
+
```ruby
|
|
14
|
+
gem 'nasa-neo'
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
And then execute:
|
|
18
|
+
|
|
19
|
+
$ bundle
|
|
20
|
+
|
|
21
|
+
Or install it yourself as:
|
|
22
|
+
|
|
23
|
+
$ gem install neo
|
|
24
|
+
|
|
25
|
+
## Instructions
|
|
26
|
+
A default api key of DEMO_KEY will let you make up to 30 requests per hour (50 per day), if you have your own api key (https://api.nasa.gov/index.html#apply-for-an-api-key) you can set it as detailed under instructions (developer API keys allow up to 1000 requests an hour)
|
|
27
|
+
|
|
28
|
+
Create client to make requests to the API (using demo api key):
|
|
29
|
+
|
|
30
|
+
```
|
|
31
|
+
client = NasaNeo::CloseObj.configure
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Set the API key (default is DEMO_KEY)
|
|
35
|
+
```
|
|
36
|
+
client.key = "MyKey"
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Change the date (default is the current day)
|
|
40
|
+
```
|
|
41
|
+
client.date = "2019-04-10"
|
|
42
|
+
```
|
|
43
|
+
Please Note: The first request for information results in an API call, unless the date is changed no more API calls are made as the information of the closet near earth object is stored on the first request.
|
|
44
|
+
|
|
45
|
+
##### Retrieving Information
|
|
46
|
+
|
|
47
|
+
Retrieve the name:
|
|
48
|
+
|
|
49
|
+
```
|
|
50
|
+
client.neo_name
|
|
51
|
+
|
|
52
|
+
eg. "(2004 VB)"
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
Retrieve the estimated diameter:
|
|
57
|
+
|
|
58
|
+
```
|
|
59
|
+
client.estimated_diameter
|
|
60
|
+
|
|
61
|
+
eg. {"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}}
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
Retrieve the miss distance to earth:
|
|
66
|
+
|
|
67
|
+
```
|
|
68
|
+
client.miss_distance
|
|
69
|
+
|
|
70
|
+
eg. {"astronomical"=>"0.1915058335", "lunar"=>"74.4957733154", "kilometers"=>"28648866", "miles"=>"17801580"}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
Retrieve the velocity:
|
|
75
|
+
|
|
76
|
+
```
|
|
77
|
+
client.velocity
|
|
78
|
+
|
|
79
|
+
eg. {"kilometers_per_second"=>"14.488889894", "kilometers_per_hour"=>"52160.0036184644", "miles_per_hour"=>"32410.1978039286"}
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
##### Exceptions
|
|
83
|
+
|
|
84
|
+
Exceptions are returned as a hash (example of wrong date):
|
|
85
|
+
```
|
|
86
|
+
client.date = "123"
|
|
87
|
+
```
|
|
88
|
+
returns:
|
|
89
|
+
```
|
|
90
|
+
{:error=>["400", ""]}
|
|
91
|
+
```
|
|
92
|
+
If an error is returned the next method request for information will make an API call
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
## Testing
|
|
96
|
+
|
|
97
|
+
Uses `RSpec 3.8`
|
|
98
|
+
|
|
99
|
+
Run tests:
|
|
100
|
+
`bundle exec rspec`
|
data/Rakefile
ADDED
data/bin/console
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "nasa-neo"
|
|
5
|
+
|
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
8
|
+
|
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
10
|
+
# require "pry"
|
|
11
|
+
# Pry.start
|
|
12
|
+
|
|
13
|
+
require "irb"
|
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/nasa-neo.rb
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Dir["#{File.dirname(__FILE__)}/**/*.rb"].each { |f| require(f) }
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
require 'open-uri'
|
|
2
|
+
require 'json'
|
|
3
|
+
|
|
4
|
+
module NasaNeo
|
|
5
|
+
module CloseObj
|
|
6
|
+
class Client
|
|
7
|
+
|
|
8
|
+
attr_accessor :date, :key
|
|
9
|
+
|
|
10
|
+
def initialize(config)
|
|
11
|
+
@config = config
|
|
12
|
+
@key = config.api_key
|
|
13
|
+
@date = parsed_date
|
|
14
|
+
@full_url = nil
|
|
15
|
+
@result = nil
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def estimated_diameter
|
|
19
|
+
call_and_rescue { retrieve_neo["estimated_diameter"] }
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def miss_distance
|
|
23
|
+
call_and_rescue { retrieve_neo["close_approach_data"][0]["miss_distance"] }
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def neo_name
|
|
27
|
+
call_and_rescue { retrieve_neo["name"] }
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def velocity
|
|
31
|
+
call_and_rescue { retrieve_neo["close_approach_data"][0]["relative_velocity"] }
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
private
|
|
35
|
+
|
|
36
|
+
def buffer_url
|
|
37
|
+
open(@full_url).read
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def call_and_rescue
|
|
41
|
+
yield if block_given?
|
|
42
|
+
rescue OpenURI::HTTPError => e
|
|
43
|
+
@full_url = nil
|
|
44
|
+
{ 'error': e.io.status }
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def get_api_data
|
|
48
|
+
@full_url = set_full_url
|
|
49
|
+
buffer = JSON.parse(buffer_url)
|
|
50
|
+
@result = buffer
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def parsed_date
|
|
54
|
+
Time.now.strftime("%Y-%m-%d")
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def retrieve_neo
|
|
58
|
+
get_api_data if @full_url != set_full_url
|
|
59
|
+
@result["near_earth_objects"]["#{@date}"][0]
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def set_full_url
|
|
63
|
+
"#{@config.host}?start_date=#{@date}&end_date=#{@date}&detailed=false&api_key=#{@key}"
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
module NasaNeo
|
|
2
|
+
module CloseObj
|
|
3
|
+
class Configuration
|
|
4
|
+
DEFAULT_HOST = 'https://api.nasa.gov/neo/rest/v1/feed'
|
|
5
|
+
DEFAULT_API_KEY = 'DEMO_KEY'
|
|
6
|
+
|
|
7
|
+
attr_accessor :api_key, :host
|
|
8
|
+
|
|
9
|
+
def initialize
|
|
10
|
+
self.api_key = DEFAULT_API_KEY
|
|
11
|
+
self.host = DEFAULT_HOST
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
data/nasa-neo.gemspec
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
3
|
+
require "nasa-neo/version"
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |s|
|
|
6
|
+
s.name = 'nasa-neo'
|
|
7
|
+
s.version = '1.0.1'
|
|
8
|
+
s.date = '2019-04-09'
|
|
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 using the NASA NEO API. "
|
|
11
|
+
s.authors = ["James Sutherland"]
|
|
12
|
+
s.email = 'jrsutherland78@googlemail.com'
|
|
13
|
+
s.homepage = 'https://github.com/LondonJim/NASA-NEO-API-Wrapper'
|
|
14
|
+
s.license = 'MIT'
|
|
15
|
+
|
|
16
|
+
s.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
|
17
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
s.bindir = 'bin'
|
|
21
|
+
s.require_paths = ['lib']
|
|
22
|
+
|
|
23
|
+
s.add_development_dependency 'bundler', '~> 2.0.1'
|
|
24
|
+
s.add_development_dependency 'rake', '~> 10.0'
|
|
25
|
+
s.add_development_dependency 'rspec', '~> 3.8'
|
|
26
|
+
s.add_development_dependency 'webmock', '~> 3.5.1'
|
|
27
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: nasa-neo
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- James Sutherland
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2019-04-09 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: bundler
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: 2.0.1
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: 2.0.1
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rake
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '10.0'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '10.0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: rspec
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '3.8'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '3.8'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: webmock
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - "~>"
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: 3.5.1
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - "~>"
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: 3.5.1
|
|
69
|
+
description: 'Retrieve information about the closest near earth object using the NASA
|
|
70
|
+
NEO API. '
|
|
71
|
+
email: jrsutherland78@googlemail.com
|
|
72
|
+
executables: []
|
|
73
|
+
extensions: []
|
|
74
|
+
extra_rdoc_files: []
|
|
75
|
+
files:
|
|
76
|
+
- ".gitignore"
|
|
77
|
+
- ".rspec"
|
|
78
|
+
- ".travis.yml"
|
|
79
|
+
- Gemfile
|
|
80
|
+
- Gemfile.lock
|
|
81
|
+
- LICENSE.txt
|
|
82
|
+
- README.md
|
|
83
|
+
- Rakefile
|
|
84
|
+
- bin/console
|
|
85
|
+
- bin/setup
|
|
86
|
+
- lib/nasa-neo.rb
|
|
87
|
+
- lib/nasa-neo/base.rb
|
|
88
|
+
- lib/nasa-neo/client.rb
|
|
89
|
+
- lib/nasa-neo/configuration.rb
|
|
90
|
+
- lib/nasa-neo/version.rb
|
|
91
|
+
- nasa-neo.gemspec
|
|
92
|
+
homepage: https://github.com/LondonJim/NASA-NEO-API-Wrapper
|
|
93
|
+
licenses:
|
|
94
|
+
- MIT
|
|
95
|
+
metadata: {}
|
|
96
|
+
post_install_message:
|
|
97
|
+
rdoc_options: []
|
|
98
|
+
require_paths:
|
|
99
|
+
- lib
|
|
100
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
101
|
+
requirements:
|
|
102
|
+
- - ">="
|
|
103
|
+
- !ruby/object:Gem::Version
|
|
104
|
+
version: '0'
|
|
105
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
106
|
+
requirements:
|
|
107
|
+
- - ">="
|
|
108
|
+
- !ruby/object:Gem::Version
|
|
109
|
+
version: '0'
|
|
110
|
+
requirements: []
|
|
111
|
+
rubygems_version: 3.0.3
|
|
112
|
+
signing_key:
|
|
113
|
+
specification_version: 4
|
|
114
|
+
summary: This gem provides a simple wrapper for https://api.nasa.gov/api.html#NeoWS
|
|
115
|
+
API
|
|
116
|
+
test_files: []
|