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

Multiple clients via features #129

Merged
merged 98 commits into from
Oct 18, 2020
Merged
Show file tree
Hide file tree
Changes from 93 commits
Commits
Show all changes
98 commits
Select commit Hold shift + click to select a range
e4f85f8
First attempt with Deref
marioortizmanero Aug 29, 2020
d0e7a5f
Formatting and Cargo.toml fix
marioortizmanero Aug 29, 2020
279c138
Implemented run_blocking macro
marioortizmanero Aug 29, 2020
7532b3f
Fix tokio import for tests, small cleanup
marioortizmanero Aug 29, 2020
e783eae
Implemented macro for a single function
marioortizmanero Aug 29, 2020
d3e821c
Now with docs too
marioortizmanero Aug 29, 2020
9c783dd
Single impl block, documentation
marioortizmanero Aug 29, 2020
675aeb7
More clear formatting
marioortizmanero Aug 29, 2020
578c13b
Applied to all endpoints with a vim macro!
marioortizmanero Aug 29, 2020
2c29637
Fixed docstrings
marioortizmanero Aug 29, 2020
f920314
Added changelog entry
marioortizmanero Aug 29, 2020
f5fbb68
Cleanup, failing miserably at generic paramters like Into<Option<u32>>
marioortizmanero Aug 29, 2020
2387313
Removing the 'Into<Option<T>>' does work, not sure if valid
marioortizmanero Aug 29, 2020
fef8801
Added comment before endpoint macro
marioortizmanero Aug 29, 2020
dfda2f7
Merge with master
marioortizmanero Sep 11, 2020
f236ce0
Fixed merge conflict
marioortizmanero Sep 20, 2020
e352947
Added to changelog
marioortizmanero Sep 20, 2020
5124dbb
Prettier macro
marioortizmanero Sep 20, 2020
f10c963
Second attempt at cleaning up the blocking module
marioortizmanero Sep 20, 2020
95c5293
Brief top-level documentation
marioortizmanero Sep 20, 2020
36df1c8
Cleaned up dependencies
marioortizmanero Sep 20, 2020
9c10893
Fixed http client function signatures
marioortizmanero Sep 20, 2020
68e2ea0
Great progress, WIP rewrite of fetch_access_token
marioortizmanero Sep 20, 2020
74b026b
Refresh access token
marioortizmanero Sep 20, 2020
c596ede
Getting it to compile
marioortizmanero Sep 21, 2020
e3061df
General errors and small fixes
marioortizmanero Sep 21, 2020
dfb1014
Working OAuth, documentation and initial ureq
marioortizmanero Sep 21, 2020
1098cda
Improved endpoints, now with json!
marioortizmanero Sep 21, 2020
b77eb08
Trying to fix requests
marioortizmanero Sep 22, 2020
4bbc2e6
Proper content types
marioortizmanero Sep 22, 2020
67884f5
Fix reqwest, base ureq impl
marioortizmanero Sep 22, 2020
60f1a0f
Fixed relative URLs
marioortizmanero Sep 22, 2020
2f633a5
Small fix and cargo fmt
marioortizmanero Sep 22, 2020
401cb2b
Update changelog
marioortizmanero Sep 22, 2020
f5fb3a3
Remove Token::token_type
marioortizmanero Sep 22, 2020
1362b47
Updated basic examples
marioortizmanero Sep 22, 2020
099426d
Fixed some tests
marioortizmanero Sep 22, 2020
29aab9a
api_urls module
marioortizmanero Sep 22, 2020
bff6a1d
Fixed "Bad Request"
marioortizmanero Sep 22, 2020
466a4d3
Fixed for ureq as well
marioortizmanero Sep 22, 2020
04166d7
Fix tests, realize that it still doesn't work
marioortizmanero Sep 22, 2020
0443226
Moved Spotify OAuth logic to oauth2 module
marioortizmanero Sep 23, 2020
be01e05
Raw string literals and import fix
marioortizmanero Sep 23, 2020
6348d01
Initial fix for Error 400: Bad Request
marioortizmanero Sep 24, 2020
3763b33
Fix tests
marioortizmanero Sep 24, 2020
b7f7fee
Some nicer endpoints
marioortizmanero Sep 24, 2020
b3db5d3
Fix for 'Length Required' error
marioortizmanero Sep 24, 2020
4223a2a
cargo fmt, add_item_to_queue now requires Premium
marioortizmanero Sep 24, 2020
c47a404
Fix Continuous Integration
marioortizmanero Sep 24, 2020
2a04a03
Tests both with sync and async clients
marioortizmanero Sep 24, 2020
57aa70d
Fix lint error
ramsayleung Sep 26, 2020
87c91d4
reformat code with cargo fmt.
ramsayleung Sep 26, 2020
f5a3064
Fix lint error.
ramsayleung Sep 26, 2020
0482831
Added CI for clippy with client-ureq, fixed features
marioortizmanero Sep 26, 2020
a496040
Fix tests
marioortizmanero Sep 26, 2020
54fd014
Ignore clippy warnings for now related to the bug
marioortizmanero Sep 26, 2020
381d466
Customizing ureq TLS as well
marioortizmanero Sep 26, 2020
40781d3
Update documentation
marioortizmanero Sep 26, 2020
8693218
Update document about async/blocking version, and how to build rspotify.
ramsayleung Sep 26, 2020
32dff3a
Merge branch 'multiple-clients' of github.com:ramsayleung/rspotify in…
ramsayleung Sep 26, 2020
b91ce5e
Update document.
ramsayleung Sep 29, 2020
7f89adc
Update document again.
ramsayleung Sep 29, 2020
2cc2192
Fix all tests in a clumsy way and update example in README.
ramsayleung Sep 29, 2020
3e5fc5a
reformat code with `cargo fmt`.
ramsayleung Sep 29, 2020
6adde82
Properly fix tests, improve Token
marioortizmanero Sep 30, 2020
c816dc8
Using url::Url::parse_with_params
marioortizmanero Oct 2, 2020
ee5b0c8
Should fix CI
marioortizmanero Oct 9, 2020
f9c8304
Update maybe-async to avoid parenthesis warnings
marioortizmanero Oct 9, 2020
24ebb68
Revert to optional payload
marioortizmanero Oct 9, 2020
a1ac650
WIP refactor to http client internals
marioortizmanero Oct 9, 2020
f4547b4
Progress for ureq
marioortizmanero Oct 9, 2020
116d6b2
Fixed ureq empty parameters
marioortizmanero Oct 9, 2020
d2f18a9
First fix for ureq tests
marioortizmanero Oct 9, 2020
4ddeda5
Back to HashMap for GET requests...
marioortizmanero Oct 10, 2020
b289100
Cleanup ureq, fix README wording, blocking -> ureq
marioortizmanero Oct 10, 2020
102e2c0
Example snippets now break, so I removed it
marioortizmanero Oct 10, 2020
8fb2db1
Formatting
marioortizmanero Oct 10, 2020
57f28ec
Changed the default limit by mistake
marioortizmanero Oct 10, 2020
496ffe9
unnecessary change of 'get_authorize_url' name
marioortizmanero Oct 10, 2020
a98c4ec
consistency: get_cached_token -> read_token_cache
marioortizmanero Oct 10, 2020
d7ec619
Improving the changelog
marioortizmanero Oct 10, 2020
596ef65
Update webapp example.
ramsayleung Oct 11, 2020
aedcb0d
Revert get_token, get_creds, get_oauth to public(in crate).
ramsayleung Oct 11, 2020
d55c4a6
Optimize code by clippy hint.
ramsayleung Oct 11, 2020
4d793f4
cargo fmt
marioortizmanero Oct 11, 2020
8cbadf3
Update webapp example.
ramsayleung Oct 11, 2020
da98dab
Merge branch 'multiple-clients' of github.com:ramsayleung/rspotify in…
ramsayleung Oct 11, 2020
9bdec0a
Excellent documentation now!
marioortizmanero Oct 11, 2020
edfd275
parse_response_code moved to oauth2.rs
marioortizmanero Oct 11, 2020
59929f1
ApiError is now APIError for consistency
marioortizmanero Oct 11, 2020
7ca2755
Fix typo
ramsayleung Oct 15, 2020
3f3a460
Merge branch 'master' into multiple-clients
marioortizmanero Oct 17, 2020
6cbe261
url crate in parse_response_code
marioortizmanero Oct 17, 2020
2461f4f
test_parse_response_code
marioortizmanero Oct 18, 2020
4f3c48a
constants for headers
marioortizmanero Oct 18, 2020
2fbf3d5
Remove some TODOs and pub(in crate) until removed
marioortizmanero Oct 18, 2020
1a4aff6
Cargo.toml cleanup
marioortizmanero Oct 18, 2020
c2865a5
fixed http::headers::SHOW_DIALOG
marioortizmanero Oct 18, 2020
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
22 changes: 18 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
uses: actions-rs/cargo@v1
with:
command: check
args: --all-targets
args: --all-targets --features=cli,env-file

cross-compile:
name: Cross Compile
Expand All @@ -35,6 +35,9 @@ jobs:
- aarch64-unknown-linux-gnu
- arm-unknown-linux-gnueabihf
- armv7-unknown-linux-gnueabihf
client:
- client-ureq,ureq-rustls-tls
- client-reqwest,reqwest-rustls-tls
steps:
- name: Checkout sources
uses: actions/checkout@v2
Expand All @@ -54,11 +57,17 @@ jobs:
uses: actions-rs/cargo@v1
with:
command: build
args: --target ${{ matrix.target }} --no-default-features --features "rustls-tls"
args: --target ${{ matrix.target }} --no-default-features --features=cli,env-file,${{ matrix.client }}


test:
name: Test Suite
runs-on: ubuntu-latest
strategy:
matrix:
client:
- client-ureq,ureq-rustls-tls
- client-reqwest,reqwest-rustls-tls
steps:
- name: Checkout sources
uses: actions/checkout@v2
Expand All @@ -74,11 +83,16 @@ jobs:
uses: actions-rs/cargo@v1
with:
command: test
args: --features env-file
args: --no-default-features --features=cli,env-file,${{ matrix.client }}

lints:
name: Lints
runs-on: ubuntu-latest
strategy:
matrix:
client:
- client-ureq,ureq-rustls-tls
- client-reqwest,reqwest-rustls-tls
steps:
- name: Checkout sources
uses: actions/checkout@v2
Expand All @@ -101,4 +115,4 @@ jobs:
uses: actions-rs/cargo@v1
with:
command: clippy
args: -- -D warnings
args: --no-default-features --features=cli,env-file,${{ matrix.client }} -- -D warnings
33 changes: 27 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,44 @@
## 0.11 (unreleased)
This release contains *lots* of breaking changes. These were necessary to continue Rspotify's development, and no more versions like this should happen again. Lots of internal code was rewritten to make Rspotify more flexible, performant and easier to use. Sorry for the inconvenience!

If we missed any change or there's something you'd like to discuss about this version, please open a new issue and let us know.

- Rewritten documentation in hopes that it's easier to get started with Rspotify.
- Reduced the number of examples. Instead of having an example for each endpoint, which is repetitive and unhelpful for newcomers, some real-life examples are now included. If you'd like to add your own example, please do! ([#113](https://github.com/ramsayleung/rspotify/pull/113))
- Add `add_item_to_queue` endpoint.
- Fix typo in `transfer_playback`: `device_id` to `device_ids`.
- Fix race condition when using a single client from multiple threads (see [#114](https://github.com/ramsayleung/rspotify/pull/114) for more information).
- Fix race condition when using a single client from multiple threads ([#114](https://github.com/ramsayleung/rspotify/pull/114)).
- Rspotify should now be considerably lighter and less bloated ([discussion in #108](https://github.com/ramsayleung/rspotify/issues/108)):
+ Remove unused dependencies: `base64`, `env_logger`, `derive_builder`, `random`, `url`. <!-- NOTE: derive_builder might not be removed after all -->
+ Remove unused dependencies: `base64`, `env_logger`, `random`, `url`.
+ Remove `itertools` dependency by using the standard library.
+ Remove `rand` in place of `getrandom` to [reduce total dependencies and compile times](https://github.com/ramsayleung/rspotify/issues/108#issuecomment-673587185).
+ `webbrowser` and access to functions that use it (`util::get_token`, `util::get_token_without_cache` and `util::request_token`) can be disabled for the non-CLI applications with the `browser` feature. It's still enabled by default due to [its frequent usage](https://github.com/ramsayleung/rspotify/pull/110#issuecomment-674410604).
+ Cleanup, reduced repetitive code and boilerplate internally in several places ([#117](https://github.com/ramsayleung/rspotify/pull/117), [#113](https://github.com/ramsayleung/rspotify/pull/113), [#107](https://github.com/ramsayleung/rspotify/pull/107), [#106](https://github.com/ramsayleung/rspotify/pull/106)).
- Updated dependencies to the latest versions, integrated Dependabot to keep track of them ([#105](https://github.com/ramsayleung/rspotify/pull/105), [#111](https://github.com/ramsayleung/rspotify/pull/111)).

**Breaking changes:**
- `dotenv` support is now optional. You can enable it with the `env-file` feature to have the same behavior as before ([#108](https://github.com/ramsayleung/rspotify/issues/108)).
- `SpotifyClientCredentials` has been renamed to `Credentials` ([#129](https://github.com/ramsayleung/rspotify/pull/129)), and its members `client_id` and `client_secret` to `id` and `secret`, respectively.
- `TokenInfo` has been renamed to `Token`. It no longer has the `token_type` member, as it's always `Bearer` for now ([#129](https://github.com/ramsayleung/rspotify/pull/129)).
- `SpotifyOAuth` has been renamed to `OAuth`. It only contains the necessary parameters for OAuth authorization instead of repeating the items from `Credentials` and `Spotify`, so `client_id`, `client_secret` and `cache_path` are no longer in `OAuth` ([#129](https://github.com/ramsayleung/rspotify/pull/129)).
- `TokenBuilder` and `OAuthBuilder` will only read from environment variables when `from_env` is used, instead of `default`.
- `dotenv` support is now optional. You can enable it with the `env-file` feature to have the same behavior as before ([#108](https://github.com/ramsayleung/rspotify/issues/108)). It may be used with `from_env` as well.
- Renamed environmental variables to `RSPOTIFY_CLIENT_ID`, `RSPOTIFY_CLIENT_SECRET` and `RSPOTIFY_REDIRECT_URI` to avoid name collisions with other libraries that use OAuth2 ([#118](https://github.com/ramsayleung/rspotify/issues/118)).
- All fallible calls in the client return a `ClientResult` rather than using `failure`, which is equivalent to a `Result<T, ClientError>`.
- `ApiError` is now `APIError` for consistency.
- A real builder pattern is used now. For example, `Token` is constructed now with `TokenBuilder::default().access_token("...").build().unwrap()`. This has been applied to `Spotify`, `OAuth`, `Token` and `Credentials` ([#129](https://github.com/ramsayleung/rspotify/pull/129)).
- The `blocking` module has been removed, since Rspotify is able to use multiple HTTP clients now. `reqwest` and `ureq` are currently supported, meaning that you can still use blocking code by enabling the `client-ureq` feature and a TLS like `ureq-rustls-tls`. Read the docs for more information ([#129](https://github.com/ramsayleung/rspotify/pull/129)).
- The authentication process has been completely rewritten in order to make it more performant and robust. Please read the docs to learn more about how that works now ([#129](https://github.com/ramsayleung/rspotify/pull/129)). These are the main changes:
+ `TokenInfo::get_cached_token` is now `TokenBuilder::from_cache` and `Spotify::read_token_cache` (using the internal cache path). Instead of panicking, the resulting `TokenBuilder` may be empty (and `build` will fail).
+ `Spotify::save_token_info` is now `Token::write_cache` and `Spotify::write_token_cache`. The latter uses the client's set cache path for the write. These functions also now return `ClientResult` instead of panicking.
+ `Spotify::is_token_expired` is now `Token::is_expired`.
+ `SpotifyOAuth2::get_authorize_url` is now `Spotify::get_authorize_url`, and it returns `ClientResult<String>` instead of panicking.
+ `SpotifyOAuth2::refresh_access_token[_without_cache]` are now `Spotify::refresh_user_token[_with_cache]`. It returns `ClientResult<()>`, and the resulting token will be saved internally instead of returned.
+ `SpotifyOAuth2::request_client_token[_without_cache]` are now `Spotify::request_client_token[_with_cache]`. It returns `ClientResult<()>`, and the resulting token will be saved internally instead of returned.
+ `SpotifyOAuth2::get_access_token[_without_cache]` are now `Spotify::request_user_token[_with_cache]`. It returns `ClientResult<()>`, and the resulting token will be saved internally instead of returned.
+ `get_token[_without_cache]` is now `Spotify::prompt_for_user_token[_without_cache]`. It returns `ClientResult<()>`, and the resulting token will be saved internally instead of returned.
- CLI-exclusive functions and are now optional under the `cli` feature:
+ `Spotify::prompt_for_user_token[_without_cache]`
+ The `ClientError::CLI` variant, for whenever user interaction goes wrong
- Fix typo in `user_playlist_remove_specific_occurrenes_of_tracks`, now it's `user_playlist_remove_specific_occurrences_of_tracks`.
- All fallible calls in the client return a `ClientError` rather than using `failure`.
- Fix typo in `transfer_playback`: `device_id` to `device_ids`.
- Changed type of `track` in `PlayHistory` to `FullTrack` ([#139](https://github.com/ramsayleung/rspotify/pull/139)).

## 0.10 (2020/07/01)
Expand Down
82 changes: 52 additions & 30 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,81 +11,103 @@ keywords = ["spotify","api"]
edition = "2018"

[dependencies]
# Temporary until https://github.com/rust-lang/rfcs/issues/2739, for
# `maybe_async`.
async-trait = "0.1.40"
base64 = "0.12.3"
chrono = { version = "0.4.13", features = ["serde", "rustc-serialize"] }
derive_builder = "0.9.0"
dotenv = { version = "0.15.0", optional = true }
getrandom = "0.2.0"
lazy_static = "1.4.0"
log = "0.4.11"
percent-encoding = "2.1.0"
getrandom = "0.2.0"
reqwest = { version = "0.10.7", features = ["json", "socks"], default-features = false }
maybe-async = "0.2.1"
reqwest = { version = "0.10.7", default-features = false, features = ["json", "socks"], optional = true }
serde = { version = "1.0.115", features = ["derive"] }
serde_json = "1.0.57"
webbrowser = { version = "0.5.5", optional = true }
thiserror = "1.0.20"
ureq = { version = "1.4.1", default-features = false, features = ["json", "cookies"], optional = true }
url = "2.1.1"
webbrowser = { version = "0.5.5", optional = true }

[dev-dependencies]
async_once = { version = "0.1.0", features = ["tokio"] }
env_logger = "0.7.1"
tokio = { version = "0.2.22", features = ["full"] }
futures = "0.3.5"

[features]
default = ["reqwest/default-tls", "browser"]
default = ["client-reqwest", "reqwest-default-tls"]
cli = ["webbrowser"]
env-file = ["dotenv"]
browser = ["webbrowser"]
blocking = ["reqwest/default-tls", "reqwest/blocking"]

# Available clients. By default they don't include a TLS so that it can be
# configured.
client-ureq = ["ureq", "__sync"]
client-reqwest = ["reqwest", "__async"]

# Passing the TLS features to reqwest.
native-tls = ["reqwest/native-tls"]
native-tls-blocking = ["reqwest/native-tls", "reqwest/blocking"]
native-tls-vendored = ["reqwest/native-tls-vendored"]
native-tls-vendored-blocking = ["reqwest/native-tls-vendored", "reqwest/blocking"]
rustls-tls = ["reqwest/rustls-tls"]
rustls-tls-blocking = ["reqwest/rustls-tls", "reqwest/blocking"]
reqwest-default-tls = ["reqwest/default-tls"]
reqwest-rustls-tls = ["reqwest/rustls-tls"]
reqwest-native-tls = ["reqwest/native-tls"]
reqwest-native-tls-vendored = ["reqwest/native-tls-vendored"]
# Same for ureq.
ureq-rustls-tls = ["ureq/tls"]
ureq-native-tls = ["ureq/native-tls"]

# Internal features for checking async or sync compilation
__async = []
__sync = ["maybe-async/is_sync"]

[package.metadata.docs.rs]
# Also documenting the blocking module
features = ["blocking"]
# Also documenting the CLI methods
features = ["cli"]

[[example]]
name = "album"
required-features = ["env-file"]
required-features = ["env-file", "cli", "client-reqwest"]
path = "examples/album.rs"

[[example]]
name = "current_user_recently_played"
required-features = ["env-file"]
required-features = ["env-file", "cli", "client-reqwest"]
path = "examples/current_user_recently_played.rs"

[[example]]
name = "oauth_tokens"
required-features = ["env-file", "cli", "client-reqwest"]
path = "examples/oauth_tokens.rs"

[[example]]
name = "track"
required-features = ["env-file"]
required-features = ["env-file", "cli", "client-reqwest"]
path = "examples/track.rs"

[[example]]
name = "tracks"
required-features = ["env-file"]
required-features = ["env-file", "cli", "client-reqwest"]
path = "examples/tracks.rs"

[[example]]
name = "with_refresh_token"
required-features = ["env-file"]
required-features = ["env-file", "cli", "client-reqwest"]
path = "examples/with_refresh_token.rs"

[[example]]
name = "device"
required-features = ["env-file", "blocking"]
path = "examples/blocking/device.rs"
required-features = ["env-file", "cli", "client-ureq"]
path = "examples/ureq/device.rs"

[[example]]
name = "me"
required-features = ["env-file", "blocking"]
path = "examples/blocking/me.rs"
required-features = ["env-file", "cli", "client-ureq"]
path = "examples/ureq/me.rs"

[[example]]
name = "blocking_search"
required-features = ["env-file", "blocking"]
path = "examples/blocking/search.rs"
name = "search"
required-features = ["env-file", "cli", "client-ureq"]
path = "examples/ureq/search.rs"

[[example]]
name = "seek_track"
required-features = ["env-file", "blocking"]
path = "examples/blocking/seek_track.rs"
required-features = ["env-file", "cli", "client-ureq"]
path = "examples/ureq/seek_track.rs"
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,30 @@ Please see the [changelog](./CHANGELOG.md) for a release history and indications

If you find any problems or have suggestions about this crate, please submit an issue. Moreover, any pull request, code review and feedback are welcome.

## Building

Rspotify uses [`maybe_async`](https://docs.rs/maybe-async/0.2.0/maybe_async/) to switch between async and blocking clients, which is triggered inside `Cargo.toml`. So that must be taken into account when building `rspotify`. Read the Configuration section in the docs for more information about how to build with custom TLS implementations, and more.

`client-reqwest` is used by default. It should be as easy as

```sh
$ cargo build
```

`client-ureq` is also available as the `blocking` interface, which compiles Rspotify with [`ureq`](https://docs.rs/ureq/) (a TLS has to be specified as well):

```sh
$ cargo build --no-default-features --features client-ureq,ureq-rustls-tls
```

Notice that you can't build `rspotify` with all features like this:

```sh
$ cargo build --all-features
```

Because in order to switch between clients, the different clients have to implement the same base trait in [src/http/mod.rs](https://github.com/ramsayleung/rspotify/blob/master/src/http/mod.rs), so if you build with all features, you'll get `duplicate definitions` error. As every coin has two sides, you can only have one side at a time, not all sides of it.

## License

[MIT](./LICENSE)
43 changes: 31 additions & 12 deletions examples/album.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,41 @@
use rspotify::client::Spotify;
use rspotify::oauth2::SpotifyClientCredentials;
use rspotify::client::SpotifyBuilder;
use rspotify::oauth2::CredentialsBuilder;

#[tokio::main]
async fn main() {
// Set client_id and client_secret in .env file or
// You can use any logger for debugging.
env_logger::init();

// Set RSPOTIFY_CLIENT_ID, RSPOTIFY_CLIENT_SECRET and
// RSPOTIFY_REDIRECT_URI in an .env file or export them manually:
//
// export RSPOTIFY_CLIENT_ID="your client_id"
// export RSPOTIFY_CLIENT_SECRET="secret"
let client_credential = SpotifyClientCredentials::default().build();

// Or set client_id and client_secret explictly
// let client_credential = SpotifyClientCredentials::default()
//
// These will then be read with `from_env`.
//
// Otherwise, set client_id and client_secret explictly:
//
// let creds = CredentialsBuilder::default()
// .client_id("this-is-my-client-id")
// .client_secret("this-is-my-client-secret")
// .build();
let spotify = Spotify::default()
.client_credentials_manager(client_credential)
.build();
// .build()
// .unwrap();
let creds = CredentialsBuilder::from_env().build().unwrap();

let mut spotify = SpotifyBuilder::default()
.credentials(creds)
.build()
.unwrap();

// Obtaining the access token. Requires to be mutable because the internal
// token will be modified. We don't need OAuth for this specific endpoint,
// so `...` is used instead of `prompt_for_user_token`.
spotify.request_client_token().await.unwrap();

ramsayleung marked this conversation as resolved.
Show resolved Hide resolved
// Running the requests
let birdy_uri = "spotify:album:0sNOF9WDwhWunNAHPD3Baj";
let albums = spotify.album(birdy_uri).await;
println!("{:?}", albums);

println!("Response: {:#?}", albums);
}
39 changes: 0 additions & 39 deletions examples/blocking/device.rs

This file was deleted.

Loading