spacex 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +53 -0
  3. data/.rspec +2 -0
  4. data/.rubocop.yml +14 -0
  5. data/.rubocop_todo.yml +24 -0
  6. data/.ruby-version +1 -0
  7. data/.travis.yml +6 -0
  8. data/CHANGELOG.md +53 -0
  9. data/CONTRIBUTING.md +35 -0
  10. data/Gemfile +7 -0
  11. data/LICENSE +21 -0
  12. data/README.md +495 -0
  13. data/Rakefile +19 -0
  14. data/lib/spacex.rb +19 -0
  15. data/lib/spacex/base_request.rb +57 -0
  16. data/lib/spacex/capsules.rb +19 -0
  17. data/lib/spacex/company_info.rb +7 -0
  18. data/lib/spacex/cores.rb +22 -0
  19. data/lib/spacex/dragon_capsules.rb +33 -0
  20. data/lib/spacex/endpoint.rb +3 -0
  21. data/lib/spacex/history.rb +7 -0
  22. data/lib/spacex/launches.rb +27 -0
  23. data/lib/spacex/missions.rb +18 -0
  24. data/lib/spacex/payloads.rb +7 -0
  25. data/lib/spacex/resource.rb +5 -0
  26. data/lib/spacex/roadster.rb +7 -0
  27. data/lib/spacex/rockets.rb +7 -0
  28. data/lib/spacex/ships.rb +33 -0
  29. data/lib/spacex/version.rb +7 -0
  30. data/rubocop.yml +8 -0
  31. data/spacex.gemspec +29 -0
  32. data/spec/fixtures/spacex/capsules.yml +83 -0
  33. data/spec/fixtures/spacex/capsules/C202.yml +123 -0
  34. data/spec/fixtures/spacex/company_info/info.yml +129 -0
  35. data/spec/fixtures/spacex/cores.yml +62 -0
  36. data/spec/fixtures/spacex/cores/B1041.yml +123 -0
  37. data/spec/fixtures/spacex/dragon_capsules/info.yml +77 -0
  38. data/spec/fixtures/spacex/dragon_capsules/info/dragon1.yml +131 -0
  39. data/spec/fixtures/spacex/history/info.yml +62 -0
  40. data/spec/fixtures/spacex/history/info/4.yml +62 -0
  41. data/spec/fixtures/spacex/launches.yml +62 -0
  42. data/spec/fixtures/spacex/launches/68.yml +69 -0
  43. data/spec/fixtures/spacex/launches/all.yml +62 -0
  44. data/spec/fixtures/spacex/launches/info.yml +62 -0
  45. data/spec/fixtures/spacex/launches/latest.yml +245 -0
  46. data/spec/fixtures/spacex/launches/next.yml +123 -0
  47. data/spec/fixtures/spacex/launches/past.yml +62 -0
  48. data/spec/fixtures/spacex/launches/upcoming.yml +64 -0
  49. data/spec/fixtures/spacex/missions/F3364BF.yml +157 -0
  50. data/spec/fixtures/spacex/missions/info.yml +62 -0
  51. data/spec/fixtures/spacex/payloads/RatSat.yml +62 -0
  52. data/spec/fixtures/spacex/payloads/info.yml +62 -0
  53. data/spec/fixtures/spacex/roadster/info.yml +133 -0
  54. data/spec/fixtures/spacex/rockets/info.yml +105 -0
  55. data/spec/fixtures/spacex/rockets/info/falcon1.yml +139 -0
  56. data/spec/fixtures/spacex/rockets/info/invalid.yml +61 -0
  57. data/spec/fixtures/spacex/ships/info.yml +139 -0
  58. data/spec/fixtures/spacex/ships/info/AMERICANCHAMPION.yml +125 -0
  59. data/spec/spacex/capsules_spec.rb +38 -0
  60. data/spec/spacex/company_info_spec.rb +27 -0
  61. data/spec/spacex/cores_spec.rb +45 -0
  62. data/spec/spacex/dragon_capsules_spec.rb +107 -0
  63. data/spec/spacex/endpoint_spec.rb +9 -0
  64. data/spec/spacex/history_spec.rb +50 -0
  65. data/spec/spacex/launches_spec.rb +652 -0
  66. data/spec/spacex/missions_spec.rb +35 -0
  67. data/spec/spacex/payloads_spec.rb +62 -0
  68. data/spec/spacex/roadster_spec.rb +36 -0
  69. data/spec/spacex/rockets_spec.rb +210 -0
  70. data/spec/spacex/ships_spec.rb +65 -0
  71. data/spec/spacex/version_spec.rb +7 -0
  72. data/spec/spec_helper.rb +20 -0
  73. data/spec/support/vcr.rb +11 -0
  74. metadata +283 -0
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ require 'bundler/gem_tasks'
6
+
7
+ Bundler.setup :default, :development
8
+
9
+ require 'rspec/core'
10
+ require 'rspec/core/rake_task'
11
+
12
+ RSpec::Core::RakeTask.new(:spec) do |spec|
13
+ spec.pattern = FileList['spec/**/*_spec.rb']
14
+ end
15
+
16
+ require 'rubocop/rake_task'
17
+ RuboCop::RakeTask.new
18
+
19
+ task default: %i[rubocop spec]
@@ -0,0 +1,19 @@
1
+ require 'faraday'
2
+ require 'faraday_middleware'
3
+ require 'faraday_middleware/response_middleware'
4
+ require 'hashie'
5
+
6
+ require_relative 'spacex/base_request'
7
+ require_relative 'spacex/capsules'
8
+ require_relative 'spacex/company_info'
9
+ require_relative 'spacex/cores'
10
+ require_relative 'spacex/dragon_capsules'
11
+ require_relative 'spacex/endpoint'
12
+ require_relative 'spacex/history'
13
+ require_relative 'spacex/launches'
14
+ require_relative 'spacex/missions'
15
+ require_relative 'spacex/payloads'
16
+ require_relative 'spacex/roadster'
17
+ require_relative 'spacex/rockets'
18
+ require_relative 'spacex/ships'
19
+ require_relative 'spacex/version'
@@ -0,0 +1,57 @@
1
+ module SPACEX
2
+ class Response < Hashie::Mash
3
+ disable_warnings
4
+ end
5
+
6
+ module BaseRequest
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 |c|
50
+ c.use ::FaradayMiddleware::ParseJson
51
+ c.use Faraday::Response::RaiseError
52
+ c.use Faraday::Adapter::NetHttp
53
+ end
54
+ end
55
+ end
56
+ end
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
@@ -0,0 +1,7 @@
1
+ module SPACEX
2
+ module CompanyInfo
3
+ def self.info
4
+ SPACEX::BaseRequest.info('info')
5
+ end
6
+ end
7
+ end
@@ -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
@@ -0,0 +1,3 @@
1
+ module SPACEX
2
+ ENDPOINT_URI = 'https://api.spacexdata.com/v3'.freeze
3
+ end
@@ -0,0 +1,7 @@
1
+ module SPACEX
2
+ module History
3
+ def self.info(id = nil)
4
+ SPACEX::BaseRequest.info("history/#{id}")
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,27 @@
1
+ module SPACEX
2
+ module Launches
3
+ def self.info(flight_number = nil)
4
+ SPACEX::BaseRequest.info("launches/#{flight_number}")
5
+ end
6
+
7
+ def self.latest
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
25
+ end
26
+ end
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
@@ -0,0 +1,7 @@
1
+ module SPACEX
2
+ module Payloads
3
+ def self.info(id = nil)
4
+ SPACEX::BaseRequest.info("payloads/#{id}")
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ module SPACEX
2
+ class Resource < Hashie::Trash
3
+ include Hashie::Extensions::IgnoreUndeclared
4
+ end
5
+ end
@@ -0,0 +1,7 @@
1
+ module SPACEX
2
+ module Roadster
3
+ def self.info
4
+ SPACEX::BaseRequest.info('roadster')
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module SPACEX
2
+ module Rockets
3
+ def self.info(rocket_id = nil)
4
+ SPACEX::BaseRequest.info("rockets/#{rocket_id}")
5
+ end
6
+ end
7
+ end
@@ -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
@@ -0,0 +1,7 @@
1
+ module SPACEX
2
+ VERSION = '1.0.1'.freeze
3
+
4
+ def self.help
5
+ puts 'https://github.com/rodolfobandeira/spacex'
6
+ end
7
+ end
@@ -0,0 +1,8 @@
1
+ AllCops:
2
+ Exclude:
3
+ - vendor/**/*
4
+
5
+ Naming/MethodName:
6
+ Enabled: false
7
+
8
+ inherit_from: .rubocop_todo.yml
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ $LOAD_PATH.push File.expand_path('lib', __dir__)
4
+ require 'spacex/version'
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = 'spacex'
8
+ s.bindir = 'bin'
9
+ s.version = SPACEX::VERSION
10
+ s.summary = 'SpaceX API with Ruby'
11
+ s.description = 'Ruby library to consume SpaceX launch data'
12
+ s.authors = ['Rodolfo Bandeira']
13
+ s.email = 'rodolfobandeira@protonmail.com'
14
+ s.platform = Gem::Platform::RUBY
15
+ s.homepage = 'https://github.com/rodolfobandeira/spacex'
16
+ s.license = 'MIT'
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- spec/*`.split("\n")
19
+ s.require_paths = ['lib']
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
+ s.add_development_dependency 'rake', '~> 10'
25
+ s.add_development_dependency 'rspec', '~> 3.8'
26
+ s.add_development_dependency 'rubocop', '0.51.0'
27
+ s.add_development_dependency 'vcr', '~> 4'
28
+ s.add_development_dependency 'webmock', '~> 3.4'
29
+ end
@@ -0,0 +1,83 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://api.spacexdata.com/v3/capsules/
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.15.3
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
+ - Mon, 15 Oct 2018 04:13:37 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=dd8346f9a0220b57866735728f74ebd191539576817; expires=Tue, 15-Oct-19
31
+ 04:13:37 GMT; path=/; domain=.spacexdata.com; HttpOnly; Secure
32
+ Vary:
33
+ - Accept-Encoding, Origin
34
+ X-Dns-Prefetch-Control:
35
+ - 'off'
36
+ X-Frame-Options:
37
+ - SAMEORIGIN
38
+ Strict-Transport-Security:
39
+ - max-age=15552000; includeSubDomains
40
+ X-Download-Options:
41
+ - noopen
42
+ X-Content-Type-Options:
43
+ - nosniff
44
+ X-Xss-Protection:
45
+ - 1; mode=block
46
+ Access-Control-Allow-Origin:
47
+ - "*"
48
+ X-Response-Time:
49
+ - 49ms
50
+ Expect-Ct:
51
+ - max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
52
+ Server:
53
+ - cloudflare
54
+ Cf-Ray:
55
+ - 469f74439912572f-IAD
56
+ body:
57
+ encoding: ASCII-8BIT
58
+ string: '[{"capsule_serial":"C201","capsule_id":"dragon2","status":"active","original_launch":null,"original_launch_unix":null,"missions":[],"landings":0,"type":"Dragon
59
+ 2.0","details":"Pressure vessel used for Dragon 2 structural testing. Rumored
60
+ to be repurposed for first Red Dragon Mission","reuse_count":0},{"capsule_serial":"C202","capsule_id":"dragon2","status":"active","original_launch":null,"original_launch_unix":null,"missions":[],"landings":0,"type":"Dragon
61
+ 2.0","details":"Capsule used to qualify Dragon 2''s environmental control
62
+ and life support systems.","reuse_count":0},{"capsule_serial":"C203","capsule_id":"dragon2","status":"active","original_launch":null,"original_launch_unix":null,"missions":[],"landings":0,"type":"Dragon
63
+ 2.0","details":"Rumored to be used for Inflight Abort Test after DM-1","reuse_count":0},{"capsule_serial":"C204","capsule_id":"dragon2","status":"active","original_launch":null,"original_launch_unix":null,"missions":[],"landings":0,"type":"Dragon
64
+ 2.0","details":"Currently in construction for use in DM-2","reuse_count":0},{"capsule_serial":"C205","capsule_id":"dragon2","status":"active","original_launch":null,"original_launch_unix":null,"missions":[],"landings":0,"type":"Dragon
65
+ 2.0","details":"In construction for use in first mission in contract under
66
+ the CCtCap contract","reuse_count":0},{"capsule_serial":"C101","capsule_id":"dragon1","status":"retired","original_launch":"2010-12-08T15:43:00.000Z","original_launch_unix":1291822980,"missions":[{"name":"COTS
67
+ 1","flight":7}],"landings":0,"type":"Dragon 1.0","details":"Reentered after
68
+ three weeks in orbit","reuse_count":0},{"capsule_serial":"C102","capsule_id":"dragon1","status":"retired","original_launch":"2012-05-02T07:44:00.000Z","original_launch_unix":1335944640,"missions":[{"name":"COTS
69
+ 2","flight":8}],"landings":1,"type":"Dragon 1.0","details":"First Dragon spacecraft","reuse_count":0},{"capsule_serial":"C103","capsule_id":"dragon1","status":"unknown","original_launch":"2012-10-08T00:35:00.000Z","original_launch_unix":1349656500,"missions":[{"name":"CRS-1","flight":9}],"landings":1,"type":"Dragon
70
+ 1.0","details":"First of twenty missions flown under the CRS1 contract","reuse_count":0},{"capsule_serial":"C104","capsule_id":"dragon1","status":"unknown","original_launch":"2013-03-01T19:10:00.000Z","original_launch_unix":1362165000,"missions":[{"name":"CRS-2","flight":10}],"landings":1,"type":"Dragon
71
+ 1.0","details":null,"reuse_count":0},{"capsule_serial":"C105","capsule_id":"dragon1","status":"unknown","original_launch":"2014-04-18T19:25:00.000Z","original_launch_unix":1397849100,"missions":[{"name":"CRS-3","flight":14}],"landings":1,"type":"Dragon
72
+ 1.1","details":"First Dragon v1.1 capsule","reuse_count":0},{"capsule_serial":"C106","capsule_id":"dragon1","status":"active","original_launch":"2014-09-21T05:52:00.000Z","original_launch_unix":1411278720,"missions":[{"name":"CRS-4","flight":18},{"name":"CRS-11","flight":41}],"landings":2,"type":"Dragon
73
+ 1.1","details":"First Dragon capsule to be reused","reuse_count":1},{"capsule_serial":"C107","capsule_id":"dragon1","status":"unknown","original_launch":"2015-01-10T09:47:00.000Z","original_launch_unix":1420883220,"missions":[{"name":"CRS-5","flight":19}],"landings":1,"type":"Dragon
74
+ 1.1","details":null,"reuse_count":0},{"capsule_serial":"C108","capsule_id":"dragon1","status":"active","original_launch":"2015-04-14T20:10:00.000Z","original_launch_unix":1429042200,"missions":[{"name":"CRS-6","flight":22},{"name":"CRS-13","flight":51}],"landings":2,"type":"Dragon
75
+ 1.1","details":"Second Dragon capsule to be reused","reuse_count":1},{"capsule_serial":"C109","capsule_id":"dragon1","status":"destroyed","original_launch":"2015-06-28T14:21:00.000Z","original_launch_unix":1435501260,"missions":[{"name":"CRS-7","flight":24}],"landings":0,"type":"Dragon
76
+ 1.1","details":"Destroyed on impact after F9 launch failure","reuse_count":0},{"capsule_serial":"C110","capsule_id":"dragon1","status":"active","original_launch":"2016-04-08T20:43:00.000Z","original_launch_unix":1460148180,"missions":[{"name":"CRS-8","flight":28},{"name":"CRS-14","flight":59}],"landings":2,"type":"Dragon
77
+ 1.1","details":null,"reuse_count":1},{"capsule_serial":"C111","capsule_id":"dragon1","status":"active","original_launch":"2016-07-18T04:45:00.000Z","original_launch_unix":1468817100,"missions":[{"name":"CRS-9","flight":32},{"name":"CRS-15","flight":64}],"landings":2,"type":"Dragon
78
+ 1.1","details":null,"reuse_count":1},{"capsule_serial":"C112","capsule_id":"dragon1","status":"active","original_launch":"2017-02-19T14:39:00.000Z","original_launch_unix":1487515140,"missions":[{"name":"CRS-10","flight":36}],"landings":1,"type":"Dragon
79
+ 1.1","details":null,"reuse_count":0},{"capsule_serial":"C113","capsule_id":"dragon1","status":"active","original_launch":"2017-08-14T16:31:00.000Z","original_launch_unix":1502728260,"missions":[{"name":"CRS-12","flight":45}],"landings":1,"type":"Dragon
80
+ 1.1","details":"The last newly manufactured Dragon 1","reuse_count":0}]'
81
+ http_version:
82
+ recorded_at: Mon, 15 Oct 2018 04:13:37 GMT
83
+ recorded_with: VCR 4.0.0