From e75a976c05ae96ef5161f5d134c81986e287cf2b Mon Sep 17 00:00:00 2001 From: Dan Hixon Date: Mon, 19 Aug 2024 11:34:28 -0700 Subject: [PATCH] adds ability to get single label from project --- lib/tracker_api/endpoints/labels.rb | 6 ++ lib/tracker_api/resources/project.rb | 4 + test/project_test.rb | 10 +++ test/vcr/cassettes/get_label.json | 1 + test/vcr/x-cassettes/get_label.json | 115 +++++++++++++++++++++++++++ 5 files changed, 136 insertions(+) create mode 100644 test/vcr/cassettes/get_label.json create mode 100644 test/vcr/x-cassettes/get_label.json diff --git a/lib/tracker_api/endpoints/labels.rb b/lib/tracker_api/endpoints/labels.rb index d3cf611..e77b47d 100644 --- a/lib/tracker_api/endpoints/labels.rb +++ b/lib/tracker_api/endpoints/labels.rb @@ -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 diff --git a/lib/tracker_api/resources/project.rb b/lib/tracker_api/resources/project.rb index 78f1fdc..63ec34a 100644 --- a/lib/tracker_api/resources/project.rb +++ b/lib/tracker_api/resources/project.rb @@ -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 diff --git a/test/project_test.rb b/test/project_test.rb index c2d026e..87a3635 100644 --- a/test/project_test.rb +++ b/test/project_test.rb @@ -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 diff --git a/test/vcr/cassettes/get_label.json b/test/vcr/cassettes/get_label.json new file mode 100644 index 0000000..7bc271f --- /dev/null +++ b/test/vcr/cassettes/get_label.json @@ -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" } \ No newline at end of file diff --git a/test/vcr/x-cassettes/get_label.json b/test/vcr/x-cassettes/get_label.json new file mode 100644 index 0000000..f4411e8 --- /dev/null +++ b/test/vcr/x-cassettes/get_label.json @@ -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" +} \ No newline at end of file