Skip to content

Commit

Permalink
Import the db with rake import after setting the authorizations.
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinBongart committed Mar 8, 2012
1 parent cc382e5 commit 1c8ad93
Show file tree
Hide file tree
Showing 41 changed files with 673 additions and 1 deletion.
3 changes: 3 additions & 0 deletions app/assets/javascripts/authorizations.js.coffee
@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/authorizations.css.scss
@@ -0,0 +1,3 @@
// Place all the styles related to the authorizations controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
56 changes: 56 additions & 0 deletions app/assets/stylesheets/scaffolds.css.scss
@@ -0,0 +1,56 @@
body {
background-color: #fff;
color: #333;
font-family: verdana, arial, helvetica, sans-serif;
font-size: 13px;
line-height: 18px; }

p, ol, ul, td {
font-family: verdana, arial, helvetica, sans-serif;
font-size: 13px;
line-height: 18px; }

pre {
background-color: #eee;
padding: 10px;
font-size: 11px; }

a {
color: #000;
&:visited {
color: #666; }
&:hover {
color: #fff;
background-color: #000; } }

div {
&.field, &.actions {
margin-bottom: 10px; } }

#notice {
color: green; }

.field_with_errors {
padding: 2px;
background-color: red;
display: table; }

#error_explanation {
width: 450px;
border: 2px solid red;
padding: 7px;
padding-bottom: 0;
margin-bottom: 20px;
background-color: #f0f0f0;
h2 {
text-align: left;
font-weight: bold;
padding: 5px 5px 5px 15px;
font-size: 12px;
margin: -7px;
margin-bottom: 0px;
background-color: #c00;
color: #fff; }
ul li {
font-size: 12px;
list-style: square; } }
83 changes: 83 additions & 0 deletions app/controllers/authorizations_controller.rb
@@ -0,0 +1,83 @@
class AuthorizationsController < ApplicationController
# GET /authorizations
# GET /authorizations.json
def index
@authorizations = Authorization.all

respond_to do |format|
format.html # index.html.erb
format.json { render :json => @authorizations }
end
end

# GET /authorizations/1
# GET /authorizations/1.json
def show
@authorization = Authorization.find(params[:id])

respond_to do |format|
format.html # show.html.erb
format.json { render :json => @authorization }
end
end

# GET /authorizations/new
# GET /authorizations/new.json
def new
@authorization = Authorization.new

respond_to do |format|
format.html # new.html.erb
format.json { render :json => @authorization }
end
end

# GET /authorizations/1/edit
def edit
@authorization = Authorization.find(params[:id])
end

# POST /authorizations
# POST /authorizations.json
def create
@authorization = Authorization.new(params[:authorization])

respond_to do |format|
if @authorization.save
format.html { redirect_to @authorization, :notice => 'Authorization was successfully created.' }
format.json { render :json => @authorization, :status => :created, :location => @authorization }
else
format.html { render :action => "new" }
format.json { render :json => @authorization.errors, :status => :unprocessable_entity }
end
end
end

# PUT /authorizations/1
# PUT /authorizations/1.json
def update
@authorization = Authorization.find(params[:id])

respond_to do |format|
if @authorization.update_attributes(params[:authorization])
format.html { redirect_to @authorization, :notice => 'Authorization was successfully updated.' }
format.json { head :no_content }
else
format.html { render :action => "edit" }
format.json { render :json => @authorization.errors, :status => :unprocessable_entity }
end
end
end

# DELETE /authorizations/1
# DELETE /authorizations/1.json
def destroy
@authorization = Authorization.find(params[:id])
@authorization.destroy

respond_to do |format|
format.html { redirect_to authorizations_url }
format.json { head :no_content }
end
end
end
4 changes: 4 additions & 0 deletions app/controllers/welcome_controller.rb
@@ -0,0 +1,4 @@
class WelcomeController < ActionController::Base
def index
end
end
2 changes: 2 additions & 0 deletions app/helpers/authorizations_helper.rb
@@ -0,0 +1,2 @@
module AuthorizationsHelper
end
2 changes: 2 additions & 0 deletions app/helpers/boards_helper.rb
@@ -0,0 +1,2 @@
module BoardsHelper
end
52 changes: 52 additions & 0 deletions app/models/action.rb
@@ -0,0 +1,52 @@
class Action < ActiveRecord::Base
belongs_to :card

default_scope order('date ASC')

def list_created_in
List.find_by_trello_id(self.list_trello_id)
end

def list_before
List.find_by_trello_id(self.list_before_trello_id)
end

def list_after
List.find_by_trello_id(self.list_after_trello_id)
end

def self.create_from_trello_data(data, card)
if data['type'] == 'createCard'
Action.create(
:trello_id => data['id'],
:card_id => card.id,
:list_trello_id => data['data']['list']['id'],
:date => data['date'].to_time
)
elsif (data['data']['listBefore'] && data['data']['listBefore'])
Action.create(
:trello_id => data['id'],
:card_id => card.id,
:list_before_trello_id => data['data']['listBefore']['id'],
:list_after_trello_id => data['data']['listBefore']['id'],
:date => data['date'].to_time
)
end
end

def self.fetch_from_trello(card)
auth = Authorization.first
base_url = "https://api.trello.com/1/"
tokens = "&key=#{auth.key}&token=#{auth.token}"
params = "cards/#{card.trello_id}/actions?filter=updateCard,createCard&limit=1000"

uri = URI.parse(base_url + params + tokens)
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Get.new(uri.request_uri)
response = JSON.parse(http.request(request).body)

response
end
end
2 changes: 2 additions & 0 deletions app/models/authorization.rb
@@ -0,0 +1,2 @@
class Authorization < ActiveRecord::Base
end
23 changes: 23 additions & 0 deletions app/models/board.rb
@@ -0,0 +1,23 @@
class Board < ActiveRecord::Base
has_many :lists

def self.create_from_trello_data(data)
Board.create(:trello_id => data['id'], :name => data['name'])
end

def self.fetch_from_trello
auth = Authorization.first
base_url = "https://api.trello.com/1/"
tokens = "&key=#{auth.key}&token=#{auth.token}"
params = "members/me?boards=open"

uri = URI.parse(base_url + params + tokens)
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Get.new(uri.request_uri)
response = JSON.parse(http.request(request).body)

response['boards']
end
end
25 changes: 25 additions & 0 deletions app/models/card.rb
@@ -0,0 +1,25 @@
class Card < ActiveRecord::Base
has_many :actions

default_scope order('trello_id ASC')

def self.create_from_trello_data(data)
Card.create(:trello_id => data['id'], :name => data['name'])
end

def self.fetch_from_trello(board)
auth = Authorization.first
base_url = "https://api.trello.com/1/"
tokens = "&key=#{auth.key}&token=#{auth.token}"
params = "boards/#{board.trello_id}/cards?"

uri = URI.parse(base_url + params + tokens)
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Get.new(uri.request_uri)
response = JSON.parse(http.request(request).body)

response
end
end
23 changes: 23 additions & 0 deletions app/models/list.rb
@@ -0,0 +1,23 @@
class List < ActiveRecord::Base
belongs_to :board

def self.create_from_trello_data(data, board)
List.create(:trello_id => data['id'], :name => data['name'], :board_id => board.id)
end

def self.fetch_from_trello(board)
auth = Authorization.first
base_url = "https://api.trello.com/1/"
tokens = "&key=#{auth.key}&token=#{auth.token}"
params = "boards/#{board.trello_id}/lists?"

uri = URI.parse(base_url + params + tokens)
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Get.new(uri.request_uri)
response = JSON.parse(http.request(request).body)

response
end
end
25 changes: 25 additions & 0 deletions app/views/authorizations/_form.html.erb
@@ -0,0 +1,25 @@
<%= form_for(@authorization) do |f| %>
<% if @authorization.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@authorization.errors.count, "error") %> prohibited this authorization from being saved:</h2>

<ul>
<% @authorization.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>

<div class="field">
<%= f.label :key %><br />
<%= f.text_field :key %>
</div>
<div class="field">
<%= f.label :token %><br />
<%= f.text_field :token %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
6 changes: 6 additions & 0 deletions app/views/authorizations/edit.html.erb
@@ -0,0 +1,6 @@
<h1>Editing authorization</h1>

<%= render 'form' %>
<%= link_to 'Show', @authorization %> |
<%= link_to 'Back', authorizations_path %>
25 changes: 25 additions & 0 deletions app/views/authorizations/index.html.erb
@@ -0,0 +1,25 @@
<h1>Listing authorizations</h1>

<table>
<tr>
<th>Key</th>
<th>Token</th>
<th></th>
<th></th>
<th></th>
</tr>

<% @authorizations.each do |authorization| %>
<tr>
<td><%= authorization.key %></td>
<td><%= authorization.token %></td>
<td><%= link_to 'Show', authorization %></td>
<td><%= link_to 'Edit', edit_authorization_path(authorization) %></td>
<td><%= link_to 'Destroy', authorization, :confirm => 'Are you sure?', :method => :delete %></td>
</tr>
<% end %>
</table>

<br />

<%= link_to 'New Authorization', new_authorization_path %>
5 changes: 5 additions & 0 deletions app/views/authorizations/new.html.erb
@@ -0,0 +1,5 @@
<h1>New authorization</h1>

<%= render 'form' %>
<%= link_to 'Back', authorizations_path %>
15 changes: 15 additions & 0 deletions app/views/authorizations/show.html.erb
@@ -0,0 +1,15 @@
<p id="notice"><%= notice %></p>

<p>
<b>Key:</b>
<%= @authorization.key %>
</p>

<p>
<b>Token:</b>
<%= @authorization.token %>
</p>


<%= link_to 'Edit', edit_authorization_path(@authorization) %> |
<%= link_to 'Back', authorizations_path %>
Empty file.
6 changes: 5 additions & 1 deletion config/routes.rb
@@ -1,4 +1,8 @@
Trellolol::Application.routes.draw do
resources :boards

resources :authorizations

# The priority is based upon order of creation:
# first created -> highest priority.

Expand Down Expand Up @@ -48,7 +52,7 @@

# You can have the root of your site routed with "root"
# just remember to delete public/index.html.
# root :to => 'welcome#index'
root :to => 'welcome#index'

# See how all your routes lay out with "rake routes"

Expand Down
10 changes: 10 additions & 0 deletions db/migrate/20120306233551_create_cards.rb
@@ -0,0 +1,10 @@
class CreateCards < ActiveRecord::Migration
def change
create_table :cards do |t|
t.string :trello_id
t.string :name

t.timestamps
end
end
end

0 comments on commit 1c8ad93

Please sign in to comment.