#' apptweak_ratings
#'
#' Convert the AppTweak list into a ratings table
#' @param x The Apptweak object
#' @seealso \code{\link{apptweak_api}} which pulls the data from the API and creates the list this function requires
#' @export
apptweak_ratings <- function(x) {
require(tidyverse)
require(lubridate)
os <- ifelse(x$application_id == "de.commerzbanking.mobil",'Android','iOS')
if (os == 'android') {
ratings <- tibble(average_rating = x$ratings$average,
total_ratings = x$ratings$count,
stars = c('1 Star','2 Star','3 Star','4 Star','5 Star'),
count = c(x$ratings$star_count$`1`,x$ratings$star_count$`2`,
x$ratings$star_count$`3`,x$ratings$star_count$`4`,x$ratings$star_count$`5`),
pct_of_ratings = count / total_ratings)
} else {
ratings <- tibble(average_rating = x$ratings$current_version$average,
total_ratings = x$ratings$current_version$count,
stars = c('1 Star','2 Star','3 Star','4 Star','5 Star'),
count = c(x$ratings$current_version$star_count$`1`,x$ratings$current_version$star_count$`2`,
x$ratings$current_version$star_count$`3`,x$ratings$current_version$star_count$`4`,x$ratings$current_version$star_count$`5`),
pct_of_ratings = count / total_ratings)
}
ratings <- ratings %>%
mutate(operating_system = os,
app_id = x$application_id,
app_version = x$store_info$versions[[1]]$version,
version_release_date = ymd(gsub(' CEST','',as.POSIXct(i3$store_info$versions[[1]]$release_date),fixed=TRUE)),
store_language = x$language,
store_country = x$country_code)
return(ratings)
}
#' apptweak_rankings
#'
#' Convert the AppTweak list into a rankings table
#' @param x The Apptweak object
#' @seealso \code{\link{apptweak_api}} which pulls the data from the API and creates the list this function requires
#' @export
apptweak_rankings <- function(x) {
os <- ifelse(x$application_id == "de.commerzbanking.mobil",'Android','iOS')
if (os == 'Android') {
start <- ymd(x$rankings[[1]]$start_date)
end <- ymd(x$rankings[[1]]$end_date)
rankings <- tibble(category = 'Finance',
date = seq.Date(start,end,by=1),
ranking = unlist(x$rankings[[1]]$ranks),
avg_ranking = mean(ranking))
} else {
start <- ymd(x$rankings[[2]]$start_date)
end <- ymd(x$rankings[[2]]$end_date)
rankings <- tibble(category = 'Finance',
date = seq.Date(start,end,by=1),
ranking = unlist(x$rankings[[2]]$ranks),
avg_ranking = mean(ranking))
}
rankings <- rankings %>%
mutate(operating_system = os,
app_id = x$application_id,
app_version = x$store_info$versions[[1]]$version,
version_release_date = ymd(gsub(' CEST','',as.POSIXct(i3$store_info$versions[[1]]$release_date),fixed=TRUE)),
store_language = x$language,
store_country = x$country_code)
return(rankings)
}
#' apptweak_reviews
#'
#' Convert the AppTweak list into a reviews table
#' @param x The Apptweak object
#' @seealso \code{\link{apptweak_api}} which pulls the data from the API and creates the list this function requires
#' @export
apptweak_reviews <- function(x) {
require(purrr)
require(tidyverse)
os <- ifelse(x$application_id == "de.commerzbanking.mobil",'Android','iOS')
if (os == 'Android') {
tbl <- tibble()
roll <- 1:length(x$reviews)
for (i in roll) {
new_tbl <- tibble(review_title = ifelse(is_empty(x$reviews[[i]]$title)==TRUE,NA,x$reviews[[i]]$title),
review_body = ifelse(is_empty(x$reviews[[i]]$body)==TRUE,NA,x$reviews[[i]]$body),
review_rating = x$reviews[[i]]$rating,
review_app_version = x$reviews[[i]]$version,
review_date = as.POSIXct(x$reviews[[i]]$date),
review_author = x$reviews[[i]]$author$name)
tbl <- bind_rows(tbl,new_tbl)
}
} else {
stop('iOS reviews not available')
}
reviews <- tbl %>%
mutate(operating_system = os,
app_id = x$application_id,
store_language = x$language,
store_country = x$country_code) %>%
arrange(desc(review_date))
return(reviews)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.