Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Some cleanup and 1.9 idioms. #1

Merged
merged 3 commits into from over 2 years ago

2 participants

Gabe Berke-Williams Alex Godin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 13 additions and 8 deletions. Show diff stats Hide diff stats

  1. +13 8 app.rb
21 app.rb
@@ -5,21 +5,26 @@
5 5 include AWS::S3
6 6
7 7 get '/bomb/:count' do |count|
8   - connect_to_s3
9   - corgis = Bucket.objects('Corgi')
10   - randomcorgis = corgis.shuffle![1..[corgis.count,count.to_i].min]
11   - corgi_urls = randomcorgis.map {|corgi| corgi.url}
12   - corgi_urls.to_json
  8 + corgis = all_corgis
  9 +
  10 + number_of_pictures_to_return = [corgis.count, count.to_i].min
  11 +
  12 + random_corgis = corgis.shuffle![1..number_of_pictures_to_return]
  13 +
  14 + random_corgis.map(&:url).to_json
13 15 end
14 16
15 17 get '/random' do
16   - connect_to_s3
17   - corgis = Bucket.objects('Corgi')
18   - randomcorgis = corgis[rand(corgis.count)].url
  18 + all_corgis.sample.url
19 19 end
20 20
21 21 private
22 22
  23 +def all_corgis
  24 + connect_to_s3
  25 + Bucket.objects('Corgi')
  26 +end
  27 +
23 28 def connect_to_s3
24 29 Base.establish_connection!(
25 30 :access_key_id => '',

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.