@@ -24,23 +24,44 @@ join_url <- function(url, endpoint) {
2424# ' @keywords internal
2525do_request <- function (url , params , timeout_seconds = 30 ) {
2626 # don't retry in case of certain status codes
27- res <- httr :: RETRY(" GET" ,
28- url = url ,
29- query = params ,
30- terminate_on = c(400 , 401 , 403 , 405 , 414 , 500 ),
31- http_headers ,
32- httr :: authenticate(" epidata" , get_api_key()),
33- httr :: timeout(timeout_seconds )
34- )
35- if (res $ status_code == 414 ) {
36- res <- httr :: RETRY(" POST" ,
27+ key <- get_api_key()
28+ if (key != " " ) {
29+ res <- httr :: RETRY(" GET" ,
3730 url = url ,
38- body = params ,
39- encode = " form" ,
31+ query = params ,
4032 terminate_on = c(400 , 401 , 403 , 405 , 414 , 500 ),
4133 http_headers ,
42- httr :: authenticate(" epidata" , get_api_key())
34+ httr :: authenticate(" epidata" , get_api_key()),
35+ httr :: timeout(timeout_seconds )
4336 )
37+ } else {
38+ res <- httr :: RETRY(" GET" ,
39+ url = url ,
40+ query = params ,
41+ terminate_on = c(400 , 401 , 403 , 405 , 414 , 500 ),
42+ http_headers ,
43+ httr :: timeout(timeout_seconds )
44+ )
45+ }
46+ if (res $ status_code == 414 ) {
47+ if (key != " " ) {
48+ res <- httr :: RETRY(" POST" ,
49+ url = url ,
50+ body = params ,
51+ encode = " form" ,
52+ terminate_on = c(400 , 401 , 403 , 405 , 414 , 500 ),
53+ http_headers ,
54+ httr :: authenticate(" epidata" , get_api_key())
55+ )
56+ } else {
57+ res <- httr :: RETRY(" POST" ,
58+ url = url ,
59+ body = params ,
60+ encode = " form" ,
61+ terminate_on = c(400 , 401 , 403 , 405 , 414 , 500 ),
62+ http_headers
63+ )
64+ }
4465 }
4566 res
4667}
0 commit comments