Skip to content

Commit e3ba38d

Browse files
Merge remote-tracking branch 'r-spacex/master'
2 parents 0c7309e + 89ab310 commit e3ba38d

File tree

6 files changed

+87
-88
lines changed

6 files changed

+87
-88
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ GET https://api.spacexdata.com/launches/upcoming
5050
```
5151
Get past launches by year
5252
```http
53-
GET https://api.spacexdata.com/launches/year=2017
53+
GET https://api.spacexdata.com/launches?year=2017
5454
```
5555
Get past launches in a date range
5656
```http
57-
GET https://api.spacexdata.com/launches/from=2011-01-20/to=2017-05-25
57+
GET https://api.spacexdata.com/launches?from=2011-01-20&to=2017-05-25
5858
```
5959

6060
## Launch info by serial #'s

app.rb

Lines changed: 29 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
# vehicle info, launch sites, and
33
# launch data.
44

5-
65
require 'sinatra'
76
require 'sinatra/subdomain'
87
require 'json'
@@ -15,38 +14,33 @@
1514
require './data/launchpads.rb'
1615
require './data/dragon.rb'
1716

18-
1917
# DB connection to MariaDB
2018
DB = Mysql2::Client.new(
21-
:host => ENV["MARIA_HOST"],
22-
:username => ENV["MARIA_USER"],
23-
:password => ENV["MARIA_PASS"],
24-
:database => ENV["MARIA_DB"],
25-
:reconnect => true)
26-
19+
:host => ENV['MARIA_HOST'],
20+
:username => ENV['MARIA_USER'],
21+
:password => ENV['MARIA_PASS'],
22+
:database => ENV['MARIA_DB'],
23+
:reconnect => true
24+
)
2725

2826
# Disables rack protection because of false positives
2927
# that were blocking connections to home page
3028
disable :protection
3129

32-
3330
# No longer necessary
3431
# Forces the use of HTTPS for the API
35-
#before do
32+
# before do
3633
# redirect request.url.sub('http', 'https') unless request.secure?
37-
#end
38-
34+
# end
3935

4036
# Method for merging hashes of static data
41-
def hash_merge *hashes
37+
def hash_merge(*hashes)
4238
hashes.inject :merge
4339
end
4440

45-
4641
# Uses subdomain api.example.com to route traffic
4742
subdomain :api do
4843

49-
5044
get '/' do
5145
content_type :json
5246
JSON.pretty_generate($home_info)
@@ -59,8 +53,7 @@ def hash_merge *hashes
5953

6054
get '/vehicles' do
6155
content_type :json
62-
merge = hash_merge($falcon9, $falcon_heavy, $dragon)
63-
JSON.pretty_generate(merge)
56+
JSON.pretty_generate([$falcon9, $falcon_heavy, $dragon])
6457
end
6558

6659
get '/vehicles/falcon9' do
@@ -86,7 +79,7 @@ def hash_merge *hashes
8679
# Returns all launches
8780
get '/launches' do
8881
content_type :json
89-
results = DB.query("SELECT * FROM launch", :cast_booleans => true)
82+
results = DB.query('SELECT * FROM launch', :cast_booleans => true)
9083
hash = results.each do |row|
9184
end
9285
JSON.pretty_generate(hash)
@@ -99,7 +92,7 @@ def hash_merge *hashes
9992
hash = results.each do |row|
10093
end
10194
if hash.empty?
102-
error = {error: 'No Matches Found'}
95+
error = { error: 'No Matches Found' }
10396
JSON.pretty_generate(error)
10497
else
10598
JSON.pretty_generate(hash)
@@ -110,12 +103,12 @@ def hash_merge *hashes
110103
get '/launches/year=:year' do
111104
content_type :json
112105
year = params['year']
113-
statement = DB.prepare("SELECT * FROM launch WHERE launch_year = ?")
106+
statement = DB.prepare('SELECT * FROM launch WHERE launch_year = ?')
114107
results = statement.execute(year)
115108
hash = results.each do |row|
116109
end
117110
if hash.empty?
118-
error = {error: 'No Matches Found'}
111+
error = { error: 'No Matches Found' }
119112
JSON.pretty_generate(error)
120113
else
121114
JSON.pretty_generate(hash)
@@ -126,12 +119,12 @@ def hash_merge *hashes
126119
get '/launches/cores/:core' do
127120
content_type :json
128121
core = params['core']
129-
statement = DB.prepare("SELECT * FROM launch WHERE core_serial = ?")
122+
statement = DB.prepare('SELECT * FROM launch WHERE core_serial = ?')
130123
results = statement.execute(core)
131124
hash = results.each do |row|
132125
end
133126
if hash.empty?
134-
error = {error: 'No Matches Found'}
127+
error = { error: 'No Matches Found' }
135128
JSON.pretty_generate(error)
136129
else
137130
JSON.pretty_generate(hash)
@@ -142,12 +135,12 @@ def hash_merge *hashes
142135
get '/parts/caps/:cap' do
143136
content_type :json
144137
cap = params['cap']
145-
statement = DB.prepare("SELECT * FROM capsule WHERE capsule_serial = ?")
138+
statement = DB.prepare('SELECT * FROM capsule WHERE capsule_serial = ?')
146139
results = statement.execute(cap)
147140
hash = results.each do |row|
148141
end
149142
if hash.empty?
150-
error = {error: 'No Matches Found'}
143+
error = { error: 'No Matches Found' }
151144
JSON.pretty_generate(error)
152145
else
153146
JSON.pretty_generate(hash)
@@ -157,11 +150,11 @@ def hash_merge *hashes
157150
# Get all Dragon Capsule information
158151
get '/parts/caps' do
159152
content_type :json
160-
results = DB.query("SELECT * FROM capsule", :cast_booleans => true)
153+
results = DB.query('SELECT * FROM capsule', :cast_booleans => true)
161154
hash = results.each do |row|
162155
end
163156
if hash.empty?
164-
error = {error: 'No Matches Found'}
157+
error = { error: 'No Matches Found' }
165158
JSON.pretty_generate(error)
166159
else
167160
JSON.pretty_generate(hash)
@@ -172,12 +165,12 @@ def hash_merge *hashes
172165
get '/launches/caps/:cap' do
173166
content_type :json
174167
cap = params['cap']
175-
statement = DB.prepare("SELECT * FROM launch WHERE cap_serial = ?")
168+
statement = DB.prepare('SELECT * FROM launch WHERE cap_serial = ?')
176169
results = statement.execute(cap)
177170
hash = results.each do |row|
178171
end
179172
if hash.empty?
180-
error = {error: 'No Matches Found'}
173+
error = { error: 'No Matches Found' }
181174
JSON.pretty_generate(error)
182175
else
183176
JSON.pretty_generate(hash)
@@ -187,11 +180,11 @@ def hash_merge *hashes
187180
# Get all Dragon core information
188181
get '/parts/cores' do
189182
content_type :json
190-
results = DB.query("SELECT * FROM core", :cast_booleans => true)
183+
results = DB.query('SELECT * FROM core', :cast_booleans => true)
191184
hash = results.each do |row|
192185
end
193186
if hash.empty?
194-
error = {error: 'No Matches Found'}
187+
error = { error: 'No Matches Found' }
195188
JSON.pretty_generate(error)
196189
else
197190
JSON.pretty_generate(hash)
@@ -202,29 +195,29 @@ def hash_merge *hashes
202195
get '/parts/cores/:core' do
203196
content_type :json
204197
core = params['core']
205-
statement = DB.prepare("SELECT * FROM core WHERE core_serial = ?")
198+
statement = DB.prepare('SELECT * FROM core WHERE core_serial = ?')
206199
results = statement.execute(core)
207200
hash = results.each do |row|
208201
end
209202
if hash.empty?
210-
error = {error: 'No Matches Found'}
203+
error = { error: 'No Matches Found' }
211204
JSON.pretty_generate(error)
212205
else
213206
JSON.pretty_generate(hash)
214207
end
215208
end
216209

217210
# Gets all launches in a date range
218-
get '/launches/from=:start/to=:final' do
211+
get '/launches/from=:start&to=:final' do
219212
content_type :json
220213
start = params['start']
221214
final = params['final']
222-
statement = DB.prepare("SELECT * FROM launch WHERE launch_date BETWEEN ? AND ?;",)
215+
statement = DB.prepare('SELECT * FROM launch WHERE launch_date BETWEEN ? AND ?;',)
223216
results = statement.execute(start, final)
224217
hash = results.each do |row|
225218
end
226219
if hash.empty?
227-
error = {error: 'No Matches Found'}
220+
error = { error: 'No Matches Found' }
228221
JSON.pretty_generate(error)
229222
else
230223
JSON.pretty_generate(hash)

data/dragon.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
$dragon = {
2-
dragon: {
2+
id: 'dragon',
33
name: 'Dragon 1',
44
active: true,
55
sidewall_angle_deg: 15,
@@ -72,5 +72,4 @@
7272
meters: 3.7,
7373
feet: 12
7474
}
75-
}
7675
}

data/falcon9.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
$falcon9 = {
2-
falcon9: {
2+
id: 'falcon9',
33
name: 'Falcon 9',
44
active: true,
55
stages: 2,
@@ -97,5 +97,4 @@
9797
material: 'carbon fiber'
9898
},
9999
description: 'Falcon 9 is a two-stage rocket designed and manufactured by SpaceX for the reliable and safe transport of satellites and the Dragon spacecraft into orbit.'
100-
}
101100
}

data/falcon_heavy.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
$falcon_heavy = {
2-
falcon_heavy: {
2+
id: 'falcon_heavy',
33
name: 'Falcon Heavy',
44
active: false,
55
stages: 2,
@@ -101,5 +101,4 @@
101101
material: 'carbon fiber'
102102
},
103103
description: 'With the ability to lift into orbit over 54 metric tons (119,000 lb)--a mass equivalent to a 737 jetliner loaded with passengers, crew, luggage and fuel--Falcon Heavy can lift more than twice the payload of the next closest operational vehicle, the Delta IV Heavy, at one-third the cost.'
104-
}
105104
}

0 commit comments

Comments
 (0)