Skip to content

Commit

Permalink
Add API Info endpoint (#69)
Browse files Browse the repository at this point in the history
* Add API Info endpoint
* Replace 'use' method with 'adapter'
* Fix PR number and spacing before it block;
  • Loading branch information
fernandomaia authored and rodolfobandeira committed Oct 2, 2019
1 parent e6f2b87 commit 0e5c8ad
Show file tree
Hide file tree
Showing 7 changed files with 110 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.
* [#69](https://github.com/rodolfobandeira/spacex/pull/69): Implement API Info endpoint [@fernandomaia](https://github.com/fernandomaia).
* [#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
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ A Ruby library that consumes the [SpaceX API](https://github.com/r-spacex/SpaceX

- [Installation](#installation)
- [Usage](#usage)
- [API Info](#api-info)
- `SPACEX::ApiInfo.info`
- [Capsules](#capsules)
- `SPACEX::Capsules.info`
- `SPACEX::Capsules.info('capsule_serial')`
Expand Down Expand Up @@ -66,6 +68,23 @@ Then run `bundle install`.

## Usage

### API Info

- Get information about the API: `SPACEX::ApiInfo.info`

Here's an example of the response:

```ruby
api_info = SPACEX::ApiInfo.info

api_info.project_name # 'SpaceX-API'
api_info.description = # 'Open Source REST API for rocket, core, capsule, pad, and launch data, created and maintained by the developers of the r/SpaceX organization'
api_info.organization = # 'r/SpaceX'
api_info.organization_link = # 'https://github.com/r-spacex'
api_info.project_link = # 'https://github.com/r-spacex/SpaceX-API'
api_info.version = # '3.1.0'
```

### Capsules

- Get information for all capsules: `SPACEX::Capsules.info`
Expand Down
1 change: 1 addition & 0 deletions lib/spacex.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require 'faraday_middleware/response_middleware'
require 'hashie'

require_relative 'spacex/api_info'
require_relative 'spacex/base_request'
require_relative 'spacex/capsules'
require_relative 'spacex/company_info'
Expand Down
7 changes: 7 additions & 0 deletions lib/spacex/api_info.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module SPACEX
module ApiInfo
def self.info
SPACEX::BaseRequest.info('')
end
end
end
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
65 changes: 65 additions & 0 deletions spec/fixtures/spacex/api_info/info.yml

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

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

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

it 'returns API info' do
expect(subject.project_name).to eq 'SpaceX-API'
expect(subject.organization).to eq 'r/SpaceX'
expect(subject.organization_link).to eq 'https://github.com/r-spacex'
expect(subject.description).to eq 'Open Source REST API for rocket, core, capsule, pad, and launch data, created and maintained by the developers of the r/SpaceX organization'
end
end
end

0 comments on commit 0e5c8ad

Please sign in to comment.