spacex 0.0.5 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/ISSUE_TEMPLATE.md +7 -0
- data/.github/PULL_REQUEST_TEMPLATE.md +6 -0
- data/.gitignore +1 -0
- data/.rubocop.yml +6 -0
- data/.rubocop_todo.yml +9 -23
- data/.ruby-version +1 -1
- data/.travis.yml +18 -3
- data/CHANGELOG.md +61 -0
- data/CONTRIBUTING.md +37 -0
- data/Gemfile +4 -2
- data/README.md +458 -25
- data/lib/spacex.rb +15 -4
- data/lib/spacex/api_info.rb +7 -0
- data/lib/spacex/base_request.rb +51 -13
- data/lib/spacex/capsules.rb +19 -0
- data/lib/spacex/company_info.rb +1 -3
- data/lib/spacex/cores.rb +22 -0
- data/lib/spacex/dragon_capsules.rb +33 -0
- data/lib/spacex/endpoint.rb +1 -3
- data/lib/spacex/history.rb +7 -0
- data/lib/spacex/landing_pads.rb +11 -0
- data/lib/spacex/launch_pads.rb +11 -0
- data/lib/spacex/launches.rb +21 -3
- data/lib/spacex/missions.rb +18 -0
- data/lib/spacex/payloads.rb +7 -0
- data/lib/spacex/resource.rb +5 -0
- data/lib/spacex/roadster.rb +7 -0
- data/lib/spacex/rockets.rb +7 -0
- data/lib/spacex/ships.rb +33 -0
- data/lib/spacex/version.rb +1 -4
- data/spacex.gemspec +8 -8
- data/spec/fixtures/spacex/api_info/info.yml +65 -0
- data/spec/fixtures/spacex/capsules.yml +83 -0
- data/spec/fixtures/spacex/capsules/C202.yml +123 -0
- data/spec/fixtures/spacex/company_info/info.yml +75 -14
- data/spec/fixtures/spacex/cores.yml +62 -0
- data/spec/fixtures/spacex/cores/B1041.yml +123 -0
- data/spec/fixtures/spacex/dragon_capsules/info.yml +77 -0
- data/spec/fixtures/spacex/dragon_capsules/info/dragon1.yml +131 -0
- data/spec/fixtures/spacex/history/info.yml +62 -0
- data/spec/fixtures/spacex/history/info/4.yml +62 -0
- data/spec/fixtures/spacex/landing_pads/info.yml +68 -0
- data/spec/fixtures/spacex/landing_pads/info/LZ-4.yml +70 -0
- data/spec/fixtures/spacex/launch_pads/info.yml +104 -0
- data/spec/fixtures/spacex/launch_pads/info/vafb_slc_4e.yml +71 -0
- data/spec/fixtures/spacex/launches.yml +62 -0
- data/spec/fixtures/spacex/launches/68.yml +69 -0
- data/spec/fixtures/spacex/launches/all.yml +62 -0
- data/spec/fixtures/spacex/launches/info.yml +62 -0
- data/spec/fixtures/spacex/launches/latest.yml +8 -8
- data/spec/fixtures/spacex/launches/next.yml +123 -0
- data/spec/fixtures/spacex/launches/past.yml +62 -0
- data/spec/fixtures/spacex/launches/upcoming.yml +64 -0
- data/spec/fixtures/spacex/missions/F3364BF.yml +157 -0
- data/spec/fixtures/spacex/missions/info.yml +62 -0
- data/spec/fixtures/spacex/payloads/RatSat.yml +62 -0
- data/spec/fixtures/spacex/payloads/info.yml +62 -0
- data/spec/fixtures/spacex/roadster/info.yml +133 -0
- data/spec/fixtures/spacex/rockets/info.yml +105 -0
- data/spec/fixtures/spacex/rockets/info/falcon1.yml +139 -0
- data/spec/fixtures/spacex/rockets/info/invalid.yml +61 -0
- data/spec/fixtures/spacex/ships/info.yml +139 -0
- data/spec/fixtures/spacex/ships/info/AMERICANCHAMPION.yml +125 -0
- data/spec/spacex/api_info_spec.rb +16 -0
- data/spec/spacex/capsules_spec.rb +38 -0
- data/spec/spacex/company_info_spec.rb +3 -5
- data/spec/spacex/cores_spec.rb +45 -0
- data/spec/spacex/dragon_capsules_spec.rb +107 -0
- data/spec/spacex/endpoint_spec.rb +9 -0
- data/spec/spacex/history_spec.rb +50 -0
- data/spec/spacex/landing_pads_spec.rb +72 -0
- data/spec/spacex/launch_pads_spec.rb +77 -0
- data/spec/spacex/launches_spec.rb +580 -16
- data/spec/spacex/missions_spec.rb +35 -0
- data/spec/spacex/payloads_spec.rb +62 -0
- data/spec/spacex/roadster_spec.rb +36 -0
- data/spec/spacex/rockets_spec.rb +210 -0
- data/spec/spacex/ships_spec.rb +65 -0
- data/spec/spacex/version_spec.rb +1 -3
- data/spec/spec_helper.rb +9 -0
- metadata +140 -23
data/lib/spacex.rb
CHANGED
@@ -1,11 +1,22 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
1
|
require 'faraday'
|
4
2
|
require 'faraday_middleware'
|
5
3
|
require 'faraday_middleware/response_middleware'
|
6
4
|
require 'hashie'
|
7
5
|
|
6
|
+
require_relative 'spacex/api_info'
|
8
7
|
require_relative 'spacex/base_request'
|
9
|
-
require_relative 'spacex/
|
10
|
-
require_relative 'spacex/launches'
|
8
|
+
require_relative 'spacex/capsules'
|
11
9
|
require_relative 'spacex/company_info'
|
10
|
+
require_relative 'spacex/cores'
|
11
|
+
require_relative 'spacex/dragon_capsules'
|
12
|
+
require_relative 'spacex/endpoint'
|
13
|
+
require_relative 'spacex/history'
|
14
|
+
require_relative 'spacex/landing_pads'
|
15
|
+
require_relative 'spacex/launch_pads'
|
16
|
+
require_relative 'spacex/launches'
|
17
|
+
require_relative 'spacex/missions'
|
18
|
+
require_relative 'spacex/payloads'
|
19
|
+
require_relative 'spacex/roadster'
|
20
|
+
require_relative 'spacex/rockets'
|
21
|
+
require_relative 'spacex/ships'
|
22
|
+
require_relative 'spacex/version'
|
data/lib/spacex/base_request.rb
CHANGED
@@ -1,19 +1,57 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
1
|
module SPACEX
|
2
|
+
class Response < Hashie::Mash
|
3
|
+
disable_warnings
|
4
|
+
end
|
5
|
+
|
4
6
|
module BaseRequest
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
7
|
+
class << self
|
8
|
+
def info(path, klass = nil, params = {})
|
9
|
+
response_body = get(path, params).body
|
10
|
+
process(response_body, klass)
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def get(path, params)
|
16
|
+
conn(path).get do |req|
|
17
|
+
req.params = params
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def process(response_body, klass)
|
22
|
+
if response_body.is_a? Array
|
23
|
+
response_body.map do |element|
|
24
|
+
processed_response(element, klass)
|
25
|
+
end
|
26
|
+
else
|
27
|
+
processed_response(response_body, klass)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def processed_response(response, klass)
|
32
|
+
if klass.nil?
|
33
|
+
spacex_response(response)
|
34
|
+
else
|
35
|
+
klass.new(spacex_response(response))
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def spacex_response(response)
|
40
|
+
SPACEX::Response.new(response)
|
41
|
+
end
|
42
|
+
|
43
|
+
def conn(path)
|
44
|
+
Faraday.new(
|
45
|
+
url: "#{SPACEX::ENDPOINT_URI}/#{path}",
|
46
|
+
request: {
|
47
|
+
params_encoder: Faraday::FlatParamsEncoder
|
48
|
+
}
|
49
|
+
) do |connection|
|
50
|
+
connection.use ::FaradayMiddleware::ParseJson
|
51
|
+
connection.use Faraday::Response::RaiseError
|
52
|
+
connection.adapter ::Faraday.default_adapter
|
53
|
+
end
|
15
54
|
end
|
16
|
-
Hashie::Mash.new(data.get.body)
|
17
55
|
end
|
18
56
|
end
|
19
57
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module SPACEX
|
2
|
+
class Capsules < Hashie::Trash
|
3
|
+
include Hashie::Extensions::IgnoreUndeclared
|
4
|
+
|
5
|
+
property 'capsule_serial'
|
6
|
+
property 'capsule_id'
|
7
|
+
property 'status'
|
8
|
+
property 'original_launch'
|
9
|
+
property 'original_launch_unix'
|
10
|
+
property 'missions'
|
11
|
+
property 'landings'
|
12
|
+
property 'type'
|
13
|
+
property 'details'
|
14
|
+
|
15
|
+
def self.info(capsule_serial = nil)
|
16
|
+
SPACEX::BaseRequest.info("capsules/#{capsule_serial}", SPACEX::Capsules)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/spacex/company_info.rb
CHANGED
data/lib/spacex/cores.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
module SPACEX
|
2
|
+
class Cores < Hashie::Trash
|
3
|
+
include Hashie::Extensions::IgnoreUndeclared
|
4
|
+
|
5
|
+
property 'core_serial'
|
6
|
+
property 'block'
|
7
|
+
property 'status'
|
8
|
+
property 'original_launch'
|
9
|
+
property 'original_launch_unix'
|
10
|
+
property 'missions'
|
11
|
+
property 'rtls_attempts'
|
12
|
+
property 'rtls_landings'
|
13
|
+
property 'asds_attempts'
|
14
|
+
property 'asds_landings'
|
15
|
+
property 'water_landing'
|
16
|
+
property 'details'
|
17
|
+
|
18
|
+
def self.info(core_serial = nil)
|
19
|
+
SPACEX::BaseRequest.info("cores/#{core_serial}", SPACEX::Cores)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module SPACEX
|
2
|
+
class DragonCapsules < Hashie::Trash
|
3
|
+
include Hashie::Extensions::IgnoreUndeclared
|
4
|
+
|
5
|
+
property 'capsule_id', from: 'id'
|
6
|
+
property 'name'
|
7
|
+
property 'type'
|
8
|
+
property 'active'
|
9
|
+
property 'crew_capacity'
|
10
|
+
property 'sidewall_angle_deg'
|
11
|
+
property 'orbit_duration_yr'
|
12
|
+
property 'dry_mass_kg'
|
13
|
+
property 'dry_mass_lb'
|
14
|
+
property 'first_flight'
|
15
|
+
property 'heat_shield'
|
16
|
+
property 'thrusters'
|
17
|
+
property 'launch_payload_mass'
|
18
|
+
property 'launch_payload_vol'
|
19
|
+
property 'return_payload_mass'
|
20
|
+
property 'return_payload_vol'
|
21
|
+
property 'pressurized_capsule'
|
22
|
+
property 'trunk'
|
23
|
+
property 'height_w_trunk'
|
24
|
+
property 'diameter'
|
25
|
+
property 'flickr_images'
|
26
|
+
property 'wikipedia'
|
27
|
+
property 'description'
|
28
|
+
|
29
|
+
def self.info(dragon_id = nil)
|
30
|
+
SPACEX::BaseRequest.info("dragons/#{dragon_id}", SPACEX::DragonCapsules)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/spacex/endpoint.rb
CHANGED
data/lib/spacex/launches.rb
CHANGED
@@ -1,9 +1,27 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
1
|
module SPACEX
|
4
2
|
module Launches
|
3
|
+
def self.info(flight_number = nil)
|
4
|
+
SPACEX::BaseRequest.info("launches/#{flight_number}")
|
5
|
+
end
|
6
|
+
|
5
7
|
def self.latest
|
6
|
-
SPACEX::BaseRequest.
|
8
|
+
SPACEX::BaseRequest.info('launches/latest')
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.next
|
12
|
+
SPACEX::BaseRequest.info('launches/next')
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.past
|
16
|
+
SPACEX::BaseRequest.info('launches/past')
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.upcoming
|
20
|
+
SPACEX::BaseRequest.info('launches/upcoming')
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.all
|
24
|
+
info
|
7
25
|
end
|
8
26
|
end
|
9
27
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module SPACEX
|
2
|
+
class Missions < Hashie::Trash
|
3
|
+
include Hashie::Extensions::IgnoreUndeclared
|
4
|
+
|
5
|
+
property 'mission_id'
|
6
|
+
property 'mission_name'
|
7
|
+
property 'manufacturers'
|
8
|
+
property 'payload_ids'
|
9
|
+
property 'wikipedia'
|
10
|
+
property 'website'
|
11
|
+
property 'twitter'
|
12
|
+
property 'description'
|
13
|
+
|
14
|
+
def self.info(mission_id = nil)
|
15
|
+
SPACEX::BaseRequest.info("missions/#{mission_id}", SPACEX::Missions)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/spacex/ships.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
module SPACEX
|
2
|
+
class Ships < Hashie::Trash
|
3
|
+
include Hashie::Extensions::IgnoreUndeclared
|
4
|
+
|
5
|
+
property 'ship_id', from: 'id'
|
6
|
+
property 'ship_name'
|
7
|
+
property 'ship_model'
|
8
|
+
property 'ship_type'
|
9
|
+
property 'roles'
|
10
|
+
property 'active'
|
11
|
+
property 'imo'
|
12
|
+
property 'mmsi'
|
13
|
+
property 'abs'
|
14
|
+
property 'ship_class', from: 'class'
|
15
|
+
property 'weight_lbs'
|
16
|
+
property 'weight_kg'
|
17
|
+
property 'year_built'
|
18
|
+
property 'home_port'
|
19
|
+
property 'status'
|
20
|
+
property 'speed_kn'
|
21
|
+
property 'course_deg'
|
22
|
+
property 'position'
|
23
|
+
property 'successful_landings'
|
24
|
+
property 'attempted_landings'
|
25
|
+
property 'missions'
|
26
|
+
property 'url'
|
27
|
+
property 'image'
|
28
|
+
|
29
|
+
def self.info(ship_id = nil)
|
30
|
+
SPACEX::BaseRequest.info("ships/#{ship_id}", SPACEX::Ships)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/spacex/version.rb
CHANGED
data/spacex.gemspec
CHANGED
@@ -7,8 +7,7 @@ Gem::Specification.new do |s|
|
|
7
7
|
s.name = 'spacex'
|
8
8
|
s.bindir = 'bin'
|
9
9
|
s.version = SPACEX::VERSION
|
10
|
-
s.
|
11
|
-
s.summary = 'Swap SpaceX API with Ruby'
|
10
|
+
s.summary = 'SpaceX API with Ruby'
|
12
11
|
s.description = 'Ruby library to consume SpaceX launch data'
|
13
12
|
s.authors = ['Rodolfo Bandeira']
|
14
13
|
s.email = 'rodolfobandeira@protonmail.com'
|
@@ -18,12 +17,13 @@ Gem::Specification.new do |s|
|
|
18
17
|
s.files = `git ls-files`.split("\n")
|
19
18
|
s.test_files = `git ls-files -- spec/*`.split("\n")
|
20
19
|
s.require_paths = ['lib']
|
21
|
-
s.add_dependency 'faraday', '
|
22
|
-
s.add_dependency 'faraday_middleware'
|
23
|
-
s.add_dependency 'hashie'
|
20
|
+
s.add_dependency 'faraday', '~> 0.9'
|
21
|
+
s.add_dependency 'faraday_middleware', '~> 0.12'
|
22
|
+
s.add_dependency 'hashie', '3.6.0'
|
23
|
+
s.add_development_dependency 'coveralls'
|
24
24
|
s.add_development_dependency 'rake', '~> 10'
|
25
|
-
s.add_development_dependency 'rspec'
|
25
|
+
s.add_development_dependency 'rspec', '~> 3.8'
|
26
26
|
s.add_development_dependency 'rubocop', '0.51.0'
|
27
|
-
s.add_development_dependency 'vcr'
|
28
|
-
s.add_development_dependency 'webmock'
|
27
|
+
s.add_development_dependency 'vcr', '~> 4'
|
28
|
+
s.add_development_dependency 'webmock', '~> 3.4'
|
29
29
|
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://api.spacexdata.com/v3/
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
User-Agent:
|
11
|
+
- Faraday v0.16.2
|
12
|
+
Accept-Encoding:
|
13
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
14
|
+
Accept:
|
15
|
+
- "*/*"
|
16
|
+
response:
|
17
|
+
status:
|
18
|
+
code: 200
|
19
|
+
message: OK
|
20
|
+
headers:
|
21
|
+
Date:
|
22
|
+
- Wed, 02 Oct 2019 01:04:51 GMT
|
23
|
+
Content-Type:
|
24
|
+
- application/json; charset=utf-8
|
25
|
+
Transfer-Encoding:
|
26
|
+
- chunked
|
27
|
+
Connection:
|
28
|
+
- keep-alive
|
29
|
+
Set-Cookie:
|
30
|
+
- __cfduid=dd7abdb6b7f9c36b6bdc298c15ec390b81569978291; expires=Thu, 01-Oct-20
|
31
|
+
01:04:51 GMT; path=/; domain=.spacexdata.com; HttpOnly; Secure
|
32
|
+
X-Dns-Prefetch-Control:
|
33
|
+
- 'off'
|
34
|
+
X-Frame-Options:
|
35
|
+
- SAMEORIGIN
|
36
|
+
Strict-Transport-Security:
|
37
|
+
- max-age=15552000; includeSubDomains
|
38
|
+
X-Download-Options:
|
39
|
+
- noopen
|
40
|
+
X-Content-Type-Options:
|
41
|
+
- nosniff
|
42
|
+
X-Xss-Protection:
|
43
|
+
- 1; mode=block
|
44
|
+
Vary:
|
45
|
+
- Origin
|
46
|
+
Access-Control-Allow-Origin:
|
47
|
+
- "*"
|
48
|
+
Access-Control-Expose-Headers:
|
49
|
+
- spacex-api-cache,spacex-api-count,spacex-api-response-time
|
50
|
+
Spacex-Api-Response-Time:
|
51
|
+
- 19ms
|
52
|
+
Expect-Ct:
|
53
|
+
- max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
|
54
|
+
Server:
|
55
|
+
- cloudflare
|
56
|
+
Cf-Ray:
|
57
|
+
- 51f2c3c2ae854a4c-GRU
|
58
|
+
body:
|
59
|
+
encoding: ASCII-8BIT
|
60
|
+
string: '{"project_name":"SpaceX-API","version":"3.1.0","project_link":"https://github.com/r-spacex/SpaceX-API","docs":"https://documenter.getpostman.com/view/2025350/RWaEzAiG","organization":"r/SpaceX","organization_link":"https://github.com/r-spacex","description":"Open
|
61
|
+
Source REST API for rocket, core, capsule, pad, and launch data, created and
|
62
|
+
maintained by the developers of the r/SpaceX organization"}'
|
63
|
+
http_version:
|
64
|
+
recorded_at: Wed, 02 Oct 2019 01:04:51 GMT
|
65
|
+
recorded_with: VCR 4.0.0
|