From 8c9058fe267fc4110cdf0484c7552d5eff69f06a Mon Sep 17 00:00:00 2001 From: James Brennan Date: Tue, 21 Oct 2014 14:42:01 -0700 Subject: [PATCH] Add labels endpoint and accessor on Project --- lib/tracker_api.rb | 1 + lib/tracker_api/endpoints/labels.rb | 20 ++++++++++++++++++++ lib/tracker_api/resources/project.rb | 5 ++++- test/project_test.rb | 14 ++++++++++++++ 4 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 lib/tracker_api/endpoints/labels.rb diff --git a/lib/tracker_api.rb b/lib/tracker_api.rb index 8e91e3d..840eb74 100644 --- a/lib/tracker_api.rb +++ b/lib/tracker_api.rb @@ -23,6 +23,7 @@ module Endpoints autoload :Epic, 'tracker_api/endpoints/epic' autoload :Epics, 'tracker_api/endpoints/epics' autoload :Iterations, 'tracker_api/endpoints/iterations' + autoload :Labels, 'tracker_api/endpoints/labels' autoload :Me, 'tracker_api/endpoints/me' autoload :Memberships, 'tracker_api/endpoints/memberships' autoload :Project, 'tracker_api/endpoints/project' diff --git a/lib/tracker_api/endpoints/labels.rb b/lib/tracker_api/endpoints/labels.rb new file mode 100644 index 0000000..4a7d9c6 --- /dev/null +++ b/lib/tracker_api/endpoints/labels.rb @@ -0,0 +1,20 @@ +module TrackerApi + module Endpoints + class Labels + attr_accessor :client + + def initialize(client) + @client = client + end + + def get(project_id) + data = client.get("/projects/#{project_id}/labels").body + raise TrackerApi::Errors::UnexpectedData, 'Array of labels expected' unless data.is_a? Array + + data.map do |label| + Resources::Label.new({ client: client, project_id: project_id }.merge(label)) + end + end + end + end +end diff --git a/lib/tracker_api/resources/project.rb b/lib/tracker_api/resources/project.rb index df2fb0e..38c360e 100644 --- a/lib/tracker_api/resources/project.rb +++ b/lib/tracker_api/resources/project.rb @@ -25,7 +25,6 @@ class Project attribute :iteration_length, Integer attribute :kind, String attribute :label_ids, Array[Integer] - attribute :labels, Array[TrackerApi::Resources::Label] attribute :name, String attribute :number_of_done_iterations_to_show, Integer attribute :point_scale, String @@ -90,6 +89,10 @@ def memberships(params = {}) def story(story_id) Endpoints::Story.new(client).get(id, story_id) end + + def labels + Endpoints::Labels.new(client).get(id) + end end end end diff --git a/test/project_test.rb b/test/project_test.rb index aee82ee..2313a67 100644 --- a/test/project_test.rb +++ b/test/project_test.rb @@ -78,4 +78,18 @@ end end end + + describe '.labels' do + it 'can get project labels' do + VCR.use_cassette('get project labels', record: :new_episodes) do + labels = project.labels + + labels.wont_be_empty + + label = labels.first + label.must_be_instance_of TrackerApi::Resources::Label + label.name.must_equal 'admin' + end + end + end end