Permalink
Browse files

Adds checklists. Not fully complete, but functional for basic purposes.

  • Loading branch information...
1 parent 41ec1c1 commit 73b71ccee49d615dcfae1c456fa054b26b97c4e7 @jeremytregunna committed Jan 8, 2012
View
@@ -11,7 +11,9 @@ module Trello
autoload :Board, 'trello/board'
autoload :Card, 'trello/card'
autoload :Client, 'trello/client'
+ autoload :Item, 'trello/item'
+ autoload :ItemState, 'trello/item_state'
autoload :List, 'trello/list'
autoload :Member, 'trello/member'
autoload :Organization, 'trello/organization'
-end
+end
View
@@ -45,6 +45,13 @@ def board
Board.find(fields['idBoard'])
end
+ def checklists
+ response = Client.query("/1/cards/#{id}/checklists")
+ JSON.parse(response.read_body).map do |checklist_fields|
+ Checklist.new(checklist_fields)
+ end
+ end
+
def list
List.find(fields['idList'])
end
View
@@ -0,0 +1,57 @@
+# Ruby wrapper around the Trello API
+# Copyright (c) 2012, Jeremy Tregunna
+# Use and distribution terms may be found in the file LICENSE included in this distribution.
+
+module Trello
+ class Checklist < BasicData
+ class << self
+ def find(id)
+ super(:checklists, id)
+ end
+ end
+
+ # Fields
+
+ def id
+ fields['id']
+ end
+
+ def name
+ fields['name']
+ end
+
+ def description
+ fields['desc']
+ end
+
+ def closed?
+ fields['closed']
+ end
+
+ def url
+ fields['url']
+ end
+
+ # Links to other data structures
+
+ def items
+ fields['checkItems'].map do |item_fields|
+ Item.new(item_fields)
+ end
+ end
+
+ def board
+ Board.find(fields['idBoard'])
+ end
+
+ def list
+ List.find(fields['idList'])
+ end
+
+ def members
+ fields['idMembers'].map do |member_id|
+ Member.find(member_id)
+ end
+ end
+ end
+end
View
@@ -0,0 +1,27 @@
+# Ruby wrapper around the Trello API
+# Copyright (c) 2012, Jeremy Tregunna
+# Use and distribution terms may be found in the file LICENSE included in this distribution.
+
+module Trello
+ class Item < BasicData
+ class << self
+ def find(nothing)
+ raise 'This operation does not make sense'
+ end
+ end
+
+ # Fields
+
+ def id
+ fields['id']
+ end
+
+ def name
+ fields['name']
+ end
+
+ def type
+ fields['type']
+ end
+ end
+end
View
@@ -0,0 +1,38 @@
+# Ruby wrapper around the Trello API
+# Copyright (c) 2012, Jeremy Tregunna
+# Use and distribution terms may be found in the file LICENSE included in this distribution.
+
+module Trello
+ class ItemState < BasicData
+ class << self
+ def find(nothing)
+ raise 'This operation does not make sense'
+ end
+ end
+
+ # Fields
+
+ def id
+ fields['id']
+ end
+
+ def state
+ fields['state']
+ end
+
+ # Until #item is implemented, this will do
+ def item_id
+ fields['idItem']
+ end
+
+ # Links to other data structures
+
+ def item
+ # Nothing here for now. I will implement it myself later, but Trello really
+ # needs an API to query check items in my estimation. Otherwise, the "idCheckItem"
+ # key serves no good purpose. I'd have to know what checklist this state belongs
+ # to, and then query all of its items, comparing the ID as I go. O(n) at the best
+ # of times. If I don't have the checklist, then we're O(m*n^2). Horrible.
+ end
+ end
+end
View
No changes.
View
@@ -0,0 +1,27 @@
+require 'spec_helper'
+
+module Trello
+ describe Item do
+ before(:all) do
+ @detail = {
+ 'id' => "abcdef123456789123456789",
+ 'name' => "test item",
+ 'type' => "check"
+ }
+
+ @item = Item.new(@detail)
+ end
+
+ it "gets its id" do
+ @item.id.should == @detail['id']
+ end
+
+ it "gets its name" do
+ @item.name.should == @detail['name']
+ end
+
+ it "knows its type" do
+ @item.type.should == @detail['type']
+ end
+ end
+end
View
No changes.

0 comments on commit 73b71cc

Please sign in to comment.