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

Fix tests #114

Merged
merged 3 commits into from
Aug 16, 2020
Merged
Changes from all commits
Commits
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
17 changes: 9 additions & 8 deletions src/blocking/client.rs
Original file line number Diff line number Diff line change
@@ -2,13 +2,12 @@
// 3rd-part library
use chrono::prelude::*;
use failure::format_err;
use lazy_static::lazy_static;
use log::{error, trace};
use reqwest::blocking::Client;
use reqwest::header::{HeaderMap, AUTHORIZATION, CONTENT_TYPE};
use reqwest::Method;
use reqwest::StatusCode;
use serde::{Deserialize, Serialize};
use serde::Deserialize;
use serde_json::map::Map;
use serde_json::{json, Value};

@@ -41,10 +40,7 @@ use crate::model::user::{PrivateUser, PublicUser};
use crate::senum::{
AdditionalType, AlbumType, Country, IncludeExternal, RepeatState, SearchType, TimeRange, Type,
};
lazy_static! {
/// HTTP Client
pub static ref CLIENT: Client = Client::new();
}

/// Describes API errors
#[derive(Debug, Deserialize)]
pub enum ApiError {
@@ -114,8 +110,9 @@ impl From<reqwest::blocking::Response> for ApiError {
}
}
/// Spotify API object
#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive(Debug, Clone)]
pub struct Spotify {
client: Client,
pub prefix: String,
pub access_token: Option<String>,
pub client_credentials_manager: Option<SpotifyClientCredentials>,
@@ -125,6 +122,7 @@ impl Spotify {
//! [examples](https://github.com/samrayleung/rspotify/tree/master/examples) in github
pub fn default() -> Spotify {
Spotify {
client: Client::new(),
prefix: "https://api.spotify.com/v1/".to_owned(),
access_token: None,
client_credentials_manager: None,
@@ -186,7 +184,10 @@ impl Spotify {
headers.insert(CONTENT_TYPE, "application/json".parse().unwrap());

let mut response = {
let builder = CLIENT.request(method, &url.into_owned()).headers(headers);
let builder = self
.client
.request(method, &url.into_owned())
.headers(headers);

// Only add body if necessary
// spotify rejects GET requests that have a body with a 400 response
17 changes: 9 additions & 8 deletions src/client.rs
Original file line number Diff line number Diff line change
@@ -2,13 +2,12 @@
// 3rd-part library
use chrono::prelude::*;
use failure::format_err;
use lazy_static::lazy_static;
use log::{error, trace};
use reqwest::header::{HeaderMap, AUTHORIZATION, CONTENT_TYPE};
use reqwest::Client;
use reqwest::Method;
use reqwest::StatusCode;
use serde::{Deserialize, Serialize};
use serde::Deserialize;
use serde_json::map::Map;
use serde_json::{json, Value};

@@ -40,10 +39,7 @@ use super::senum::{
AdditionalType, AlbumType, Country, IncludeExternal, RepeatState, SearchType, TimeRange, Type,
};
use super::util::convert_map_to_string;
lazy_static! {
/// HTTP Client
pub static ref CLIENT: Client = Client::new();
}

/// Describes API errors
#[derive(Debug, Deserialize)]
pub enum ApiError {
@@ -113,8 +109,9 @@ impl ApiError {
}
}
/// Spotify API object
#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive(Debug, Clone)]
pub struct Spotify {
client: Client,
pub prefix: String,
pub access_token: Option<String>,
pub client_credentials_manager: Option<SpotifyClientCredentials>,
@@ -124,6 +121,7 @@ impl Spotify {
//! [examples](https://github.com/samrayleung/rspotify/tree/master/examples) in github
pub fn default() -> Spotify {
Spotify {
client: Client::new(),
prefix: "https://api.spotify.com/v1/".to_owned(),
access_token: None,
client_credentials_manager: None,
@@ -185,7 +183,10 @@ impl Spotify {
headers.insert(CONTENT_TYPE, "application/json".parse().unwrap());

let response = {
let builder = CLIENT.request(method, &url.into_owned()).headers(headers);
let builder = self
.client
.request(method, &url.into_owned())
.headers(headers);

// only add body if necessary
// spotify rejects GET requests that have a body with a 400 response