Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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

  • Loading branch information...
commit 437f77d4aa20f40539675ab3bb914a8507587713 2 parents 266c0a2 + a09825e
@jeremytregunna authored
View
1  lib/trello.rb
@@ -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
6 lib/trello/card.rb
@@ -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
19 lib/trello/label.rb
@@ -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
13 spec/card_spec.rb
@@ -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
11 spec/spec_helper.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.