Permalink
Browse files

Merge branch 'master' of github.com:jeremytregunna/ruby-trello

  • Loading branch information...
2 parents 266c0a2 + a09825e commit 437f77d4aa20f40539675ab3bb914a8507587713 @jeremytregunna committed Feb 14, 2012
Showing with 50 additions and 0 deletions.
  1. +1 −0 lib/trello.rb
  2. +6 −0 lib/trello/card.rb
  3. +19 −0 lib/trello/label.rb
  4. +13 −0 spec/card_spec.rb
  5. +11 −0 spec/spec_helper.rb
View
@@ -37,6 +37,7 @@ module Trello
autoload :HasActions, 'trello/has_actions'
autoload :Item, 'trello/item'
autoload :ItemState, 'trello/item_state'
+ autoload :Label, 'trello/label'
autoload :List, 'trello/list'
autoload :Member, 'trello/member'
autoload :MultiAssociation, 'trello/multi_association'
View
@@ -110,6 +110,12 @@ def add_checklist(checklist)
})
end
+ # Retrieve a list of labels
+ def labels
+ labels = Client.get("/cards/#{id}/labels").json_into(Label)
+ MultiAssociation.new(self, labels).proxy
+ end
+
# Add a label
def add_label(colour)
unless %w{green yellow orange red purple blue}.include? colour
View
@@ -0,0 +1,19 @@
+module Trello
+
+ # A colored Label attached to a card
+ class Label < BasicData
+ register_attributes :name, :color
+
+ # Update the fields of a label.
+ #
+ # Supply a hash of stringkeyed data retrieved from the Trello API representing
+ # a label.
+ def update_fields(fields)
+ attributes[:name] = fields['name']
+ attributes[:color] = fields['color']
+ self
+ end
+
+ end
+
+end
View
@@ -146,6 +146,19 @@ module Trello
end
context "labels" do
+ it "can retrieve labels" do
+ Client.stub(:get).with("/cards/abcdef123456789123456789/labels").
+ and_return label_payload
+ labels = @card.labels
+ labels.size.should == 2
+
+ labels[0].color.should == 'yellow'
+ labels[0].name.should == 'iOS'
+
+ labels[1].color.should == 'purple'
+ labels[1].name.should == 'Issue or bug'
+ end
+
it "can add a label" do
Client.stub(:post).with("/cards/abcdef123456789123456789/labels", { :value => 'green' }).
and_return "not important"
View
@@ -230,4 +230,15 @@ def token_details
def token_payload
JSON.generate(token_details)
end
+
+ def label_details
+ [
+ {"color" => "yellow", "name" => "iOS"},
+ {"color" => "purple", "name" => "Issue or bug"}
+ ]
+ end
+
+ def label_payload
+ JSON.generate(label_details)
+ end
end

0 comments on commit 437f77d

Please sign in to comment.