spacex 0.0.5 → 1.0.2

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.
Files changed (82) hide show
  1. checksums.yaml +4 -4
  2. data/.github/ISSUE_TEMPLATE.md +7 -0
  3. data/.github/PULL_REQUEST_TEMPLATE.md +6 -0
  4. data/.gitignore +1 -0
  5. data/.rubocop.yml +6 -0
  6. data/.rubocop_todo.yml +9 -23
  7. data/.ruby-version +1 -1
  8. data/.travis.yml +18 -3
  9. data/CHANGELOG.md +61 -0
  10. data/CONTRIBUTING.md +37 -0
  11. data/Gemfile +4 -2
  12. data/README.md +458 -25
  13. data/lib/spacex.rb +15 -4
  14. data/lib/spacex/api_info.rb +7 -0
  15. data/lib/spacex/base_request.rb +51 -13
  16. data/lib/spacex/capsules.rb +19 -0
  17. data/lib/spacex/company_info.rb +1 -3
  18. data/lib/spacex/cores.rb +22 -0
  19. data/lib/spacex/dragon_capsules.rb +33 -0
  20. data/lib/spacex/endpoint.rb +1 -3
  21. data/lib/spacex/history.rb +7 -0
  22. data/lib/spacex/landing_pads.rb +11 -0
  23. data/lib/spacex/launch_pads.rb +11 -0
  24. data/lib/spacex/launches.rb +21 -3
  25. data/lib/spacex/missions.rb +18 -0
  26. data/lib/spacex/payloads.rb +7 -0
  27. data/lib/spacex/resource.rb +5 -0
  28. data/lib/spacex/roadster.rb +7 -0
  29. data/lib/spacex/rockets.rb +7 -0
  30. data/lib/spacex/ships.rb +33 -0
  31. data/lib/spacex/version.rb +1 -4
  32. data/spacex.gemspec +8 -8
  33. data/spec/fixtures/spacex/api_info/info.yml +65 -0
  34. data/spec/fixtures/spacex/capsules.yml +83 -0
  35. data/spec/fixtures/spacex/capsules/C202.yml +123 -0
  36. data/spec/fixtures/spacex/company_info/info.yml +75 -14
  37. data/spec/fixtures/spacex/cores.yml +62 -0
  38. data/spec/fixtures/spacex/cores/B1041.yml +123 -0
  39. data/spec/fixtures/spacex/dragon_capsules/info.yml +77 -0
  40. data/spec/fixtures/spacex/dragon_capsules/info/dragon1.yml +131 -0
  41. data/spec/fixtures/spacex/history/info.yml +62 -0
  42. data/spec/fixtures/spacex/history/info/4.yml +62 -0
  43. data/spec/fixtures/spacex/landing_pads/info.yml +68 -0
  44. data/spec/fixtures/spacex/landing_pads/info/LZ-4.yml +70 -0
  45. data/spec/fixtures/spacex/launch_pads/info.yml +104 -0
  46. data/spec/fixtures/spacex/launch_pads/info/vafb_slc_4e.yml +71 -0
  47. data/spec/fixtures/spacex/launches.yml +62 -0
  48. data/spec/fixtures/spacex/launches/68.yml +69 -0
  49. data/spec/fixtures/spacex/launches/all.yml +62 -0
  50. data/spec/fixtures/spacex/launches/info.yml +62 -0
  51. data/spec/fixtures/spacex/launches/latest.yml +8 -8
  52. data/spec/fixtures/spacex/launches/next.yml +123 -0
  53. data/spec/fixtures/spacex/launches/past.yml +62 -0
  54. data/spec/fixtures/spacex/launches/upcoming.yml +64 -0
  55. data/spec/fixtures/spacex/missions/F3364BF.yml +157 -0
  56. data/spec/fixtures/spacex/missions/info.yml +62 -0
  57. data/spec/fixtures/spacex/payloads/RatSat.yml +62 -0
  58. data/spec/fixtures/spacex/payloads/info.yml +62 -0
  59. data/spec/fixtures/spacex/roadster/info.yml +133 -0
  60. data/spec/fixtures/spacex/rockets/info.yml +105 -0
  61. data/spec/fixtures/spacex/rockets/info/falcon1.yml +139 -0
  62. data/spec/fixtures/spacex/rockets/info/invalid.yml +61 -0
  63. data/spec/fixtures/spacex/ships/info.yml +139 -0
  64. data/spec/fixtures/spacex/ships/info/AMERICANCHAMPION.yml +125 -0
  65. data/spec/spacex/api_info_spec.rb +16 -0
  66. data/spec/spacex/capsules_spec.rb +38 -0
  67. data/spec/spacex/company_info_spec.rb +3 -5
  68. data/spec/spacex/cores_spec.rb +45 -0
  69. data/spec/spacex/dragon_capsules_spec.rb +107 -0
  70. data/spec/spacex/endpoint_spec.rb +9 -0
  71. data/spec/spacex/history_spec.rb +50 -0
  72. data/spec/spacex/landing_pads_spec.rb +72 -0
  73. data/spec/spacex/launch_pads_spec.rb +77 -0
  74. data/spec/spacex/launches_spec.rb +580 -16
  75. data/spec/spacex/missions_spec.rb +35 -0
  76. data/spec/spacex/payloads_spec.rb +62 -0
  77. data/spec/spacex/roadster_spec.rb +36 -0
  78. data/spec/spacex/rockets_spec.rb +210 -0
  79. data/spec/spacex/ships_spec.rb +65 -0
  80. data/spec/spacex/version_spec.rb +1 -3
  81. data/spec/spec_helper.rb +9 -0
  82. metadata +140 -23
@@ -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/version'
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'
@@ -0,0 +1,7 @@
1
+ module SPACEX
2
+ module ApiInfo
3
+ def self.info
4
+ SPACEX::BaseRequest.info('')
5
+ end
6
+ end
7
+ end
@@ -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
- def self.get(path)
6
- data = Faraday.new(
7
- url: "#{SPACEX::ROOT_URI}/#{path}",
8
- request: {
9
- params_encoder: Faraday::FlatParamsEncoder
10
- }
11
- ) do |c|
12
- c.use ::FaradayMiddleware::ParseJson
13
- c.use Faraday::Response::RaiseError
14
- c.use Faraday::Adapter::NetHttp
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
@@ -1,9 +1,7 @@
1
- # frozen_string_literal: true
2
-
3
1
  module SPACEX
4
2
  module CompanyInfo
5
3
  def self.info
6
- SPACEX::BaseRequest.get('info')
4
+ SPACEX::BaseRequest.info('info')
7
5
  end
8
6
  end
9
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
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  module SPACEX
4
- ENDPOINT = 'https://api.spacexdata.com/v2/'
2
+ ENDPOINT_URI = 'https://api.spacexdata.com/v3'.freeze
5
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,11 @@
1
+ module SPACEX
2
+ module LandingPads
3
+ def self.info(id = nil)
4
+ SPACEX::BaseRequest.info("landpads/#{id}")
5
+ end
6
+
7
+ def self.all
8
+ info
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module SPACEX
2
+ module LaunchPads
3
+ def self.info(site_id = nil)
4
+ SPACEX::BaseRequest.info("launchpads/#{site_id}")
5
+ end
6
+
7
+ def self.all
8
+ info
9
+ end
10
+ end
11
+ end
@@ -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.get('launches/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
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
@@ -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
@@ -1,8 +1,5 @@
1
- # frozen_string_literal: true
2
-
3
1
  module SPACEX
4
- VERSION = '0.0.5'
5
- ROOT_URI = 'https://api.spacexdata.com/v2'
2
+ VERSION = '1.0.2'.freeze
6
3
 
7
4
  def self.help
8
5
  puts 'https://github.com/rodolfobandeira/spacex'
@@ -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.date = '2018-08-17'
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', '>= 0.9'
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