This repository has been archived by the owner on Sep 19, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.r
63 lines (47 loc) · 1.69 KB
/
index.r
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
library(httr)
library(jsonlite)
getSmSurveys <- function(auth_token, page, per_page) {
if (missing(auth_token)) {
auth_token <- readline('Enter your auth token for SurveyMonkey: ')
}
# defaults
if (missing(page)) {
page <- 1
}
if (missing(per_page)) {
per_page <- 250
}
auth <- paste("bearer", auth_token, sep=" ");
url <- paste('https://api.surveymonkey.net/v3/surveys?page=', page, '&per_page=', per_page, sep='')
survey_list_response <- GET(url=url, add_headers("Content-Type" = "application/json", "Authorization" = auth ))
if (survey_list_response$status_code != 200) {
stop(paste('Bad response from server: ', http_status(survey_list_response)))
}
json <- content(survey_list_response, as = 'text')
survey_list <- fromJSON(json)
invisible(survey_list)
}
getSmResponses <- function(auth_token, survey_id, page, per_page) {
if (missing(auth_token)) {
auth_token <- readline('Enter your auth token for SurveyMonkey: ')
}
if (missing(survey_id)) {
stop('Survey ID is required')
}
# defaults
if (missing(page)) {
page <- 1
}
if (missing(per_page)) {
per_page <- 250
}
auth <- paste("bearer", auth_token, sep=" ");
url <- paste('https://api.surveymonkey.net/v3/surveys/', survey_id, '/responses?page=', page, '&per_page=', per_page, sep='')
survey_responses_response <- GET(url=url, add_headers("Content-Type" = "application/json", "Authorization" = auth ))
if (survey_responses_response$status_code != 200) {
stop(c('Bad response from server: ', http_status(survey_responses_response)))
}
json <- content(survey_responses_response, as = 'text')
survey_responses <- fromJSON(json)
invisible(survey_responses)
}