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

Add payloads information #51

Merged
merged 10 commits into from
Oct 24, 2018
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
### 1.0.1 (next)
* [#45](https://github.com/rodolfobandeira/spacex/pull/45): Implement History endpoint [@invacuo](http://github.com/invacuo).
* [#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).

* Your contribution here.

Expand Down
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ A Ruby library that consumes the [SpaceX API](https://github.com/r-spacex/SpaceX
- [Missions](#missions)
- `SPACEX::Missions.info`
- `SPACEX::Missions.info('mission_id')`
- [Payloads](#payloads)
- `SPACEX::Payloads.info`
- `SPACEX::Payloads.info('payload_id')`
- [Roadster](#roadster) - `SPACEX::Roadster.info`
- [Rockets](#rockets)
- `SPACEX::Rockets.info`
Expand Down Expand Up @@ -313,6 +316,28 @@ 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."
```

### Payloads

- Get information on all payloads: `SPACEX::Payloads.info`
- Get information about a specific payload (e.g., `FalconSAT-2`): `SPACEX::Payloads.info('payload_id')`

The following code shows how to get information about a specific payload and lists the payload data fields:

```ruby
payload = SPACEX::Payloads.info('FalconSAT-2')

payload.payload_id # 'FalconSAT-2'
payload.reused # false
payload.customers # ['DARPA']
payload.nationality # 'United States'
payload.manufacturer # 'SSTL'
payload.payload_type # 'Satellite'
payload.payload_mass_kg # 20
payload.payload_mass_lbs # 43
payload.orbit # 'LEO'
payload.orbit_params # {"reference_system"=>"geocentric", "regime"=>"low-earth", "longitude"=>nil, "semi_major_axis_km"=>nil, "eccentricity"=>nil, "periapsis_km"=>400, "apoapsis_km"=>500, "inclination_deg"=>39, "period_min"=>nil, "lifespan_years"=>nil, "epoch"=>nil, "mean_motion"=>nil, "raan"=>nil, "arg_of_pericenter"=>nil, "mean_anomaly"=>nil}
```

### Roadster

- Get roadster orbital data: `SPACEX::Roadster.info`
Expand Down
1 change: 1 addition & 0 deletions lib/spacex.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
require_relative 'spacex/history'
require_relative 'spacex/launches'
require_relative 'spacex/missions'
require_relative 'spacex/payloads'
require_relative 'spacex/roadster'
require_relative 'spacex/rockets'
require_relative 'spacex/ships'
Expand Down
7 changes: 7 additions & 0 deletions lib/spacex/payloads.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module SPACEX
module Payloads
def self.info(id = nil)
SPACEX::BaseRequest.info("payloads/#{id}")
end
end
end
62 changes: 62 additions & 0 deletions spec/fixtures/spacex/payloads/RatSat.yml

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

62 changes: 62 additions & 0 deletions spec/fixtures/spacex/payloads/info.yml

Large diffs are not rendered by default.

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

describe SPACEX::Payloads do
context '#info', vcr: { cassette_name: 'payloads/info' } do
subject do
SPACEX::Payloads.info
end
it 'returns payloads info' do
expect(subject.first.payload_id).to eq 'FalconSAT-2'
expect(subject.first.reused).to eq false
expect(subject.first.customers).to eq ['DARPA']
expect(subject.first.nationality).to eq 'United States'
expect(subject.first.manufacturer).to eq 'SSTL'
expect(subject.first.payload_type).to eq 'Satellite'
expect(subject.first.payload_mass_kg).to eq 20
expect(subject.first.payload_mass_lbs).to eq 43
expect(subject.first.orbit).to eq 'LEO'
expect(subject.first.orbit_params.reference_system).to eq 'geocentric'
expect(subject.first.orbit_params.regime).to eq 'low-earth'
expect(subject.first.orbit_params.longitude).to eq nil
expect(subject.first.orbit_params.semi_major_axis_km).to eq nil
expect(subject.first.orbit_params.eccentricity).to eq nil
expect(subject.first.orbit_params.periapsis_km).to eq 400
expect(subject.first.orbit_params.apoapsis_km).to eq 500
expect(subject.first.orbit_params.inclination_deg).to eq 39
expect(subject.first.orbit_params.period_min).to eq nil
expect(subject.first.orbit_params.lifespan_years).to eq nil
end
end

context "#info('RatSat')", vcr: { cassette_name: 'payloads/RatSat' } do
subject do
SPACEX::Payloads.info('RatSat')
end
it 'return specific payload info' do
expect(subject.payload_id).to eq 'RatSat'
expect(subject.reused).to eq false
expect(subject.customers).to eq ['SpaceX']
expect(subject.nationality).to eq 'United States'
expect(subject.manufacturer).to eq 'SpaceX'
expect(subject.payload_type).to eq 'Satellite'
expect(subject.payload_mass_kg).to eq 165
expect(subject.payload_mass_lbs).to eq 363
expect(subject.orbit).to eq 'LEO'
expect(subject.orbit_params.apoapsis_km).to eq 638.145
expect(subject.orbit_params.arg_of_pericenter).to eq 262.0542
expect(subject.orbit_params.eccentricity).to eq 0.0009194
expect(subject.orbit_params.epoch).to eq '2008-09-28T22:51:02.000Z'
expect(subject.orbit_params.inclination_deg).to eq 9.3329
expect(subject.orbit_params.lifespan_years).to eq nil
expect(subject.orbit_params.longitude).to eq nil
expect(subject.orbit_params.mean_anomaly).to eq 98.2248
expect(subject.orbit_params.mean_motion).to eq 14.79249332
expect(subject.orbit_params.periapsis_km).to eq 625.256
expect(subject.orbit_params.period_min).to eq 97.346
expect(subject.orbit_params.raan).to eq 63.3956
expect(subject.orbit_params.reference_system).to eq 'geocentric'
expect(subject.orbit_params.regime).to eq 'low-earth'
expect(subject.orbit_params.semi_major_axis_km).to eq 7009.836
end
end
end