Skip to content
This repository has been archived by the owner on Jul 17, 2019. It is now read-only.

Commit

Permalink
Goal creation.
Browse files Browse the repository at this point in the history
  • Loading branch information
dividedmind committed Dec 29, 2012
1 parent 1e4c3c8 commit e0f8018
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 6 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ gem 'schema_plus'

gem 'oauth-plugin'

gem 'beeminder'

group :test do
gem 'rspec-rails'
gem 'simplecov'
Expand Down
11 changes: 11 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,15 @@ GEM
i18n (~> 0.6)
multi_json (~> 1.0)
arel (3.0.2)
beeminder (0.2.4)
activesupport (~> 3.2)
chronic (~> 0.7)
highline (~> 1.6)
json
trollop (~> 2)
tzinfo
builder (3.0.4)
chronic (0.9.0)
diff-lcs (1.1.3)
erubis (2.7.0)
execjs (1.4.0)
Expand All @@ -42,6 +50,7 @@ GEM
activesupport (>= 3.1, < 4.1)
haml (~> 3.1)
railties (>= 3.1, < 4.1)
highline (1.6.15)
hike (1.2.1)
httpauth (0.2.0)
i18n (0.6.1)
Expand Down Expand Up @@ -141,6 +150,7 @@ GEM
treetop (1.4.12)
polyglot
polyglot (>= 0.3.1)
trollop (2.0)
tzinfo (0.3.35)
uglifier (1.3.0)
execjs (>= 0.3.0)
Expand All @@ -151,6 +161,7 @@ PLATFORMS
ruby

DEPENDENCIES
beeminder
haml-rails
libv8
livescript-rails
Expand Down
7 changes: 6 additions & 1 deletion app/controllers/beeminder_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class BeeminderController < ApplicationController
def index
def show
if current_user && current_user.beeminder.nil?
redirect_to authorization_url
else
Expand All @@ -17,6 +17,11 @@ def destroy
redirect_to root_path
end

def create_goal
current_user.beeminder.create_goal
redirect_to root_path
end

private
def authorization_url
"https://www.beeminder.com/apps/authorize?client_id=#{client_id}&redirect_uri=#{callback_uri}&response_type=token"
Expand Down
43 changes: 43 additions & 0 deletions app/models/beeminder_token.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,46 @@
class BeeminderToken < ActiveRecord::Base
belongs_to :user

def client
@client ||= create_client
end

def goal
client.goal goal_name rescue nil
end

def create_goal
client.create_goal goal_options
end

private

def create_client
u = Beeminder::User.new access_token, auth_type: :oauth
class << u
def _connection *a
p *a
super *a
end
end
u
end

def goal_name
'beemindesk'
end

def goal_options
{
slug: goal_name,
title: "Hours on ODesk",
goal_type: :custom,
rate: 0,
goaldate: 1.year.from_now.utc.to_i,
ephem: true,
kyoom: true,
aggday: :last,
steppy: true
}
end
end
4 changes: 4 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@ class User < ActiveRecord::Base
def hours
odesk.client.hours
end

def goal
beeminder.goal
end
end
7 changes: 5 additions & 2 deletions app/views/dashboard/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
- if @user && @user.odesk
%p
Logged into ODesk as
= @user.id
= "#{@user.id}."
= button_to "logout", oauth_consumer_path(:odesk), method: :delete, class: :destroy

%table
Expand All @@ -25,8 +25,11 @@
- if @user.beeminder
%p
Logged into Beeminder as
= @user.beeminder.username
= "#{@user.beeminder.username}."
= #button_to "logout", beeminder_path, method: :delete, class: :destroy
- unless @user.goal
%p Goal doesn't exist.
= button_to "create it", create_goal_beeminder_path
- else
%p
Not logged into Beeminder.
Expand Down
7 changes: 4 additions & 3 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
Beemindesk::Application.routes.draw do

get "beeminder" => 'beeminder#index'
delete "beeminder" => 'beeminder#destroy'
get "beeminder/callback"
resource :beeminder, controller: :beeminder do
get 'callback'
post 'create_goal'
end

root to: 'dashboard#index'

Expand Down

0 comments on commit e0f8018

Please sign in to comment.