From 359a5cd62697ebcb9c25f8ed36847bd8e4cba189 Mon Sep 17 00:00:00 2001 From: Michael Wendland Date: Sun, 23 Nov 2014 18:47:56 +0100 Subject: [PATCH] there is no search request for tags Oo --- tag.go | 48 -------------------------------------- tag_test.go | 67 ----------------------------------------------------- 2 files changed, 115 deletions(-) delete mode 100644 tag_test.go diff --git a/tag.go b/tag.go index 1e315c0..15d4a0d 100644 --- a/tag.go +++ b/tag.go @@ -30,51 +30,3 @@ type Tag struct { Count int `xml:"count,attr"` Name string `xml:"name"` } - -// SearchTag queries MusicBrainz' Search Server for Tags. -// searchTerm only contains the tag field. For more information visit -// https://musicbrainz.org/doc/Development/XML_Web_Service/Version_2/Search#Tag -func (c *WS2Client) SearchTag(searchTerm string, limit, offset int) (*TagSearchResponse, error) { - - result := tagListResult{} - err := c.searchRequest("/tag", &result, searchTerm, limit, offset) - - rsp := TagSearchResponse{} - rsp.WS2ListResponse = result.TagList.WS2ListResponse - rsp.Scores = make(ScoreMap) - - for i, v := range result.TagList.Tags { - rsp.Tags = append(rsp.Tags, v.Tag) - rsp.Scores[rsp.Tags[i]] = v.Score - } - - return &rsp, err -} - -// TagSearchResponse is the response type returned by the SearchTag method. -type TagSearchResponse struct { - WS2ListResponse - Tags []*Tag - Scores ScoreMap -} - -// ResultsWithScore returns a slice of Tags with a specific score. -func (r *TagSearchResponse) ResultsWithScore(score int) []*Tag { - var res []*Tag - for k, v := range r.Scores { - if v == score { - res = append(res, k.(*Tag)) - } - } - return res -} - -type tagListResult struct { - TagList struct { - WS2ListResponse - Tags []struct { - *Tag - Score int `xml:"http://musicbrainz.org/ns/ext#-2.0 score,attr"` - } `xml:"tag"` - } `xml:"tag-list"` -} diff --git a/tag_test.go b/tag_test.go deleted file mode 100644 index 87a6080..0000000 --- a/tag_test.go +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (c) 2014 Michael Wendland - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS - * IN THE SOFTWARE. - * - * Authors: - * Michael Wendland - */ - -package gomusicbrainz - -import ( - "reflect" - "testing" -) - -func TestSearchTag(t *testing.T) { - - want := TagSearchResponse{ - WS2ListResponse: WS2ListResponse{ - Count: 2, - Offset: 0, - }, - Tags: []*Tag{ - { - Name: "shoegaze", - }, - { - Name: "rock shoegaze", - }, - }, - } - - setupHTTPTesting() - defer server.Close() - serveTestFile("/tag", "SearchTag.xml", t) - - returned, err := client.SearchTag("shoegaze", -1, -1) - if err != nil { - t.Error(err) - } - - want.Scores = ScoreMap{ - returned.Tags[0]: 100, - returned.Tags[1]: 62, - } - - if !reflect.DeepEqual(*returned, want) { - t.Error(requestDiff(&want, returned)) - } -}