Skip to content

Commit

Permalink
version 2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
csgillespie authored and cran-robot committed Aug 28, 2018
1 parent b02b41d commit a0b008a
Show file tree
Hide file tree
Showing 48 changed files with 1,112 additions and 770 deletions.
15 changes: 8 additions & 7 deletions DESCRIPTION
@@ -1,7 +1,7 @@
Package: rtypeform
Type: Package
Title: Interface to 'typeform' Results
Version: 0.4.0
Version: 2.0.0
Authors@R: person(given = "Colin",
family = "Gillespie",
email = "csgillespie@gmail.com",
Expand All @@ -13,12 +13,13 @@ Description: An R interface to the 'typeform' <https://typeform.com> application
Also provides functions for downloading your results.
License: GPL-2 | GPL-3
LazyData: TRUE
Imports: jsonlite, httr, purrr, utils, tibble
Suggests: testthat, curl, dplyr, shiny(>= 1.0.0), miniUI(>= 0.1.1),
rstudioapi(>= 0.5)
RoxygenNote: 6.0.1
Imports: jsonlite, httr, purrr, utils, tibble, dplyr, glue, lubridate,
tidyr
Suggests: testthat
RoxygenNote: 6.1.0
Encoding: UTF-8
NeedsCompilation: no
Packaged: 2018-07-27 07:45:16 UTC; ncsg3
Packaged: 2018-08-28 21:30:54 UTC; ncsg3
Author: Colin Gillespie [aut, cre]
Repository: CRAN
Date/Publication: 2018-07-27 09:20:03 UTC
Date/Publication: 2018-08-28 21:40:02 UTC
55 changes: 32 additions & 23 deletions MD5
@@ -1,24 +1,33 @@
6c05bc6efd75a22e2acf10d7801e0589 *DESCRIPTION
4890d6970d4669d2cc2e268c48504fd1 *NAMESPACE
e5881100ec0a199245da98fedbb85bdb *NEWS.md
26662bb0b2875415117dadd42b25014a *R/check_api_response.R
434b2a2e3ce3aba877ac1c1163eeec0f *R/get_api.R
58e7a89766b77ad6c7322e771f04758a *R/get_results.R
9f1a357b7b7048569562c8a50436da79 *R/get_typeforms.R
aa238f4c557affa2ba8c2251ec5884f7 *R/print.R
8c0c9d8f3f199aa0c6d1e496b3ecb0f5 *R/set_api.R
f45d31ff94075318a593a5af87ed852d *R/typeformAddin.R
667feb3300631f38bcea12c87853ea8b *R/zzz.R
ef8f8bc32a434d19517f96de456f09af *README.md
d42807774e857785d57a16bec0dd1fbf *inst/rstudio/addins.dcf
e3a774e0cea1d583948842acf0156605 *man/get_api.Rd
711ff1f1ba8749bdc27fd2ae46920af4 *man/get_questionnaire.Rd
cf61ab7737d747dec54321dd78932b89 *man/get_typeforms.Rd
4280d21cbfadebd22e1a3d9d34155081 *man/set_api.Rd
1acd2ba6cc70201c00083e65f60ec300 *man/typeformAddin.Rd
81a646d38b2e3b6db553d7f3ffd2e38c *DESCRIPTION
fd0c5ea391a1e3797a2dfe644dc09102 *NAMESPACE
90b88bd7adc9edc9bbdcbe98f3e40177 *NEWS.md
ec4f83eeeeae26a3c802e16ffb00c2b4 *R/delete_form.R
ec8572ee036f7a2cd93a1ab42ed57517 *R/delete_responses.R
e9cc7ce1c8c9e1203aff715b872f9344 *R/get_api.R
30e2114d899a902b828a133c5b69dddc *R/get_form.R
448c1de06a5f5849cc44f5eaa83e6d3d *R/get_forms.R
f5454863a2f9e48f5d9464646004fabb *R/get_me.R
a82692f1b62a313e8990ca6fe0895321 *R/get_responses.R
d7a6d109f7ae20e34c68a0d48d365864 *R/httr_responses.R
ab4d23e720b02aaa19acf97462413e5f *R/rest_argument_formatting.R
b87db923050475b3d983984b85c22979 *R/teams.R
8f444fcabda656089a58bae128a6950c *R/themes.R
8e8866720070cc63a9d3d7a50a848b8b *R/workspaces.R
327d3794c779ad639c6c433427d4aaf7 *R/zzz.R
392e294251744f4b708f1f110f50929f *README.md
0cb161b78d9f53744e8d36486b68f081 *man/create_theme.Rd
c85b5c659797d93c9500d50f929579cd *man/delete_form.Rd
1170d23090953608163aae72731d6de9 *man/delete_responses.Rd
e8c3146bdfd477782c289737b9998fa7 *man/get_api.Rd
6b381b23da1a19526413e3337c479795 *man/get_forms.Rd
81715703a1b68bcac259da599f447dca *man/get_me.Rd
c5df267cd29636263e3a3dee1a4f48bb *man/get_responses.Rd
68d55f545cedd37ece882b040bfc4dce *man/get_teams.Rd
52362534a13d5fec3bce790fe966f967 *man/get_workspaces.Rd
fdd4d6b2f737f7cb02bf00b0bb2af68b *tests/testthat.R
f38f7e55a5a5ad8cedd039c4c045e5c9 *tests/testthat/test_api_response.R
4b27552aaabab51ba21770162a4858db *tests/testthat/test_get_all_typeforms.R
779461d4b0531461745e4b3184d7a9f7 *tests/testthat/test_get_linux_time.R
790d1379d73c030d96aa8c7f84a492be *tests/testthat/test_get_results.R
d3cc58d6b3d2548df484647660878079 *tests/testthat/test_print.R
e9d07d124d972d20f7d2a6b7d119e206 *tests/testthat/form.rds
1b514e8eac315a08da3094c47a594048 *tests/testthat/test_api_response.R
5c6649ba2648e22ecf58c91910e0f515 *tests/testthat/test_get_forms.R
20a712abc32c32c14e6c4d8853a985bc *tests/testthat/test_get_responses.R
8fd9aab8902e5a44a860c8416e4e9a0b *tests/testthat/test_teams.R
b59ff56421e4b521cf6628584174ca16 *tests/testthat/test_workspaces.R
47 changes: 37 additions & 10 deletions NAMESPACE
@@ -1,24 +1,51 @@
# Generated by roxygen2: do not edit by hand

S3method(print,rtypeform_all)
S3method(print,rtypeform_results)
export(get_all_typeforms)
export(create_theme)
export(create_workspace)
export(delete_form)
export(delete_responses)
export(delete_theme)
export(delete_workspace)
export(get_api)
export(get_questionnaire)
export(get_results)
export(get_typeforms)
export(set_api)
export(get_forms)
export(get_me)
export(get_number_of_forms)
export(get_number_of_seats)
export(get_number_of_workspace)
export(get_responses)
export(get_teams)
export(get_theme)
export(get_themes)
export(get_workspace)
export(get_workspaces)
export(update_theme)
export(update_workspace)
import(dplyr)
import(purrr)
importFrom(dplyr,matches)
importFrom(glue,glue)
importFrom(glue,glue_collapse)
importFrom(httr,DELETE)
importFrom(httr,GET)
importFrom(httr,POST)
importFrom(httr,PUT)
importFrom(httr,add_headers)
importFrom(httr,content)
importFrom(httr,content_type_json)
importFrom(httr,status_code)
importFrom(httr,user_agent)
importFrom(httr,verbose)
importFrom(jsonlite,fromJSON)
importFrom(jsonlite,toJSON)
importFrom(jsonlite,unbox)
importFrom(lubridate,is.POSIXct)
importFrom(lubridate,tz)
importFrom(lubridate,with_tz)
importFrom(lubridate,ymd_hms)
importFrom(purrr,"%>%")
importFrom(purrr,flatten_df)
importFrom(purrr,keep)
importFrom(purrr,map)
importFrom(purrr,map_df)
importFrom(tibble,as_tibble)
importFrom(tibble,tibble)
importFrom(tidyr,unnest)
importFrom(utils,read.csv)
importFrom(utils,type.convert)
4 changes: 4 additions & 0 deletions NEWS.md
@@ -1,3 +1,7 @@
# Version 2.0.0
* Move to the new typeform API - breaking changes
* Jumped to Version 2 to match the V2 API.

# Version 0.4.0
* Bug fix: Empty data frames now returned
* Intended to the final version using the V1 data API. Added a start-up message.
Expand Down
18 changes: 0 additions & 18 deletions R/check_api_response.R

This file was deleted.

10 changes: 10 additions & 0 deletions R/delete_form.R
@@ -0,0 +1,10 @@
#' Deletes a typeform
#'
#' Delete the specified typeform.
#' @inheritParams get_api
#' @inheritParams get_responses
#' @export
delete_form = function(form_id, api = NULL) {
url = glue("https://api.typeform.com/forms/{form_id}")
delete_response(api, url)
}
19 changes: 19 additions & 0 deletions R/delete_responses.R
@@ -0,0 +1,19 @@
#' Delete Responses
#'
#' Delete entries in a type form- use with care!
#' @inheritParams get_api
#' @inheritParams get_responses
#' @param included_tokens A vector of tokens to delete. Maximum 1000. Token ids
#' can be extracted from the meta data frame via \code{get_form}.
#' @return If successful, the function will return (invisibily) \code{TRUE}
#' @importFrom glue glue_collapse
#' @export
delete_responses = function(form_id, api = NULL, included_tokens = NULL) {
included_tokens = glue_collapse(included_tokens, sep = ",")
included_tokens = create_argument(included_tokens)

url = glue("https://api.typeform.com/forms/{form_id}/responses?\\
{included_tokens}")
delete_response(api = api, url)
}

19 changes: 11 additions & 8 deletions R/get_api.R
@@ -1,13 +1,16 @@
#' Retrieve API key from Renviron
#'
#' If the entry \code{typeform_api} exists in your
#' If the entry \code{typeform_api2} exists in your
#' \code{.Renviron} return that value. Otherwise, raise an error.
#' @inheritParams get_all_typeforms
#' @param api Default \code{NULL}. Your private api key. If \code{api} is \code{NULL},
#' the environment variable \code{Sys.getenv("typeform_api2")} is used.
#' @details In version 1 of the typeform API, rtypeform looked for the key \code{typeform_api},
#' @export
get_api = function(api=NULL){
if(is.null(api))
api = Sys.getenv("typeform_api")
if(nchar(api) == 0)
stop("Invalid api key.")
api
get_api = function(api = NULL){
if(is.null(api)) api = Sys.getenv("typeform_api2")

if(nchar(api) != 0) return(api)
if(nchar(Sys.getenv("typeform_api")) > 0)
stop("Old key")
stop("Invalid api key.", call. = FALSE)
}
7 changes: 7 additions & 0 deletions R/get_form.R
@@ -0,0 +1,7 @@
get_form = function(form_id, api = NULL) {

url = glue::glue("https://api.typeform.com/forms/{form_id}")
content = get_response(api = api, url)
content
}

73 changes: 73 additions & 0 deletions R/get_forms.R
@@ -0,0 +1,73 @@
#' @importFrom glue glue
#' @rdname get_forms
#' @export
get_number_of_forms = function(api = NULL,
search = "",
workspace_id = NULL) {
page_size = 1
page_size = create_argument(page_size)
search = create_argument(search)
workspace_id = create_argument(workspace_id)
url = glue("https://api.typeform.com/forms?{page_size}&{search}&{workspace_id}")
content = get_response(api = api, url)
content$total_items
}

globalVariables(c("settings", "self", "theme", "href", "href1", "display", "last_updated_at"))
#' Fetch all available typeforms
#'
#' This function returns a two column data frame containing the typeform names and
#' their associated ids.
#' @importFrom jsonlite fromJSON
#' @param api Default \code{NULL}. Your private api key. If \code{api} is \code{NULL},
#' the environment variable \code{Sys.getenv("typeform_api")} is used.
#' @param search Returns items that contain the specified string.
#' @param page The page of results to retrieve. Default 1 is the first page of results.
#' @param page_size Number of results to retrieve per page. Default is 10. Maximum is 200.
#' @param workspace_id Retrieve typeforms for the specified workspace.
#' @return A list containing content and the response.
#' @import dplyr purrr
#' @importFrom tidyr unnest
#' @export
get_forms = function(api = NULL,
page = 1,
page_size = 10,
search = "",
workspace_id = NULL) {
if (page_size > 200) {
warning("Maximum size is 200. Setting page size to 200")
page_size = 200
}

page = create_argument(page)
page_size = create_argument(page_size)
search = create_argument(search)
workspace_id = create_argument(workspace_id)

url = glue::glue("https://api.typeform.com/forms?{page}&{page_size}&{search}&{workspace_id}")
content = get_response(api = api, url)

items = content$items
if (length(items) == 0) {
items = tibble(form_id = "", title = "", last_updated = "", is_public = "",
is_trial = "", questions = "", theme = "", questionnaire_url = "")[0,]
return(items)
}
items = items %>%
select(-settings, -self, -theme, -"_links") %>%
as_tibble() %>%
bind_cols(items$settings,
items$self,
items$theme,
items$`_links`) %>%
rename(questions = href,
theme = href1,
questionnaire_url = display,
last_updated = last_updated_at,
form_id = id) %>%
mutate(last_updated = lubridate::ymd_hms(items$last_updated))
attr(items, "total_items") = content$total_items
attr(items, "page_count") = content$page_count
items
}

10 changes: 10 additions & 0 deletions R/get_me.R
@@ -0,0 +1,10 @@
#' Retrieve your own account information.
#'
#' Returns alias, email and language.
#' @inheritParams get_api
#' @export
get_me = function(api = NULL) {
url = "https://api.typeform.com/me"
content = get_response(api = api, url)
unlist(content)
}

0 comments on commit a0b008a

Please sign in to comment.