Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #1 from gabebw/gbw-some_cleanup

Some @gabebw fancyness
  • Loading branch information...
commit 564e80272252032735bd58495ea186319a7c00a0 2 parents d460ce5 + 4d49df3
Alex Godin authored
Showing with 13 additions and 8 deletions.
  1. +13 −8 app.rb
21 app.rb
View
@@ -5,21 +5,26 @@
include AWS::S3
get '/bomb/:count' do |count|
- connect_to_s3
- corgis = Bucket.objects('Corgi')
- randomcorgis = corgis.shuffle![1..[corgis.count,count.to_i].min]
- corgi_urls = randomcorgis.map {|corgi| corgi.url}
- corgi_urls.to_json
+ corgis = all_corgis
+
+ number_of_pictures_to_return = [corgis.count, count.to_i].min
+
+ random_corgis = corgis.shuffle![1..number_of_pictures_to_return]
+
+ random_corgis.map(&:url).to_json
end
get '/random' do
- connect_to_s3
- corgis = Bucket.objects('Corgi')
- randomcorgis = corgis[rand(corgis.count)].url
+ all_corgis.sample.url
end
private
+def all_corgis
+ connect_to_s3
+ Bucket.objects('Corgi')
+end
+
def connect_to_s3
Base.establish_connection!(
:access_key_id => '',
Please sign in to comment.
Something went wrong with that request. Please try again.