From fcd66404396795b8129b44b04b5dd7ceb315f498 Mon Sep 17 00:00:00 2001 From: Chen Han Date: Thu, 17 Oct 2019 23:07:01 +0800 Subject: [PATCH 1/4] add library functions --- NAMESPACE | 2 + R/library.R | 83 ++++++++++++++++++++++++++++++++++++++ man/get_my_saved_albums.Rd | 34 ++++++++++++++++ man/get_my_saved_tracks.Rd | 34 ++++++++++++++++ 4 files changed, 153 insertions(+) create mode 100644 R/library.R create mode 100644 man/get_my_saved_albums.Rd create mode 100644 man/get_my_saved_tracks.Rd diff --git a/NAMESPACE b/NAMESPACE index 4a3ff7e..efcad0d 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -30,6 +30,8 @@ export(get_my_followed_artists) export(get_my_playlists) export(get_my_profile) export(get_my_recently_played) +export(get_my_saved_albums) +export(get_my_saved_tracks) export(get_my_top_artists_or_tracks) export(get_new_releases) export(get_playlist) diff --git a/R/library.R b/R/library.R new file mode 100644 index 0000000..660a556 --- /dev/null +++ b/R/library.R @@ -0,0 +1,83 @@ +#' Get Current User's Saved Albums +#' +#' Get a list of the albums saved in the current Spotify user’s ‘Your Music’ library. +#' +#' @param limit Optional. \cr +#' Maximum number of albums to return. \cr +#' Default: 20 \cr +#' Minimum: 1 \cr +#' Maximum: 50 \cr +#' @param offset Optional. \cr +#' The index of the first albums to return. \cr +#' Default: 0 (the first object). Maximum offset: 100,000. Use with \code{limit} to get the next set of albums. +#' @param market Optional. \cr +#' An \href{http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2}{ISO 3166-1 alpha-2 country code} or the string \code{"from_token"}. Provide this parameter if you want to apply \href{https://developer.spotify.com/documentation/general/guides/track-relinking-guide/}{Track Relinking} +#' @param authorization Required. A valid access token from the Spotify Accounts service. See the \href{https://developer.spotify.com/documentation/general/guides/authorization-guide/}{Web API authorization Guide} for more details. Defaults to \code{spotifyr::get_spotify_authorization_code()}. The access token must have been issued on behalf of the current user. +#' @param include_meta_info Optional. Boolean indicating whether to include full result, with meta information such as \code{"total"}, and \code{"limit"}. Defaults to \code{FALSE}. +#' @return +#' Returns a data frame of results containing user profile information. See \url{https://developer.spotify.com/documentation/web-api/reference/library/get-users-saved-albums/} for more information. +#' @export + +get_my_saved_albums <- function(limit = 20, offset = 0, market = NULL, authorization = get_spotify_authorization_code(), include_meta_info = FALSE) { + base_url <- 'https://api.spotify.com/v1/me/albums' + if (!is.null(market)) { + if (str_detect(market, '^[[:alpha:]]{2}$')) { + stop('"market" must be an ISO 3166-1 alpha-2 country code') + } + } + params <- list( + limit = limit, + offset = offset, + market = market + ) + res <- RETRY('GET', base_url, query = params, config(token = authorization), encode = 'json') + stop_for_status(res) + res <- fromJSON(content(res, as = 'text', encoding = 'UTF-8'), flatten = TRUE) + + if (!include_meta_info) { + res <- res$items + } + return(res) +} + +#' Get a User's Saved Tracks +#' +#'Get a list of the songs saved in the current Spotify user’s ‘Your Music’ library. +#' +#' @param limit Optional. \cr +#' Maximum number of tracks to return. \cr +#' Default: 20 \cr +#' Minimum: 1 \cr +#' Maximum: 50 \cr +#' @param offset Optional. \cr +#' The index of the first track to return. \cr +#' Default: 0 (the first object). Maximum offset: 100,000. Use with \code{limit} to get the next set of tracks. +#' @param market Optional. \cr +#' An \href{http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2}{ISO 3166-1 alpha-2 country code} or the string \code{"from_token"}. Provide this parameter if you want to apply \href{https://developer.spotify.com/documentation/general/guides/track-relinking-guide/}{Track Relinking} +#' @param authorization Required. A valid access token from the Spotify Accounts service. See the \href{https://developer.spotify.com/documentation/general/guides/authorization-guide/}{Web API authorization Guide} for more details. Defaults to \code{spotifyr::get_spotify_authorization_code()}. The access token must have been issued on behalf of the current user. +#' @param include_meta_info Optional. Boolean indicating whether to include full result, with meta information such as \code{"total"}, and \code{"limit"}. Defaults to \code{FALSE}. +#' @return +#' Returns a data frame of results containing user profile information. See \url{https://developer.spotify.com/documentation/web-api/reference/users-profile/get-current-users-profile/} for more information. +#' @export + +get_my_saved_tracks <- function(limit = 20, offset = 0, market = NULL, authorization = get_spotify_authorization_code(), include_meta_info = FALSE) { + base_url <- 'https://api.spotify.com/v1/me/tracks' + if (!is.null(market)) { + if (str_detect(market, '^[[:alpha:]]{2}$')) { + stop('"market" must be an ISO 3166-1 alpha-2 country code') + } + } + params <- list( + limit = limit, + offset = offset, + market = market + ) + res <- RETRY('GET', base_url, query = params, config(token = authorization), encode = 'json') + stop_for_status(res) + res <- fromJSON(content(res, as = 'text', encoding = 'UTF-8'), flatten = TRUE) + + if (!include_meta_info) { + res <- res$items + } + return(res) +} diff --git a/man/get_my_saved_albums.Rd b/man/get_my_saved_albums.Rd new file mode 100644 index 0000000..b79196f --- /dev/null +++ b/man/get_my_saved_albums.Rd @@ -0,0 +1,34 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/library.R +\name{get_my_saved_albums} +\alias{get_my_saved_albums} +\title{Get Current User's Saved Albums} +\usage{ +get_my_saved_albums(limit = 20, offset = 0, market = NULL, + authorization = get_spotify_authorization_code(), + include_meta_info = FALSE) +} +\arguments{ +\item{limit}{Optional. \cr +Maximum number of albums to return. \cr +Default: 20 \cr +Minimum: 1 \cr +Maximum: 50 \cr} + +\item{offset}{Optional. \cr +The index of the first albums to return. \cr +Default: 0 (the first object). Maximum offset: 100,000. Use with \code{limit} to get the next set of albums.} + +\item{market}{Optional. \cr +An \href{http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2}{ISO 3166-1 alpha-2 country code} or the string \code{"from_token"}. Provide this parameter if you want to apply \href{https://developer.spotify.com/documentation/general/guides/track-relinking-guide/}{Track Relinking}} + +\item{authorization}{Required. A valid access token from the Spotify Accounts service. See the \href{https://developer.spotify.com/documentation/general/guides/authorization-guide/}{Web API authorization Guide} for more details. Defaults to \code{spotifyr::get_spotify_authorization_code()}. The access token must have been issued on behalf of the current user.} + +\item{include_meta_info}{Optional. Boolean indicating whether to include full result, with meta information such as \code{"total"}, and \code{"limit"}. Defaults to \code{FALSE}.} +} +\value{ +Returns a data frame of results containing user profile information. See \url{https://developer.spotify.com/documentation/web-api/reference/library/get-users-saved-albums/} for more information. +} +\description{ +Get a list of the albums saved in the current Spotify user’s ‘Your Music’ library. +} diff --git a/man/get_my_saved_tracks.Rd b/man/get_my_saved_tracks.Rd new file mode 100644 index 0000000..6410286 --- /dev/null +++ b/man/get_my_saved_tracks.Rd @@ -0,0 +1,34 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/library.R +\name{get_my_saved_tracks} +\alias{get_my_saved_tracks} +\title{Get a User's Saved Tracks} +\usage{ +get_my_saved_tracks(limit = 20, offset = 0, market = NULL, + authorization = get_spotify_authorization_code(), + include_meta_info = FALSE) +} +\arguments{ +\item{limit}{Optional. \cr +Maximum number of tracks to return. \cr +Default: 20 \cr +Minimum: 1 \cr +Maximum: 50 \cr} + +\item{offset}{Optional. \cr +The index of the first track to return. \cr +Default: 0 (the first object). Maximum offset: 100,000. Use with \code{limit} to get the next set of tracks.} + +\item{market}{Optional. \cr +An \href{http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2}{ISO 3166-1 alpha-2 country code} or the string \code{"from_token"}. Provide this parameter if you want to apply \href{https://developer.spotify.com/documentation/general/guides/track-relinking-guide/}{Track Relinking}} + +\item{authorization}{Required. A valid access token from the Spotify Accounts service. See the \href{https://developer.spotify.com/documentation/general/guides/authorization-guide/}{Web API authorization Guide} for more details. Defaults to \code{spotifyr::get_spotify_authorization_code()}. The access token must have been issued on behalf of the current user.} + +\item{include_meta_info}{Optional. Boolean indicating whether to include full result, with meta information such as \code{"total"}, and \code{"limit"}. Defaults to \code{FALSE}.} +} +\value{ +Returns a data frame of results containing user profile information. See \url{https://developer.spotify.com/documentation/web-api/reference/users-profile/get-current-users-profile/} for more information. +} +\description{ +Get a list of the songs saved in the current Spotify user’s ‘Your Music’ library. +} From 175a77eb0ccd09a19bff1d9e252e043bacdb478a Mon Sep 17 00:00:00 2001 From: Chen Han Date: Wed, 10 Jun 2020 17:27:26 +0800 Subject: [PATCH 2/4] add check saved albums/shows/tracks and get saved albums/shows --- NAMESPACE | 4 ++ R/library.R | 109 ++++++++++++++++++++++++++++++++++- man/check_my_saved_albums.Rd | 19 ++++++ man/check_my_saved_shows.Rd | 19 ++++++ man/check_my_saved_tracks.Rd | 19 ++++++ man/get_my_saved_albums.Rd | 2 +- man/get_my_saved_show.Rd | 34 +++++++++++ man/get_my_saved_tracks.Rd | 2 +- 8 files changed, 204 insertions(+), 4 deletions(-) create mode 100644 man/check_my_saved_albums.Rd create mode 100644 man/check_my_saved_shows.Rd create mode 100644 man/check_my_saved_tracks.Rd create mode 100644 man/get_my_saved_show.Rd diff --git a/NAMESPACE b/NAMESPACE index e69f377..4ba53e5 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -5,6 +5,9 @@ S3method(tidy,playlist) export(add_tracks_to_playlist) export(change_playlist_details) export(check_me_following) +export(check_my_saved_albums) +export(check_my_saved_shows) +export(check_my_saved_tracks) export(check_users_following) export(create_playlist) export(dedupe_album_names) @@ -34,6 +37,7 @@ export(get_my_playlists) export(get_my_profile) export(get_my_recently_played) export(get_my_saved_albums) +export(get_my_saved_show) export(get_my_saved_tracks) export(get_my_top_artists_or_tracks) export(get_new_releases) diff --git a/R/library.R b/R/library.R index 660a556..40fa9d7 100644 --- a/R/library.R +++ b/R/library.R @@ -1,3 +1,73 @@ +#' Check User's Saved Albums +#' +#'Check if one or more albums is already saved in the current Spotify user’s ‘Your Music’ library. +#' +#' @param ids Required. A comma-separated list of the \href{https://developer.spotify.com/documentation/web-api/#spotify-uris-and-ids}{Spotify IDs} for the albums. Maximum: 50 IDs. +#' +#' @param authorization Required. A valid access token from the Spotify Accounts service. See the \href{https://developer.spotify.com/documentation/general/guides/authorization-guide/}{Web API authorization Guide} for more details. Defaults to \code{spotifyr::get_spotify_authorization_code()}. The access token must have been issued on behalf of the current user. +#' +#' @return +#' Returns a data frame of results containing album id and saved status. See \url{https://developer.spotify.com/documentation/web-api/reference/library/check-users-saved-albums/} for more information. +#' @export + +check_my_saved_albums <- function(ids, authorization = get_spotify_authorization_code()) { + base_url = 'https://api.spotify.com/v1/me/albums/contains' + params <- list(ids = ids) + # params <- ids + res <- RETRY('GET', base_url, query = params, config(token = authorization), encode = 'json') + stop_for_status(res) + res <- fromJSON(content(res, as = 'text', encoding = 'UTF-8'), flatten = TRUE) + + tibble(album_id = ids, + is_saved = res) +} +#' Check User's Saved Shows +#' +#'Check if one or more shows is already saved in the current Spotify user’s library. +#' +#' @param ids Required. A comma-separated list of the \href{https://developer.spotify.com/documentation/web-api/#spotify-uris-and-ids}{Spotify IDs} for the albums. Maximum: 50 IDs. +#' +#' @param authorization Required. A valid access token from the Spotify Accounts service. See the \href{https://developer.spotify.com/documentation/general/guides/authorization-guide/}{Web API authorization Guide} for more details. Defaults to \code{spotifyr::get_spotify_authorization_code()}. The access token must have been issued on behalf of the current user. +#' +#' @return +#' Returns a data frame of results containing show id and saved status. See \url{https://developer.spotify.com/documentation/web-api/reference/library/check-users-saved-albums/} for more information. +#' @export + +check_my_saved_shows <- function(ids, authorization = get_spotify_authorization_code()) { + base_url = 'https://api.spotify.com/v1/me/shows/contains' + params <- list(ids = ids) + # params <- ids + res <- RETRY('GET', base_url, query = params, config(token = authorization), encode = 'json') + stop_for_status(res) + res <- fromJSON(content(res, as = 'text', encoding = 'UTF-8'), flatten = TRUE) + + tibble(album_id = ids, + is_saved = res) +} +#' Check User's Saved Tracks +#' +#'Check if one or more tracks is already saved in the current Spotify user’s ‘Your Music’ library. +#' +#' @param ids Required. A comma-separated list of the \href{https://developer.spotify.com/documentation/web-api/#spotify-uris-and-ids}{Spotify IDs} for the albums. Maximum: 50 IDs. +#' +#' @param authorization Required. A valid access token from the Spotify Accounts service. See the \href{https://developer.spotify.com/documentation/general/guides/authorization-guide/}{Web API authorization Guide} for more details. Defaults to \code{spotifyr::get_spotify_authorization_code()}. The access token must have been issued on behalf of the current user. +#' +#' @return +#' Returns a data frame of results containing track id and saved status. See \url{https://developer.spotify.com/documentation/web-api/reference/library/check-users-saved-albums/} for more information. +#' @export + +check_my_saved_tracks <- function(ids, authorization = get_spotify_authorization_code()) { + base_url = 'https://api.spotify.com/v1/me/tracks/contains' + params <- list(ids = ids) + # params <- ids + res <- RETRY('GET', base_url, query = params, config(token = authorization), encode = 'json') + stop_for_status(res) + res <- fromJSON(content(res, as = 'text', encoding = 'UTF-8'), flatten = TRUE) + + tibble(album_id = ids, + is_saved = res) +} + #' Get Current User's Saved Albums #' #' Get a list of the albums saved in the current Spotify user’s ‘Your Music’ library. @@ -15,7 +85,7 @@ #' @param authorization Required. A valid access token from the Spotify Accounts service. See the \href{https://developer.spotify.com/documentation/general/guides/authorization-guide/}{Web API authorization Guide} for more details. Defaults to \code{spotifyr::get_spotify_authorization_code()}. The access token must have been issued on behalf of the current user. #' @param include_meta_info Optional. Boolean indicating whether to include full result, with meta information such as \code{"total"}, and \code{"limit"}. Defaults to \code{FALSE}. #' @return -#' Returns a data frame of results containing user profile information. See \url{https://developer.spotify.com/documentation/web-api/reference/library/get-users-saved-albums/} for more information. +#' Returns a data frame of results containing user saved albums information. See \url{https://developer.spotify.com/documentation/web-api/reference/library/get-users-saved-albums/} for more information. #' @export get_my_saved_albums <- function(limit = 20, offset = 0, market = NULL, authorization = get_spotify_authorization_code(), include_meta_info = FALSE) { @@ -40,6 +110,41 @@ get_my_saved_albums <- function(limit = 20, offset = 0, market = NULL, authoriza return(res) } +#' Get User's Saved Shows +#' +#' Get a list of shows saved in the current Spotify user’s library. Optional parameters can be used to limit the number of shows returned. +#' +#' @param limit Optional. \cr +#' Maximum number of shows to return. \cr +#' Default: 20 \cr +#' Minimum: 1 \cr +#' Maximum: 50 \cr +#' @param offset Optional. \cr +#' The index of the first show to return. \cr +#' Default: 0 (the first object). Use with \code{limit} to get the next set of shows. +#' @param authorization Required. A valid access token from the Spotify Accounts service. See the \href{https://developer.spotify.com/documentation/general/guides/authorization-guide/}{Web API authorization Guide} for more details. Defaults to \code{spotifyr::get_spotify_authorization_code()}. The access token must have been issued on behalf of the current user. +#' @param include_meta_info Optional. Boolean indicating whether to include full result, with meta information such as \code{"total"}, and \code{"limit"}. Defaults to \code{FALSE}. +#' +#' @return +#' Returns a data frame of results containing saved shows information. See \url{https://developer.spotify.com/documentation/web-api/reference/library/get-users-saved-shows/} for more information. +#' @export + +get_my_saved_show <- function(limit = 20, offset = 0, authorization = get_spotify_authorization_code(), include_meta_info = FALSE) { + base_url <- 'https://api.spotify.com/v1/me/shows' + params <- list( + limit = limit, + offset = offset + ) + res <- RETRY('GET', base_url, query = params, config(token = authorization), encode = 'json') + stop_for_status(res) + res <- fromJSON(content(res, as = 'text', encoding = 'UTF-8'), flatten = TRUE) + + if(!include_meta_info) { + res <- res$items + } + return(res) +} + #' Get a User's Saved Tracks #' #'Get a list of the songs saved in the current Spotify user’s ‘Your Music’ library. @@ -57,7 +162,7 @@ get_my_saved_albums <- function(limit = 20, offset = 0, market = NULL, authoriza #' @param authorization Required. A valid access token from the Spotify Accounts service. See the \href{https://developer.spotify.com/documentation/general/guides/authorization-guide/}{Web API authorization Guide} for more details. Defaults to \code{spotifyr::get_spotify_authorization_code()}. The access token must have been issued on behalf of the current user. #' @param include_meta_info Optional. Boolean indicating whether to include full result, with meta information such as \code{"total"}, and \code{"limit"}. Defaults to \code{FALSE}. #' @return -#' Returns a data frame of results containing user profile information. See \url{https://developer.spotify.com/documentation/web-api/reference/users-profile/get-current-users-profile/} for more information. +#' Returns a data frame of results containing user saved tracks information. See \url{https://developer.spotify.com/documentation/web-api/reference/users-profile/get-users-saved-tracks/} for more information. #' @export get_my_saved_tracks <- function(limit = 20, offset = 0, market = NULL, authorization = get_spotify_authorization_code(), include_meta_info = FALSE) { diff --git a/man/check_my_saved_albums.Rd b/man/check_my_saved_albums.Rd new file mode 100644 index 0000000..451af9e --- /dev/null +++ b/man/check_my_saved_albums.Rd @@ -0,0 +1,19 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/library.R +\name{check_my_saved_albums} +\alias{check_my_saved_albums} +\title{Check User's Saved Albums} +\usage{ +check_my_saved_albums(ids, authorization = get_spotify_authorization_code()) +} +\arguments{ +\item{ids}{Required. A comma-separated list of the \href{https://developer.spotify.com/documentation/web-api/#spotify-uris-and-ids}{Spotify IDs} for the albums. Maximum: 50 IDs.} + +\item{authorization}{Required. A valid access token from the Spotify Accounts service. See the \href{https://developer.spotify.com/documentation/general/guides/authorization-guide/}{Web API authorization Guide} for more details. Defaults to \code{spotifyr::get_spotify_authorization_code()}. The access token must have been issued on behalf of the current user.} +} +\value{ +Returns a data frame of results containing album id and saved status. See \url{https://developer.spotify.com/documentation/web-api/reference/library/check-users-saved-albums/} for more information. +} +\description{ +Check if one or more albums is already saved in the current Spotify user’s ‘Your Music’ library. +} diff --git a/man/check_my_saved_shows.Rd b/man/check_my_saved_shows.Rd new file mode 100644 index 0000000..778870c --- /dev/null +++ b/man/check_my_saved_shows.Rd @@ -0,0 +1,19 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/library.R +\name{check_my_saved_shows} +\alias{check_my_saved_shows} +\title{Check User's Saved Shows} +\usage{ +check_my_saved_shows(ids, authorization = get_spotify_authorization_code()) +} +\arguments{ +\item{ids}{Required. A comma-separated list of the \href{https://developer.spotify.com/documentation/web-api/#spotify-uris-and-ids}{Spotify IDs} for the albums. Maximum: 50 IDs.} + +\item{authorization}{Required. A valid access token from the Spotify Accounts service. See the \href{https://developer.spotify.com/documentation/general/guides/authorization-guide/}{Web API authorization Guide} for more details. Defaults to \code{spotifyr::get_spotify_authorization_code()}. The access token must have been issued on behalf of the current user.} +} +\value{ +Returns a data frame of results containing show id and saved status. See \url{https://developer.spotify.com/documentation/web-api/reference/library/check-users-saved-albums/} for more information. +} +\description{ +Check if one or more shows is already saved in the current Spotify user’s library. +} diff --git a/man/check_my_saved_tracks.Rd b/man/check_my_saved_tracks.Rd new file mode 100644 index 0000000..7119038 --- /dev/null +++ b/man/check_my_saved_tracks.Rd @@ -0,0 +1,19 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/library.R +\name{check_my_saved_tracks} +\alias{check_my_saved_tracks} +\title{Check User's Saved Tracks} +\usage{ +check_my_saved_tracks(ids, authorization = get_spotify_authorization_code()) +} +\arguments{ +\item{ids}{Required. A comma-separated list of the \href{https://developer.spotify.com/documentation/web-api/#spotify-uris-and-ids}{Spotify IDs} for the albums. Maximum: 50 IDs.} + +\item{authorization}{Required. A valid access token from the Spotify Accounts service. See the \href{https://developer.spotify.com/documentation/general/guides/authorization-guide/}{Web API authorization Guide} for more details. Defaults to \code{spotifyr::get_spotify_authorization_code()}. The access token must have been issued on behalf of the current user.} +} +\value{ +Returns a data frame of results containing track id and saved status. See \url{https://developer.spotify.com/documentation/web-api/reference/library/check-users-saved-albums/} for more information. +} +\description{ +Check if one or more tracks is already saved in the current Spotify user’s ‘Your Music’ library. +} diff --git a/man/get_my_saved_albums.Rd b/man/get_my_saved_albums.Rd index e8804c1..1b37a10 100644 --- a/man/get_my_saved_albums.Rd +++ b/man/get_my_saved_albums.Rd @@ -31,7 +31,7 @@ An \href{http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2}{ISO 3166-1 alpha-2 cou \item{include_meta_info}{Optional. Boolean indicating whether to include full result, with meta information such as \code{"total"}, and \code{"limit"}. Defaults to \code{FALSE}.} } \value{ -Returns a data frame of results containing user profile information. See \url{https://developer.spotify.com/documentation/web-api/reference/library/get-users-saved-albums/} for more information. +Returns a data frame of results containing user saved albums information. See \url{https://developer.spotify.com/documentation/web-api/reference/library/get-users-saved-albums/} for more information. } \description{ Get a list of the albums saved in the current Spotify user’s ‘Your Music’ library. diff --git a/man/get_my_saved_show.Rd b/man/get_my_saved_show.Rd new file mode 100644 index 0000000..46168f1 --- /dev/null +++ b/man/get_my_saved_show.Rd @@ -0,0 +1,34 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/library.R +\name{get_my_saved_show} +\alias{get_my_saved_show} +\title{Get User's Saved Shows} +\usage{ +get_my_saved_show( + limit = 20, + offset = 0, + authorization = get_spotify_authorization_code(), + include_meta_info = FALSE +) +} +\arguments{ +\item{limit}{Optional. \cr +Maximum number of shows to return. \cr +Default: 20 \cr +Minimum: 1 \cr +Maximum: 50 \cr} + +\item{offset}{Optional. \cr +The index of the first show to return. \cr +Default: 0 (the first object). Use with \code{limit} to get the next set of shows.} + +\item{authorization}{Required. A valid access token from the Spotify Accounts service. See the \href{https://developer.spotify.com/documentation/general/guides/authorization-guide/}{Web API authorization Guide} for more details. Defaults to \code{spotifyr::get_spotify_authorization_code()}. The access token must have been issued on behalf of the current user.} + +\item{include_meta_info}{Optional. Boolean indicating whether to include full result, with meta information such as \code{"total"}, and \code{"limit"}. Defaults to \code{FALSE}.} +} +\value{ +Returns a data frame of results containing saved shows information. See \url{https://developer.spotify.com/documentation/web-api/reference/library/get-users-saved-shows/} for more information. +} +\description{ +Get a list of shows saved in the current Spotify user’s library. Optional parameters can be used to limit the number of shows returned. +} diff --git a/man/get_my_saved_tracks.Rd b/man/get_my_saved_tracks.Rd index f53e38d..0184f9e 100644 --- a/man/get_my_saved_tracks.Rd +++ b/man/get_my_saved_tracks.Rd @@ -31,7 +31,7 @@ An \href{http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2}{ISO 3166-1 alpha-2 cou \item{include_meta_info}{Optional. Boolean indicating whether to include full result, with meta information such as \code{"total"}, and \code{"limit"}. Defaults to \code{FALSE}.} } \value{ -Returns a data frame of results containing user profile information. See \url{https://developer.spotify.com/documentation/web-api/reference/users-profile/get-current-users-profile/} for more information. +Returns a data frame of results containing user saved tracks information. See \url{https://developer.spotify.com/documentation/web-api/reference/users-profile/get-users-saved-tracks/} for more information. } \description{ Get a list of the songs saved in the current Spotify user’s ‘Your Music’ library. From fe6c85236b8b327f12744e497959b12a02b35988 Mon Sep 17 00:00:00 2001 From: Chen Han Date: Wed, 10 Jun 2020 20:14:50 +0800 Subject: [PATCH 3/4] add remove_my_saved_tracks/albums/shows --- NAMESPACE | 5 +- R/library.R | 125 +++++++++++++++--- man/check_my_saved_albums.Rd | 6 +- man/check_my_saved_shows.Rd | 6 +- man/check_my_saved_tracks.Rd | 6 +- man/get_my_saved_albums.Rd | 6 +- ...my_saved_show.Rd => get_my_saved_shows.Rd} | 12 +- man/get_my_saved_tracks.Rd | 6 +- man/remove_my_saved_albums.Rd | 26 ++++ man/remove_my_saved_shows.Rd | 26 ++++ man/remove_my_saved_tracks.Rd | 26 ++++ 11 files changed, 215 insertions(+), 35 deletions(-) rename man/{get_my_saved_show.Rd => get_my_saved_shows.Rd} (58%) create mode 100644 man/remove_my_saved_albums.Rd create mode 100644 man/remove_my_saved_shows.Rd create mode 100644 man/remove_my_saved_tracks.Rd diff --git a/NAMESPACE b/NAMESPACE index 4ba53e5..362800d 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -37,7 +37,7 @@ export(get_my_playlists) export(get_my_profile) export(get_my_recently_played) export(get_my_saved_albums) -export(get_my_saved_show) +export(get_my_saved_shows) export(get_my_saved_tracks) export(get_my_top_artists_or_tracks) export(get_new_releases) @@ -60,6 +60,9 @@ export(get_user_profile) export(is_uri) export(pause_my_playback) export(pitch_class_lookup) +export(remove_my_saved_albums) +export(remove_my_saved_shows) +export(remove_my_saved_tracks) export(remove_tracks_from_playlist) export(scopes) export(search_spotify) diff --git a/R/library.R b/R/library.R index 40fa9d7..0641322 100644 --- a/R/library.R +++ b/R/library.R @@ -2,10 +2,10 @@ #' #'Check if one or more albums is already saved in the current Spotify user’s ‘Your Music’ library. #' -#' @param ids Required. A comma-separated list of the \href{https://developer.spotify.com/documentation/web-api/#spotify-uris-and-ids}{Spotify IDs} for the albums. Maximum: 50 IDs. -#' -#' @param authorization Required. A valid access token from the Spotify Accounts service. See the \href{https://developer.spotify.com/documentation/general/guides/authorization-guide/}{Web API authorization Guide} for more details. Defaults to \code{spotifyr::get_spotify_authorization_code()}. The access token must have been issued on behalf of the current user. -#' +#' @param ids Required. \cr +#' A comma-separated list of the \href{https://developer.spotify.com/documentation/web-api/#spotify-uris-and-ids}{Spotify IDs} for the albums. Maximum: 50 IDs. +#' @param authorization Required. \cr +#' A valid access token from the Spotify Accounts service. See the \href{https://developer.spotify.com/documentation/general/guides/authorization-guide/}{Web API authorization Guide} for more details. Defaults to \code{spotifyr::get_spotify_authorization_code()}. The access token must have been issued on behalf of the current user. #' @return #' Returns a data frame of results containing album id and saved status. See \url{https://developer.spotify.com/documentation/web-api/reference/library/check-users-saved-albums/} for more information. #' @export @@ -25,10 +25,10 @@ check_my_saved_albums <- function(ids, authorization = get_spotify_authorization #' #'Check if one or more shows is already saved in the current Spotify user’s library. #' -#' @param ids Required. A comma-separated list of the \href{https://developer.spotify.com/documentation/web-api/#spotify-uris-and-ids}{Spotify IDs} for the albums. Maximum: 50 IDs. -#' -#' @param authorization Required. A valid access token from the Spotify Accounts service. See the \href{https://developer.spotify.com/documentation/general/guides/authorization-guide/}{Web API authorization Guide} for more details. Defaults to \code{spotifyr::get_spotify_authorization_code()}. The access token must have been issued on behalf of the current user. -#' +#' @param ids Required. \cr +#' A comma-separated list of the \href{https://developer.spotify.com/documentation/web-api/#spotify-uris-and-ids}{Spotify IDs} for the albums. Maximum: 50 IDs. +#' @param authorization Required. \cr +#' A valid access token from the Spotify Accounts service. See the \href{https://developer.spotify.com/documentation/general/guides/authorization-guide/}{Web API authorization Guide} for more details. Defaults to \code{spotifyr::get_spotify_authorization_code()}. The access token must have been issued on behalf of the current user. #' @return #' Returns a data frame of results containing show id and saved status. See \url{https://developer.spotify.com/documentation/web-api/reference/library/check-users-saved-albums/} for more information. #' @export @@ -48,10 +48,10 @@ check_my_saved_shows <- function(ids, authorization = get_spotify_authorization_ #' #'Check if one or more tracks is already saved in the current Spotify user’s ‘Your Music’ library. #' -#' @param ids Required. A comma-separated list of the \href{https://developer.spotify.com/documentation/web-api/#spotify-uris-and-ids}{Spotify IDs} for the albums. Maximum: 50 IDs. -#' -#' @param authorization Required. A valid access token from the Spotify Accounts service. See the \href{https://developer.spotify.com/documentation/general/guides/authorization-guide/}{Web API authorization Guide} for more details. Defaults to \code{spotifyr::get_spotify_authorization_code()}. The access token must have been issued on behalf of the current user. -#' +#' @param ids Required. \cr +#' A comma-separated list of the \href{https://developer.spotify.com/documentation/web-api/#spotify-uris-and-ids}{Spotify IDs} for the albums. Maximum: 50 IDs. +#' @param authorization Required. \cr +#' A valid access token from the Spotify Accounts service. See the \href{https://developer.spotify.com/documentation/general/guides/authorization-guide/}{Web API authorization Guide} for more details. Defaults to \code{spotifyr::get_spotify_authorization_code()}. The access token must have been issued on behalf of the current user. #' @return #' Returns a data frame of results containing track id and saved status. See \url{https://developer.spotify.com/documentation/web-api/reference/library/check-users-saved-albums/} for more information. #' @export @@ -82,8 +82,10 @@ check_my_saved_tracks <- function(ids, authorization = get_spotify_authorization #' Default: 0 (the first object). Maximum offset: 100,000. Use with \code{limit} to get the next set of albums. #' @param market Optional. \cr #' An \href{http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2}{ISO 3166-1 alpha-2 country code} or the string \code{"from_token"}. Provide this parameter if you want to apply \href{https://developer.spotify.com/documentation/general/guides/track-relinking-guide/}{Track Relinking} -#' @param authorization Required. A valid access token from the Spotify Accounts service. See the \href{https://developer.spotify.com/documentation/general/guides/authorization-guide/}{Web API authorization Guide} for more details. Defaults to \code{spotifyr::get_spotify_authorization_code()}. The access token must have been issued on behalf of the current user. -#' @param include_meta_info Optional. Boolean indicating whether to include full result, with meta information such as \code{"total"}, and \code{"limit"}. Defaults to \code{FALSE}. +#' @param authorization Required.\cr +#' A valid access token from the Spotify Accounts service. See the \href{https://developer.spotify.com/documentation/general/guides/authorization-guide/}{Web API authorization Guide} for more details. Defaults to \code{spotifyr::get_spotify_authorization_code()}. The access token must have been issued on behalf of the current user. +#' @param include_meta_info Optional.\cr +#' Boolean indicating whether to include full result, with meta information such as \code{"total"}, and \code{"limit"}. Defaults to \code{FALSE}. #' @return #' Returns a data frame of results containing user saved albums information. See \url{https://developer.spotify.com/documentation/web-api/reference/library/get-users-saved-albums/} for more information. #' @export @@ -122,14 +124,16 @@ get_my_saved_albums <- function(limit = 20, offset = 0, market = NULL, authoriza #' @param offset Optional. \cr #' The index of the first show to return. \cr #' Default: 0 (the first object). Use with \code{limit} to get the next set of shows. -#' @param authorization Required. A valid access token from the Spotify Accounts service. See the \href{https://developer.spotify.com/documentation/general/guides/authorization-guide/}{Web API authorization Guide} for more details. Defaults to \code{spotifyr::get_spotify_authorization_code()}. The access token must have been issued on behalf of the current user. -#' @param include_meta_info Optional. Boolean indicating whether to include full result, with meta information such as \code{"total"}, and \code{"limit"}. Defaults to \code{FALSE}. +#' @param authorization Required. \cr +#' A valid access token from the Spotify Accounts service. See the \href{https://developer.spotify.com/documentation/general/guides/authorization-guide/}{Web API authorization Guide} for more details. Defaults to \code{spotifyr::get_spotify_authorization_code()}. The access token must have been issued on behalf of the current user. +#' @param include_meta_info Optional. \cr +#' Boolean indicating whether to include full result, with meta information such as \code{"total"}, and \code{"limit"}. Defaults to \code{FALSE}. #' #' @return #' Returns a data frame of results containing saved shows information. See \url{https://developer.spotify.com/documentation/web-api/reference/library/get-users-saved-shows/} for more information. #' @export -get_my_saved_show <- function(limit = 20, offset = 0, authorization = get_spotify_authorization_code(), include_meta_info = FALSE) { +get_my_saved_shows <- function(limit = 20, offset = 0, authorization = get_spotify_authorization_code(), include_meta_info = FALSE) { base_url <- 'https://api.spotify.com/v1/me/shows' params <- list( limit = limit, @@ -159,8 +163,10 @@ get_my_saved_show <- function(limit = 20, offset = 0, authorization = get_spotif #' Default: 0 (the first object). Maximum offset: 100,000. Use with \code{limit} to get the next set of tracks. #' @param market Optional. \cr #' An \href{http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2}{ISO 3166-1 alpha-2 country code} or the string \code{"from_token"}. Provide this parameter if you want to apply \href{https://developer.spotify.com/documentation/general/guides/track-relinking-guide/}{Track Relinking} -#' @param authorization Required. A valid access token from the Spotify Accounts service. See the \href{https://developer.spotify.com/documentation/general/guides/authorization-guide/}{Web API authorization Guide} for more details. Defaults to \code{spotifyr::get_spotify_authorization_code()}. The access token must have been issued on behalf of the current user. -#' @param include_meta_info Optional. Boolean indicating whether to include full result, with meta information such as \code{"total"}, and \code{"limit"}. Defaults to \code{FALSE}. +#' @param authorization Required. \cr +#' A valid access token from the Spotify Accounts service. See the \href{https://developer.spotify.com/documentation/general/guides/authorization-guide/}{Web API authorization Guide} for more details. Defaults to \code{spotifyr::get_spotify_authorization_code()}. The access token must have been issued on behalf of the current user. +#' @param include_meta_info Optional. \cr +#' Boolean indicating whether to include full result, with meta information such as \code{"total"}, and \code{"limit"}. Defaults to \code{FALSE}. #' @return #' Returns a data frame of results containing user saved tracks information. See \url{https://developer.spotify.com/documentation/web-api/reference/users-profile/get-users-saved-tracks/} for more information. #' @export @@ -186,3 +192,84 @@ get_my_saved_tracks <- function(limit = 20, offset = 0, market = NULL, authoriza } return(res) } + +#' Remove Albums for Current User +#' +#' Remove one or more albums from the current user’s ‘Your Music’ library. \cr +#' Changes to a user’s saved albums may not be visible in other Spotify applications immediately. +#' +#' @param ids Required. \cr +#' A comma-separated list of the \href{https://developer.spotify.com/documentation/web-api/#spotify-uris-and-ids}{Spotify IDs} for the albums. Maximum: 50 IDs. +#' @param authorization Required. \cr +#' A valid access token from the Spotify Accounts service. See the \href{https://developer.spotify.com/documentation/general/guides/authorization-guide/}{Web API authorization Guide} for more details. Defaults to \code{spotifyr::get_spotify_authorization_code()}. The access token must have been issued on behalf of the current user. +#' @param echo Optional.\cr +#' Boolean indicating whether to return the response or work silently. +#' +#' @export + +remove_my_saved_albums <- function(ids, authorization = get_spotify_authorization_code(), echo =FALSE) { + base_url <- 'https://api.spotify.com/v1/me/albums' + + params <- toJSON(ids) + + res <- RETRY('DELETE', base_url, body = params, config(token = authorization), encode = 'json') + stop_for_status(res) + + if (echo) { + return(res) + } +} + +#' Remove User's Saved Shows +#' +#'Delete one or more shows from current Spotify user’s library.\cr +#'Changes to a user’s saved shows may not be visible in other Spotify applications immediately. +#' +#' @param ids Required. \cr +#' A comma-separated list of the \href{https://developer.spotify.com/documentation/web-api/#spotify-uris-and-ids}{Spotify IDs} for the albums. Maximum: 50 IDs. +#' @param authorization Required. \cr +#' A valid access token from the Spotify Accounts service. See the \href{https://developer.spotify.com/documentation/general/guides/authorization-guide/}{Web API authorization Guide} for more details. Defaults to \code{spotifyr::get_spotify_authorization_code()}. The access token must have been issued on behalf of the current user. +#' @param echo Optional.\cr +#' Boolean indicating whether to return the response or work silently. +#' +#' @export + +remove_my_saved_shows <- function(ids, authorization = get_spotify_authorization_code(), echo =FALSE) { + base_url <- 'https://api.spotify.com/v1/me/shows' + + params <- toJSON(ids) + + res <- RETRY('DELETE', base_url, body = params, config(token = authorization), encode = 'json') + stop_for_status(res) + + if (echo) { + return(res) + } +} + +#' Remove User's Saved Tracks +#' +#'Remove one or more tracks from the current user’s ‘Your Music’ library. \cr +#'Changes to a user’s saved tracks may not be visible in other Spotify applications immediately. +#' +#' @param ids Required. \cr +#' A comma-separated list of the \href{https://developer.spotify.com/documentation/web-api/#spotify-uris-and-ids}{Spotify IDs} for the albums. Maximum: 50 IDs. +#' @param authorization Required. \cr +#' A valid access token from the Spotify Accounts service. See the \href{https://developer.spotify.com/documentation/general/guides/authorization-guide/}{Web API authorization Guide} for more details. Defaults to \code{spotifyr::get_spotify_authorization_code()}. The access token must have been issued on behalf of the current user. +#' @param echo Optional.\cr +#' Boolean indicating whether to return the response or work silently. +#' +#' @export + +remove_my_saved_tracks <- function(ids, authorization = get_spotify_authorization_code(), echo =FALSE) { + base_url <- 'https://api.spotify.com/v1/me/tracks' + + params <- toJSON(ids) + + res <- RETRY('DELETE', base_url, body = params, config(token = authorization), encode = 'json') + stop_for_status(res) + + if (echo) { + return(res) + } +} diff --git a/man/check_my_saved_albums.Rd b/man/check_my_saved_albums.Rd index 451af9e..44babaa 100644 --- a/man/check_my_saved_albums.Rd +++ b/man/check_my_saved_albums.Rd @@ -7,9 +7,11 @@ check_my_saved_albums(ids, authorization = get_spotify_authorization_code()) } \arguments{ -\item{ids}{Required. A comma-separated list of the \href{https://developer.spotify.com/documentation/web-api/#spotify-uris-and-ids}{Spotify IDs} for the albums. Maximum: 50 IDs.} +\item{ids}{Required. \cr +A comma-separated list of the \href{https://developer.spotify.com/documentation/web-api/#spotify-uris-and-ids}{Spotify IDs} for the albums. Maximum: 50 IDs.} -\item{authorization}{Required. A valid access token from the Spotify Accounts service. See the \href{https://developer.spotify.com/documentation/general/guides/authorization-guide/}{Web API authorization Guide} for more details. Defaults to \code{spotifyr::get_spotify_authorization_code()}. The access token must have been issued on behalf of the current user.} +\item{authorization}{Required. \cr +A valid access token from the Spotify Accounts service. See the \href{https://developer.spotify.com/documentation/general/guides/authorization-guide/}{Web API authorization Guide} for more details. Defaults to \code{spotifyr::get_spotify_authorization_code()}. The access token must have been issued on behalf of the current user.} } \value{ Returns a data frame of results containing album id and saved status. See \url{https://developer.spotify.com/documentation/web-api/reference/library/check-users-saved-albums/} for more information. diff --git a/man/check_my_saved_shows.Rd b/man/check_my_saved_shows.Rd index 778870c..355b7d3 100644 --- a/man/check_my_saved_shows.Rd +++ b/man/check_my_saved_shows.Rd @@ -7,9 +7,11 @@ check_my_saved_shows(ids, authorization = get_spotify_authorization_code()) } \arguments{ -\item{ids}{Required. A comma-separated list of the \href{https://developer.spotify.com/documentation/web-api/#spotify-uris-and-ids}{Spotify IDs} for the albums. Maximum: 50 IDs.} +\item{ids}{Required. \cr +A comma-separated list of the \href{https://developer.spotify.com/documentation/web-api/#spotify-uris-and-ids}{Spotify IDs} for the albums. Maximum: 50 IDs.} -\item{authorization}{Required. A valid access token from the Spotify Accounts service. See the \href{https://developer.spotify.com/documentation/general/guides/authorization-guide/}{Web API authorization Guide} for more details. Defaults to \code{spotifyr::get_spotify_authorization_code()}. The access token must have been issued on behalf of the current user.} +\item{authorization}{Required. \cr +A valid access token from the Spotify Accounts service. See the \href{https://developer.spotify.com/documentation/general/guides/authorization-guide/}{Web API authorization Guide} for more details. Defaults to \code{spotifyr::get_spotify_authorization_code()}. The access token must have been issued on behalf of the current user.} } \value{ Returns a data frame of results containing show id and saved status. See \url{https://developer.spotify.com/documentation/web-api/reference/library/check-users-saved-albums/} for more information. diff --git a/man/check_my_saved_tracks.Rd b/man/check_my_saved_tracks.Rd index 7119038..f5797d8 100644 --- a/man/check_my_saved_tracks.Rd +++ b/man/check_my_saved_tracks.Rd @@ -7,9 +7,11 @@ check_my_saved_tracks(ids, authorization = get_spotify_authorization_code()) } \arguments{ -\item{ids}{Required. A comma-separated list of the \href{https://developer.spotify.com/documentation/web-api/#spotify-uris-and-ids}{Spotify IDs} for the albums. Maximum: 50 IDs.} +\item{ids}{Required. \cr +A comma-separated list of the \href{https://developer.spotify.com/documentation/web-api/#spotify-uris-and-ids}{Spotify IDs} for the albums. Maximum: 50 IDs.} -\item{authorization}{Required. A valid access token from the Spotify Accounts service. See the \href{https://developer.spotify.com/documentation/general/guides/authorization-guide/}{Web API authorization Guide} for more details. Defaults to \code{spotifyr::get_spotify_authorization_code()}. The access token must have been issued on behalf of the current user.} +\item{authorization}{Required. \cr +A valid access token from the Spotify Accounts service. See the \href{https://developer.spotify.com/documentation/general/guides/authorization-guide/}{Web API authorization Guide} for more details. Defaults to \code{spotifyr::get_spotify_authorization_code()}. The access token must have been issued on behalf of the current user.} } \value{ Returns a data frame of results containing track id and saved status. See \url{https://developer.spotify.com/documentation/web-api/reference/library/check-users-saved-albums/} for more information. diff --git a/man/get_my_saved_albums.Rd b/man/get_my_saved_albums.Rd index 1b37a10..7344233 100644 --- a/man/get_my_saved_albums.Rd +++ b/man/get_my_saved_albums.Rd @@ -26,9 +26,11 @@ Default: 0 (the first object). Maximum offset: 100,000. Use with \code{limit} to \item{market}{Optional. \cr An \href{http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2}{ISO 3166-1 alpha-2 country code} or the string \code{"from_token"}. Provide this parameter if you want to apply \href{https://developer.spotify.com/documentation/general/guides/track-relinking-guide/}{Track Relinking}} -\item{authorization}{Required. A valid access token from the Spotify Accounts service. See the \href{https://developer.spotify.com/documentation/general/guides/authorization-guide/}{Web API authorization Guide} for more details. Defaults to \code{spotifyr::get_spotify_authorization_code()}. The access token must have been issued on behalf of the current user.} +\item{authorization}{Required.\cr +A valid access token from the Spotify Accounts service. See the \href{https://developer.spotify.com/documentation/general/guides/authorization-guide/}{Web API authorization Guide} for more details. Defaults to \code{spotifyr::get_spotify_authorization_code()}. The access token must have been issued on behalf of the current user.} -\item{include_meta_info}{Optional. Boolean indicating whether to include full result, with meta information such as \code{"total"}, and \code{"limit"}. Defaults to \code{FALSE}.} +\item{include_meta_info}{Optional.\cr +Boolean indicating whether to include full result, with meta information such as \code{"total"}, and \code{"limit"}. Defaults to \code{FALSE}.} } \value{ Returns a data frame of results containing user saved albums information. See \url{https://developer.spotify.com/documentation/web-api/reference/library/get-users-saved-albums/} for more information. diff --git a/man/get_my_saved_show.Rd b/man/get_my_saved_shows.Rd similarity index 58% rename from man/get_my_saved_show.Rd rename to man/get_my_saved_shows.Rd index 46168f1..490af31 100644 --- a/man/get_my_saved_show.Rd +++ b/man/get_my_saved_shows.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/library.R -\name{get_my_saved_show} -\alias{get_my_saved_show} +\name{get_my_saved_shows} +\alias{get_my_saved_shows} \title{Get User's Saved Shows} \usage{ -get_my_saved_show( +get_my_saved_shows( limit = 20, offset = 0, authorization = get_spotify_authorization_code(), @@ -22,9 +22,11 @@ Maximum: 50 \cr} The index of the first show to return. \cr Default: 0 (the first object). Use with \code{limit} to get the next set of shows.} -\item{authorization}{Required. A valid access token from the Spotify Accounts service. See the \href{https://developer.spotify.com/documentation/general/guides/authorization-guide/}{Web API authorization Guide} for more details. Defaults to \code{spotifyr::get_spotify_authorization_code()}. The access token must have been issued on behalf of the current user.} +\item{authorization}{Required. \cr +A valid access token from the Spotify Accounts service. See the \href{https://developer.spotify.com/documentation/general/guides/authorization-guide/}{Web API authorization Guide} for more details. Defaults to \code{spotifyr::get_spotify_authorization_code()}. The access token must have been issued on behalf of the current user.} -\item{include_meta_info}{Optional. Boolean indicating whether to include full result, with meta information such as \code{"total"}, and \code{"limit"}. Defaults to \code{FALSE}.} +\item{include_meta_info}{Optional. \cr +Boolean indicating whether to include full result, with meta information such as \code{"total"}, and \code{"limit"}. Defaults to \code{FALSE}.} } \value{ Returns a data frame of results containing saved shows information. See \url{https://developer.spotify.com/documentation/web-api/reference/library/get-users-saved-shows/} for more information. diff --git a/man/get_my_saved_tracks.Rd b/man/get_my_saved_tracks.Rd index 0184f9e..00bc804 100644 --- a/man/get_my_saved_tracks.Rd +++ b/man/get_my_saved_tracks.Rd @@ -26,9 +26,11 @@ Default: 0 (the first object). Maximum offset: 100,000. Use with \code{limit} to \item{market}{Optional. \cr An \href{http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2}{ISO 3166-1 alpha-2 country code} or the string \code{"from_token"}. Provide this parameter if you want to apply \href{https://developer.spotify.com/documentation/general/guides/track-relinking-guide/}{Track Relinking}} -\item{authorization}{Required. A valid access token from the Spotify Accounts service. See the \href{https://developer.spotify.com/documentation/general/guides/authorization-guide/}{Web API authorization Guide} for more details. Defaults to \code{spotifyr::get_spotify_authorization_code()}. The access token must have been issued on behalf of the current user.} +\item{authorization}{Required. \cr +A valid access token from the Spotify Accounts service. See the \href{https://developer.spotify.com/documentation/general/guides/authorization-guide/}{Web API authorization Guide} for more details. Defaults to \code{spotifyr::get_spotify_authorization_code()}. The access token must have been issued on behalf of the current user.} -\item{include_meta_info}{Optional. Boolean indicating whether to include full result, with meta information such as \code{"total"}, and \code{"limit"}. Defaults to \code{FALSE}.} +\item{include_meta_info}{Optional. \cr +Boolean indicating whether to include full result, with meta information such as \code{"total"}, and \code{"limit"}. Defaults to \code{FALSE}.} } \value{ Returns a data frame of results containing user saved tracks information. See \url{https://developer.spotify.com/documentation/web-api/reference/users-profile/get-users-saved-tracks/} for more information. diff --git a/man/remove_my_saved_albums.Rd b/man/remove_my_saved_albums.Rd new file mode 100644 index 0000000..d1786fb --- /dev/null +++ b/man/remove_my_saved_albums.Rd @@ -0,0 +1,26 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/library.R +\name{remove_my_saved_albums} +\alias{remove_my_saved_albums} +\title{Remove Albums for Current User} +\usage{ +remove_my_saved_albums( + ids, + authorization = get_spotify_authorization_code(), + echo = FALSE +) +} +\arguments{ +\item{ids}{Required. \cr +A comma-separated list of the \href{https://developer.spotify.com/documentation/web-api/#spotify-uris-and-ids}{Spotify IDs} for the albums. Maximum: 50 IDs.} + +\item{authorization}{Required. \cr +A valid access token from the Spotify Accounts service. See the \href{https://developer.spotify.com/documentation/general/guides/authorization-guide/}{Web API authorization Guide} for more details. Defaults to \code{spotifyr::get_spotify_authorization_code()}. The access token must have been issued on behalf of the current user.} + +\item{echo}{Optional.\cr +Boolean indicating whether to return the response or work silently.} +} +\description{ +Remove one or more albums from the current user’s ‘Your Music’ library. \cr +Changes to a user’s saved albums may not be visible in other Spotify applications immediately. +} diff --git a/man/remove_my_saved_shows.Rd b/man/remove_my_saved_shows.Rd new file mode 100644 index 0000000..ef5eaa2 --- /dev/null +++ b/man/remove_my_saved_shows.Rd @@ -0,0 +1,26 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/library.R +\name{remove_my_saved_shows} +\alias{remove_my_saved_shows} +\title{Remove User's Saved Shows} +\usage{ +remove_my_saved_shows( + ids, + authorization = get_spotify_authorization_code(), + echo = FALSE +) +} +\arguments{ +\item{ids}{Required. \cr +A comma-separated list of the \href{https://developer.spotify.com/documentation/web-api/#spotify-uris-and-ids}{Spotify IDs} for the albums. Maximum: 50 IDs.} + +\item{authorization}{Required. \cr +A valid access token from the Spotify Accounts service. See the \href{https://developer.spotify.com/documentation/general/guides/authorization-guide/}{Web API authorization Guide} for more details. Defaults to \code{spotifyr::get_spotify_authorization_code()}. The access token must have been issued on behalf of the current user.} + +\item{echo}{Optional.\cr +Boolean indicating whether to return the response or work silently.} +} +\description{ +Delete one or more shows from current Spotify user’s library.\cr +Changes to a user’s saved shows may not be visible in other Spotify applications immediately. +} diff --git a/man/remove_my_saved_tracks.Rd b/man/remove_my_saved_tracks.Rd new file mode 100644 index 0000000..7f92dee --- /dev/null +++ b/man/remove_my_saved_tracks.Rd @@ -0,0 +1,26 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/library.R +\name{remove_my_saved_tracks} +\alias{remove_my_saved_tracks} +\title{Remove User's Saved Tracks} +\usage{ +remove_my_saved_tracks( + ids, + authorization = get_spotify_authorization_code(), + echo = FALSE +) +} +\arguments{ +\item{ids}{Required. \cr +A comma-separated list of the \href{https://developer.spotify.com/documentation/web-api/#spotify-uris-and-ids}{Spotify IDs} for the albums. Maximum: 50 IDs.} + +\item{authorization}{Required. \cr +A valid access token from the Spotify Accounts service. See the \href{https://developer.spotify.com/documentation/general/guides/authorization-guide/}{Web API authorization Guide} for more details. Defaults to \code{spotifyr::get_spotify_authorization_code()}. The access token must have been issued on behalf of the current user.} + +\item{echo}{Optional.\cr +Boolean indicating whether to return the response or work silently.} +} +\description{ +Remove one or more tracks from the current user’s ‘Your Music’ library. \cr +Changes to a user’s saved tracks may not be visible in other Spotify applications immediately. +} From 2acac814d939573bd74b125038eed51791d4053d Mon Sep 17 00:00:00 2001 From: Chen Han Date: Wed, 10 Jun 2020 20:30:16 +0800 Subject: [PATCH 4/4] Add save_albums/tracks/shows_to_library --- NAMESPACE | 3 ++ R/library.R | 96 +++++++++++++++++++++++++++++++++-- man/remove_my_saved_albums.Rd | 3 ++ man/remove_my_saved_shows.Rd | 3 ++ man/remove_my_saved_tracks.Rd | 3 ++ man/save_albums_to_library.Rd | 28 ++++++++++ man/save_shows_to_library.Rd | 28 ++++++++++ man/save_tracks_to_library.Rd | 28 ++++++++++ 8 files changed, 188 insertions(+), 4 deletions(-) create mode 100644 man/save_albums_to_library.Rd create mode 100644 man/save_shows_to_library.Rd create mode 100644 man/save_tracks_to_library.Rd diff --git a/NAMESPACE b/NAMESPACE index 362800d..b51e818 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -64,6 +64,9 @@ export(remove_my_saved_albums) export(remove_my_saved_shows) export(remove_my_saved_tracks) export(remove_tracks_from_playlist) +export(save_albums_to_library) +export(save_shows_to_library) +export(save_tracks_to_library) export(scopes) export(search_spotify) export(seek_to_position) diff --git a/R/library.R b/R/library.R index 0641322..fa8a959 100644 --- a/R/library.R +++ b/R/library.R @@ -205,6 +205,8 @@ get_my_saved_tracks <- function(limit = 20, offset = 0, market = NULL, authoriza #' @param echo Optional.\cr #' Boolean indicating whether to return the response or work silently. #' +#' @return +#' Returns a respinse status. See \url{https://developer.spotify.com/documentation/web-api/#response-status-codes} for more information. #' @export remove_my_saved_albums <- function(ids, authorization = get_spotify_authorization_code(), echo =FALSE) { @@ -222,8 +224,8 @@ remove_my_saved_albums <- function(ids, authorization = get_spotify_authorizatio #' Remove User's Saved Shows #' -#'Delete one or more shows from current Spotify user’s library.\cr -#'Changes to a user’s saved shows may not be visible in other Spotify applications immediately. +#' Delete one or more shows from current Spotify user’s library.\cr +#' Changes to a user’s saved shows may not be visible in other Spotify applications immediately. #' #' @param ids Required. \cr #' A comma-separated list of the \href{https://developer.spotify.com/documentation/web-api/#spotify-uris-and-ids}{Spotify IDs} for the albums. Maximum: 50 IDs. @@ -232,6 +234,8 @@ remove_my_saved_albums <- function(ids, authorization = get_spotify_authorizatio #' @param echo Optional.\cr #' Boolean indicating whether to return the response or work silently. #' +#' @return +#' Returns a respinse status. See \url{https://developer.spotify.com/documentation/web-api/#response-status-codes} for more information. #' @export remove_my_saved_shows <- function(ids, authorization = get_spotify_authorization_code(), echo =FALSE) { @@ -249,8 +253,8 @@ remove_my_saved_shows <- function(ids, authorization = get_spotify_authorization #' Remove User's Saved Tracks #' -#'Remove one or more tracks from the current user’s ‘Your Music’ library. \cr -#'Changes to a user’s saved tracks may not be visible in other Spotify applications immediately. +#' Remove one or more tracks from the current user’s ‘Your Music’ library. \cr +#' Changes to a user’s saved tracks may not be visible in other Spotify applications immediately. #' #' @param ids Required. \cr #' A comma-separated list of the \href{https://developer.spotify.com/documentation/web-api/#spotify-uris-and-ids}{Spotify IDs} for the albums. Maximum: 50 IDs. @@ -259,6 +263,8 @@ remove_my_saved_shows <- function(ids, authorization = get_spotify_authorization #' @param echo Optional.\cr #' Boolean indicating whether to return the response or work silently. #' +#' @return +#' Returns a respinse status. See \url{https://developer.spotify.com/documentation/web-api/#response-status-codes} for more information. #' @export remove_my_saved_tracks <- function(ids, authorization = get_spotify_authorization_code(), echo =FALSE) { @@ -273,3 +279,85 @@ remove_my_saved_tracks <- function(ids, authorization = get_spotify_authorizatio return(res) } } + + +#' Save Albums for Current User +#' +#' Save one or more albums to the current user’s ‘Your Music’ library. +#' +#' @param ids Required. \cr +#' A comma-separated list of the \href{https://developer.spotify.com/documentation/web-api/#spotify-uris-and-ids}{Spotify IDs} for the albums. Maximum: 50 IDs. +#' @param authorization Required. \cr +#' A valid access token from the Spotify Accounts service. See the \href{https://developer.spotify.com/documentation/general/guides/authorization-guide/}{Web API authorization Guide} for more details. Defaults to \code{spotifyr::get_spotify_authorization_code()}. The access token must have been issued on behalf of the current user. +#' @param echo Optional.\cr +#' Boolean indicating whether to return the response or work silently. +#' +#' @return +#' Returns a respinse status. See \url{https://developer.spotify.com/documentation/web-api/#response-status-codes} for more information. +#' @export + +save_albums_to_library <- function(ids, authorization = get_spotify_authorization_code(), echo = FALSE){ + base_url <- 'https://api.spotify.com/v1/me/albums' + + params <- toJSON(ids) + res <- RETRY('PUT', base_url, body = params, config(token = authorization), encode = 'json') + stop_for_status(res) + + if (echo) { + return(res) + } +} + +#' Save Shows for Current User +#' +#' Save one or more shows to current Spotify user’s library. +#' +#' @param ids Required. \cr +#' A comma-separated list of the \href{https://developer.spotify.com/documentation/web-api/#spotify-uris-and-ids}{Spotify IDs} for the albums. Maximum: 50 IDs. +#' @param authorization Required. \cr +#' A valid access token from the Spotify Accounts service. See the \href{https://developer.spotify.com/documentation/general/guides/authorization-guide/}{Web API authorization Guide} for more details. Defaults to \code{spotifyr::get_spotify_authorization_code()}. The access token must have been issued on behalf of the current user. +#' @param echo Optional.\cr +#' Boolean indicating whether to return the response or work silently. +#' +#' @return +#' Returns a respinse status. See \url{https://developer.spotify.com/documentation/web-api/#response-status-codes} for more information. +#' @export + +save_shows_to_library <- function(ids, authorization = get_spotify_authorization_code(), echo = FALSE){ + base_url <- 'https://api.spotify.com/v1/me/shows' + + params <- toJSON(ids) + res <- RETRY('PUT', base_url, body = params, config(token = authorization), encode = 'json') + stop_for_status(res) + + if (echo) { + return(res) + } +} + +#' Save Tracks for Current User +#' +#' Save Tracks for User Save one or more tracks to the current user’s ‘Your Music’ library. +#' +#' @param ids Required. \cr +#' A comma-separated list of the \href{https://developer.spotify.com/documentation/web-api/#spotify-uris-and-ids}{Spotify IDs} for the albums. Maximum: 50 IDs. +#' @param authorization Required. \cr +#' A valid access token from the Spotify Accounts service. See the \href{https://developer.spotify.com/documentation/general/guides/authorization-guide/}{Web API authorization Guide} for more details. Defaults to \code{spotifyr::get_spotify_authorization_code()}. The access token must have been issued on behalf of the current user. +#' @param echo Optional.\cr +#' Boolean indicating whether to return the response or work silently. +#' +#' @return +#' Returns a respinse status. See \url{https://developer.spotify.com/documentation/web-api/#response-status-codes} for more information. +#' @export + +save_tracks_to_library <- function(ids, authorization = get_spotify_authorization_code(), echo = FALSE){ + base_url <- 'https://api.spotify.com/v1/me/tracks' + + params <- toJSON(ids) + res <- RETRY('PUT', base_url, body = params, config(token = authorization), encode = 'json') + stop_for_status(res) + + if (echo) { + return(res) + } +} diff --git a/man/remove_my_saved_albums.Rd b/man/remove_my_saved_albums.Rd index d1786fb..e902d3e 100644 --- a/man/remove_my_saved_albums.Rd +++ b/man/remove_my_saved_albums.Rd @@ -20,6 +20,9 @@ A valid access token from the Spotify Accounts service. See the \href{https://de \item{echo}{Optional.\cr Boolean indicating whether to return the response or work silently.} } +\value{ +Returns a respinse status. See \url{https://developer.spotify.com/documentation/web-api/#response-status-codes} for more information. +} \description{ Remove one or more albums from the current user’s ‘Your Music’ library. \cr Changes to a user’s saved albums may not be visible in other Spotify applications immediately. diff --git a/man/remove_my_saved_shows.Rd b/man/remove_my_saved_shows.Rd index ef5eaa2..c286585 100644 --- a/man/remove_my_saved_shows.Rd +++ b/man/remove_my_saved_shows.Rd @@ -20,6 +20,9 @@ A valid access token from the Spotify Accounts service. See the \href{https://de \item{echo}{Optional.\cr Boolean indicating whether to return the response or work silently.} } +\value{ +Returns a respinse status. See \url{https://developer.spotify.com/documentation/web-api/#response-status-codes} for more information. +} \description{ Delete one or more shows from current Spotify user’s library.\cr Changes to a user’s saved shows may not be visible in other Spotify applications immediately. diff --git a/man/remove_my_saved_tracks.Rd b/man/remove_my_saved_tracks.Rd index 7f92dee..14f5911 100644 --- a/man/remove_my_saved_tracks.Rd +++ b/man/remove_my_saved_tracks.Rd @@ -20,6 +20,9 @@ A valid access token from the Spotify Accounts service. See the \href{https://de \item{echo}{Optional.\cr Boolean indicating whether to return the response or work silently.} } +\value{ +Returns a respinse status. See \url{https://developer.spotify.com/documentation/web-api/#response-status-codes} for more information. +} \description{ Remove one or more tracks from the current user’s ‘Your Music’ library. \cr Changes to a user’s saved tracks may not be visible in other Spotify applications immediately. diff --git a/man/save_albums_to_library.Rd b/man/save_albums_to_library.Rd new file mode 100644 index 0000000..c7a5480 --- /dev/null +++ b/man/save_albums_to_library.Rd @@ -0,0 +1,28 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/library.R +\name{save_albums_to_library} +\alias{save_albums_to_library} +\title{Save Albums for Current User} +\usage{ +save_albums_to_library( + ids, + authorization = get_spotify_authorization_code(), + echo = FALSE +) +} +\arguments{ +\item{ids}{Required. \cr +A comma-separated list of the \href{https://developer.spotify.com/documentation/web-api/#spotify-uris-and-ids}{Spotify IDs} for the albums. Maximum: 50 IDs.} + +\item{authorization}{Required. \cr +A valid access token from the Spotify Accounts service. See the \href{https://developer.spotify.com/documentation/general/guides/authorization-guide/}{Web API authorization Guide} for more details. Defaults to \code{spotifyr::get_spotify_authorization_code()}. The access token must have been issued on behalf of the current user.} + +\item{echo}{Optional.\cr +Boolean indicating whether to return the response or work silently.} +} +\value{ +Returns a respinse status. See \url{https://developer.spotify.com/documentation/web-api/#response-status-codes} for more information. +} +\description{ +Save one or more albums to the current user’s ‘Your Music’ library. +} diff --git a/man/save_shows_to_library.Rd b/man/save_shows_to_library.Rd new file mode 100644 index 0000000..2726021 --- /dev/null +++ b/man/save_shows_to_library.Rd @@ -0,0 +1,28 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/library.R +\name{save_shows_to_library} +\alias{save_shows_to_library} +\title{Save Shows for Current User} +\usage{ +save_shows_to_library( + ids, + authorization = get_spotify_authorization_code(), + echo = FALSE +) +} +\arguments{ +\item{ids}{Required. \cr +A comma-separated list of the \href{https://developer.spotify.com/documentation/web-api/#spotify-uris-and-ids}{Spotify IDs} for the albums. Maximum: 50 IDs.} + +\item{authorization}{Required. \cr +A valid access token from the Spotify Accounts service. See the \href{https://developer.spotify.com/documentation/general/guides/authorization-guide/}{Web API authorization Guide} for more details. Defaults to \code{spotifyr::get_spotify_authorization_code()}. The access token must have been issued on behalf of the current user.} + +\item{echo}{Optional.\cr +Boolean indicating whether to return the response or work silently.} +} +\value{ +Returns a respinse status. See \url{https://developer.spotify.com/documentation/web-api/#response-status-codes} for more information. +} +\description{ +Save one or more shows to current Spotify user’s library. +} diff --git a/man/save_tracks_to_library.Rd b/man/save_tracks_to_library.Rd new file mode 100644 index 0000000..e78c7ba --- /dev/null +++ b/man/save_tracks_to_library.Rd @@ -0,0 +1,28 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/library.R +\name{save_tracks_to_library} +\alias{save_tracks_to_library} +\title{Save Tracks for Current User} +\usage{ +save_tracks_to_library( + ids, + authorization = get_spotify_authorization_code(), + echo = FALSE +) +} +\arguments{ +\item{ids}{Required. \cr +A comma-separated list of the \href{https://developer.spotify.com/documentation/web-api/#spotify-uris-and-ids}{Spotify IDs} for the albums. Maximum: 50 IDs.} + +\item{authorization}{Required. \cr +A valid access token from the Spotify Accounts service. See the \href{https://developer.spotify.com/documentation/general/guides/authorization-guide/}{Web API authorization Guide} for more details. Defaults to \code{spotifyr::get_spotify_authorization_code()}. The access token must have been issued on behalf of the current user.} + +\item{echo}{Optional.\cr +Boolean indicating whether to return the response or work silently.} +} +\value{ +Returns a respinse status. See \url{https://developer.spotify.com/documentation/web-api/#response-status-codes} for more information. +} +\description{ +Save Tracks for User Save one or more tracks to the current user’s ‘Your Music’ library. +}