Skip to content

Commit 7dced91

Browse files
Merge remote-tracking branch 'r-spacex/master'
# Conflicts: # data/launchpads.rb
2 parents 2b3e5ae + 1c92d9f commit 7dced91

File tree

10 files changed

+196
-132
lines changed

10 files changed

+196
-132
lines changed

.travis.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
language: ruby
2+
3+
sudo: required
4+
dist: trusty
5+
6+
before_install:
7+
- gem update --system
8+
- gem --version

CONTRIBUTING.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
## Contribution Steps (New Contributors)
2+
3+
1. Fork the repo, make changes, commit, and submit a Pull Request
4+
5+
2. New Pull Requests will automatically trigger a Travis CI Build
6+
7+
3. If the build fails, look at the [Build Logs](https://travis-ci.org/r-spacex/SpaceX-API).
8+
Changes will not be merged unless the build passes.
9+
10+
4. If the build succeeds, the pull request will be merged, and automatically
11+
pushed to the staging server at [http://api.spacexdev.com](http://api.spacexdev.com) for a
12+
final check before promoting changes to production at [https://api.spacexdata.com](https://api.spacexdata.com).
13+
14+
## Contribution Steps (Org Members)
15+
16+
1. Make changes, create a commit, and push to master
17+
18+
2. New pushes will trigger a Travis CI build automatically
19+
20+
3. If the build fails, look at the [Build Logs](https://travis-ci.org/r-spacex/SpaceX-API).
21+
Heroku will not accept a failing build onto the staging server.
22+
23+
4. If the build succeeds, Heroku will automatically deploy to
24+
the staging server at [http://api.spacexdev.com](http://api.spacexdev.com)
25+
26+
5. After a final check, the changes can be promoted to the Heroku production server at [https://api.spacexdata.com](https://api.spacexdata.com)

Gemfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@ gem 'sinatra'
33
gem 'sinatra-subdomain'
44
gem 'json'
55
gem 'mysql2'
6+
gem 'rack-test'
7+
gem 'test-unit'
8+
gem 'rake'

Gemfile.lock

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,22 @@ GEM
44
json (2.1.0)
55
mustermann (1.0.0)
66
mysql2 (0.4.6)
7+
power_assert (1.0.2)
78
rack (2.0.3)
89
rack-protection (2.0.0)
910
rack
11+
rack-test (0.6.3)
12+
rack (>= 1.0)
13+
rake (12.0.0)
1014
sinatra (2.0.0)
1115
mustermann (~> 1.0)
1216
rack (~> 2.0)
1317
rack-protection (= 2.0.0)
1418
tilt (~> 2.0)
1519
sinatra-subdomain (0.3.0)
1620
sinatra
21+
test-unit (3.2.5)
22+
power_assert
1723
tilt (2.0.7)
1824

1925
PLATFORMS
@@ -22,8 +28,11 @@ PLATFORMS
2228
DEPENDENCIES
2329
json
2430
mysql2
31+
rack-test
32+
rake
2533
sinatra
2634
sinatra-subdomain
35+
test-unit
2736

2837
BUNDLED WITH
2938
1.15.1

README.md

Lines changed: 11 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -4,123 +4,24 @@
44

55
![Imgur](http://i.imgur.com/EdfIdgC.jpg)
66

7-
# SpaceX JSON Data API
7+
# SpaceX Data REST API
88

9+
[![Build Status](https://travis-ci.org/r-spacex/SpaceX-API.svg?branch=master)](https://travis-ci.org/r-spacex/SpaceX-API)
910
[![GitHub release](https://img.shields.io/github/release/jakewmeyer/SpaceX-API.svg)]()
1011
[![Language](https://img.shields.io/badge/language-Ruby-red.svg)]()
1112
[![license](https://img.shields.io/github/license/mashape/apistatus.svg)]()
1213
[![Platform](https://img.shields.io/badge/platform-REST--API-brightgreen.svg)]()
1314

14-
### JSON API for data regarding company info, vehicles, launch sites, and launch data.
15+
### REST API for data regarding company info, vehicles, launch sites, and launch data.
1516
<br></br>
16-
# Usage / Endpoints
17-
</div>
18-
19-
20-
## Basic Info
21-
Get API info
22-
```http
23-
GET https://api.spacexdata.com
24-
```
25-
Get company info
26-
```http
27-
GET https://api.spacexdata.com/info
28-
```
29-
Get vehicle information
30-
```http
31-
GET https://api.spacexdata.com/vehicles
32-
```
33-
```http
34-
GET https://api.spacexdata.com/vehicles/falcon9
35-
GET https://api.spacexdata.com/vehicles/falconheavy
36-
GET https://api.spacexdata.com/vehicles/dragon
37-
```
38-
Get launchpad information
39-
```http
40-
GET https://api.spacexdata.com/launchpads
41-
```
42-
## Launch information by dates
43-
Get all launches
44-
```http
45-
GET https://api.spacexdata.com/launches
46-
```
47-
Get all future launches
48-
```http
49-
GET https://api.spacexdata.com/launches/upcoming
50-
```
51-
Get past launches by year
52-
```http
53-
GET https://api.spacexdata.com/launches?year=2017
54-
```
55-
Get past launches in a date range
56-
```http
57-
GET https://api.spacexdata.com/launches?from=2011-01-20&to=2017-05-25
58-
```
59-
60-
## Launch info by serial #'s
61-
Get launches by core serial #
62-
```http
63-
GET https://api.spacexdata.com/launches/cores/B1021
64-
```
65-
Get launches by capsule serial #
66-
```http
67-
GET https://api.spacexdata.com/launches/caps/C106
68-
```
6917

70-
## Detailed info about each capsule
71-
Get detailed info on all capsules
72-
```http
73-
GET https://api.spacexdata.com/parts/caps
74-
```
75-
Get detailed capsule information by serial #
76-
```http
77-
GET https://api.spacexdata.com/parts/caps/C106
78-
```
79-
80-
## Detailed info about each core
81-
Get detailed info on all cores
82-
```http
83-
GET https://api.spacexdata.com/parts/cores
84-
```
85-
Get detailed core information by serial #
86-
```http
87-
GET https://api.spacexdata.com/parts/cores/B1021
88-
```
89-
90-
## JSON launch response example
18+
</div>
9119

92-
```json
93-
{
94-
"flight_number": 42,
95-
"launch_year": "2017",
96-
"launch_date": "2017-06-23",
97-
"time_utc": "19:10",
98-
"time_local": "03:10 pm EDT",
99-
"rocket": "Falcon 9",
100-
"rocket_type": "FT",
101-
"core_serial": "B1029",
102-
"cap_serial": "",
103-
"launch_site": "KSC LC39A",
104-
"payload_1": "BulgariaSat-1",
105-
"payload_2": "",
106-
"payload_type": "Satelite",
107-
"payload_mass_kg": 3669,
108-
"payload_mass_lbs": 8089,
109-
"orbit": "GTO",
110-
"customer_1": "Bulgaria Sat",
111-
"customer_2": "",
112-
"launch_success": true,
113-
"reused": true,
114-
"land_success": true,
115-
"landing_type": "ASDS",
116-
"mission_patch": "http://i.imgur.com/VAvulaO.png",
117-
"article_link": "https://en.wikipedia.org/wiki/BulgariaSat-1",
118-
"video_link": "https://www.youtube.com/watch?v=Y8mLi-rRTh8",
119-
"details": "Second time a booster will be reused: Second flight of B1029 after the Iridium mission of January 2017. The satellite will be the first commercial Bulgarian-owned communications satellite and it will provide television broadcasts and other communications services over southeast Europe."
120-
},
121-
```
122-
<br></br>
20+
## Usage / Endpoints
21+
See the [Wiki](https://github.com/r-spacex/SpaceX-API/wiki) for API Documentation
12322

23+
## Contributions
24+
See the [Contribution](https://github.com/r-spacex/SpaceX-API/blob/master/CONTRIBUTING.md) guide for detailed steps
12425

12526
## FAQ's
12627
* If you have any questions or corrections, please open an issue and we'll get it merged ASAP
@@ -129,9 +30,7 @@ GET https://api.spacexdata.com/parts/cores/B1021
12930
* For any other questions or concerns, just shoot me an email
13031

13132
## Technical Details
132-
* API is using [Sinatra](http://www.sinatrarb.com/) as a framework in Ruby
133-
* Launch, Capsule, and Core data implemented in [MariaDB](https://mariadb.org/)
134-
* Vehicle, Launchpad, and Company data is stored directly in JSON
33+
* API is using [Sinatra](http://www.sinatrarb.com/) framework
34+
* Launch, Capsule, and Core data stored in [MariaDB](https://mariadb.org/)
35+
* Vehicle, Launchpad, and Company data is stored in Ruby hashes.
13536
* API is deployed on [Heroku](https://www.heroku.com/)
136-
* This repo deploys to a staging server first, so the production server might
137-
be a few commits behind, this allows for testing, and preserves stability

Rakefile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
require 'bundler'
2+
require "test/unit"
3+
require "rack/test"
4+
5+
require 'rake/testtask'
6+
Rake::TestTask.new(:test) do |test|
7+
test.libs << 'lib' << 'test'
8+
test.pattern = 'test/test.rb'
9+
test.warning = true
10+
test.verbose = true
11+
end
12+
13+
task :default => [:test]

app.rb

Lines changed: 76 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
#
12
# SpaceX API for searching company info,
23
# vehicle info, launch sites, and
34
# launch data.
5+
#
46

7+
require 'bundler/setup'
58
require 'sinatra'
69
require 'sinatra/subdomain'
710
require 'json'
@@ -14,6 +17,10 @@
1417
require './data/launchpads.rb'
1518
require './data/dragon.rb'
1619

20+
# Uses the modular version of Sinatra
21+
class SpacexAPI < Sinatra::Base
22+
register Sinatra::Subdomain
23+
1724
# DB connection to MariaDB
1825
DB = Mysql2::Client.new(
1926
:host => ENV['MARIA_HOST'],
@@ -41,6 +48,9 @@ def hash_merge(*hashes)
4148
# Uses subdomain api.example.com to route traffic
4249
subdomain :api do
4350

51+
#
52+
# Basic Info Endpoints
53+
#
4454
get '/' do
4555
content_type :json
4656
JSON.pretty_generate($home_info)
@@ -85,10 +95,13 @@ def hash_merge(*hashes)
8595
JSON.pretty_generate(hash)
8696
end
8797

88-
# Gets upcoming launches
98+
99+
#
100+
# Upcoming launch endpoints
101+
#
89102
get '/launches/upcoming' do
90103
content_type :json
91-
results = DB.query("SELECT * FROM launch WHERE launch_year = 'upcoming'", :cast_booleans => true)
104+
results = DB.query("SELECT * FROM upcoming", :cast_booleans => true)
92105
hash = results.each do |row|
93106
end
94107
if hash.empty?
@@ -99,6 +112,44 @@ def hash_merge(*hashes)
99112
end
100113
end
101114

115+
# Gets upcoming launches sorted by year
116+
get '/launches/upcoming/year=:year' do
117+
content_type :json
118+
year = params['year']
119+
statement = DB.prepare('SELECT * FROM upcoming WHERE launch_year = ?')
120+
results = statement.execute(year)
121+
hash = results.each do |row|
122+
end
123+
if hash.empty?
124+
error = { error: 'No Matches Found' }
125+
JSON.pretty_generate(error)
126+
else
127+
JSON.pretty_generate(hash)
128+
end
129+
end
130+
131+
# Gets upcoming launches in a date range
132+
get '/launches/upcoming/from=:start&to=:final' do
133+
content_type :json
134+
start = params['start']
135+
final = params['final']
136+
statement = DB.prepare('SELECT * FROM upcoming WHERE launch_date BETWEEN ? AND ?;',)
137+
results = statement.execute(start, final)
138+
hash = results.each do |row|
139+
end
140+
if hash.empty?
141+
error = { error: 'No Matches Found' }
142+
JSON.pretty_generate(error)
143+
else
144+
JSON.pretty_generate(hash)
145+
end
146+
end
147+
148+
149+
#
150+
# Launches by year endpoints
151+
#
152+
102153
# Gets launches sorted by year
103154
get '/launches/year=:year' do
104155
content_type :json
@@ -115,7 +166,29 @@ def hash_merge(*hashes)
115166
end
116167
end
117168

118-
# Get all launches with a serial number
169+
# Gets all launches in a date range
170+
get '/launches/from=:start&to=:final' do
171+
content_type :json
172+
start = params['start']
173+
final = params['final']
174+
statement = DB.prepare('SELECT * FROM launch WHERE launch_date BETWEEN ? AND ?;',)
175+
results = statement.execute(start, final)
176+
hash = results.each do |row|
177+
end
178+
if hash.empty?
179+
error = { error: 'No Matches Found' }
180+
JSON.pretty_generate(error)
181+
else
182+
JSON.pretty_generate(hash)
183+
end
184+
end
185+
186+
187+
#
188+
# Launches by part serial #'s'
189+
#
190+
191+
# Get all launches with a core serial number
119192
get '/launches/cores/:core' do
120193
content_type :json
121194
core = params['core']
@@ -206,21 +279,5 @@ def hash_merge(*hashes)
206279
JSON.pretty_generate(hash)
207280
end
208281
end
209-
210-
# Gets all launches in a date range
211-
get '/launches/from=:start&to=:final' do
212-
content_type :json
213-
start = params['start']
214-
final = params['final']
215-
statement = DB.prepare('SELECT * FROM launch WHERE launch_date BETWEEN ? AND ?;',)
216-
results = statement.execute(start, final)
217-
hash = results.each do |row|
218-
end
219-
if hash.empty?
220-
error = { error: 'No Matches Found' }
221-
JSON.pretty_generate(error)
222-
else
223-
JSON.pretty_generate(hash)
224-
end
225282
end
226283
end

config.ru

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
# Rack uses this to start the application
22

3+
require 'bundler'
34
require './app'
4-
run Sinatra::Application
5+
6+
Bundler.require
7+
8+
run SpacexAPI

0 commit comments

Comments
 (0)