neows 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 17dbb6ecc1a0411e3963aca66841eabbff019618
4
+ data.tar.gz: 8b3c081fb995b500409b33aa4d8bf1178c61f6a0
5
+ SHA512:
6
+ metadata.gz: e43e73b27dae8a903dbfcd7b2e3a1bb1914c0d254e8f22295efa1b605af49787a33c554e734f37e86aeb1515ef0e72394677b46e47117f1473b4d44a6a7cc694
7
+ data.tar.gz: 50f4a01c9120fb9a8f9f5fe30a2e0f34e43a06e8ab31a52eca82c05bed80a203af77143f9f051bd87938452b3b7c7ff7e19936d2dd6b2e1920643a56ed9b0ff9
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .idea/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.rubocop.yml ADDED
@@ -0,0 +1,32 @@
1
+ Metrics/BlockNesting:
2
+ Max: 2
3
+
4
+ Metrics/LineLength:
5
+ AllowURI: true
6
+ Enabled: false
7
+
8
+ Metrics/MethodLength:
9
+ CountComments: false
10
+ Max: 10
11
+
12
+ Metrics/ParameterLists:
13
+ Max: 5
14
+ CountKeywordArgs: true
15
+
16
+ Style/AccessModifierIndentation:
17
+ EnforcedStyle: outdent
18
+
19
+ Style/Documentation:
20
+ Enabled: false
21
+
22
+ Style/DoubleNegation:
23
+ Enabled: false
24
+
25
+ Style/SpaceInsideHashLiteralBraces:
26
+ EnforcedStyle: no_space
27
+
28
+ Style/TrailingComma:
29
+ Enabled: false
30
+
31
+ Style/NumericLiterals:
32
+ Enabled: false
data/.travis.yml ADDED
@@ -0,0 +1,11 @@
1
+ sudo: false
2
+
3
+ language: ruby
4
+
5
+ cache: bundler
6
+
7
+ rvm:
8
+ - 1.9.3
9
+ - 2.0.0
10
+ - 2.1
11
+ - 2.2
data/.yardopts ADDED
@@ -0,0 +1,5 @@
1
+ --no-private
2
+ --protected
3
+ --markup markdown
4
+ -
5
+ LICENSE.md
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source 'https://rubygems.org'
2
+
3
+ group :test do
4
+ gem 'coveralls'
5
+ gem 'rspec', '>= 3.2.0'
6
+ gem 'rubocop', '>= 0.27'
7
+ gem 'simplecov', '>= 0.9'
8
+ gem 'webmock', '>= 1.21.0'
9
+ gem 'yardstick', '>= 0.9.9'
10
+ end
11
+
12
+ gemspec
data/LICENSE.md ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2015 Jason English
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,63 @@
1
+ [![Build Status](https://travis-ci.org/SpaceRocks/neows-ruby.svg?branch=master)](https://travis-ci.org/SpaceRocks/neows-ruby)
2
+ [![Coverage Status](https://coveralls.io/repos/SpaceRocks/neows-ruby/badge.svg?branch=master&service=github)](https://coveralls.io/github/SpaceRocks/neows-ruby?branch=master)
3
+
4
+ # NeoWs Ruby Gem
5
+
6
+ A Ruby interface to the NeoWs API
7
+
8
+ ## Installation
9
+
10
+ ```
11
+ $ gem install neows
12
+ ```
13
+
14
+ ## Configuration
15
+ ```ruby
16
+ client = Neows::REST::Client.new
17
+ ```
18
+
19
+ ## Usage Examples
20
+ With a configured `client` you can:
21
+
22
+ **View a Feed (grouped by date)**
23
+
24
+ ```ruby
25
+ client.feed('2015-07-01', '2015-07-04')
26
+ ```
27
+
28
+ **Browse Near Earth Objects**
29
+
30
+ ```ruby
31
+ client.browse
32
+ ```
33
+
34
+ **Easily navigate between pages in Feed and Browse**
35
+
36
+ ```ruby
37
+ feed = client.feed('2015-07-01', '2015-07-04')
38
+ feed.next
39
+
40
+ browse = client.browse
41
+ browse.next
42
+ ```
43
+
44
+ **Fetch a Near Earth Object (by ID)**
45
+
46
+ ```ruby
47
+ client.neo('3724245')
48
+ ```
49
+
50
+ **See stats relating to the NeoWs database**
51
+
52
+ ```ruby
53
+ client.stats
54
+ ```
55
+
56
+ ## Supported Ruby Versions
57
+
58
+ This library supports and is tested against the following Ruby versions:
59
+
60
+ * Ruby 1.9.3
61
+ * Ruby 2.0.0
62
+ * Ruby 2.1
63
+ * Ruby 2.2
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ require 'rspec/core/rake_task'
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task test: :spec
7
+
8
+ task default: [:spec]
@@ -0,0 +1,23 @@
1
+ module Neows
2
+ module Attributes
3
+ class SanitizedInteger < Virtus::Attribute
4
+ # Coerces a string with commas to an Integer
5
+ #
6
+ # @param value [String]
7
+ # @return [Integer]
8
+ def coerce(value)
9
+ value.delete(',').to_i
10
+ end
11
+ end
12
+
13
+ class SanitizedFloat < Virtus::Attribute
14
+ # Coerces a string with commas to a Float
15
+ #
16
+ # @param value [String]
17
+ # @return [Float]
18
+ def coerce(value)
19
+ value.delete(',').to_f
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,27 @@
1
+ require 'neows/version'
2
+
3
+ module Neows
4
+ class Client
5
+ attr_accessor :base_url
6
+
7
+ # Initializes a new Client object
8
+ #
9
+ # @param options [Hash]
10
+ # @return [Neows::Client]
11
+ def initialize(options = {})
12
+ options.each do |key, value|
13
+ instance_variable_set("@#{key}", value)
14
+ end
15
+ yield(self) if block_given?
16
+ end
17
+
18
+ def base_url
19
+ @base_url ||= url
20
+ end
21
+
22
+ # @return [String]
23
+ def user_agent
24
+ "NeowsRubyGem/#{Neows::VERSION}"
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,16 @@
1
+ require 'virtus'
2
+
3
+ module Neows
4
+ module Models
5
+ class BaseModel
6
+ include Virtus.model
7
+
8
+ attr_accessor :client
9
+
10
+ def initialize(attributes = {})
11
+ @client = attributes.delete :client
12
+ super(attributes)
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,32 @@
1
+ require 'virtus'
2
+ require 'neows/models/base_model'
3
+ require 'neows/models/links'
4
+ require 'neows/models/page'
5
+ require 'neows/models/pagination'
6
+ require 'neows/models/near_earth_object'
7
+
8
+ module Neows
9
+ module Models
10
+ # @todo remove wrapper when _embedded is removed from api
11
+ class EmbeddedResults < Neows::Models::BaseModel
12
+ attribute :nearEarthObjectFeedDtoes, Array[Neows::Models::NearEarthObject]
13
+ end
14
+
15
+ class Browse < Neows::Models::BaseModel
16
+ include Neows::Models::LinkNavigation
17
+ include Neows::Models::Pagination
18
+
19
+ # @!attribute [rw]
20
+ # @note Temporary wrapper around the result set. Use #near_earth_objects
21
+ # @return [EmbeddedResults]
22
+ attribute :_embedded, EmbeddedResults
23
+
24
+ # Helper accessor for #_embedded.near_earth_objects
25
+ #
26
+ # @return [Array<Neows::Models::NearEarthObject>] list of Near Earth Objects
27
+ def near_earth_objects
28
+ _embedded.nearEarthObjectFeedDtoes
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,30 @@
1
+ require 'virtus'
2
+ require 'neows/models/base_model'
3
+ require 'neows/models/miss_distance'
4
+ require 'neows/models/relative_velocity'
5
+
6
+ module Neows
7
+ module Models
8
+ class CloseApproachData < Neows::Models::BaseModel
9
+ # @!attribute [rw]
10
+ # @return [Neows::Models::RelativeVelocity]
11
+ attribute :relative_velocity, Neows::Models::RelativeVelocity
12
+
13
+ # @!attribute [rw]
14
+ # @return [Neows::Models::MissDistance]
15
+ attribute :miss_distance, Neows::Models::MissDistance
16
+
17
+ # @!attribute [rw]
18
+ # @return [Date]
19
+ attribute :close_approach_date, Date
20
+
21
+ # @!attribute [rw]
22
+ # @return [Integer]
23
+ attribute :epoch_date_close_approach, Integer
24
+
25
+ # @!attribute [rw]
26
+ # @return [String]
27
+ attribute :orbiting_body, String
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,25 @@
1
+ require 'virtus'
2
+ require 'neows/models/base_model'
3
+ require 'neows/models/estimated_diameter_min_max'
4
+
5
+ module Neows
6
+ module Models
7
+ class EstimatedDiameter < Neows::Models::BaseModel
8
+ # @!attribute [rw]
9
+ # @return [Neows::Models::EstimatedDiameterMinMax]
10
+ attribute :kilometers, Neows::Models::EstimatedDiameterMinMax
11
+
12
+ # @!attribute [rw]
13
+ # @return [Neows::Models::EstimatedDiameterMinMax]
14
+ attribute :meters, Neows::Models::EstimatedDiameterMinMax
15
+
16
+ # @!attribute [rw]
17
+ # @return [Neows::Models::EstimatedDiameterMinMax]
18
+ attribute :miles, Neows::Models::EstimatedDiameterMinMax
19
+
20
+ # @!attribute [rw]
21
+ # @return [Neows::Models::EstimatedDiameterMinMax]
22
+ attribute :feet, Neows::Models::EstimatedDiameterMinMax
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,15 @@
1
+ require 'neows/models/base_model'
2
+
3
+ module Neows
4
+ module Models
5
+ class EstimatedDiameterMinMax < Neows::Models::BaseModel
6
+ # @!attribute [rw]
7
+ # @return [Float]
8
+ attribute :estimated_diameter_min, Float
9
+
10
+ # @!attribute [rw]
11
+ # @return [Integer]
12
+ attribute :estimated_diameter_max, Float
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,37 @@
1
+ require 'virtus'
2
+ require 'neows/utils'
3
+ require 'neows/models/base_model'
4
+ require 'neows/models/near_earth_object'
5
+ require 'neows/models/link_navigation'
6
+
7
+ module Neows
8
+ module Models
9
+ # Reverses the contents of a String or IO object.
10
+ #
11
+ # @return [Boolean] if success
12
+ class Feed < Neows::Models::BaseModel
13
+ include Neows::Utils
14
+ include Neows::Models::LinkNavigation
15
+
16
+ # @!attribute [rw]
17
+ # @return [Integer] number of results
18
+ attribute :element_count, Integer
19
+
20
+ # @!attribute [rw]
21
+ # @return [Hash[String => Array<Neows::Models::NearEarthObject>]] list of Near Earth Objects grouped by
22
+ # date (YYYY-MM-DD) strings
23
+ attribute :near_earth_objects, Hash[String => Array]
24
+
25
+ # Modifies existing list of hashes representing Near Earth Objects and coerces them each into #NearEarthObject
26
+ #
27
+ # @return [self]
28
+ def coerce!
29
+ near_earth_objects.each_with_index do |data|
30
+ near_earth_objects[data.first] = classify_list!(data[1], Neows::Models::NearEarthObject)
31
+ end
32
+
33
+ self
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,11 @@
1
+ require 'neows/models/base_model'
2
+
3
+ module Neows
4
+ module Models
5
+ class Link < Neows::Models::BaseModel
6
+ # @!attribute [rw]
7
+ # @return [String]
8
+ attribute :href, String
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,32 @@
1
+ require 'virtus'
2
+ require 'neows/models/base_model'
3
+ require 'neows/models/links'
4
+ require 'neows/rest/utils'
5
+
6
+ module Neows
7
+ module Models
8
+ module LinkNavigation
9
+ include Virtus.model
10
+ include Neows::REST::Utils
11
+
12
+ # @!attribute [rw] links
13
+ # @return [Neows::Models::Links]
14
+ attribute :_links, Neows::Models::Links
15
+ alias_method :links, :_links
16
+
17
+ # Request the objects next results
18
+ #
19
+ # @return [self]
20
+ def next
21
+ perform_get(links.next.href, self.class)
22
+ end
23
+
24
+ # Request the objects previous results
25
+ #
26
+ # @return [self]
27
+ def prev
28
+ perform_get(links.prev.href, self.class)
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,21 @@
1
+ require 'virtus'
2
+ require 'neows/models/base_model'
3
+ require 'neows/models/link'
4
+
5
+ module Neows
6
+ module Models
7
+ class Links < Neows::Models::BaseModel
8
+ # @!attribute [rw]
9
+ # @return [Neows::Models::Link]
10
+ attribute :self, Neows::Models::Link
11
+
12
+ # @!attribute [rw]
13
+ # @return [Neows::Models::Link]
14
+ attribute :next, Neows::Models::Link
15
+
16
+ # @!attribute [rw]
17
+ # @return [Neows::Models::Link]
18
+ attribute :prev, Neows::Models::Link
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,26 @@
1
+ require 'neows/attributes'
2
+ require 'neows/models/base_model'
3
+
4
+ module Neows
5
+ module Models
6
+ class MissDistance < Neows::Models::BaseModel
7
+ # @!attribute [rw]
8
+ # @return [Float]
9
+ attribute :astronomical, Float
10
+
11
+ # @!attribute [rw]
12
+ # @return [Float]
13
+ attribute :lunar, Float
14
+
15
+ # @!attribute [rw]
16
+ # @todo Switch from using SanitizedInteger to Integer after API removes commas
17
+ # @return [Integer]
18
+ attribute :kilometers, Neows::Attributes::SanitizedInteger
19
+
20
+ # @!attribute [rw]
21
+ # @todo Switch from using SanitizedInteger to Integer after API removes commas
22
+ # @return [Integer]
23
+ attribute :miles, Neows::Attributes::SanitizedInteger
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,43 @@
1
+ require 'neows/models/base_model'
2
+ require 'neows/models/close_approach_data'
3
+ require 'neows/models/estimated_diameter'
4
+ require 'neows/models/orbital_data'
5
+
6
+ module Neows
7
+ module Models
8
+ class NearEarthObject < Neows::Models::BaseModel
9
+ attribute :isPotentiallyHazardousAsteroid, Boolean
10
+ # @!attribute [rw]
11
+ # @return [Boolean]
12
+ alias_method :is_potentially_hazardous_asteroid, :isPotentiallyHazardousAsteroid
13
+
14
+ # @!attribute [rw]
15
+ # @return [Integer]
16
+ attribute :neo_reference_id, Integer
17
+
18
+ # @!attribute [rw]
19
+ # @return [String]
20
+ attribute :name, String
21
+
22
+ # @!attribute [rw]
23
+ # @return [String]
24
+ attribute :nasa_jpl_url, String
25
+
26
+ # @!attribute [rw]
27
+ # @return [Integer]
28
+ attribute :absolute_magnitude_h, Integer
29
+
30
+ # @!attribute [rw]
31
+ # @return [Neows::Models::EstimatedDiameter]
32
+ attribute :estimated_diameter, Neows::Models::EstimatedDiameter
33
+
34
+ # @!attribute [rw]
35
+ # @return [Neows::Models::CloseApproachData]
36
+ attribute :close_approach_data, Array[Neows::Models::CloseApproachData]
37
+
38
+ # @!attribute [rw]
39
+ # @return [Neows::Models::OrbitalData]
40
+ attribute :orbital_data, Neows::Models::OrbitalData
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,79 @@
1
+ require 'neows/models/base_model'
2
+
3
+ module Neows
4
+ module Models
5
+ class OrbitalData < Neows::Models::BaseModel
6
+ # @!attribute [rw]
7
+ # @return [String]
8
+ attribute :orbit_id, String
9
+
10
+ # @!attribute [rw]
11
+ # @return [DateTime]
12
+ attribute :orbit_determination_date, DateTime
13
+
14
+ # @!attribute [rw]
15
+ # @return [Integer]
16
+ attribute :orbit_uncertainty, Integer
17
+
18
+ # @!attribute [rw]
19
+ # @return [Float]
20
+ attribute :minimum_orbit_intersection, Float
21
+
22
+ # @!attribute [rw]
23
+ # @return [Float]
24
+ attribute :jupiter_tisserand_invariant, Float
25
+
26
+ # @!attribute [rw]
27
+ # @return [Float]
28
+ attribute :epoch_osculation, Float
29
+
30
+ # @!attribute [rw]
31
+ # @return [Float]
32
+ attribute :eccentricity, Float
33
+
34
+ # @!attribute [rw]
35
+ # @return [Float]
36
+ attribute :semi_major_axis, Float
37
+
38
+ # @!attribute [rw]
39
+ # @return [Float]
40
+ attribute :inclination, Float
41
+
42
+ # @!attribute [rw]
43
+ # @return [Float]
44
+ attribute :ascending_node_longitude, Float
45
+
46
+ # @!attribute [rw]
47
+ # @return [Float]
48
+ attribute :orbital_period, Float
49
+
50
+ # @!attribute [rw]
51
+ # @return [Float]
52
+ attribute :perihelion_distance, Float
53
+
54
+ # @!attribute [rw]
55
+ # @return [Float]
56
+ attribute :perihelion_argument, Float
57
+
58
+ # @!attribute [rw]
59
+ # @return [Float]
60
+ attribute :aphelion_distance, Float
61
+
62
+ # @!attribute [rw]
63
+ # @return [Float]
64
+ attribute :perihelion_time, Float
65
+
66
+ # @!attribute [rw]
67
+ # @return [Float]
68
+ attribute :mean_anomaly, Float
69
+
70
+ # @!attribute [rw]
71
+ # @return [Float]
72
+ attribute :mean_motion, Float
73
+
74
+ # @!attribute [rw]
75
+ # @return [String]
76
+ attribute :equinox, String
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,25 @@
1
+ require 'neows/models/base_model'
2
+
3
+ module Neows
4
+ module Models
5
+ class Page < Neows::Models::BaseModel
6
+ # @!attribute [rw]
7
+ # @return [Integer]
8
+ attribute :size, Integer
9
+
10
+ # @!attribute [rw] total_elements
11
+ # @return [Integer]
12
+ attribute :totalElements, Integer
13
+ alias_method :total_elements, :totalElements
14
+
15
+ # @!attribute [rw] total_pages
16
+ # @return [Integer]
17
+ attribute :totalPages, Integer
18
+ alias_method :total_pages, :totalPages
19
+
20
+ # @!attribute [rw]
21
+ # @return [Integer]
22
+ attribute :number, Integer
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,13 @@
1
+ require 'virtus'
2
+
3
+ module Neows
4
+ module Models
5
+ module Pagination
6
+ include Virtus.model
7
+
8
+ # @!attribute [rw]
9
+ # @return [Neows::Models::Page]
10
+ attribute :page, Page
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,22 @@
1
+ require 'neows/attributes'
2
+ require 'neows/models/base_model'
3
+
4
+ module Neows
5
+ module Models
6
+ class RelativeVelocity < Neows::Models::BaseModel
7
+ # @!attribute [rw]
8
+ # @return [Float]
9
+ attribute :kms, Float
10
+
11
+ # @!attribute [rw]
12
+ # @todo Switch from using SanitizedFloat to Float after API removes commas
13
+ # @return [Float]
14
+ attribute :kph, Neows::Attributes::SanitizedFloat
15
+
16
+ # @!attribute [rw]
17
+ # @todo Switch from using SanitizedFloat to Float after API removes commas
18
+ # @return [Float]
19
+ attribute :mph, Neows::Attributes::SanitizedFloat
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,15 @@
1
+ require 'neows/models/base_model'
2
+
3
+ module Neows
4
+ module Models
5
+ class Stat < Neows::Models::BaseModel
6
+ # @!attribute [rw]
7
+ # @return [Integer]
8
+ attribute :near_earth_object_count, Integer
9
+
10
+ # @!attribute [rw]
11
+ # @return [Integer]
12
+ attribute :close_approach_count, Integer
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,13 @@
1
+ require 'neows/rest/stats'
2
+ require 'neows/rest/feed'
3
+ require 'neows/rest/neo'
4
+
5
+ module Neows
6
+ module REST
7
+ module API
8
+ include Neows::REST::Stats
9
+ include Neows::REST::Feed
10
+ include Neows::REST::Neo
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,16 @@
1
+ require 'neows/rest/api'
2
+ require 'neows/client'
3
+
4
+ module Neows
5
+ module REST
6
+ class Client < Neows::Client
7
+ BASE_URL = 'http://www.neowsapp.com/rest/v1'
8
+ include Neows::REST::API
9
+
10
+ # @return [String]
11
+ def url
12
+ BASE_URL
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,20 @@
1
+ require 'neows/utils'
2
+ require 'neows/models/feed'
3
+ require 'neows/rest/utils'
4
+
5
+ module Neows
6
+ module REST
7
+ module Feed
8
+ include Neows::REST::Utils
9
+
10
+ # Near Earth Objects grouped by Date
11
+ #
12
+ # @param start_date [String] date in format YYYY-MM-DD
13
+ # @param end_date [String] date in format YYYY-MM-DD
14
+ # @return [Neows::Models::Feed]
15
+ def feed(start_date, end_date)
16
+ perform_get('/feed', Neows::Models::Feed, start_date: start_date, end_date: end_date)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,26 @@
1
+ require 'neows/models/near_earth_object'
2
+ require 'neows/models/browse'
3
+ require 'neows/rest/utils'
4
+
5
+ module Neows
6
+ module REST
7
+ module Neo
8
+ include Neows::REST::Utils
9
+
10
+ # A single Near Earth Object by id
11
+ #
12
+ # @param neo_reference_id [String|Integer]
13
+ # @return [Neows::Models::NearEarthObject]
14
+ def neo(neo_reference_id)
15
+ perform_get("/neo/#{neo_reference_id}", Neows::Models::NearEarthObject)
16
+ end
17
+
18
+ # Find other Near Earth Objects
19
+ #
20
+ # @return [Neows::Models::Browse]
21
+ def browse
22
+ perform_get('/neo/browse', Neows::Models::Browse)
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,49 @@
1
+ require 'http'
2
+
3
+ module Neows
4
+ module REST
5
+ class Request
6
+ attr_accessor :client, :path, :options
7
+
8
+ # Creates an instance of Request
9
+ #
10
+ # @param request_method [Symbol] :get
11
+ # @param path [String]
12
+ # @param klass [Class]
13
+ # @param options [Hash]
14
+ # @return [Neows::REST::Request]
15
+ def initialize(client, request_method, path, klass, options = {})
16
+ @client = client
17
+ @request_method = request_method
18
+ @path = path.gsub @client.base_url, ''
19
+ @options = options
20
+ @klass = klass
21
+ end
22
+
23
+ # @return [String]
24
+ def uri
25
+ @client.base_url + @path
26
+ end
27
+
28
+ # Makes the request passing the response into the given class. If a class provides a coerce! method,
29
+ # it will be called to handle custom coercion of data.
30
+ #
31
+ # @return [Class] instance of Klass
32
+ def perform
33
+ response = HTTP.with(request_headers).public_send(@request_method, uri, params: @options)
34
+ klass = @klass.new JSON.parse(response.to_s).merge(client: @client)
35
+ klass.coerce! if klass.respond_to?(:coerce!)
36
+ klass
37
+ end
38
+
39
+ private
40
+
41
+ def request_headers
42
+ {
43
+ user_agent: @client.user_agent,
44
+ accept: 'application/json'
45
+ }
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,17 @@
1
+ require 'neows/models/stat'
2
+ require 'neows/rest/utils'
3
+
4
+ module Neows
5
+ module REST
6
+ module Stats
7
+ include Neows::REST::Utils
8
+
9
+ # Stats relating to the NeoWs database
10
+ #
11
+ # @return [Neows::Models::Stat]
12
+ def stats
13
+ perform_get('/stats', Neows::Models::Stat)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,13 @@
1
+ require 'neows/rest/request'
2
+
3
+ module Neows
4
+ module REST
5
+ module Utils
6
+ private
7
+
8
+ def perform_get(path, klass, options = {})
9
+ Neows::REST::Request.new(@client || self, :get, path, klass, options).perform
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,12 @@
1
+ module Neows
2
+ module Utils
3
+ # Modifies given list creating an instance of klass for each item
4
+ #
5
+ # @param list [Array]
6
+ # @param klass [Class]
7
+ # @return [list]
8
+ def classify_list!(list, klass)
9
+ list.map! { |h| klass.new(h) }
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,3 @@
1
+ module Neows
2
+ VERSION = '0.0.1'
3
+ end
data/lib/neows.rb ADDED
@@ -0,0 +1,2 @@
1
+ require 'neows/version'
2
+ require 'neows/rest/client'
data/neows.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'neows/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'neows'
8
+ spec.version = Neows::VERSION
9
+ spec.authors = ['Jason English']
10
+ spec.email = ['jnenglish@gmail.com']
11
+ spec.description = 'A Ruby interface to the NeoWs API'
12
+ spec.summary = spec.description
13
+ spec.homepage = 'https://github.com/SpaceRocks/neows-ruby'
14
+ spec.licenses = %w(MIT)
15
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
16
+ spec.bindir = 'exe'
17
+ spec.require_paths = %w(lib)
18
+ spec.required_ruby_version = '>= 1.9.3'
19
+ spec.add_dependency 'http', '~> 0.8.4'
20
+ spec.add_dependency 'virtus', '~> 1.0.5'
21
+ spec.add_development_dependency 'bundler', '~> 1.0'
22
+ spec.add_development_dependency 'rake', '~> 10.0'
23
+ end
metadata ADDED
@@ -0,0 +1,139 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: neows
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jason English
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-08-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: http
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.8.4
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.8.4
27
+ - !ruby/object:Gem::Dependency
28
+ name: virtus
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 1.0.5
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 1.0.5
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ description: A Ruby interface to the NeoWs API
70
+ email:
71
+ - jnenglish@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".rubocop.yml"
79
+ - ".travis.yml"
80
+ - ".yardopts"
81
+ - Gemfile
82
+ - LICENSE.md
83
+ - README.md
84
+ - Rakefile
85
+ - lib/neows.rb
86
+ - lib/neows/attributes.rb
87
+ - lib/neows/client.rb
88
+ - lib/neows/models/base_model.rb
89
+ - lib/neows/models/browse.rb
90
+ - lib/neows/models/close_approach_data.rb
91
+ - lib/neows/models/estimated_diameter.rb
92
+ - lib/neows/models/estimated_diameter_min_max.rb
93
+ - lib/neows/models/feed.rb
94
+ - lib/neows/models/link.rb
95
+ - lib/neows/models/link_navigation.rb
96
+ - lib/neows/models/links.rb
97
+ - lib/neows/models/miss_distance.rb
98
+ - lib/neows/models/near_earth_object.rb
99
+ - lib/neows/models/orbital_data.rb
100
+ - lib/neows/models/page.rb
101
+ - lib/neows/models/pagination.rb
102
+ - lib/neows/models/relative_velocity.rb
103
+ - lib/neows/models/stat.rb
104
+ - lib/neows/rest/api.rb
105
+ - lib/neows/rest/client.rb
106
+ - lib/neows/rest/feed.rb
107
+ - lib/neows/rest/neo.rb
108
+ - lib/neows/rest/request.rb
109
+ - lib/neows/rest/stats.rb
110
+ - lib/neows/rest/utils.rb
111
+ - lib/neows/utils.rb
112
+ - lib/neows/version.rb
113
+ - neows.gemspec
114
+ homepage: https://github.com/SpaceRocks/neows-ruby
115
+ licenses:
116
+ - MIT
117
+ metadata: {}
118
+ post_install_message:
119
+ rdoc_options: []
120
+ require_paths:
121
+ - lib
122
+ required_ruby_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: 1.9.3
127
+ required_rubygems_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ requirements: []
133
+ rubyforge_project:
134
+ rubygems_version: 2.4.5
135
+ signing_key:
136
+ specification_version: 4
137
+ summary: A Ruby interface to the NeoWs API
138
+ test_files: []
139
+ has_rdoc: