Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Upcoming Launches #56

Merged
8 changes: 4 additions & 4 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2018-10-23 18:08:15 -0400 using RuboCop version 0.51.0.
# on 2018-11-01 20:09:44 -0400 using RuboCop version 0.51.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
Expand All @@ -12,12 +12,12 @@ Lint/ParenthesesAsGroupedExpression:
- 'spec/spacex/dragon_capsules_spec.rb'
- 'spec/spacex/ships_spec.rb'

# Offense count: 30
# Offense count: 36
mtking2 marked this conversation as resolved.
Show resolved Hide resolved
# Configuration parameters: CountComments, ExcludedMethods.
Metrics/BlockLength:
Max: 423
Max: 625

# Offense count: 128
# Offense count: 136
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https
Metrics/LineLength:
Expand Down
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
* [#48](https://github.com/rodolfobandeira/spacex/pull/48): Add ability to query specific Launch via `.info('flight_number')` - [@mtking2](http://github.com/mtking2).
* [#51](https://github.com/rodolfobandeira/spacex/pull/51): Added payloads endpoint [@maiafernando](http://github.com/maiafernando).
* [#52](https://github.com/rodolfobandeira/spacex/pull/52): Add ability to query Past Launches - [@mtking2](http://github.com/mtking2).
* [#52](https://github.com/rodolfobandeira/spacex/pull/54): Refactor ENDPOINT_URI - [@ludamillion](http://github.com/ludamillion).
* [#54](https://github.com/rodolfobandeira/spacex/pull/54): Refactor ENDPOINT_URI - [@ludamillion](http://github.com/ludamillion).
* [#56](https://github.com/rodolfobandeira/spacex/pull/56): Add ability to query upcoming launches - [@mtking2](http://github.com/mtking2).
* Your contribution here.

### 1.0.0 (2018/10/15)
Expand Down
21 changes: 18 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,10 @@ first_event.links['wikipedia'] # https://en.wikipedia.org/wiki/Falcon_1

- Get information for all launches: `SPACEX::Launches.all` or `SPACEX::Launches.info`
- Get information about a specific launch: `SPACEX::Launches.info('flight_number')`
- Get information on past launches: `SPACEX::Launches.past`
- Get information on the next launch: `SPACEX::Launches.next`
- Get the latest launch information: `SPACEX::Launches.latest`
- Get information on upcoming launches: `SPACEX::Launches.upcoming`

This code snippet shows how to get information for a specific launch by flight number and list the fields:

Expand Down Expand Up @@ -242,9 +246,7 @@ past_launches.last.rocket.first_stage.cores.first.land_success # true
past_launches.last.launch_success # true
```

- Get information on past launches: `SPACEX::Launches.past`
- Get information on the next launch: `SPACEX::Launches.next`
- Get the latest launch information: `SPACEX::Launches.latest`


The following code snippet shows the latest launch information and the data fields available on the Launch object:

Expand Down Expand Up @@ -318,6 +320,19 @@ latest_launch.upcoming # false
latest_launch.static_fire_date_utc # '2018-08-02T15:53:00.000Z'
```

This code snippet shows how to get information on upcoming launches:
mtking2 marked this conversation as resolved.
Show resolved Hide resolved
```ruby
upcoming_launches = SPACEX::Launches.upcoming

upcoming_launches.first.flight_number # 70
upcoming_launches.first.mission_name # 'Es’hail 2'
upcoming_launches.first.launch_date_utc # '2018-11-14T20:46:00.000Z'

upcoming_launches.last.flight_number # 91
upcoming_launches.last.mission_name # 'GPS IIIA-3'
upcoming_launches.last.launch_date_utc # '2019-10-01T00:00:00.000Z'
```

### Missions

- Get information for all mission: `SPACEX::Missions.info`
Expand Down
4 changes: 4 additions & 0 deletions lib/spacex/launches.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ def self.past
SPACEX::BaseRequest.info('launches/past')
end

def self.upcoming
SPACEX::BaseRequest.info('launches/upcoming')
end

def self.all
info
end
Expand Down
64 changes: 64 additions & 0 deletions spec/fixtures/spacex/launches/upcoming.yml

Large diffs are not rendered by default.

207 changes: 207 additions & 0 deletions spec/spacex/launches_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,213 @@
end
end

context '#upcoming', vcr: { cassette_name: 'launches/upcoming' } do
subject do
SPACEX::Launches.upcoming
end

it 'returns and array of upcoming launch hashes' do
expect(subject).to be_an Array
expect(subject.first).to be_a Hash
expect(subject.all?(&:upcoming)).to be true
end

it 'returns launches scheduled in the future' do
mtking2 marked this conversation as resolved.
Show resolved Hide resolved
subject.each do |launch|
expect(launch.launch_year).to be >= Time.now.year.to_s
expect(Time.parse(launch.launch_date_utc)).to be >= Time.now.utc
expect(launch.rocket.first_stage.cores.first.land_success).to be nil
expect(launch.launch_success).to be nil
end
end

context 'returns upcoming launches' do
it 'returns the next upcoming launch' do
expect(subject.first.flight_number).to eq 70
expect(subject.first.mission_name).to eq 'Es’hail 2'
expect(subject.first.mission_id).to eq []
expect(subject.first.launch_year).to eq '2018'
expect(subject.first.launch_date_unix).to eq 1_542_228_360
expect(subject.first.launch_date_utc).to eq '2018-11-14T20:46:00.000Z'
expect(subject.first.launch_date_local).to eq '2018-11-14T15:46:00-05:00'
expect(subject.first.is_tentative).to eq true
expect(subject.first.tentative_max_precision).to eq 'hour'
expect(subject.first.rocket.rocket_id).to eq 'falcon9'
expect(subject.first.rocket.rocket_name).to eq 'Falcon 9'
expect(subject.first.rocket.rocket_type).to eq 'FT'
expect(subject.first.rocket.first_stage.cores).to be_an(Array)
expect(subject.first.rocket.first_stage.cores.first).to eq(
'core_serial' => nil,
'flight' => nil,
'block' => 5,
'gridfins' => true,
'legs' => true,
'reused' => false,
'land_success' => nil,
'landing_intent' => true,
'landing_type' => 'ASDS',
'landing_vehicle' => 'OCISLY'
)
expect(subject.first.rocket.second_stage.block).to eq 5
expect(subject.first.rocket.second_stage.payloads).to be_an(Array)
expect(subject.first.rocket.second_stage.payloads.first).to eq(
'payload_id' => 'Es’hail 2',
'norad_id' => [],
'reused' => false,
'customers' => ['Es’hailSat'],
'nationality' => 'Qatar',
'manufacturer' => 'Mitsubishi Electric',
'payload_type' => 'Satellite',
'payload_mass_kg' => 3000,
'payload_mass_lbs' => 6613.868,
'orbit' => 'GTO',
'orbit_params' => {
'reference_system' => 'geocentric',
'regime' => 'geostationary',
'longitude' => 25.5,
'semi_major_axis_km' => nil,
'eccentricity' => nil,
'periapsis_km' => nil,
'apoapsis_km' => nil,
'inclination_deg' => nil,
'period_min' => nil,
'lifespan_years' => 15,
'epoch' => nil,
'mean_motion' => nil,
'raan' => nil,
'arg_of_pericenter' => nil,
'mean_anomaly' => nil
}
)
expect(subject.first.rocket.fairings).to eq(
'reused' => false,
'recovery_attempt' => false,
'recovered' => false,
'ship' => nil
)
expect(subject.first.ships).to eq []
expect(subject.first.telemetry.flight_club).to eq nil
expect(subject.first.launch_site).to eq(
'site_id' => 'ccafs_slc_40',
'site_name' => 'CCAFS SLC 40',
'site_name_long' => 'Cape Canaveral Air Force Station Space Launch Complex 40'
)
expect(subject.first.launch_success).to eq nil
expect(subject.first.links).to eq(
'mission_patch' => nil,
'mission_patch_small' => nil,
'reddit_campaign' => 'https://www.reddit.com/r/spacex/comments/9p82jt/eshail_2_launch_campaign_thread/',
'reddit_launch' => nil,
'reddit_recovery' => nil,
'reddit_media' => nil,
'presskit' => nil,
'article_link' => nil,
'wikipedia' => nil,
'video_link' => nil,
'flickr_images' => []
)
expect(subject.first.details).to eq 'SpaceX\'s eighteenth flight of 2018 will '\
'be its first for Es\'hailSat. Es\'hail-2 is a communications satellite '\
'that will deliver television and internet to Qatar and the surrounding '\
'region. It will be launched into a geostationary transfer orbit from '\
'LC-39A at Kennedy Space Center. The booster is expected to land on OCISLY.'
expect(subject.first.upcoming).to eq true
expect(subject.first.static_fire_date_utc).to eq nil
expect(subject.first.static_fire_date_unix).to eq nil
end

it 'returns the last upcoming launch' do
expect(subject.last.flight_number).to eq 91
expect(subject.last.mission_name).to eq 'GPS IIIA-3'
expect(subject.last.mission_id).to eq []
expect(subject.last.launch_year).to eq '2019'
expect(subject.last.launch_date_unix).to eq 1_569_888_000
expect(subject.last.launch_date_utc).to eq '2019-10-01T00:00:00.000Z'
expect(subject.last.launch_date_local).to eq '2019-09-30T20:00:00-04:00'
expect(subject.last.is_tentative).to eq true
expect(subject.last.tentative_max_precision).to eq 'month'
expect(subject.last.rocket.rocket_id).to eq 'falcon9'
expect(subject.last.rocket.rocket_name).to eq 'Falcon 9'
expect(subject.last.rocket.rocket_type).to eq 'FT'
expect(subject.last.rocket.first_stage.cores).to be_an(Array)
expect(subject.last.rocket.first_stage.cores.first).to eq(
'core_serial' => nil,
'flight' => nil,
'block' => nil,
'gridfins' => nil,
'legs' => nil,
'reused' => false,
'land_success' => nil,
'landing_intent' => nil,
'landing_type' => nil,
'landing_vehicle' => nil
)
expect(subject.last.rocket.second_stage.block).to eq nil
expect(subject.last.rocket.second_stage.payloads).to be_an(Array)
expect(subject.last.rocket.second_stage.payloads.first).to eq(
'payload_id' => 'GPS IIIA-3',
'norad_id' => [],
'reused' => false,
'customers' => ['USAF'],
'nationality' => 'United States',
'manufacturer' => 'Lockheed Martin',
'payload_type' => 'Satellite',
'payload_mass_kg' => 3880,
'payload_mass_lbs' => 8553.94,
'orbit' => 'MEO',
'orbit_params' => {
'reference_system' => nil,
'regime' => nil,
'longitude' => nil,
'semi_major_axis_km' => nil,
'eccentricity' => nil,
'periapsis_km' => nil,
'apoapsis_km' => nil,
'inclination_deg' => nil,
'period_min' => nil,
'lifespan_years' => 15,
'epoch' => nil,
'mean_motion' => nil,
'raan' => nil,
'arg_of_pericenter' => nil,
'mean_anomaly' => nil
}
)
expect(subject.last.rocket.fairings).to eq(
'reused' => false,
'recovery_attempt' => nil,
'recovered' => nil,
'ship' => nil
)
expect(subject.last.ships).to eq []
expect(subject.last.telemetry.flight_club).to eq nil
expect(subject.last.launch_site).to eq(
'site_id' => 'ccafs_slc_40',
'site_name' => 'CCAFS SLC 40',
'site_name_long' => 'Cape Canaveral Air Force Station Space Launch Complex 40'
)
expect(subject.last.launch_success).to eq nil
expect(subject.last.links).to eq(
'mission_patch' => nil,
'mission_patch_small' => nil,
'reddit_campaign' => nil,
'reddit_launch' => nil,
'reddit_recovery' => nil,
'reddit_media' => nil,
'presskit' => nil,
'article_link' => nil,
'wikipedia' => nil,
'video_link' => nil,
'flickr_images' => []
)
expect(subject.last.details).to eq nil
expect(subject.last.upcoming).to eq true
expect(subject.last.static_fire_date_utc).to eq nil
expect(subject.last.static_fire_date_unix).to eq nil
end
end
end

context '#all', vcr: { cassette_name: 'launches/all' } do
subject do
SPACEX::Launches.all
Expand Down