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.
@@ -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
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.6.1
7
+ before_install: gem install bundler -v 1.17.2
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in neo.gemspec
6
+ gemspec
@@ -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
@@ -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.
@@ -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`
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -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__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1 @@
1
+ Dir["#{File.dirname(__FILE__)}/**/*.rb"].each { |f| require(f) }
@@ -0,0 +1,14 @@
1
+ require_relative 'configuration'
2
+ require_relative 'client'
3
+
4
+ module NasaNeo
5
+ module CloseObj
6
+ def self.client
7
+ @client
8
+ end
9
+
10
+ def self.configure
11
+ @client = Client.new(Configuration.new)
12
+ end
13
+ end
14
+ end
@@ -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
@@ -0,0 +1,3 @@
1
+ module NasaNeo
2
+ VERSION = "1.0.1"
3
+ end
@@ -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: []