Permalink
Browse files

Easier Setup

* Added setup instructions to the readme
* Renamed config files
* Get secret_token from settings.yml
* Renamed Settings.key & Settings.secret to client_id and client_secret
  • Loading branch information...
1 parent c578481 commit 5832b565466ad0cc8fc829e3abbec564e727a2ba @gerrit gerrit committed Jan 4, 2013
View
@@ -3,3 +3,5 @@ db/*.sqlite3
log/*.log
tmp/
.sass-cache/
+config/settings.local.yml
+config/settings/*.local.yml
View
@@ -2,4 +2,11 @@
Host a contest, powered by [SoundCloud](http://soundcloud.com).
-SoundCloud-Competition is Copyright (c) 2010 Lee Martin and SoundCloud, released under the MIT License.
+## Setup
+
+1. Go to https://soundcloud.com/you/apps and register a new SoundCloud app. Note the values for "Client ID" and "Client Secret".
+2. Edit the data in `config/settings.yml`.
+3. Replace images in app/assets/images with your own
+4. Run `rake db:setup` to set up the local database with the default data
+
+SoundCloud-Competition is Copyright (c) 2010-2012 Lee Martin and SoundCloud, released under the MIT License.
@@ -4,6 +4,8 @@ class CompetitionsController < ApplicationController
def show
@competition = Competition.find(params[:id])
+ rescue ActiveRecord::RecordNotFound
+ render text: 'No Competition set up. Please edit db/seeds.rb and run `rake db:seed`', status: 404
end
def edit
View
@@ -24,15 +24,19 @@ def self.identify_or_create_from_omniauth(auth)
end
def soundcloud
- Soundcloud.new(:client_id => Settings.key, :client_secret => Settings.secret, :access_token => token)
+ Soundcloud.new(
+ :client_id => Settings.client_id,
+ :client_secret => Settings.client_secret,
+ :access_token => token
+ )
end
def soundcloud_tracks
tracks = []
- eof = false
+ eof = false
offset = 0
- until eof == true do
+ until eof == true do
new_tracks = soundcloud.get("/me/tracks.json?offset=#{offset}")
eof = true if new_tracks.length == 0
@@ -31,5 +31,5 @@
= render "footer"
:javascript
- group = "http://api.soundcloud.com/groups/#{@competition.group}?consumer_key=#{Settings.key}";
- key = "#{Settings.key}";
+ group = "http://api.soundcloud.com/groups/#{@competition.group}?consumer_key=#{Settings.client_id}";
+ key = "#{Settings.client_id}";
@@ -1,3 +1,3 @@
Rails.application.config.middleware.use OmniAuth::Builder do
- provider :soundcloud, Settings.key, Settings.secret, :scope => "non-expiring"
+ provider :soundcloud, Settings.client_id, Settings.client_secret, :scope => "non-expiring"
end
@@ -4,4 +4,4 @@
# If you change this key, all old signed cookies will become invalid!
# Make sure the secret is at least 30 characters and all random,
# no regular words or you'll be exposed to dictionary attacks.
-SoundCloudCompetition::Application.config.secret_token = ''
+SoundCloudCompetition::Application.config.secret_token = Settings.secret_token
No changes.
View
@@ -0,0 +1,26 @@
+# Be sure to restart your server after you modify this file.
+
+# Register your app at https://soundcloud.com/you/apps and copy&paste Client ID and Secret here
+client_id: ''
+client_secret: ''
+
+# Your secret key for verifying the integrity of signed cookies.
+# If you change this key, all old signed cookies will become invalid!
+# Make sure the secret is at least 30 characters and all random,
+# no regular words or you'll be exposed to dictionary attacks.
+secret_token: ''
+
+# Replace these defaults with the right values for your competition
+# These will only be applied the first time you run `rake db:setup`
+competition:
+ host: 'SoundCloud'
+ title: 'Competition'
+ intro: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam volutpat leo vitae leo rutrum ullamcorper. Maecenas in orci nulla. Aenean gravida adipiscing arcu at sodales.'
+ description: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam volutpat leo vitae leo rutrum ullamcorper. Maecenas in orci nulla. Aenean gravida adipiscing arcu at sodales. Donec nisl lacus, gravida sit amet aliquam vitae, pulvinar at sapien. Nullam congue convallis libero, ut luctus erat posuere eu. Fusce sit amet ante nisi, ac viverra ligula. Etiam vel velit tellus. Phasellus pharetra, ligula fermentum interdum lobortis, lorem arcu pulvinar urna, vel blandit augue augue pulvinar elit. Duis nec justo ut mi sollicitudin eleifend sed sit amet leo. Quisque aliquet quam eget tortor tincidunt malesuada. Vivamus at neque ut sem molestie vulputate ac id diam. Fusce ut pulvinar leo. Curabitur sit amet dui ut nulla venenatis pretium ac vel dolor. Aliquam id imperdiet arcu. Vestibulum molestie venenatis tellus, sed lobortis nisi sodales ac.'
+ prizes: '* Prize 1'
+ about: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam volutpat leo vitae leo rutrum ullamcorper. Maecenas in orci nulla. Aenean gravida adipiscing arcu at sodales.'
+ #group: ''
+ #rules: ''
+ #download: ''
+ start_date:
+ end_date:
@@ -1,2 +0,0 @@
-key: "9c621bb793d60983757f2894b7dd550f"
-secret: "8199e36f9ee704d5a96c2b9a9232d00a"
@@ -0,0 +1,3 @@
+# These are default settings for you to get started using the app in development mode only
+client_id: "9c621bb793d60983757f2894b7dd550f"
+client_secret: "8199e36f9ee704d5a96c2b9a9232d00a"
@@ -1,2 +0,0 @@
-key: ""
-secret: ""
No changes.
@@ -1,2 +0,0 @@
-key: ""
-secret: ""
View
@@ -1,25 +1,3 @@
-# This file should contain all the record creation needed to seed the database with its default values.
-# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
-#
-# Examples:
-#
-# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
-# Mayor.create(name: 'Emanuel', city: cities.first)
-
-data = {
- host: 'SoundCloud',
- title: 'Competition',
- intro: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam volutpat leo vitae leo rutrum ullamcorper. Maecenas in orci nulla. Aenean gravida adipiscing arcu at sodales.',
- description: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam volutpat leo vitae leo rutrum ullamcorper. Maecenas in orci nulla. Aenean gravida adipiscing arcu at sodales. Donec nisl lacus, gravida sit amet aliquam vitae, pulvinar at sapien. Nullam congue convallis libero, ut luctus erat posuere eu. Fusce sit amet ante nisi, ac viverra ligula. Etiam vel velit tellus. Phasellus pharetra, ligula fermentum interdum lobortis, lorem arcu pulvinar urna, vel blandit augue augue pulvinar elit. Duis nec justo ut mi sollicitudin eleifend sed sit amet leo. Quisque aliquet quam eget tortor tincidunt malesuada. Vivamus at neque ut sem molestie vulputate ac id diam. Fusce ut pulvinar leo. Curabitur sit amet dui ut nulla venenatis pretium ac vel dolor. Aliquam id imperdiet arcu. Vestibulum molestie venenatis tellus, sed lobortis nisi sodales ac.',
- prizes: '* Prize 1',
- about: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam volutpat leo vitae leo rutrum ullamcorper. Maecenas in orci nulla. Aenean gravida adipiscing arcu at sodales.',
- #group: '',
- #rules: '',
- #download: '',
- start_date: Time.now,
- end_date: Time.now + 30.days
-}
-
-Competition.create(data)
+Competition.create(Settings.competition.to_hash)
puts "Competition, fuck yeh."
View
@@ -1,35 +1,35 @@
namespace :competition do
desc "Import tracks from SoundCloud Group"
task :import => :environment do
-
+
# rake competition:import GROUP=http://soundcloud.com/groups/test
-
- @group = HTTParty.get("http://api.soundcloud.com/resolve?url=#{ENV["GROUP"]}&consumer_key=#{Settings.key}&format=json")
-
+
+ @group = HTTParty.get("http://api.soundcloud.com/resolve?url=#{ENV["GROUP"]}&consumer_key=#{Settings.client_id}&format=json")
+
if @group.response.code == "404"
-
+
puts "Group Not Found"
-
- else
-
+
+ else
+
puts "Group Found"
-
+
# Search for Tracks
-
+
end_of_group = false
offset = 0
-
+
until end_of_group do
-
- tracks = HTTParty.get("http://api.soundcloud.com/groups/#{@group["id"]}/tracks.json?consumer_key=#{Settings.key}&offset=#{offset}")
-
+
+ tracks = HTTParty.get("http://api.soundcloud.com/groups/#{@group["id"]}/tracks.json?consumer_key=#{Settings.client_id}&offset=#{offset}")
+
puts "#{tracks.length} Tracks Found"
-
+
end_of_group = true if tracks.length == 0
-
+
for track in tracks
if track["sharing"] == "public"
-
+
# Find or Create User
user = User.find_or_initialize_by_uid(track["user"]["id"])
@@ -41,12 +41,12 @@ namespace :competition do
})
# Identify or Create Track
- track = user.tracks.identify_or_create_from_soundcloud(track)
- end
+ track = user.tracks.identify_or_create_from_soundcloud(track)
+ end
end
-
+
offset += 50
-
+
end
end
end

0 comments on commit 5832b56

Please sign in to comment.