Skip to content

Commit 2c093a7

Browse files
committed
Added escaped search method, fixes #131
1 parent fe9d02b commit 2c093a7

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

SpotifyAPI.Web/SpotifyWebAPI.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System;
66
using System.Collections.Generic;
77
using System.Linq;
8+
using System.Net;
89
using System.Threading;
910
using System.Threading.Tasks;
1011

@@ -119,6 +120,36 @@ public Task<SearchItem> SearchItemsAsync(string q, SearchType type, int limit =
119120
{
120121
return DownloadDataAsync<SearchItem>(_builder.SearchItems(q, type, limit, offset, market));
121122
}
123+
124+
/// <summary>
125+
/// Get Spotify catalog information about artists, albums, tracks or playlists that match a keyword string.
126+
/// </summary>
127+
/// <param name="q">The search query's keywords (and optional field filters and operators), for example q=roadhouse+blues. (properly escaped)</param>
128+
/// <param name="type">A list of item types to search across.</param>
129+
/// <param name="limit">The maximum number of items to return. Default: 20. Minimum: 1. Maximum: 50.</param>
130+
/// <param name="offset">The index of the first result to return. Default: 0</param>
131+
/// <param name="market">An ISO 3166-1 alpha-2 country code or the string from_token.</param>
132+
/// <returns></returns>
133+
public SearchItem SearchItemsEscaped(string q, SearchType type, int limit = 20, int offset = 0, string market = "")
134+
{
135+
string escapedQuery = WebUtility.UrlEncode(q);
136+
return DownloadData<SearchItem>(_builder.SearchItems(escapedQuery, type, limit, offset, market));
137+
}
138+
139+
/// <summary>
140+
/// Get Spotify catalog information about artists, albums, tracks or playlists that match a keyword string asynchronously.
141+
/// </summary>
142+
/// <param name="q">The search query's keywords (and optional field filters and operators), for example q=roadhouse+blues. (properly escaped)</param>
143+
/// <param name="type">A list of item types to search across.</param>
144+
/// <param name="limit">The maximum number of items to return. Default: 20. Minimum: 1. Maximum: 50.</param>
145+
/// <param name="offset">The index of the first result to return. Default: 0</param>
146+
/// <param name="market">An ISO 3166-1 alpha-2 country code or the string from_token.</param>
147+
/// <returns></returns>
148+
public Task<SearchItem> SearchItemsEscapedAsync(string q, SearchType type, int limit = 20, int offset = 0, string market = "")
149+
{
150+
string escapedQuery = WebUtility.UrlEncode(q);
151+
return DownloadDataAsync<SearchItem>(_builder.SearchItems(escapedQuery, type, limit, offset, market));
152+
}
122153

123154
#endregion Search
124155

0 commit comments

Comments
 (0)