Skip to content

Commit

Permalink
Merge 42d30f5 into e6f2b87
Browse files Browse the repository at this point in the history
  • Loading branch information
invacuo committed Oct 2, 2019
2 parents e6f2b87 + 42d30f5 commit 84f8b9c
Show file tree
Hide file tree
Showing 8 changed files with 297 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
### 1.0.2 (next)

* Your contribution here.
* [#70](https://github.com/rodolfobandeira/spacex/pull/70): Implement Landing Pads endpoint [@invacuo](http://github.com/invacuo).
* [#65](https://github.com/rodolfobandeira/spacex/pull/65): Add CodeClimate test coverage [@rodolfobandeira](http://github.com/rodolfobandeira).
* [#64](https://github.com/rodolfobandeira/spacex/pull/64): Fix failing build on Travis-CI [@rodolfobandeira](http://github.com/rodolfobandeira).

Expand Down
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ A Ruby library that consumes the [SpaceX API](https://github.com/r-spacex/SpaceX
- [History](#history)
- `SPACEX::History.info`
- `SPACEX::History.info(4)`
- [LaunchPads](#launch_pads)
- `SPACEX::LaunchPads.info`
- `SPACEX::LaunchPads.info('vafb_slc_4e')`
- [Launches](#launches)
- `SPACEX::Launches.all`
- `SPACEX::Launches.info`
Expand Down Expand Up @@ -211,6 +214,34 @@ first_event.links['article'] # http://www.spacex.com/news/2013/02/11/flight-4-la
first_event.links['wikipedia'] # https://en.wikipedia.org/wiki/Falcon_1
```


### LaunchPads

- Get information for all LaunchPads: `SPACEX::LaunchPads.info`
- Get information about a specific LaunchPad: `SPACEX::LaunchPads.info('vafb_slc_4e')`

This code shows how to get the information for a specific LaunchPad by site_id and lists the fields:

```ruby
launch_pad = SPACEX::LaunchPads.info('vafb_slc_4e')

launch_pad.id # 6
launch_pad.name # 'VAFB SLC 4E'
launch_pad.status # 'active'
launch_pad.location['name'] # 'Vandenberg Air Force Base',
launch_pad.location['region'] # 'California',
launch_pad.location['latitude'] # 34.632093,
launch_pad.location['longitude'] # -120.610829
launch_pad.vehicles_launched # ['Falcon 9']
launch_pad.attempted_launches # 15
launch_pad.successful_launches # 15
launch_pad.wikipedia # 'https://en.wikipedia.org/wiki/Vandenberg_AFB_Space_Launch_Complex_4'
launch_pad.details # 'SpaceX primary west coast launch pad for polar orbits and sun synchronous orbits, primarily used for Iridium. Also intended to be capable of launching Falcon Heavy.'
launch_pad.site_id # 'vafb_slc_4e'
launch_pad.site_name_long # 'Vandenberg Air Force Base Space Launch Complex 4E'
```


### Launches

- Get information for all launches: `SPACEX::Launches.all` or `SPACEX::Launches.info`
Expand Down
1 change: 1 addition & 0 deletions lib/spacex.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
require_relative 'spacex/dragon_capsules'
require_relative 'spacex/endpoint'
require_relative 'spacex/history'
require_relative 'spacex/launch_pads'
require_relative 'spacex/launches'
require_relative 'spacex/missions'
require_relative 'spacex/payloads'
Expand Down
2 changes: 1 addition & 1 deletion lib/spacex/base_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def conn(path)
) do |c|
c.use ::FaradayMiddleware::ParseJson
c.use Faraday::Response::RaiseError
c.use Faraday::Adapter::NetHttp
c.adapter Faraday::Adapter::NetHttp
end
end
end
Expand Down
11 changes: 11 additions & 0 deletions lib/spacex/launch_pads.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module SPACEX
module LaunchPads
def self.info(site_id = nil)
SPACEX::BaseRequest.info("launchpads/#{site_id}")
end

def self.all
info
end
end
end
104 changes: 104 additions & 0 deletions spec/fixtures/spacex/launch_pads/info.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

71 changes: 71 additions & 0 deletions spec/fixtures/spacex/launch_pads/info/vafb_slc_4e.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

77 changes: 77 additions & 0 deletions spec/spacex/launch_pads_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
require 'spec_helper'

describe SPACEX::LaunchPads do
context '#info', vcr: { cassette_name: 'launch_pads/info' } do
subject do
SPACEX::LaunchPads.info
end

it "returns all LaunchPads' info when no id is passed" do
first_subject = subject.first

expect(subject.class).to eq Array
expect(first_subject.id).to eq 5
expect(first_subject.name).to eq 'VAFB SLC 3W'
expect(first_subject.status).to eq 'retired'
expect(first_subject.location).to eq(
'name' => 'Vandenberg Air Force Base',
'region' => 'California',
'latitude' => 34.6440904,
'longitude' => -120.5931438
)
expect(first_subject.vehicles_launched).to eq [
'Falcon 1'
]
expect(first_subject.attempted_launches).to eq 0
expect(first_subject.successful_launches).to eq 0
expect(first_subject.wikipedia).to eq(
'https://en.wikipedia.org/wiki/Vandenberg_AFB_Space_Launch_Complex_3'
)
expect(first_subject.details).to eq 'SpaceX original ' \
'west coast launch pad for Falcon 1. Performed a static fire but was ' \
'never used for a launch and abandoned due to scheduling conflicts.'
expect(first_subject.site_id).to eq 'vafb_slc_3w'
expect(first_subject.site_name_long).to eq(
'Vandenberg Air Force Base Space Launch Complex 3W'
)
end
end

context "#info('vafb_slc_4e')", vcr: {
cassette_name: 'launch_pads/info/vafb_slc_4e'
} do
subject do
SPACEX::LaunchPads.info('vafb_slc_4e')
end

it 'returns LaunchPad info for "vafb_slc_4e"' do
expect(subject.class).to eq SPACEX::Response
expect(subject.id).to eq 6
expect(subject.name).to eq 'VAFB SLC 4E'
expect(subject.status).to eq 'active'
expect(subject.location).to eq(
'name' => 'Vandenberg Air Force Base',
'region' => 'California',
'latitude' => 34.632093,
'longitude' => -120.610829
)
expect(subject.vehicles_launched).to eq [
'Falcon 9'
]
expect(subject.attempted_launches).to eq 15
expect(subject.successful_launches).to eq 15
expect(subject.wikipedia).to eq(
'https://en.wikipedia.org/wiki/Vandenberg_AFB_Space_Launch_Complex_4'
)

expect(subject.details).to eq 'SpaceX primary ' \
'west coast launch pad for polar orbits and sun synchronous orbits, ' \
'primarily used for Iridium. Also intended to be capable of ' \
'launching Falcon Heavy.'
expect(subject.site_id).to eq 'vafb_slc_4e'
expect(subject.site_name_long).to eq(
'Vandenberg Air Force Base Space Launch Complex 4E'
)
end
end
end

0 comments on commit 84f8b9c

Please sign in to comment.