Permalink
Browse files

Update cron for Rails, Preferences, OAuth changes

  • Loading branch information...
1 parent 29cb83a commit 1e84f4bc3aa32f06df6b2cb86bb576f19358dd7a @joanwolk joanwolk committed Aug 30, 2011
Showing with 19 additions and 27 deletions.
  1. +3 −1 app/helpers/application_helper.rb
  2. +12 −16 lib/day_pass.rb
  3. +2 −5 lib/tasks/day_pass.rake
  4. +2 −5 spec/day_pass_spec.rb
@@ -20,8 +20,10 @@ def base_url(subdomain = @subdomain)
"https://#{subdomain}.cobot.me/api"
end
- def access_token
+ def user_access_token
@access_token ||= OAuth2::AccessToken.new(client, session[:token])
+ @access_token.options[:header_format] = "OAuth %s"
+ @access_token
end
def client
View
@@ -1,23 +1,15 @@
-require "rubygems"
-require "bundler/setup"
-
-require 'omniauth'
-require 'json'
-require 'active_support/time'
-require 'pony'
-
class DayPass
- def initialize(subdomain, access_token_string, expire_after_days)
- @subdomain = subdomain
+ def initialize(subdomain_name, access_token_string, expire_after_days)
+ @subdomain = subdomain_name
@access_token_string = access_token_string
@expire_after_days = expire_after_days
end
def self.delete_unused
- spaces = JSON.parse(ENV['COBOT_SPACES'])
- spaces.each do |subdomain, options|
- new(subdomain, options['access_token'], options['expire_after_days']).delete_unused
+ spaces = Preference.all
+ spaces.each do |space|
+ new(space.subdomain_name, space.access_token_string, space.expire_after_days).delete_unused
end
end
@@ -85,19 +77,23 @@ def base_url(subdomain = @subdomain)
def access_token
@access_token ||= OAuth2::AccessToken.new(client, @access_token_string)
+ @access_token.options[:header_format] = "OAuth %s"
+ @access_token
end
def client
@client ||= OAuth2::Client.new(
- nil,
- nil,
+ ENV['client_id'],
+ ENV['client_secret'],
site: {
url: "https://#{@subdomain}.cobot.me",
ssl: {
verify: false
}
},
- parse_json: true
+ raise_errors: false,
+ authorize_path: '/oauth2/authorize',
+ access_token_path: '/oauth2/access_token'
)
end
end
View
@@ -1,9 +1,6 @@
+require 'day_pass.rb'
desc "This task is called by the Heroku cron add-on"
-task :cron do
- begin
+task :cron => :environment do
DayPass.delete_unused
- rescue => e
- HoptoadNotifier.notify e
- end
end
View
@@ -1,14 +1,11 @@
require 'spec_helper'
require_relative '../lib/day_pass'
-require 'omniauth'
-require 'timecop'
-
describe DayPass, '.delete_unused' do
it "should initialize a new day pass for each space" do
- ENV['COBOT_SPACES'] = {'co-up' => {expire_after_days: 30, access_token: '123'}}.to_json
+ space1 = Preference.create!(subdomain_name: "test1", access_token_string: "123", expire_after_days: 30)
- DayPass.should_receive(:new).with('co-up', '123', 30).and_return(stub.as_null_object)
+ DayPass.should_receive(:new).with('test1', '123', 30).and_return(stub.as_null_object)
DayPass.delete_unused
end

0 comments on commit 1e84f4b

Please sign in to comment.