Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
fernandomaia committed Oct 28, 2018
2 parents eebc5ab + 59dc485 commit a07565b
Show file tree
Hide file tree
Showing 11 changed files with 124 additions and 8 deletions.
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-22 22:10:27 -0400 using RuboCop version 0.51.0.
# on 2018-10-23 18:08:15 -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: 29
# Offense count: 30
# Configuration parameters: CountComments, ExcludedMethods.
Metrics/BlockLength:
Max: 389
Max: 423

# Offense count: 122
# Offense count: 128
# 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 @@ -2,7 +2,8 @@
* [#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).

* [#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).
* Your contribution here.

### 1.0.0 (2018/10/15)
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ A Ruby library that consumes the [SpaceX API](https://github.com/r-spacex/SpaceX
- `SPACEX::Launches.info(68)`
- `SPACEX::Launches.latest`
- `SPACEX::Launches.next`
- `SPACEX::Launches.past`
- [Missions](#missions)
- `SPACEX::Missions.info`
- `SPACEX::Missions.info('mission_id')`
Expand Down
1 change: 1 addition & 0 deletions lib/spacex.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
require_relative 'spacex/company_info'
require_relative 'spacex/cores'
require_relative 'spacex/dragon_capsules'
require_relative 'spacex/endpoint'
require_relative 'spacex/history'
require_relative 'spacex/launches'
require_relative 'spacex/missions'
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 @@ -42,7 +42,7 @@ def spacex_response(response)

def conn(path)
Faraday.new(
url: "#{SPACEX::ROOT_URI}/#{path}",
url: "#{SPACEX::ENDPOINT_URI}/#{path}",
request: {
params_encoder: Faraday::FlatParamsEncoder
}
Expand Down
2 changes: 1 addition & 1 deletion lib/spacex/endpoint.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module SPACEX
ENDPOINT = 'https://api.spacexdata.com/v3/'.freeze
ENDPOINT_URI = 'https://api.spacexdata.com/v3'.freeze
end
4 changes: 4 additions & 0 deletions lib/spacex/launches.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ def self.next
SPACEX::BaseRequest.info('launches/next')
end

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

def self.all
info
end
Expand Down
1 change: 0 additions & 1 deletion lib/spacex/version.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
module SPACEX
VERSION = '1.0.0'.freeze
ROOT_URI = 'https://api.spacexdata.com/v3'.freeze

def self.help
puts 'https://github.com/rodolfobandeira/spacex'
Expand Down
62 changes: 62 additions & 0 deletions spec/fixtures/spacex/launches/past.yml

Large diffs are not rendered by default.

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

describe SPACEX::ENDPOINT_URI do
subject { SPACEX::ENDPOINT_URI }

it 'returns the URI for v3 of the SpaceX API' do
expect(subject).to eq 'https://api.spacexdata.com/v3'
end
end
39 changes: 39 additions & 0 deletions spec/spacex/launches_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -403,4 +403,43 @@
expect(subject.first.mission_name).to eq 'FalconSat'
end
end

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

it 'returns and array of launch hashes' do
expect(subject).to be_an Array
expect(subject.first).to be_a Hash
end

it 'returns the correct number of launches' do
expect(subject.count).to eq 69
end

context 'returns past launches' do
it 'returns the first launch' do
expect(subject.first.flight_number).to eq(1)
expect(subject.first.mission_name).to eq('FalconSat')
expect(subject.first.rocket.rocket_name).to eq('Falcon 1')
expect(subject.first.rocket.first_stage.cores.first.core_serial).to eq('Merlin1A')
expect(subject.first.rocket.second_stage.payloads.first.payload_id).to eq('FalconSAT-2')
expect(subject.first.rocket.second_stage.payloads.first.orbit_params.regime).to eq('low-earth')
expect(subject.first.launch_site.site_id).to eq('kwajalein_atoll')
expect(subject.first.launch_success).to eq(false)
end

it 'returns the last past launch' do
expect(subject.last.flight_number).to eq(69)
expect(subject.last.mission_name).to eq('SAOCOM 1A')
expect(subject.last.rocket.rocket_name).to eq('Falcon 9')
expect(subject.last.rocket.first_stage.cores.first.core_serial).to eq('B1048')
expect(subject.last.rocket.second_stage.payloads.first.payload_id).to eq('SAOCOM 1A')
expect(subject.last.rocket.second_stage.payloads.first.orbit_params.regime).to eq('sun-synchronous')
expect(subject.last.launch_site.site_id).to eq('vafb_slc_4e')
expect(subject.last.launch_success).to eq(true)
end
end
end
end

0 comments on commit a07565b

Please sign in to comment.