Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds ability to get single label from project #166

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions lib/tracker_api/endpoints/labels.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ def initialize(client)
@client = client
end

def get_label(project_id, id, params={})
data = client.get("/projects/#{project_id}/labels/#{id}", params: params).body

Resources::Label.new({ client: client }.merge(data))
end

def get(project_id, params={})
data = client.paginate("/projects/#{project_id}/labels", params: params)
raise Errors::UnexpectedData, 'Array of labels expected' unless data.is_a? Array
Expand Down
4 changes: 4 additions & 0 deletions lib/tracker_api/resources/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ def labels(params = {})
end
end

def label(label_id, params = {})
Endpoints::Labels.new(client).get_label(id,label_id, params)
end

# Provides a list of all the epics in the project.
#
# @param [Hash] params
Expand Down
10 changes: 10 additions & 0 deletions test/project_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,16 @@
end
end

describe '.label' do
it 'gets a single label from this project' do
VCR.use_cassette('get label', record: :new_episodes) do
label = project.label(7849080)

_(label).must_be_instance_of TrackerApi::Resources::Label
end
end
end

describe '.iterations' do
it 'can get only done iterations' do
VCR.use_cassette('get done iterations', record: :new_episodes) do
Expand Down
1 change: 1 addition & 0 deletions test/vcr/cassettes/get_label.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"http_interactions": [{"request": {"method": "get", "uri": "https://www.pivotaltracker.com/services/v5/projects/1027488/labels/5431", "body": {"encoding": "US-ASCII", "string": "" }, "headers": {"User-Agent": ["Ruby/2.7.5 (arm64-darwin21; ruby) TrackerApi/1.16.0 Faraday/2.8.1" ], "X-TrackerToken": ["d55c3bc1f74346b843ca84ba340b29bf" ], "Accept": ["application/json" ] } }, "response": {"status": {"code": 404, "message": "Not Found" }, "headers": {"content-type": ["application/json; charset=utf-8" ], "status": ["404 Not Found" ], "cache-control": ["no-cache" ], "x-request-id": ["2f2cfed8-9bc7-49c7-94ed-a67e5f89d414" ], "x-runtime": ["0.133386" ], "x-frame-options": ["SAMEORIGIN" ], "x-content-type-options": ["nosniff, nosniff" ], "date": ["Mon, 19 Aug 2024 18:30:35 GMT" ], "x-powered-by": ["Phusion Passenger" ], "server": ["nginx + Phusion Passenger" ], "access-control-allow-origin": ["*" ], "access-control-allow-credentials": ["false" ], "access-control-allow-methods": ["GET, POST, PUT, DELETE, OPTIONS" ], "access-control-allow-headers": ["X-TrackerToken,DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,X-Tracker-Warn-Unless-Project-Version-Is" ], "x-tracker-client-pinger-interval": ["20" ], "strict-transport-security": ["max-age=31536000; includeSubDomains; preload" ], "x-xss-protection": ["1; mode=block" ], "content-encoding": ["gzip" ], "via": ["1.1 google" ], "alt-svc": ["h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000" ], "transfer-encoding": ["chunked" ] }, "body": {"encoding": "UTF-8", "string": "{\"code\":\"unfound_resource\",\"kind\":\"error\",\"error\":\"The object you tried to access could not be found. It may have been removed by another user, you may be using the ID of another object type, or you may be trying to access a sub-resource at the wrong point in a tree.\"}" } }, "recorded_at": "Mon, 19 Aug 2024 18:30:34 GMT" }, {"request": {"method": "get", "uri": "https://www.pivotaltracker.com/services/v5/projects/1027488/labels/7849080", "body": {"encoding": "US-ASCII", "string": "" }, "headers": {"User-Agent": ["Ruby/2.7.5 (arm64-darwin21; ruby) TrackerApi/1.16.0 Faraday/2.8.1" ], "X-TrackerToken": ["d55c3bc1f74346b843ca84ba340b29bf" ], "Accept": ["application/json" ] } }, "response": {"status": {"code": 200, "message": "OK" }, "headers": {"content-type": ["application/json; charset=utf-8" ], "status": ["200 OK" ], "cache-control": ["max-age=0, private, must-revalidate" ], "x-tracker-project-version": ["728" ], "x-request-id": ["0fd34d62-bdda-48a9-b63f-3513c65cd0f0" ], "etag": ["W/\"fc0ba785ea8bde512fd0417626fc0bf9\"" ], "x-frame-options": ["SAMEORIGIN" ], "x-runtime": ["0.080823" ], "x-content-type-options": ["nosniff, nosniff" ], "date": ["Mon, 19 Aug 2024 18:31:45 GMT" ], "x-powered-by": ["Phusion Passenger" ], "server": ["nginx + Phusion Passenger" ], "access-control-allow-origin": ["*" ], "access-control-allow-credentials": ["false" ], "access-control-allow-methods": ["GET, POST, PUT, DELETE, OPTIONS" ], "access-control-allow-headers": ["X-TrackerToken,DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,X-Tracker-Warn-Unless-Project-Version-Is" ], "x-tracker-client-pinger-interval": ["20" ], "strict-transport-security": ["max-age=31536000; includeSubDomains; preload" ], "x-xss-protection": ["1; mode=block" ], "content-encoding": ["gzip" ], "via": ["1.1 google" ], "alt-svc": ["h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000" ], "transfer-encoding": ["chunked" ] }, "body": {"encoding": "UTF-8", "string": "{\"kind\":\"label\",\"id\":7849080,\"project_id\":1027488,\"name\":\"admin\",\"created_at\":\"2014-03-02T07:11:04Z\",\"updated_at\":\"2014-03-02T07:11:04Z\"}" } }, "recorded_at": "Mon, 19 Aug 2024 18:31:45 GMT" } ], "recorded_with": "VCR 6.3.0" }
115 changes: 115 additions & 0 deletions test/vcr/x-cassettes/get_label.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
{
"http_interactions":
[
{
"request":
{
"method": "get",
"uri": "https://www.pivotaltracker.com/services/v5/projects/1027488/label/5431",
"body":
{
"encoding": "US-ASCII",
"string": ""
},
"headers":
{
"User-Agent":
[
"Ruby/2.2.3 (x86_64-darwin15; ruby) TrackerApi/0.2.12 Faraday/0.9.2"
],
"X-TrackerToken":
[
"d55c3bc1f74346b843ca84ba340b29bf"
]
}
},
"response":
{
"status":
{
"code": 200,
"message": null
},
"headers":
{
"Content-Type":
[
"application/json; charset=utf-8"
],
"Status":
[
"200 OK"
],
"Cache-Control":
[
"max-age=0, private, must-revalidate"
],
"Date":
[
"Sat, 13 Feb 2016 23:35:55 GMT"
],
"X-Tracker-Project-Version":
[
"112"
],
"X-Request-Id":
[
"47d462e385f9e42fa2121b900e118f50"
],
"X-UA-Compatible":
[
"IE=Edge,chrome=1"
],
"ETag":
[
"\"09b7b80839393f41a467e3262507852b\""
],
"X-Runtime":
[
"0.045784"
],
"X-Rack-Cache":
[
"miss"
],
"X-Powered-By":
[
"Phusion Passenger Enterprise"
],
"Server":
[
"nginx + Phusion Passenger"
],
"Access-Control-Allow-Origin":
[
"*"
],
"Access-Control-Allow-Credentials":
[
"false"
],
"Access-Control-Allow-Methods":
[
"GET, POST, PUT, DELETE, OPTIONS"
],
"Access-Control-Allow-Headers":
[
"X-TrackerToken,DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,X-Tracker-Warn-Unless-Project-Version-Is"
],
"X-Tracker-Client-Pinger-Interval":
[
"12"
]
},
"body":
{
"encoding": "UTF-8",
"string": "{\"kind\":\"label\",\"id\":7849080,\"project_id\":1027488,\"name\":\"admin\",\"created_at\":\"2014-03-02T07:11:04Z\",\"updated_at\":\"2014-03-02T07:11:04Z\"}"
},
"http_version": null
},
"recorded_at": "Sat, 13 Feb 2016 23:35:55 GMT"
}
],
"recorded_with": "VCR 2.9.3"
}
Loading