Skip to content

Commit

Permalink
conform code to style guide
Browse files Browse the repository at this point in the history
  • Loading branch information
leeper committed May 28, 2016
1 parent 4a5598f commit ff96406
Show file tree
Hide file tree
Showing 47 changed files with 185 additions and 140 deletions.
3 changes: 2 additions & 1 deletion R/account.r
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
account <-
function(account = 'me', ...){
if(!"token" %in% names(list(...)) && account == 'me')
if (!"token" %in% names(list(...)) && account == 'me') {
stop("This operation can only be performed for account 'me' using an OAuth token.")
}
out <- imgurGET(paste0('account/', account), ...)
structure(out, class = 'imgur_account')
}
3 changes: 2 additions & 1 deletion R/account_album_count.r
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
account_album_count <-
function(account = 'me',
...){
if(!"token" %in% names(list(...)) && account == 'me')
if (!"token" %in% names(list(...)) && account == 'me') {
stop("This operation can only be performed for account 'me' using an OAuth token.")
}
out <- imgurGET(paste0('account/', account, '/albums/count'), ...)
structure(out, class = 'imgur_basic')
}
6 changes: 3 additions & 3 deletions R/account_albums.r
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ account_albums <-
function(account = 'me',
ids = TRUE,
...){
if(!"token" %in% names(list(...)) && account == 'me')
if (!"token" %in% names(list(...)) && account == 'me') {
stop("This operation can only be performed for account 'me' using an OAuth token.")
if(ids) {
}
if (ids) {
out <- imgurGET(paste0('account/', account, '/albums/ids'), ...)
structure(out, class = 'imgur_basic')
} else {
out <- imgurGET(paste0('account/', account, '/albums/'), ...)
lapply(out, `class<-`, 'imgur_album')
}

}
3 changes: 2 additions & 1 deletion R/account_comment_count.r
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
account_comment_count <-
function(account = 'me',
...){
if(!"token" %in% names(list(...)) && account == 'me')
if (!"token" %in% names(list(...)) && account == 'me') {
stop("This operation can only be performed for account 'me' using an OAuth token.")
}
out <- imgurGET(paste0('account/', account, '/comments/count'), ...)
structure(out, class = 'imgur_basic')
}
5 changes: 3 additions & 2 deletions R/account_comments.r
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ account_comments <-
function(account = 'me',
ids = FALSE,
...){
if(!"token" %in% names(list(...)) && account == 'me')
if (!"token" %in% names(list(...)) && account == 'me') {
stop("This operation can only be performed for account 'me' using an OAuth token.")
if(ids) {
}
if (ids) {
out <- imgurGET(paste0('account/', account, '/comments/ids'), ...)
structure(out, class = 'imgur_basic')
} else {
Expand Down
8 changes: 5 additions & 3 deletions R/account_favorites.r
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ account_favorites <-
function(account = 'me',
gallery = FALSE,
...){
if(!"token" %in% names(list(...)) && account == 'me')
if (!"token" %in% names(list(...)) && account == 'me') {
stop("This operation can only be performed for account 'me' using an OAuth token.")
}
out <- imgurGET(paste0('account/', account,
ifelse(gallery, '/gallery_favorites', '/favorites')),
...)
if(gallery)
if (gallery) {
structure(out, class = 'imgur_gallery_album') # check this
else
} else {
structure(out, class = 'imgur_image') # check this
}
}
3 changes: 2 additions & 1 deletion R/account_gallery.r
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
account_gallery <-
function(account = 'me', ...){
if(!"token" %in% names(list(...)) && account == 'me')
if (!"token" %in% names(list(...)) && account == 'me') {
stop("This operation can only be performed for account 'me' using an OAuth token.")
}
out <- imgurGET(paste0('account/', account, '/gallery_profile'), ...)
structure(out, class = 'imgur_gallery_profile')
}
3 changes: 2 additions & 1 deletion R/account_image_count.r
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
account_image_count <-
function(account = 'me', ...){
if(!"token" %in% names(list(...)) && account == 'me')
if (!"token" %in% names(list(...)) && account == 'me') {
stop("This operation can only be performed for account 'me' using an OAuth token.")
}
out <- imgurGET(paste0('account/', account, '/images/count'), ...)
structure(out, class = 'imgur_basic')
}
5 changes: 3 additions & 2 deletions R/account_images.r
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ function(account = 'me',
page = NULL,
ids = TRUE,
...){
if(!"token" %in% names(list(...)) && account == 'me')
if (!"token" %in% names(list(...)) && account == 'me') {
stop("This operation can only be performed for account 'me' using an OAuth token.")
if(ids) {
}
if (ids) {
out <- imgurGET(paste0('account/', account, '/images/ids'), ...)
structure(out, class = 'imgur_basic')
} else {
Expand Down
19 changes: 12 additions & 7 deletions R/account_settings.r
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,27 @@ function(bio = NULL,
album_privacy = NULL,
accepted_gallery_terms = NULL,
...){
if(!"token" %in% names(list(...)))
if (!"token" %in% names(list(...))) {
stop("This operation can only be performed using an OAuth token.")
}
a <- list()
if(!is.null(bio))
if (!is.null(bio)) {
a$bio <- bio
if(!is.null(public_images))
}
if (!is.null(public_images)) {
a$public_images <- public_images
if(!is.null(messaging_enabled))
}
if (!is.null(messaging_enabled)) {
a$messaging_enabled <- messaging_enabled
if(!is.null(album_privacy)) {
}
if (!is.null(album_privacy)) {
stopifnot(album_privacy %in% c('public', 'hidden', 'secret'))
a$album_privacy <- album_privacy
}
if(!is.null(accepted_gallery_terms))
if (!is.null(accepted_gallery_terms)) {
a$accepted_gallery_terms <- accepted_gallery_terms
if(any(!sapply(a, is.null))) {
}
if (any(!sapply(a, is.null))) {
out <- imgurPOST(paste0('account/me/settings'), body = a, ...)
structure(out, class = 'imgur_basic')
} else {
Expand Down
3 changes: 2 additions & 1 deletion R/account_verified.r
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
account_verified <-
function(...){
if(!"token" %in% names(list(...)))
if (!"token" %in% names(list(...))) {
stop("This operation can only be performed using an OAuth token.")
}
out <- imgurGET(paste0('account/me/verifyemail'), ...)
structure(out, class = 'imgur_basic')
}
12 changes: 7 additions & 5 deletions R/add_album_images.r
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@ add_album_images <-
function(album,
id,
...){
if(!"token" %in% names(list(...)))
if (!"token" %in% names(list(...))) {
stop("This operation can only be performed using an OAuth token.")
if(inherits(album, 'imgur_album'))
}
if (inherits(album, 'imgur_album')) {
album <- album$id
if(inherits(id, 'imgur_image')) {
}
if (inherits(id, 'imgur_image')) {
id <- id$id
} else if(is.list(id)) {
} else if (is.list(id)) {
id <- sapply(id, `$`, 'id')
}
b <- list(ids = paste(id, collapse = ','))
out <- imgurPOST(paste0('album/', album, '/add'), body = b, ...)
structure(out, class = 'imgur_basic')
}
}
12 changes: 7 additions & 5 deletions R/add_gallery_images.r
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@ function(album = NULL,
...){
b <- list(title = title,
terms = 1)
if(!is.null(image)) {
if(is.null(title))
if (!is.null(image)) {
if (is.null(title)) {
b$title <- get_image(id, ...)$title
}
out <- imgurPOST(paste0('gallery/image/', image), body = b, ...)
structure(out, class = 'imgur_gallery_image')
}
if(!is.null(album)){
if(is.null(title))
if (!is.null(album)) {
if (is.null(title)) {
b$title <- get_album(album, ...)$title
}
out <- imgurPOST(paste0('gallery/album/', album), body = b, ...)
structure(out, class = 'imgur_gallery_album')
}
}
}
3 changes: 2 additions & 1 deletion R/block_sender.r
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
block_sender <-
function(username,
...){
if(!"token" %in% names(list(...)))
if (!"token" %in% names(list(...))) {
stop("This operation can only be performed using an OAuth token.")
}
out <- imgurPOST(paste0('conversations/block/', username), ...)
structure(out, class = 'imgur_basic')
}
21 changes: 12 additions & 9 deletions R/create_album.r
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,30 @@ function(id = NULL,
cover_id = NULL,
...){
b <- list()
if(!is.null(title))
if (!is.null(title)) {
b$title <- title
if(!is.null(description))
}
if (!is.null(description)) {
b$description <- description
if(!is.null(privacy)) {
}
if (!is.null(privacy)) {
stopifnot(privacy %in% c('public', 'hidden', 'secret'))
b$privacy <- privacy
}
if(!is.null(layout)) {
if (!is.null(layout)) {
stopifnot(layout %in% c('blog', 'grid', 'horizontal', 'vertical'))
b$layout <- layout
}
if(!is.null(cover_id)){
if(inherits(cover_id, 'imgur_image'))
if (!is.null(cover_id)) {
if (inherits(cover_id, 'imgur_image')) {
cover_id <- cover_id$id
}
b$cover_id <- cover_id
}
if(!is.null(id)){
if(inherits(id, 'imgur_image')) {
if (!is.null(id)) {
if (inherits(id, 'imgur_image')) {
id <- id$id
} else if(is.list(id)) {
} else if (is.list(id)) {
id <- sapply(id, `$`, 'id')
}
b$ids <- paste(id, collapse = ',')
Expand Down
9 changes: 6 additions & 3 deletions R/create_comment.r
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@ function(id,
comment,
parent = NULL,
...){
if(!"token" %in% names(list(...)))
if (!"token" %in% names(list(...))) {
stop("This operation can only be performed using an OAuth token.")
if(inherits(id, 'imgur_image'))
}
if (inherits(id, 'imgur_image')) {
id <- id$id
}
b <- list(image_id = id,
comment = comment)
if(!is.null(parent))
if (!is.null(parent)) {
b$parent_comment <- parent
}
out <- imgurPOST('comment/',
body = b,
...)
Expand Down
5 changes: 3 additions & 2 deletions R/delete_album.r
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
delete_album <-
function(album, ...){
if(inherits(album, 'imgur_album'))
if (inherits(album, 'imgur_album')) {
album <- album$id
}
out <- imgurDELETE(paste0('album/', album), ...)
structure(out, class = 'imgur_basic')
}
}
3 changes: 2 additions & 1 deletion R/delete_comment.r
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
delete_comment <-
function(comment, ...){
if(!"token" %in% names(list(...)))
if (!"token" %in% names(list(...))) {
stop("This operation can only be performed using an OAuth token.")
}
out <- imgurDELETE(paste0('comment/', comment), ...)
structure(out, class = 'imgur_basic')
}
3 changes: 2 additions & 1 deletion R/delete_image.r
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
delete_image <-
function(id, ...){
if(inherits(id, 'imgur_image'))
if (inherits(id, 'imgur_image')) {
id <- id$id
}
out <- imgurDELETE(paste0('image/', id), ...)
structure(out, class = 'imgur_basic')
}
5 changes: 3 additions & 2 deletions R/favorite_album.r
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
favorite_album <-
function(album, ...){
if(inherits(album, 'imgur_album'))
if (inherits(album, 'imgur_album')) {
album <- album$id
}
out <- imgurPOST(paste0('album/', album, 'favorite'), ...)
structure(out, class = 'imgur_basic')
}
}
5 changes: 3 additions & 2 deletions R/favorite_image.r
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
favorite_image <-
function(id, ...){
if(inherits(id, 'imgur_image'))
if (inherits(id, 'imgur_image')) {
id <- id$id
}
out <- imgurPOST(paste0('image/', id, '/favorite'), ...)
structure(out, class = 'imgur_basic')
}
}
3 changes: 2 additions & 1 deletion R/get_album.r
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
get_album <-
function(album, ...){
if(inherits(album, 'imgur_album') || inherits(album, 'imgur_gallery_album'))
if (inherits(album, 'imgur_album') || inherits(album, 'imgur_gallery_album')) {
album <- album$id
}
out <- imgurGET(paste0('album/', album), ...)
out[['images']] <- lapply(out[['images']], `class<-`, 'imgur_image')
structure(out, class = 'imgur_album')
Expand Down
3 changes: 2 additions & 1 deletion R/get_album_images.r
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
get_album_images <-
function(album, ...){
if(inherits(album, 'imgur_album') || inherits(album, 'imgur_gallery_album'))
if (inherits(album, 'imgur_album') || inherits(album, 'imgur_gallery_album')) {
album <- album$id
}
out <- imgurGET(paste0('album/', album, '/images'), ...)
lapply(out, structure, class = 'imgur_image')
}
5 changes: 3 additions & 2 deletions R/get_comment.r
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ get_comment <-
function(comment,
replies = FALSE,
...){
if(replies)
if (replies) {
out <- imgurGET(paste0('comment/', comment, '/replies'), ...)
else
} else {
out <- imgurGET(paste0('comment/', comment), ...)
}
structure(out, class = 'imgur_comment')
}
2 changes: 1 addition & 1 deletion R/get_conversations.r
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
get_conversations <-
function(id = NULL, ...){
if(!is.null(id)) {
if (!is.null(id)) {
out <- imgurGET(paste0('conversations/', id), ...)
} else {
out <- imgurGET('conversations/', ...)
Expand Down
3 changes: 2 additions & 1 deletion R/get_gallery.r
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ function(section = 'hot',
showViral = TRUE,
...){
stopifnot(section %in% c('hot', 'top', 'user'))
if(!is.null(window))
if (!is.null(window)) {
stopifnot(window %in% c('day', 'week', 'month', 'year', 'all'))
}
stopifnot(sort %in% c('viral', 'time'))
stopifnot(is.numeric(as.numeric(page)))
stopifnot(is.logical(showViral))
Expand Down
Loading

0 comments on commit ff96406

Please sign in to comment.