Skip to content

Commit 02957bb

Browse files
committed
rubocop linter fixes and changes
1 parent 6670e91 commit 02957bb

File tree

1 file changed

+27
-33
lines changed

1 file changed

+27
-33
lines changed

app.rb

Lines changed: 27 additions & 33 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)
@@ -86,7 +80,7 @@ def hash_merge *hashes
8680
# Returns all launches
8781
get '/launches' do
8882
content_type :json
89-
results = DB.query("SELECT * FROM launch", :cast_booleans => true)
83+
results = DB.query('SELECT * FROM launch', :cast_booleans => true)
9084
hash = results.each do |row|
9185
end
9286
JSON.pretty_generate(hash)
@@ -99,7 +93,7 @@ def hash_merge *hashes
9993
hash = results.each do |row|
10094
end
10195
if hash.empty?
102-
error = {error: 'No Matches Found'}
96+
error = { error: 'No Matches Found' }
10397
JSON.pretty_generate(error)
10498
else
10599
JSON.pretty_generate(hash)
@@ -110,12 +104,12 @@ def hash_merge *hashes
110104
get '/launches/year=:year' do
111105
content_type :json
112106
year = params['year']
113-
statement = DB.prepare("SELECT * FROM launch WHERE launch_year = ?")
107+
statement = DB.prepare('SELECT * FROM launch WHERE launch_year = ?')
114108
results = statement.execute(year)
115109
hash = results.each do |row|
116110
end
117111
if hash.empty?
118-
error = {error: 'No Matches Found'}
112+
error = { error: 'No Matches Found' }
119113
JSON.pretty_generate(error)
120114
else
121115
JSON.pretty_generate(hash)
@@ -126,12 +120,12 @@ def hash_merge *hashes
126120
get '/launches/cores/:core' do
127121
content_type :json
128122
core = params['core']
129-
statement = DB.prepare("SELECT * FROM launch WHERE core_serial = ?")
123+
statement = DB.prepare('SELECT * FROM launch WHERE core_serial = ?')
130124
results = statement.execute(core)
131125
hash = results.each do |row|
132126
end
133127
if hash.empty?
134-
error = {error: 'No Matches Found'}
128+
error = { error: 'No Matches Found' }
135129
JSON.pretty_generate(error)
136130
else
137131
JSON.pretty_generate(hash)
@@ -142,12 +136,12 @@ def hash_merge *hashes
142136
get '/parts/caps/:cap' do
143137
content_type :json
144138
cap = params['cap']
145-
statement = DB.prepare("SELECT * FROM capsule WHERE capsule_serial = ?")
139+
statement = DB.prepare('SELECT * FROM capsule WHERE capsule_serial = ?')
146140
results = statement.execute(cap)
147141
hash = results.each do |row|
148142
end
149143
if hash.empty?
150-
error = {error: 'No Matches Found'}
144+
error = { error: 'No Matches Found' }
151145
JSON.pretty_generate(error)
152146
else
153147
JSON.pretty_generate(hash)
@@ -157,11 +151,11 @@ def hash_merge *hashes
157151
# Get all Dragon Capsule information
158152
get '/parts/caps' do
159153
content_type :json
160-
results = DB.query("SELECT * FROM capsule", :cast_booleans => true)
154+
results = DB.query('SELECT * FROM capsule', :cast_booleans => true)
161155
hash = results.each do |row|
162156
end
163157
if hash.empty?
164-
error = {error: 'No Matches Found'}
158+
error = { error: 'No Matches Found' }
165159
JSON.pretty_generate(error)
166160
else
167161
JSON.pretty_generate(hash)
@@ -172,12 +166,12 @@ def hash_merge *hashes
172166
get '/launches/caps/:cap' do
173167
content_type :json
174168
cap = params['cap']
175-
statement = DB.prepare("SELECT * FROM launch WHERE cap_serial = ?")
169+
statement = DB.prepare('SELECT * FROM launch WHERE cap_serial = ?')
176170
results = statement.execute(cap)
177171
hash = results.each do |row|
178172
end
179173
if hash.empty?
180-
error = {error: 'No Matches Found'}
174+
error = { error: 'No Matches Found' }
181175
JSON.pretty_generate(error)
182176
else
183177
JSON.pretty_generate(hash)
@@ -187,11 +181,11 @@ def hash_merge *hashes
187181
# Get all Dragon core information
188182
get '/parts/cores' do
189183
content_type :json
190-
results = DB.query("SELECT * FROM core", :cast_booleans => true)
184+
results = DB.query('SELECT * FROM core', :cast_booleans => true)
191185
hash = results.each do |row|
192186
end
193187
if hash.empty?
194-
error = {error: 'No Matches Found'}
188+
error = { error: 'No Matches Found' }
195189
JSON.pretty_generate(error)
196190
else
197191
JSON.pretty_generate(hash)
@@ -202,12 +196,12 @@ def hash_merge *hashes
202196
get '/parts/cores/:core' do
203197
content_type :json
204198
core = params['core']
205-
statement = DB.prepare("SELECT * FROM core WHERE core_serial = ?")
199+
statement = DB.prepare('SELECT * FROM core WHERE core_serial = ?')
206200
results = statement.execute(core)
207201
hash = results.each do |row|
208202
end
209203
if hash.empty?
210-
error = {error: 'No Matches Found'}
204+
error = { error: 'No Matches Found' }
211205
JSON.pretty_generate(error)
212206
else
213207
JSON.pretty_generate(hash)
@@ -219,12 +213,12 @@ def hash_merge *hashes
219213
content_type :json
220214
start = params['start']
221215
final = params['final']
222-
statement = DB.prepare("SELECT * FROM launch WHERE launch_date BETWEEN ? AND ?;",)
216+
statement = DB.prepare('SELECT * FROM launch WHERE launch_date BETWEEN ? AND ?;',)
223217
results = statement.execute(start, final)
224218
hash = results.each do |row|
225219
end
226220
if hash.empty?
227-
error = {error: 'No Matches Found'}
221+
error = { error: 'No Matches Found' }
228222
JSON.pretty_generate(error)
229223
else
230224
JSON.pretty_generate(hash)

0 commit comments

Comments
 (0)