From 08886fb00fe1db52d88cf235801dc20f5ae713ac Mon Sep 17 00:00:00 2001 From: Chaitanya Kale Date: Thu, 11 Oct 2018 22:52:28 -0400 Subject: [PATCH 1/5] Implement Rockets endpoint ***Why?*** - To retrieve rocket's info using the rockets API endpoint provided by SpaceX ***How?*** - Created a Rockets model that exposes an `info` method - This method accepts an optional `rocket_id` - When none passed, it returns the information of all the rockets - Otherwise returns info of the specified rocket id ***Side effects*** - This implementation only makes the info method public whereas other classes in the module are exposing all the methods. This is something that can be fixed in a separate PR --- lib/spacex.rb | 1 + lib/spacex/rockets.rb | 48 ++++ spec/fixtures/spacex/rockets/info.yml | 107 +++++++++ spec/fixtures/spacex/rockets/info/falcon1.yml | 71 ++++++ spec/fixtures/spacex/rockets/info/invalid.yml | 61 +++++ spec/spacex/rockets_spec.rb | 218 ++++++++++++++++++ 6 files changed, 506 insertions(+) create mode 100644 lib/spacex/rockets.rb create mode 100644 spec/fixtures/spacex/rockets/info.yml create mode 100644 spec/fixtures/spacex/rockets/info/falcon1.yml create mode 100644 spec/fixtures/spacex/rockets/info/invalid.yml create mode 100644 spec/spacex/rockets_spec.rb diff --git a/lib/spacex.rb b/lib/spacex.rb index c6ea56d..3f40cc0 100644 --- a/lib/spacex.rb +++ b/lib/spacex.rb @@ -11,3 +11,4 @@ require_relative 'spacex/dragon_capsules' require_relative 'spacex/ships' require_relative 'spacex/missions' +require_relative 'spacex/rockets' diff --git a/lib/spacex/rockets.rb b/lib/spacex/rockets.rb new file mode 100644 index 0000000..cbe23e3 --- /dev/null +++ b/lib/spacex/rockets.rb @@ -0,0 +1,48 @@ +module SPACEX + class Rockets < Hashie::Trash + include Hashie::Extensions::IgnoreUndeclared + + property 'id' + property 'active' + property 'stages' + property 'boosters' + property 'cost_per_launch' + property 'success_rate_pct' + property 'first_flight' + property 'country' + property 'company' + property 'height' + property 'diameter' + property 'mass' + property 'payload_weights' + property 'first_stage' + property 'second_stage' + property 'engines' + property 'landing_legs' + property 'wikipedia' + property 'description' + property 'rocket_id' + property 'rocket_name' + property 'rocket_type' + + class << self + def info(rocket_id = nil) + get(rocket_id) + end + + private + + def retrieve_all + data = SPACEX::BaseRequest.call_api('rockets') + data.get.body.map { |k| SPACEX::Rockets.new(k) } + end + + def get(rocket_id = nil) + return retrieve_all if rocket_id.nil? + + data = SPACEX::BaseRequest.get("rockets/#{rocket_id}") + SPACEX::Rockets.new(data) + end + end + end +end diff --git a/spec/fixtures/spacex/rockets/info.yml b/spec/fixtures/spacex/rockets/info.yml new file mode 100644 index 0000000..3d70289 --- /dev/null +++ b/spec/fixtures/spacex/rockets/info.yml @@ -0,0 +1,107 @@ +--- +http_interactions: +- request: + method: get + uri: https://api.spacexdata.com/v3/rockets + body: + encoding: US-ASCII + string: '' + headers: + User-Agent: + - Faraday v0.15.3 + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + response: + status: + code: 200 + message: OK + headers: + Date: + - Fri, 12 Oct 2018 02:10:27 GMT + Content-Type: + - application/json; charset=utf-8 + Transfer-Encoding: + - chunked + Connection: + - keep-alive + Set-Cookie: + - __cfduid=d30c9e8194b786bd40a0a7204f2bf02e01539310227; expires=Sat, 12-Oct-19 + 02:10:27 GMT; path=/; domain=.spacexdata.com; HttpOnly; Secure + Vary: + - Accept-Encoding, Origin + X-Dns-Prefetch-Control: + - 'off' + X-Frame-Options: + - SAMEORIGIN + Strict-Transport-Security: + - max-age=15552000; includeSubDomains + X-Download-Options: + - noopen + X-Content-Type-Options: + - nosniff + X-Xss-Protection: + - 1; mode=block + Access-Control-Allow-Origin: + - "*" + X-Koa-Redis-Cache: + - 'true' + X-Response-Time: + - 2ms + Expect-Ct: + - max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct" + Server: + - cloudflare + Cf-Ray: + - 468607b7aea75735-IAD + body: + encoding: ASCII-8BIT + string: '[{"id":1,"active":false,"stages":2,"boosters":0,"cost_per_launch":6700000,"success_rate_pct":40,"first_flight":"2006-03-24","country":"Republic + of the Marshall Islands","company":"SpaceX","height":{"meters":22.25,"feet":73},"diameter":{"meters":1.68,"feet":5.5},"mass":{"kg":30146,"lb":66460},"payload_weights":[{"id":"leo","name":"Low + Earth Orbit","kg":450,"lb":992}],"first_stage":{"reusable":false,"engines":1,"fuel_amount_tons":44.3,"burn_time_sec":169,"thrust_sea_level":{"kN":420,"lbf":94000},"thrust_vacuum":{"kN":480,"lbf":110000}},"second_stage":{"engines":1,"fuel_amount_tons":3.38,"burn_time_sec":378,"thrust":{"kN":31,"lbf":7000},"payloads":{"option_1":"composite + fairing","composite_fairing":{"height":{"meters":3.5,"feet":11.5},"diameter":{"meters":1.5,"feet":4.9}}}},"engines":{"number":1,"type":"merlin","version":"1C","layout":"single","engine_loss_max":0,"propellant_1":"liquid + oxygen","propellant_2":"RP-1 kerosene","thrust_sea_level":{"kN":420,"lbf":94000},"thrust_vacuum":{"kN":480,"lbf":110000},"thrust_to_weight":96},"landing_legs":{"number":0,"material":null},"flickr_images":["https://www.spacex.com/sites/spacex/files/styles/media_gallery_large/public/2009_-_01_liftoff_south_full_wide_ro8a1280_edit.jpg?itok=8loiSGt1","https://www.spacex.com/sites/spacex/files/styles/media_gallery_large/public/2009_-_02_default_liftoff_west_full_wide_nn6p2062_xl.jpg?itok=p776nHsM"],"wikipedia":"https://en.wikipedia.org/wiki/Falcon_1","description":"The + Falcon 1 was an expendable launch system privately developed and manufactured + by SpaceX during 2006-2009. On 28 September 2008, Falcon 1 became the first + privately-developed liquid-fuel launch vehicle to go into orbit around the + Earth.","rocket_id":"falcon1","rocket_name":"Falcon 1","rocket_type":"rocket"},{"id":2,"active":true,"stages":2,"boosters":0,"cost_per_launch":50000000,"success_rate_pct":97,"first_flight":"2010-06-04","country":"United + States","company":"SpaceX","height":{"meters":70,"feet":229.6},"diameter":{"meters":3.7,"feet":12},"mass":{"kg":549054,"lb":1207920},"payload_weights":[{"id":"leo","name":"Low + Earth Orbit","kg":22800,"lb":50265},{"id":"gto","name":"Geosynchronous Transfer + Orbit","kg":8300,"lb":18300},{"id":"mars","name":"Mars Orbit","kg":4020,"lb":8860}],"first_stage":{"reusable":true,"engines":9,"fuel_amount_tons":385,"burn_time_sec":162,"thrust_sea_level":{"kN":7607,"lbf":1710000},"thrust_vacuum":{"kN":8227,"lbf":1849500}},"second_stage":{"engines":1,"fuel_amount_tons":90,"burn_time_sec":397,"thrust":{"kN":934,"lbf":210000},"payloads":{"option_1":"dragon","option_2":"composite + fairing","composite_fairing":{"height":{"meters":13.1,"feet":43},"diameter":{"meters":5.2,"feet":17.1}}}},"engines":{"number":9,"type":"merlin","version":"1D+","layout":"octaweb","engine_loss_max":2,"propellant_1":"liquid + oxygen","propellant_2":"RP-1 kerosene","thrust_sea_level":{"kN":845,"lbf":190000},"thrust_vacuum":{"kN":914,"lbf":205500},"thrust_to_weight":180.1},"landing_legs":{"number":4,"material":"carbon + fiber"},"flickr_images":["https://farm1.staticflickr.com/929/28787338307_3453a11a77_b.jpg","https://farm4.staticflickr.com/3955/32915197674_eee74d81bb_b.jpg","https://farm1.staticflickr.com/293/32312415025_6841e30bf1_b.jpg","https://farm1.staticflickr.com/623/23660653516_5b6cb301d1_b.jpg","https://farm6.staticflickr.com/5518/31579784413_d853331601_b.jpg","https://farm1.staticflickr.com/745/32394687645_a9c54a34ef_b.jpg"],"wikipedia":"https://en.wikipedia.org/wiki/Falcon_9","description":"Falcon + 9 is a two-stage rocket designed and manufactured by SpaceX for the reliable + and safe transport of satellites and the Dragon spacecraft into orbit.","rocket_id":"falcon9","rocket_name":"Falcon + 9","rocket_type":"rocket"},{"id":3,"active":true,"stages":2,"boosters":2,"cost_per_launch":90000000,"success_rate_pct":100,"first_flight":"2018-02-06","country":"United + States","company":"SpaceX","height":{"meters":70,"feet":229.6},"diameter":{"meters":12.2,"feet":39.9},"mass":{"kg":1420788,"lb":3125735},"payload_weights":[{"id":"leo","name":"Low + Earth Orbit","kg":63800,"lb":140660},{"id":"gto","name":"Geosynchronous Transfer + Orbit","kg":26700,"lb":58860},{"id":"mars","name":"Mars Orbit","kg":16800,"lb":37040},{"id":"pluto","name":"Pluto + Orbit","kg":3500,"lb":7720}],"first_stage":{"reusable":true,"engines":27,"fuel_amount_tons":1155,"cores":3,"burn_time_sec":162,"thrust_sea_level":{"kN":22819,"lbf":5130000},"thrust_vacuum":{"kN":24681,"lbf":5548500}},"second_stage":{"engines":1,"burn_time_sec":397,"thrust":{"kN":934,"lbf":210000},"payloads":{"option_1":"dragon","option_2":"composite + fairing","composite_fairing":{"height":{"meters":13.1,"feet":43},"diameter":{"meters":5.2,"feet":17.1}}}},"engines":{"number":27,"type":"merlin","version":"1D+","layout":"octaweb","engine_loss_max":6,"propellant_1":"liquid + oxygen","propellant_2":"RP-1 kerosene","thrust_sea_level":{"kN":845,"lbf":190000},"thrust_vacuum":{"kN":914,"lbf":205500},"thrust_to_weight":180.1},"landing_legs":{"number":12,"material":"carbon + fiber"},"flickr_images":["https://farm5.staticflickr.com/4599/38583829295_581f34dd84_b.jpg","https://farm5.staticflickr.com/4645/38583830575_3f0f7215e6_b.jpg","https://farm5.staticflickr.com/4696/40126460511_b15bf84c85_b.jpg","https://farm5.staticflickr.com/4711/40126461411_aabc643fd8_b.jpg"],"wikipedia":"https://en.wikipedia.org/wiki/Falcon_Heavy","description":"With + the ability to lift into orbit over 54 metric tons (119,000 lb)--a mass equivalent + to a 737 jetliner loaded with passengers, crew, luggage and fuel--Falcon Heavy + can lift more than twice the payload of the next closest operational vehicle, + the Delta IV Heavy, at one-third the cost.","rocket_id":"falconheavy","rocket_name":"Falcon + Heavy","rocket_type":"rocket"},{"id":4,"active":false,"stages":2,"boosters":0,"cost_per_launch":7000000,"success_rate_pct":0,"first_flight":"2019-12-01","country":"United + States","company":"SpaceX","height":{"meters":118,"feet":387},"diameter":{"meters":9,"feet":30},"mass":{"kg":4400000,"lb":9700000},"payload_weights":[{"id":"leo","name":"Low + Earth Orbit","kg":150000,"lb":330000},{"id":"mars","name":"Mars Orbit","kg":100000,"lb":220000}],"first_stage":{"reusable":true,"engines":31,"fuel_amount_tons":6700,"burn_time_sec":0,"thrust_sea_level":{"kN":128000,"lbf":28775544},"thrust_vacuum":{"kN":138000,"lbf":31023634}},"second_stage":{"engines":6,"fuel_amount_tons":1100,"burn_time_sec":0,"thrust":{"kN":1900,"lbf":427136},"payloads":{"option_1":"Spaceship","option_2":"composite + fairing","composite_fairing":{"height":{"meters":null,"feet":null},"diameter":{"meters":null,"feet":null}}}},"engines":{"number":31,"type":"raptor","version":"","layout":null,"engine_loss_max":null,"propellant_1":"liquid + oxygen","propellant_2":"liquid methane","thrust_sea_level":{"kN":1700,"lbf":382175},"thrust_vacuum":{"kN":1900,"lbf":427136},"thrust_to_weight":null},"landing_legs":{"number":4,"material":"carbon + fiber"},"flickr_images":["https://farm2.staticflickr.com/1861/30934146988_f3de261bb4_b.jpg","https://farm2.staticflickr.com/1854/30934146778_765ea9f486_b.jpg","https://farm2.staticflickr.com/1898/30934147078_31b54027b0_b.jpg","https://farm2.staticflickr.com/1845/43895099105_7329ee6bba_b.jpg"],"wikipedia":"https://en.wikipedia.org/wiki/BFR_(rocket)","description":"BFR + is a privately funded next-generation reusable launch vehicle and spacecraft + system developed by SpaceX. It was announced by Elon Musk in September 2017; + the first spacecraft prototype was being manufactured as of March 2018 and + will begin testing in early 2019. The overall space vehicle architecture includes + both launch vehicles and spacecraft that are intended to completely replace + all of SpaceX''s existing space hardware by the early 2020s as well as ground + infrastructure for rapid launch and relaunch, and zero-gravity propellant + transfer technology to be deployed in low Earth orbit (LEO). The large payload + to Earth orbit of up to 150,000 kg (330,000 lb) makes BFR a super heavy-lift + launch vehicle.","rocket_id":"bfr","rocket_name":"Big Falcon Rocket","rocket_type":"rocket"}]' + http_version: + recorded_at: Fri, 12 Oct 2018 02:10:27 GMT +recorded_with: VCR 4.0.0 diff --git a/spec/fixtures/spacex/rockets/info/falcon1.yml b/spec/fixtures/spacex/rockets/info/falcon1.yml new file mode 100644 index 0000000..936ab47 --- /dev/null +++ b/spec/fixtures/spacex/rockets/info/falcon1.yml @@ -0,0 +1,71 @@ +--- +http_interactions: +- request: + method: get + uri: https://api.spacexdata.com/v3/rockets/falcon1 + body: + encoding: US-ASCII + string: '' + headers: + User-Agent: + - Faraday v0.15.3 + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + response: + status: + code: 200 + message: OK + headers: + Date: + - Fri, 12 Oct 2018 02:10:27 GMT + Content-Type: + - application/json; charset=utf-8 + Transfer-Encoding: + - chunked + Connection: + - keep-alive + Set-Cookie: + - __cfduid=dfaf0f3f41e0848934a92bd657b8b0adb1539310227; expires=Sat, 12-Oct-19 + 02:10:27 GMT; path=/; domain=.spacexdata.com; HttpOnly; Secure + Vary: + - Accept-Encoding, Origin + X-Dns-Prefetch-Control: + - 'off' + X-Frame-Options: + - SAMEORIGIN + Strict-Transport-Security: + - max-age=15552000; includeSubDomains + X-Download-Options: + - noopen + X-Content-Type-Options: + - nosniff + X-Xss-Protection: + - 1; mode=block + Access-Control-Allow-Origin: + - "*" + X-Koa-Redis-Cache: + - 'true' + X-Response-Time: + - 4ms + Expect-Ct: + - max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct" + Server: + - cloudflare + Cf-Ray: + - 468607b8985cc172-IAD + body: + encoding: ASCII-8BIT + string: '{"id":1,"active":false,"stages":2,"boosters":0,"cost_per_launch":6700000,"success_rate_pct":40,"first_flight":"2006-03-24","country":"Republic + of the Marshall Islands","company":"SpaceX","height":{"meters":22.25,"feet":73},"diameter":{"meters":1.68,"feet":5.5},"mass":{"kg":30146,"lb":66460},"payload_weights":[{"id":"leo","name":"Low + Earth Orbit","kg":450,"lb":992}],"first_stage":{"reusable":false,"engines":1,"fuel_amount_tons":44.3,"burn_time_sec":169,"thrust_sea_level":{"kN":420,"lbf":94000},"thrust_vacuum":{"kN":480,"lbf":110000}},"second_stage":{"engines":1,"fuel_amount_tons":3.38,"burn_time_sec":378,"thrust":{"kN":31,"lbf":7000},"payloads":{"option_1":"composite + fairing","composite_fairing":{"height":{"meters":3.5,"feet":11.5},"diameter":{"meters":1.5,"feet":4.9}}}},"engines":{"number":1,"type":"merlin","version":"1C","layout":"single","engine_loss_max":0,"propellant_1":"liquid + oxygen","propellant_2":"RP-1 kerosene","thrust_sea_level":{"kN":420,"lbf":94000},"thrust_vacuum":{"kN":480,"lbf":110000},"thrust_to_weight":96},"landing_legs":{"number":0,"material":null},"flickr_images":["https://www.spacex.com/sites/spacex/files/styles/media_gallery_large/public/2009_-_01_liftoff_south_full_wide_ro8a1280_edit.jpg?itok=8loiSGt1","https://www.spacex.com/sites/spacex/files/styles/media_gallery_large/public/2009_-_02_default_liftoff_west_full_wide_nn6p2062_xl.jpg?itok=p776nHsM"],"wikipedia":"https://en.wikipedia.org/wiki/Falcon_1","description":"The + Falcon 1 was an expendable launch system privately developed and manufactured + by SpaceX during 2006-2009. On 28 September 2008, Falcon 1 became the first + privately-developed liquid-fuel launch vehicle to go into orbit around the + Earth.","rocket_id":"falcon1","rocket_name":"Falcon 1","rocket_type":"rocket"}' + http_version: + recorded_at: Fri, 12 Oct 2018 02:10:27 GMT +recorded_with: VCR 4.0.0 diff --git a/spec/fixtures/spacex/rockets/info/invalid.yml b/spec/fixtures/spacex/rockets/info/invalid.yml new file mode 100644 index 0000000..09eb18d --- /dev/null +++ b/spec/fixtures/spacex/rockets/info/invalid.yml @@ -0,0 +1,61 @@ +--- +http_interactions: +- request: + method: get + uri: https://api.spacexdata.com/v3/rockets/invalid + body: + encoding: US-ASCII + string: '' + headers: + User-Agent: + - Faraday v0.15.3 + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + response: + status: + code: 404 + message: Not Found + headers: + Date: + - Fri, 12 Oct 2018 02:59:50 GMT + Content-Type: + - application/json; charset=utf-8 + Transfer-Encoding: + - chunked + Connection: + - keep-alive + Set-Cookie: + - __cfduid=d64b40402217803e462c3cd3b6aad69261539313190; expires=Sat, 12-Oct-19 + 02:59:50 GMT; path=/; domain=.spacexdata.com; HttpOnly; Secure + Vary: + - Accept-Encoding, Origin + X-Dns-Prefetch-Control: + - 'off' + X-Frame-Options: + - SAMEORIGIN + Strict-Transport-Security: + - max-age=15552000; includeSubDomains + X-Download-Options: + - noopen + X-Content-Type-Options: + - nosniff + X-Xss-Protection: + - 1; mode=block + Access-Control-Allow-Origin: + - "*" + X-Response-Time: + - 42ms + Expect-Ct: + - max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct" + Server: + - cloudflare + Cf-Ray: + - 46865010ac54c181-IAD + body: + encoding: ASCII-8BIT + string: '{"error":"Not Found"}' + http_version: + recorded_at: Fri, 12 Oct 2018 02:59:50 GMT +recorded_with: VCR 4.0.0 diff --git a/spec/spacex/rockets_spec.rb b/spec/spacex/rockets_spec.rb new file mode 100644 index 0000000..33aca66 --- /dev/null +++ b/spec/spacex/rockets_spec.rb @@ -0,0 +1,218 @@ +require 'spec_helper' + +describe SPACEX do + context 'Rockets', vcr: { cassette_name: 'rockets/info' } do + subject do + SPACEX::Rockets.info + end + + it "returns all Rockets' when no id is passed info" do + first_subject = subject.first + expect(first_subject.id).to eq 1 + expect(first_subject.active).to eq false + expect(first_subject.stages).to eq 2 + expect(first_subject.boosters).to eq 0 + expect(first_subject.cost_per_launch).to eq 6_700_000 + expect(first_subject.success_rate_pct).to eq 40 + expect(first_subject.first_flight).to eq '2006-03-24' + expect(first_subject.country).to eq 'Republic of the Marshall Islands' + expect(first_subject.company).to eq 'SpaceX' + expect(first_subject.height).to eq( + 'meters' => 22.25, + 'feet' => 73 + ) + expect(first_subject.diameter).to eq( + 'meters' => 1.68, + 'feet' => 5.5 + ) + expect(first_subject.mass).to eq( + 'kg' => 30_146, + 'lb' => 66_460 + ) + expect(first_subject.payload_weights).to eq [{ + 'id' => 'leo', + 'name' => 'Low Earth Orbit', + 'kg' => 450, + 'lb' => 992 + }] + expect(first_subject.first_stage).to eq( + 'reusable' => false, + 'engines' => 1, + 'fuel_amount_tons' => 44.3, + 'burn_time_sec' => 169, + 'thrust_sea_level' => { + 'kN' => 420, + 'lbf' => 94_000 + }, + 'thrust_vacuum' => { + 'kN' => 480, + 'lbf' => 110_000 + } + ) + expect(first_subject.second_stage).to eq( + 'engines' => 1, + 'fuel_amount_tons' => 3.38, + 'burn_time_sec' => 378, + 'thrust' => { + 'kN' => 31, + 'lbf' => 7000 + }, + 'payloads' => { + 'option_1' => 'composite fairing', + 'composite_fairing' => { + 'height' => { + 'meters' => 3.5, + 'feet' => 11.5 + }, + 'diameter' => { + 'meters' => 1.5, + 'feet' => 4.9 + } + } + } + ) + expect(first_subject.engines).to eq( + 'number' => 1, + 'type' => 'merlin', + 'version' => '1C', + 'layout' => 'single', + 'engine_loss_max' => 0, + 'propellant_1' => 'liquid oxygen', + 'propellant_2' => 'RP-1 kerosene', + 'thrust_sea_level' => { + 'kN' => 420, + 'lbf' => 94_000 + }, + 'thrust_vacuum' => { + 'kN' => 480, + 'lbf' => 110_000 + }, + 'thrust_to_weight' => 96 + ) + expect(first_subject.landing_legs).to eq( + 'number' => 0, + 'material' => nil + ) + expect(first_subject.wikipedia).to eq( + 'https://en.wikipedia.org/wiki/Falcon_1' + ) + expect(first_subject.description).to eq( + 'The Falcon 1 was an expendable launch system '\ + 'privately developed and manufactured by SpaceX during 2006-2009. '\ + 'On 28 September 2008, Falcon 1 became the first '\ + 'privately-developed liquid-fuel launch vehicle to '\ + 'go into orbit around the Earth.' + ) + expect(first_subject.rocket_id).to eq 'falcon1' + expect(first_subject.rocket_name).to eq 'Falcon 1' + expect(first_subject.rocket_type).to eq 'rocket' + end + end + + context 'Get specific Rocket', vcr: { cassette_name: 'rockets/info/falcon1' } do + subject do + SPACEX::Rockets.info('falcon1') + end + + it 'returns Rocket info for "falcon1"' do + expect(subject.id).to eq 1 + expect(subject.active).to eq false + expect(subject.stages).to eq 2 + expect(subject.boosters).to eq 0 + expect(subject.cost_per_launch).to eq 6_700_000 + expect(subject.success_rate_pct).to eq 40 + expect(subject.first_flight).to eq '2006-03-24' + expect(subject.country).to eq 'Republic of the Marshall Islands' + expect(subject.company).to eq 'SpaceX' + expect(subject.height).to eq( + 'meters' => 22.25, + 'feet' => 73 + ) + expect(subject.diameter).to eq( + 'meters' => 1.68, + 'feet' => 5.5 + ) + expect(subject.mass).to eq( + 'kg' => 30_146, + 'lb' => 66_460 + ) + expect(subject.payload_weights).to eq [{ + 'id' => 'leo', + 'name' => 'Low Earth Orbit', + 'kg' => 450, + 'lb' => 992 + }] + expect(subject.first_stage).to eq( + 'reusable' => false, + 'engines' => 1, + 'fuel_amount_tons' => 44.3, + 'burn_time_sec' => 169, + 'thrust_sea_level' => { + 'kN' => 420, + 'lbf' => 94_000 + }, + 'thrust_vacuum' => { + 'kN' => 480, + 'lbf' => 110_000 + } + ) + expect(subject.second_stage).to eq( + 'engines' => 1, + 'fuel_amount_tons' => 3.38, + 'burn_time_sec' => 378, + 'thrust' => { + 'kN' => 31, + 'lbf' => 7000 + }, + 'payloads' => { + 'option_1' => 'composite fairing', + 'composite_fairing' => { + 'height' => { + 'meters' => 3.5, + 'feet' => 11.5 + }, + 'diameter' => { + 'meters' => 1.5, + 'feet' => 4.9 + } + } + } + ) + expect(subject.engines).to eq( + 'number' => 1, + 'type' => 'merlin', + 'version' => '1C', + 'layout' => 'single', + 'engine_loss_max' => 0, + 'propellant_1' => 'liquid oxygen', + 'propellant_2' => 'RP-1 kerosene', + 'thrust_sea_level' => { + 'kN' => 420, + 'lbf' => 94_000 + }, + 'thrust_vacuum' => { + 'kN' => 480, + 'lbf' => 110_000 + }, + 'thrust_to_weight' => 96 + ) + expect(subject.landing_legs).to eq( + 'number' => 0, + 'material' => nil + ) + expect(subject.wikipedia).to eq( + 'https://en.wikipedia.org/wiki/Falcon_1' + ) + expect(subject.description).to eq( + 'The Falcon 1 was an expendable launch system '\ + 'privately developed and manufactured by SpaceX during 2006-2009. '\ + 'On 28 September 2008, Falcon 1 became the first '\ + 'privately-developed liquid-fuel launch vehicle to '\ + 'go into orbit around the Earth.' + ) + expect(subject.rocket_id).to eq 'falcon1' + expect(subject.rocket_name).to eq 'Falcon 1' + expect(subject.rocket_type).to eq 'rocket' + end + end +end From d9b61ae991ec9d1893a4cd5feb2d1283f8164ff8 Mon Sep 17 00:00:00 2001 From: Chaitanya Kale Date: Thu, 11 Oct 2018 23:14:31 -0400 Subject: [PATCH 2/5] Updated changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a06126d..26ad557 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ ### 0.0.8 (next) +* [#35](https://github.com/rodolfobandeira/spacex/pull/35): Implement Rockets endpoint - [@invacuo](https://github.com/invacuo) * [#28](https://github.com/rodolfobandeira/spacex/pull/28): Add ability to query all launches - [@ludamillion](https://github.com/ludamillion) * [#26](https://github.com/rodolfobandeira/spacex/pull/26): Fix dependencies - [@harman28](https://github.com/harman28). * [#25](https://github.com/rodolfobandeira/spacex/pull/25): Add code coverage tools - [@harman28](https://github.com/harman28). From 8de0f03d6cdb5d2e7e7e3d4cbc1fd4d0dede8841 Mon Sep 17 00:00:00 2001 From: Chaitanya Kale Date: Thu, 11 Oct 2018 23:18:18 -0400 Subject: [PATCH 3/5] Rubocop fixes --- spec/spacex/rockets_spec.rb | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/spec/spacex/rockets_spec.rb b/spec/spacex/rockets_spec.rb index 33aca66..d6e2721 100644 --- a/spec/spacex/rockets_spec.rb +++ b/spec/spacex/rockets_spec.rb @@ -124,18 +124,9 @@ expect(subject.first_flight).to eq '2006-03-24' expect(subject.country).to eq 'Republic of the Marshall Islands' expect(subject.company).to eq 'SpaceX' - expect(subject.height).to eq( - 'meters' => 22.25, - 'feet' => 73 - ) - expect(subject.diameter).to eq( - 'meters' => 1.68, - 'feet' => 5.5 - ) - expect(subject.mass).to eq( - 'kg' => 30_146, - 'lb' => 66_460 - ) + expect(subject.height).to eq('meters' => 22.25, 'feet' => 73) + expect(subject.diameter).to eq('meters' => 1.68, 'feet' => 5.5) + expect(subject.mass).to eq('kg' => 30_146, 'lb' => 66_460) expect(subject.payload_weights).to eq [{ 'id' => 'leo', 'name' => 'Low Earth Orbit', @@ -196,13 +187,8 @@ }, 'thrust_to_weight' => 96 ) - expect(subject.landing_legs).to eq( - 'number' => 0, - 'material' => nil - ) - expect(subject.wikipedia).to eq( - 'https://en.wikipedia.org/wiki/Falcon_1' - ) + expect(subject.landing_legs).to eq('number' => 0, 'material' => nil) + expect(subject.wikipedia).to eq 'https://en.wikipedia.org/wiki/Falcon_1' expect(subject.description).to eq( 'The Falcon 1 was an expendable launch system '\ 'privately developed and manufactured by SpaceX during 2006-2009. '\ From cfe00a606b9c611cd71e48dd330dcc8a637ff5d2 Mon Sep 17 00:00:00 2001 From: Chaitanya Kale Date: Thu, 11 Oct 2018 23:32:22 -0400 Subject: [PATCH 4/5] Fix the cassette --- spec/fixtures/spacex/rockets/info/falcon1.yml | 80 +++++++++++++++++-- 1 file changed, 74 insertions(+), 6 deletions(-) diff --git a/spec/fixtures/spacex/rockets/info/falcon1.yml b/spec/fixtures/spacex/rockets/info/falcon1.yml index 936ab47..e4c03bd 100644 --- a/spec/fixtures/spacex/rockets/info/falcon1.yml +++ b/spec/fixtures/spacex/rockets/info/falcon1.yml @@ -19,7 +19,7 @@ http_interactions: message: OK headers: Date: - - Fri, 12 Oct 2018 02:10:27 GMT + - Fri, 12 Oct 2018 03:32:14 GMT Content-Type: - application/json; charset=utf-8 Transfer-Encoding: @@ -27,8 +27,8 @@ http_interactions: Connection: - keep-alive Set-Cookie: - - __cfduid=dfaf0f3f41e0848934a92bd657b8b0adb1539310227; expires=Sat, 12-Oct-19 - 02:10:27 GMT; path=/; domain=.spacexdata.com; HttpOnly; Secure + - __cfduid=d41185f13de8dc3fd36ee65d1a88d9ad81539315133; expires=Sat, 12-Oct-19 + 03:32:13 GMT; path=/; domain=.spacexdata.com; HttpOnly; Secure Vary: - Accept-Encoding, Origin X-Dns-Prefetch-Control: @@ -48,13 +48,13 @@ http_interactions: X-Koa-Redis-Cache: - 'true' X-Response-Time: - - 4ms + - 5ms Expect-Ct: - max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct" Server: - cloudflare Cf-Ray: - - 468607b8985cc172-IAD + - 46867f8358945717-IAD body: encoding: ASCII-8BIT string: '{"id":1,"active":false,"stages":2,"boosters":0,"cost_per_launch":6700000,"success_rate_pct":40,"first_flight":"2006-03-24","country":"Republic @@ -67,5 +67,73 @@ http_interactions: privately-developed liquid-fuel launch vehicle to go into orbit around the Earth.","rocket_id":"falcon1","rocket_name":"Falcon 1","rocket_type":"rocket"}' http_version: - recorded_at: Fri, 12 Oct 2018 02:10:27 GMT + recorded_at: Fri, 12 Oct 2018 03:32:14 GMT +- request: + method: get + uri: https://api.spacexdata.com/v3/rockets/falcon1 + body: + encoding: US-ASCII + string: '' + headers: + User-Agent: + - Faraday v0.15.3 + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + response: + status: + code: 200 + message: OK + headers: + Date: + - Fri, 12 Oct 2018 03:32:14 GMT + Content-Type: + - application/json; charset=utf-8 + Transfer-Encoding: + - chunked + Connection: + - keep-alive + Set-Cookie: + - __cfduid=d6999e3f035d1724a0d856b2bc6bb33d91539315134; expires=Sat, 12-Oct-19 + 03:32:14 GMT; path=/; domain=.spacexdata.com; HttpOnly; Secure + Vary: + - Accept-Encoding, Origin + X-Dns-Prefetch-Control: + - 'off' + X-Frame-Options: + - SAMEORIGIN + Strict-Transport-Security: + - max-age=15552000; includeSubDomains + X-Download-Options: + - noopen + X-Content-Type-Options: + - nosniff + X-Xss-Protection: + - 1; mode=block + Access-Control-Allow-Origin: + - "*" + X-Koa-Redis-Cache: + - 'true' + X-Response-Time: + - 1ms + Expect-Ct: + - max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct" + Server: + - cloudflare + Cf-Ray: + - 46867f843e60572f-IAD + body: + encoding: ASCII-8BIT + string: '{"id":1,"active":false,"stages":2,"boosters":0,"cost_per_launch":6700000,"success_rate_pct":40,"first_flight":"2006-03-24","country":"Republic + of the Marshall Islands","company":"SpaceX","height":{"meters":22.25,"feet":73},"diameter":{"meters":1.68,"feet":5.5},"mass":{"kg":30146,"lb":66460},"payload_weights":[{"id":"leo","name":"Low + Earth Orbit","kg":450,"lb":992}],"first_stage":{"reusable":false,"engines":1,"fuel_amount_tons":44.3,"burn_time_sec":169,"thrust_sea_level":{"kN":420,"lbf":94000},"thrust_vacuum":{"kN":480,"lbf":110000}},"second_stage":{"engines":1,"fuel_amount_tons":3.38,"burn_time_sec":378,"thrust":{"kN":31,"lbf":7000},"payloads":{"option_1":"composite + fairing","composite_fairing":{"height":{"meters":3.5,"feet":11.5},"diameter":{"meters":1.5,"feet":4.9}}}},"engines":{"number":1,"type":"merlin","version":"1C","layout":"single","engine_loss_max":0,"propellant_1":"liquid + oxygen","propellant_2":"RP-1 kerosene","thrust_sea_level":{"kN":420,"lbf":94000},"thrust_vacuum":{"kN":480,"lbf":110000},"thrust_to_weight":96},"landing_legs":{"number":0,"material":null},"flickr_images":["https://www.spacex.com/sites/spacex/files/styles/media_gallery_large/public/2009_-_01_liftoff_south_full_wide_ro8a1280_edit.jpg?itok=8loiSGt1","https://www.spacex.com/sites/spacex/files/styles/media_gallery_large/public/2009_-_02_default_liftoff_west_full_wide_nn6p2062_xl.jpg?itok=p776nHsM"],"wikipedia":"https://en.wikipedia.org/wiki/Falcon_1","description":"The + Falcon 1 was an expendable launch system privately developed and manufactured + by SpaceX during 2006-2009. On 28 September 2008, Falcon 1 became the first + privately-developed liquid-fuel launch vehicle to go into orbit around the + Earth.","rocket_id":"falcon1","rocket_name":"Falcon 1","rocket_type":"rocket"}' + http_version: + recorded_at: Fri, 12 Oct 2018 03:32:14 GMT recorded_with: VCR 4.0.0 From 3e8ede3872b46a24b9d02e46e0f8cee53865f47d Mon Sep 17 00:00:00 2001 From: Chaitanya Kale Date: Thu, 11 Oct 2018 23:36:06 -0400 Subject: [PATCH 5/5] Updated README --- README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c4da674..d27d9e0 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ Ruby library that consumes SpaceX API - [Missions](#missions) - `SPACEX::Missions.info` - `SPACEX::Missions.info('mission_id')` -- [Contributing](#contributing) +- [Contributing](#contributing) - [Contributors / Changelog](#contributors) - [Copyright](#copyright) @@ -276,6 +276,12 @@ missions.first.twitter # "https://twitter.com/IridiumBoss?lang=en" missions.first.description # "In 2017, Iridium began launching Iridium NEXT, a second-generation worldwide network of telecommunications satellites, consisting of 66 active satellites, with another nine in-orbit spares and six on-ground spares. These satellites will incorporate features such as data transmission that were not emphasized in the original design. The constellation will provide L-band data speeds of up to 128 kbit/s to mobile terminals, up to 1.5 Mbit/s to Iridium Pilot marine terminals, and high-speed Ka-band service of up to 8 Mbit/s to fixed/transportable terminals. The next-generation terminals and service are expected to be commercially available by the end of 2018. However, Iridium's proposed use of its next-generation satellites has raised concerns the service will harmfully interfere with GPS devices. The satellites will incorporate a secondary payload for Aireon, a space-qualified ADS-B data receiver. This is for use by air traffic control and, via FlightAware, for use by airlines. A tertiary payload on 58 satellites is a marine AIS ship-tracker receiver, for Canadian company exactEarth Ltd. Iridium can also be used to provide a data link to other satellites in space, enabling command and control of other space assets regardless of the position of ground stations and gateways." ``` +### Rockets + +- `SPACEX::Rockets.info` Retrieve all Rockets; +- `SPACEX::Rockets.info('falcon1')` Retrieve a specific rocket. Ex: `falcon1` + + ## Contributing See [CONTRIBUTING](CONTRIBUTING.md).