Skip to content
This repository was archived by the owner on Apr 13, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/tracker_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
20 changes: 20 additions & 0 deletions lib/tracker_api/endpoints/labels.rb
Original file line number Diff line number Diff line change
@@ -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
5 changes: 4 additions & 1 deletion lib/tracker_api/resources/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
14 changes: 14 additions & 0 deletions test/project_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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