Comments (10)
Mhh, or is passing None
equivalent to from_token
?
from rspotify.
Could you show which search_*
function you are using to search for tracks, I am not sure which from_token
you are talking about ?
from rspotify.
For instance, search_track
(https://github.com/samrayleung/rspotify/blob/master/src/spotify/client.rs#L420):
The documentation states the following for market:
market - An ISO 3166-1 alpha-2 country code or the string from_token.
Maybe I misread it? The way I interpreted it, is that market
either gets an alpha-2 country code or the literal "from_token", but in the signature the type is declared as Option<Country>
. So for me, it was unclear how to set the parameter to derive the market from the token.
from rspotify.
Perhaps you could check this example search_track, every function should have a relative example to demonstrate how to use them. If you have time to check senum.rs
, you could find each country are define as a enum field https://github.com/samrayleung/rspotify/blob/f8463a302f1df9393cf4e05a27252ffd2b3ff2c3/src/spotify/senum.rs#L126, and they all have a relative representation(you call them as An ISO 3166-1 alpha-2 country code
)
https://github.com/samrayleung/rspotify/blob/f8463a302f1df9393cf4e05a27252ffd2b3ff2c3/src/spotify/senum.rs#L615
from rspotify.
Yes, I know how to pass a Country enum, but it's not clear how to pass "from_token". The way it is described in the function documentation is not possible, as the "from_token" literal is not a valid parameter for Option.
from rspotify.
What would be the best course of action if we want to enable using the user tokens country instead of having to supply a country ourselves?
A solution would be a type of Country | FromToken using an enum maybe?
enum Market {
Country(Country),
FromToken
}
And then using it like this?
if let Some(market) = market {
params.insert("country".to_owned(), match market {
Market::Country(c) => c.to_string(),
Market::FromToken => "from_token".to_string()
});
}
As @hrkfdn mentioned, country defaults to US if no country was supplied and country is required, would not "from_token" be a better default here?
from rspotify.
Any thoughts on this? I'm willing to implement this myself and send a PR but I would need to know which way you would prefer.
from rspotify.
Sorry about that. Yes, I think that's the best solution to keep it type-safe. Go ahead and make a PR if you want :)
The API doesn't specify a default value so I'm not sure what you're referring to with defaulting to US. If anything I would just not send that parameter.
from rspotify.
The API doesn't specify a default value so I'm not sure what you're referring to with defaulting to US. If anything I would just not send that parameter.
Sorry, seems like it was only one function that defaulted it to the US while it is optional everywhere else.
Lines 329 to 332 in 18f2396
I feel like defaulting to "from_token" is the better option here.
from rspotify.
Yes, I would consider that code snippet wrong; it shouldn't default to the US.
In that case it is a required field for the endpoint, so I just wouldn't use an Option
at all. Why not just keep it as close as possible to the real API?
from rspotify.
Related Issues (20)
- Client method to sync playlist content efficiently using multible api calls. HOT 2
- Auth code flow, redirect server. HOT 2
- 0.11.17 breaks PKCE auth HOT 1
- `tracks_features` breaks on deserialization when a track is requested that doesn't have audio features HOT 1
- Missing market field on the album API call HOT 1
- Yank version 0.11.7 from crates.io HOT 3
- Is Add Custom Playlist Cover Image request implemented ? HOT 2
- json parse error: unknown variant `Smartwatch`
- Route `/v1/shows/{id}` requires market query parameter but `get_a_show` market parameter is `Option` HOT 2
- queryArtistOverview / artist stats (monthly listeners) HOT 2
- AuthCodeSpotify with token and refresh HOT 2
- Incorrect url in OAuthClient documentation HOT 1
- json parse error when calling `artist` method HOT 24
- json parse error when getting playlist with no image HOT 20
- SimplifiedAlbum added onto SimplifiedTrack Struct
- Release a new version HOT 2
- Getting bad request error(400)
- Not able to get playlist, when reading token from a file HOT 1
- JSON parsing error when fetching a playlist with user's own local track
- Update the examples HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rspotify.