Skip to content

Commit

Permalink
Switched auth details to env variables. Updated docs. Added build bad…
Browse files Browse the repository at this point in the history
…ges.
  • Loading branch information
phillc73 committed Feb 16, 2016
1 parent 73110e0 commit 2acd1e8
Show file tree
Hide file tree
Showing 17 changed files with 85 additions and 87 deletions.
19 changes: 10 additions & 9 deletions R/b2AuthorizeAccount.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,14 @@
#' B2 account. This may be obtained by clicking \emph{Show Account ID and
#' Application Key} hypertext from the B2 My Account area, after logging in
#' with a web browser.
#' @return If successful, an authorisation token will be returned and stored in
#' an Rds file called \emph{accountAuthorization.Rds} in the current working
#' directory. The data in this Rds file will be used in all other functions in
#' this package. Specific B2 documentation regarding this API call can be
#' @return If successful, an authorisation token, API URL, download URL and your
#' Account ID will be returned. These are then stored in envrionment
#' variables. These environment variables will be used in all other functions
#' in this package. Specific B2 documentation regarding this API call can be
#' found here:
#'
#' \url{https://www.backblaze.com/b2/docs/b2_authorize_account.html}
#'
#' @section Note: Consider programmtically deleting
#' \emph{accountAuthorization.Rds} on exit.
#'
#' @examples
#' \dontrun{
#' b2AuthorizeAccount(url = "https://api.backblaze.com/b2api/v1/b2_authorize_account",
Expand Down Expand Up @@ -70,9 +67,13 @@ b2AuthorizeAccount <- function(url, accountId, authorizationKey) {
)

} else {
# Output as dataframe. Save as Rds file.
# Output as dataframe.
accountAuthorization <-
as.data.frame(jsonlite::fromJSON(httr::content(b2Return, type = "text")))
saveRDS(accountAuthorization, "accountAuthorization.rds")
# Set environment variables to save authorisation details
Sys.setenv(apiUrl = accountAuthorization$apiUrl)
Sys.setenv(accountId = accountAuthorization$accountId)
Sys.setenv(authorizationToken = accountAuthorization$authorizationToken)
Sys.setenv(downloadUrl = accountAuthorization$downloadUrl)
}
}
13 changes: 7 additions & 6 deletions R/b2CreateBucket.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,13 @@
#' @export

b2CreateBucket <- function(bucketName, bucketType) {
# Read Account Authorisation file
accountAuthorization <- NULL
accountAuthorization <- readRDS("accountAuthorization.rds")
# Read Environment variables for authorisation details
apiUrl <- Sys.getenv('apiUrl')
accountId <- Sys.getenv('accountId')
authorizationToken <- Sys.getenv('authorizationToken')

# Function options from input, make a dataframe
accountId <- as.character(accountAuthorization$accountId)
accountId <- as.character(accountId)
accountId <- as.data.frame(accountId, stringsAsFactors = FALSE)
bucketName <- as.data.frame(bucketName, stringsAsFactors = FALSE)
bucketType <- as.data.frame(bucketType, stringsAsFactors = FALSE)
Expand All @@ -51,9 +52,9 @@ b2CreateBucket <- function(bucketName, bucketType) {
b2Return <-
httr::POST(
paste(
accountAuthorization$apiUrl,"/b2api/v1/b2_create_bucket", sep = ""
apiUrl,"/b2api/v1/b2_create_bucket", sep = ""
), body = jsonlite::toJSON(jsonlite::unbox(vars), pretty = TRUE), httr::add_headers(
'Authorization' = as.character(accountAuthorization$authorizationToken)
'Authorization' = as.character(authorizationToken)
)
)

Expand Down
13 changes: 7 additions & 6 deletions R/b2DeleteBucket.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@
#' @export

b2DeleteBucket <- function(bucketId) {
# Read Account Authorisation file
accountAuthorization <- NULL
accountAuthorization <- readRDS("accountAuthorization.rds")
# Read Environment variables for authorisation details
apiUrl <- Sys.getenv('apiUrl')
accountId <- Sys.getenv('accountId')
authorizationToken <- Sys.getenv('authorizationToken')

# Function options from input, make a dataframe
accountId <- as.character(accountAuthorization$accountId)
accountId <- as.character(accountId)
bucketId <- as.data.frame(bucketId, stringsAsFactors = FALSE)

# Bind function option data frames together
Expand All @@ -41,9 +42,9 @@ b2DeleteBucket <- function(bucketId) {
b2Return <-
httr::POST(
paste(
accountAuthorization$apiUrl,"/b2api/v1/b2_delete_bucket", sep = ""
apiUrl,"/b2api/v1/b2_delete_bucket", sep = ""
), body = jsonlite::toJSON(jsonlite::unbox(vars), pretty = TRUE), httr::add_headers(
'Authorization' = as.character(accountAuthorization$authorizationToken)
'Authorization' = as.character(authorizationToken)
)
)

Expand Down
10 changes: 5 additions & 5 deletions R/b2DeleteFileVersion.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
#' @export

b2DeleteFileVersion <- function(fileName, fileId) {
# Read Account Authorisation file
accountAuthorization <- NULL
accountAuthorization <- readRDS("accountAuthorization.rds")
# Read Environment variables for authorisation details
apiUrl <- Sys.getenv('apiUrl')
authorizationToken <- Sys.getenv('authorizationToken')

# Function options from input, make a dataframe
fileName <- as.data.frame(fileName, stringsAsFactors = FALSE)
Expand All @@ -47,9 +47,9 @@ b2DeleteFileVersion <- function(fileName, fileId) {
b2Return <-
httr::POST(
paste(
accountAuthorization$apiUrl,"/b2api/v1/b2_delete_file_version", sep = ""
apiUrl,"/b2api/v1/b2_delete_file_version", sep = ""
), body = jsonlite::toJSON(jsonlite::unbox(vars), pretty = TRUE), httr::add_headers(
'Authorization' = as.character(accountAuthorization$authorizationToken)
'Authorization' = as.character(authorizationToken)
)
)

Expand Down
10 changes: 5 additions & 5 deletions R/b2DownloadFileById.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@
#' @export

b2DownloadFileById <- function(fileId, overwrite = FALSE) {
# Read Account Authorisation file
accountAuthorization <- NULL
accountAuthorization <- readRDS("accountAuthorization.rds")
# Read Environment variables for authorisation details
downloadUrl <- Sys.getenv('downloadUrl')
authorizationToken <- Sys.getenv('authorizationToken')

# Function options from input, make a dataframe
fileId <- as.data.frame(fileId, stringsAsFactors = FALSE)
Expand All @@ -45,10 +45,10 @@ b2DownloadFileById <- function(fileId, overwrite = FALSE) {
b2Return <-
httr::POST(
paste(
accountAuthorization$downloadUrl,"/b2api/v1/b2_download_file_by_id", sep =
downloadUrl,"/b2api/v1/b2_download_file_by_id", sep =
""
), body = jsonlite::toJSON(jsonlite::unbox(fileId), pretty = TRUE), httr::add_headers(
'Authorization' = as.character(accountAuthorization$authorizationToken)
'Authorization' = as.character(authorizationToken)
), httr::write_disk("tmp", overwrite = overwrite)
)

Expand Down
10 changes: 5 additions & 5 deletions R/b2DownloadFileByName.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@

b2DownloadFileByName <-
function(bucketName, fileName, overwrite = FALSE) {
# Read Account Authorisation file
accountAuthorization <- NULL
accountAuthorization <- readRDS("accountAuthorization.rds")
# Read Environment variables for authorisation details
downloadUrl <- Sys.getenv('downloadUrl')
authorizationToken <- Sys.getenv('authorizationToken')

# Function options from input, make a dataframe
fileName <- as.data.frame(fileName, stringsAsFactors = FALSE)
Expand All @@ -52,10 +52,10 @@ b2DownloadFileByName <-
b2Return <-
httr::GET(
url = paste(
accountAuthorization$downloadUrl,"/file/", bucketName, "/", fileName, sep =
downloadUrl,"/file/", bucketName, "/", fileName, sep =
""
), httr::add_headers(
'Authorization' = as.character(accountAuthorization$authorizationToken)
'Authorization' = as.character(authorizationToken)
), httr::write_disk("tmp", overwrite = overwrite)
)

Expand Down
10 changes: 5 additions & 5 deletions R/b2GetFileInfo.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
#' @export

b2GetFileInfo <- function(fileId) {
# Read Account Authorisation file
accountAuthorization <- NULL
accountAuthorization <- readRDS("accountAuthorization.rds")
# Read Environment variables for authorisation details
apiUrl <- Sys.getenv('apiUrl')
authorizationToken <- Sys.getenv('authorizationToken')

# Function options from input, make a dataframe
fileId <- as.data.frame(fileId, stringsAsFactors = FALSE)
Expand All @@ -38,9 +38,9 @@ b2GetFileInfo <- function(fileId) {
b2Return <-
httr::POST(
paste(
accountAuthorization$apiUrl,"/b2api/v1/b2_get_file_info", sep = ""
apiUrl,"/b2api/v1/b2_get_file_info", sep = ""
), body = jsonlite::toJSON(jsonlite::unbox(fileId), pretty = TRUE), httr::add_headers(
'Authorization' = as.character(accountAuthorization$authorizationToken)
'Authorization' = as.character(authorizationToken)
)
)

Expand Down
10 changes: 5 additions & 5 deletions R/b2GetUploadUrl.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
#' @export

b2GetUploadUrl <- function(bucketId) {
# Read Account Authorisation file
accountAuthorization <- NULL
accountAuthorization <- readRDS("accountAuthorization.rds")
# Read Environment variables for authorisation details
apiUrl <- Sys.getenv('apiUrl')
authorizationToken <- Sys.getenv('authorizationToken')

# Function options from input, make a dataframe
bucketId <- as.data.frame(bucketId, stringsAsFactors = FALSE)
Expand All @@ -40,9 +40,9 @@ b2GetUploadUrl <- function(bucketId) {
b2Return <-
httr::POST(
paste(
accountAuthorization$apiUrl,"/b2api/v1/b2_get_upload_url", sep = ""
apiUrl,"/b2api/v1/b2_get_upload_url", sep = ""
), body = jsonlite::toJSON(jsonlite::unbox(bucketId), pretty = TRUE), httr::add_headers(
'Authorization' = as.character(accountAuthorization$authorizationToken)
'Authorization' = as.character(authorizationToken)
)
)

Expand Down
10 changes: 5 additions & 5 deletions R/b2HideFile.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
#' @export

b2HideFile <- function(bucketId, fileName) {
# Read Account Authorisation file
accountAuthorization <- NULL
accountAuthorization <- readRDS("accountAuthorization.rds")
# Read Environment variables for authorisation details
apiUrl <- Sys.getenv('apiUrl')
authorizationToken <- Sys.getenv('authorizationToken')

# Function options from input, make a dataframe
fileName <- as.data.frame(fileName, stringsAsFactors = FALSE)
Expand All @@ -44,9 +44,9 @@ b2HideFile <- function(bucketId, fileName) {
b2Return <-
httr::POST(
paste(
accountAuthorization$apiUrl,"/b2api/v1/b2_hide_file", sep = ""
apiUrl,"/b2api/v1/b2_hide_file", sep = ""
), body = jsonlite::toJSON(jsonlite::unbox(vars), pretty = TRUE), httr::add_headers(
'Authorization' = as.character(accountAuthorization$authorizationToken)
'Authorization' = as.character(authorizationToken)
)
)

Expand Down
11 changes: 6 additions & 5 deletions R/b2ListBuckets.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,19 @@
#' @export

b2ListBuckets <- function() {
# Read Account Authorisation file
accountAuthorization <- NULL
accountAuthorization <- readRDS("accountAuthorization.rds")
# Read Environment variables for authorisation details
apiUrl <- Sys.getenv('apiUrl')
accountId <- Sys.getenv('accountId')
authorizationToken <- Sys.getenv('authorizationToken')

# API call
b2Return <-
httr::GET(
paste(
accountAuthorization$apiUrl,"/b2api/v1/b2_list_buckets?accountId=",accountAuthorization$accountId,sep =
apiUrl,"/b2api/v1/b2_list_buckets?accountId=",accountId,sep =
""
), httr::add_headers(
'Authorization' = as.character(accountAuthorization$authorizationToken)
'Authorization' = as.character(authorizationToken)
)
)

Expand Down
10 changes: 5 additions & 5 deletions R/b2ListFileNames.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@

b2ListFileNames <-
function(bucketId, startFileName = "", maxFileCount = 100) {
# Read Account Authorisation file
accountAuthorization <- NULL
accountAuthorization <- readRDS("accountAuthorization.rds")
# Read Environment variables for authorisation details
apiUrl <- Sys.getenv('apiUrl')
authorizationToken <- Sys.getenv('authorizationToken')

# Function options from input, make a dataframe
bucketId <- as.data.frame(bucketId, stringsAsFactors = FALSE)
Expand All @@ -66,9 +66,9 @@ b2ListFileNames <-
b2Return <-
httr::POST(
paste(
accountAuthorization$apiUrl,"/b2api/v1/b2_list_file_names", sep = ""
apiUrl,"/b2api/v1/b2_list_file_names", sep = ""
), body = jsonlite::toJSON(jsonlite::unbox(vars), pretty = TRUE), httr::add_headers(
'Authorization' = as.character(accountAuthorization$authorizationToken)
'Authorization' = as.character(authorizationToken)
)
)

Expand Down
10 changes: 5 additions & 5 deletions R/b2ListFileVersions.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@

b2ListFileVersions <-
function(bucketId, startFileName = "", startFileId = "", maxFileCount = 100) {
# Read Account Authorisation file
accountAuthorization <- NULL
accountAuthorization <- readRDS("accountAuthorization.rds")
# Read Environment variables for authorisation details
apiUrl <- Sys.getenv('apiUrl')
authorizationToken <- Sys.getenv('authorizationToken')

# Function options from input, make a dataframe
bucketId <- as.data.frame(bucketId, stringsAsFactors = FALSE)
Expand All @@ -76,9 +76,9 @@ b2ListFileVersions <-
b2Return <-
httr::POST(
paste(
accountAuthorization$apiUrl,"/b2api/v1/b2_list_file_versions", sep = ""
apiUrl,"/b2api/v1/b2_list_file_versions", sep = ""
), body = jsonlite::toJSON(jsonlite::unbox(vars), pretty = TRUE), httr::add_headers(
'Authorization' = as.character(accountAuthorization$authorizationToken)
'Authorization' = as.character(authorizationToken)
)
)

Expand Down
13 changes: 7 additions & 6 deletions R/b2UpdateBucket.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,13 @@
#' @export

b2UpdateBucket <- function(bucketId, bucketType) {
# Read Account Authorisation file
accountAuthorization <- NULL
accountAuthorization <- readRDS("accountAuthorization.rds")
# Read Environment variables for authorisation details
apiUrl <- Sys.getenv('apiUrl')
accountId <- Sys.getenv('accountId')
authorizationToken <- Sys.getenv('authorizationToken')

# Function options from input, make a dataframe
accountId <- as.character(accountAuthorization$accountId)
accountId <- as.character(accountId)
accountId <- as.data.frame(accountId, stringsAsFactors = FALSE)
bucketId <- as.data.frame(bucketId, stringsAsFactors = FALSE)
bucketType <- as.data.frame(bucketType, stringsAsFactors = FALSE)
Expand All @@ -51,9 +52,9 @@ b2UpdateBucket <- function(bucketId, bucketType) {
b2Return <-
httr::POST(
paste(
accountAuthorization$apiUrl,"/b2api/v1/b2_update_bucket", sep = ""
apiUrl,"/b2api/v1/b2_update_bucket", sep = ""
), body = jsonlite::toJSON(jsonlite::unbox(vars), pretty = TRUE), httr::add_headers(
'Authorization' = as.character(accountAuthorization$authorizationToken)
'Authorization' = as.character(authorizationToken)
)
)

Expand Down
3 changes: 0 additions & 3 deletions R/b2UploadFile.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@
#' @export

b2UploadFile <- function(authToken, uploadUrl, fileName) {
# Read Account Authorisation file
accountAuthorization <- NULL
accountAuthorization <- readRDS("accountAuthorization.rds")

# Function options from input, make a dataframe
# File Name
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Backblazer
=======
[![CRAN version](http://www.r-pkg.org/badges/version/backblazer)](http://cran.rstudio.com/web/packages/backblazer/index.html)
[![CRAN Downloads](http://cranlogs.r-pkg.org/badges/grand-total/backblazer)](http://cran.rstudio.com/web/packages/backblazer/index.html)
[![Build Status](https://travis-ci.org/phillc73/backblazer.svg?branch=master)](https://travis-ci.org/phillc73/backblazer)

An R package with bindings to the [Backblaze B2 API](https://www.backblaze.com/b2/docs/).

Expand Down Expand Up @@ -80,7 +82,7 @@ Please refer directly to the [Backblaze B2 API documentation](https://www.backbl

This should be largely complete and covers all Backblaze B2 API calls.

Current Version: 0.1
Current Version: 0.2

### Issues

Expand Down
Loading

0 comments on commit 2acd1e8

Please sign in to comment.