Skip to content

Commit 90bd1f3

Browse files
committed
update samples
1 parent 0357a1b commit 90bd1f3

File tree

8 files changed

+41
-24
lines changed

8 files changed

+41
-24
lines changed

samples/client/echo_api/r/R/api_client.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ ApiClient <- R6::R6Class(
270270
api_response <- ApiResponse$new()
271271
api_response$status_code <- httr::status_code(httr_response)
272272
api_response$status_code_desc <- httr::http_status(httr_response)$reason
273-
api_response$response <- httr::content(httr_response, "text", encoding = "UTF-8")
273+
api_response$response <- httr::content(httr_response, "raw")
274274
api_response$headers <- httr::headers(httr_response)
275275

276276
api_response

samples/client/echo_api/r/R/api_response.R

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,23 @@ ApiResponse <- R6::R6Class(
4545
self$status_code <- status_code
4646
self$status_code_desc <- status_code_desc
4747
self$headers <- headers
48+
},
49+
50+
#' Return the response as text
51+
#'
52+
#' @description
53+
#' The response is stored as a raw vector. Use this to access the response after
54+
#' converting it to text. If the response is not coercible to text NA is returned.
55+
#'
56+
#' @param from_encoding The encoding of the raw response.
57+
#' @param to_encoding The target encoding of the return value.
58+
#' @export
59+
response_as_text = function(from_encoding = NULL, to_encoding = "UTF-8") {
60+
text_response <- iconv(readBin(self$response, character()), from = from_encoding, to = to_encoding)
61+
if (is.na(text_response)) {
62+
warning("The response is binary and will not be converted to text.")
63+
}
64+
return(text_response)
4865
}
4966
)
5067
)

samples/client/echo_api/r/R/auth_api.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ AuthApi <- R6::R6Class(
176176
}
177177

178178
deserialized_resp_obj <- tryCatch(
179-
self$api_client$deserialize(local_var_resp$response, "character", loadNamespace("openapi")),
179+
self$api_client$deserialize(local_var_resp$response_as_text(), "character", loadNamespace("openapi")),
180180
error = function(e) {
181181
stop("Failed to deserialize response")
182182
}
@@ -266,7 +266,7 @@ AuthApi <- R6::R6Class(
266266
}
267267

268268
deserialized_resp_obj <- tryCatch(
269-
self$api_client$deserialize(local_var_resp$response, "character", loadNamespace("openapi")),
269+
self$api_client$deserialize(local_var_resp$response_as_text(), "character", loadNamespace("openapi")),
270270
error = function(e) {
271271
stop("Failed to deserialize response")
272272
}

samples/client/echo_api/r/R/body_api.R

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ BodyApi <- R6::R6Class(
379379
}
380380

381381
deserialized_resp_obj <- tryCatch(
382-
self$api_client$deserialize(local_var_resp$response, "data.frame", loadNamespace("openapi")),
382+
self$api_client$deserialize(local_var_resp$response_as_text(), "data.frame", loadNamespace("openapi")),
383383
error = function(e) {
384384
stop("Failed to deserialize response")
385385
}
@@ -474,7 +474,7 @@ BodyApi <- R6::R6Class(
474474
}
475475

476476
deserialized_resp_obj <- tryCatch(
477-
self$api_client$deserialize(local_var_resp$response, "character", loadNamespace("openapi")),
477+
self$api_client$deserialize(local_var_resp$response_as_text(), "character", loadNamespace("openapi")),
478478
error = function(e) {
479479
stop("Failed to deserialize response")
480480
}
@@ -568,7 +568,7 @@ BodyApi <- R6::R6Class(
568568
}
569569

570570
deserialized_resp_obj <- tryCatch(
571-
self$api_client$deserialize(local_var_resp$response, "character", loadNamespace("openapi")),
571+
self$api_client$deserialize(local_var_resp$response_as_text(), "character", loadNamespace("openapi")),
572572
error = function(e) {
573573
stop("Failed to deserialize response")
574574
}
@@ -658,7 +658,7 @@ BodyApi <- R6::R6Class(
658658
}
659659

660660
deserialized_resp_obj <- tryCatch(
661-
self$api_client$deserialize(local_var_resp$response, "character", loadNamespace("openapi")),
661+
self$api_client$deserialize(local_var_resp$response_as_text(), "character", loadNamespace("openapi")),
662662
error = function(e) {
663663
stop("Failed to deserialize response")
664664
}
@@ -753,7 +753,7 @@ BodyApi <- R6::R6Class(
753753
}
754754

755755
deserialized_resp_obj <- tryCatch(
756-
self$api_client$deserialize(local_var_resp$response, "Pet", loadNamespace("openapi")),
756+
self$api_client$deserialize(local_var_resp$response_as_text(), "Pet", loadNamespace("openapi")),
757757
error = function(e) {
758758
stop("Failed to deserialize response")
759759
}
@@ -848,7 +848,7 @@ BodyApi <- R6::R6Class(
848848
}
849849

850850
deserialized_resp_obj <- tryCatch(
851-
self$api_client$deserialize(local_var_resp$response, "character", loadNamespace("openapi")),
851+
self$api_client$deserialize(local_var_resp$response_as_text(), "character", loadNamespace("openapi")),
852852
error = function(e) {
853853
stop("Failed to deserialize response")
854854
}
@@ -943,7 +943,7 @@ BodyApi <- R6::R6Class(
943943
}
944944

945945
deserialized_resp_obj <- tryCatch(
946-
self$api_client$deserialize(local_var_resp$response, "Pet", loadNamespace("openapi")),
946+
self$api_client$deserialize(local_var_resp$response_as_text(), "Pet", loadNamespace("openapi")),
947947
error = function(e) {
948948
stop("Failed to deserialize response")
949949
}
@@ -1038,7 +1038,7 @@ BodyApi <- R6::R6Class(
10381038
}
10391039

10401040
deserialized_resp_obj <- tryCatch(
1041-
self$api_client$deserialize(local_var_resp$response, "character", loadNamespace("openapi")),
1041+
self$api_client$deserialize(local_var_resp$response_as_text(), "character", loadNamespace("openapi")),
10421042
error = function(e) {
10431043
stop("Failed to deserialize response")
10441044
}
@@ -1133,7 +1133,7 @@ BodyApi <- R6::R6Class(
11331133
}
11341134

11351135
deserialized_resp_obj <- tryCatch(
1136-
self$api_client$deserialize(local_var_resp$response, "character", loadNamespace("openapi")),
1136+
self$api_client$deserialize(local_var_resp$response_as_text(), "character", loadNamespace("openapi")),
11371137
error = function(e) {
11381138
stop("Failed to deserialize response")
11391139
}

samples/client/echo_api/r/R/form_api.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ FormApi <- R6::R6Class(
195195
}
196196

197197
deserialized_resp_obj <- tryCatch(
198-
self$api_client$deserialize(local_var_resp$response, "character", loadNamespace("openapi")),
198+
self$api_client$deserialize(local_var_resp$response_as_text(), "character", loadNamespace("openapi")),
199199
error = function(e) {
200200
stop("Failed to deserialize response")
201201
}
@@ -305,7 +305,7 @@ FormApi <- R6::R6Class(
305305
}
306306

307307
deserialized_resp_obj <- tryCatch(
308-
self$api_client$deserialize(local_var_resp$response, "character", loadNamespace("openapi")),
308+
self$api_client$deserialize(local_var_resp$response_as_text(), "character", loadNamespace("openapi")),
309309
error = function(e) {
310310
stop("Failed to deserialize response")
311311
}

samples/client/echo_api/r/R/header_api.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ HeaderApi <- R6::R6Class(
172172
}
173173

174174
deserialized_resp_obj <- tryCatch(
175-
self$api_client$deserialize(local_var_resp$response, "character", loadNamespace("openapi")),
175+
self$api_client$deserialize(local_var_resp$response_as_text(), "character", loadNamespace("openapi")),
176176
error = function(e) {
177177
stop("Failed to deserialize response")
178178
}

samples/client/echo_api/r/R/path_api.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ PathApi <- R6::R6Class(
189189
}
190190

191191
deserialized_resp_obj <- tryCatch(
192-
self$api_client$deserialize(local_var_resp$response, "character", loadNamespace("openapi")),
192+
self$api_client$deserialize(local_var_resp$response_as_text(), "character", loadNamespace("openapi")),
193193
error = function(e) {
194194
stop("Failed to deserialize response")
195195
}

samples/client/echo_api/r/R/query_api.R

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ QueryApi <- R6::R6Class(
372372
}
373373

374374
deserialized_resp_obj <- tryCatch(
375-
self$api_client$deserialize(local_var_resp$response, "character", loadNamespace("openapi")),
375+
self$api_client$deserialize(local_var_resp$response_as_text(), "character", loadNamespace("openapi")),
376376
error = function(e) {
377377
stop("Failed to deserialize response")
378378
}
@@ -473,7 +473,7 @@ QueryApi <- R6::R6Class(
473473
}
474474

475475
deserialized_resp_obj <- tryCatch(
476-
self$api_client$deserialize(local_var_resp$response, "character", loadNamespace("openapi")),
476+
self$api_client$deserialize(local_var_resp$response_as_text(), "character", loadNamespace("openapi")),
477477
error = function(e) {
478478
stop("Failed to deserialize response")
479479
}
@@ -574,7 +574,7 @@ QueryApi <- R6::R6Class(
574574
}
575575

576576
deserialized_resp_obj <- tryCatch(
577-
self$api_client$deserialize(local_var_resp$response, "character", loadNamespace("openapi")),
577+
self$api_client$deserialize(local_var_resp$response_as_text(), "character", loadNamespace("openapi")),
578578
error = function(e) {
579579
stop("Failed to deserialize response")
580580
}
@@ -665,7 +665,7 @@ QueryApi <- R6::R6Class(
665665
}
666666

667667
deserialized_resp_obj <- tryCatch(
668-
self$api_client$deserialize(local_var_resp$response, "character", loadNamespace("openapi")),
668+
self$api_client$deserialize(local_var_resp$response_as_text(), "character", loadNamespace("openapi")),
669669
error = function(e) {
670670
stop("Failed to deserialize response")
671671
}
@@ -756,7 +756,7 @@ QueryApi <- R6::R6Class(
756756
}
757757

758758
deserialized_resp_obj <- tryCatch(
759-
self$api_client$deserialize(local_var_resp$response, "character", loadNamespace("openapi")),
759+
self$api_client$deserialize(local_var_resp$response_as_text(), "character", loadNamespace("openapi")),
760760
error = function(e) {
761761
stop("Failed to deserialize response")
762762
}
@@ -847,7 +847,7 @@ QueryApi <- R6::R6Class(
847847
}
848848

849849
deserialized_resp_obj <- tryCatch(
850-
self$api_client$deserialize(local_var_resp$response, "character", loadNamespace("openapi")),
850+
self$api_client$deserialize(local_var_resp$response_as_text(), "character", loadNamespace("openapi")),
851851
error = function(e) {
852852
stop("Failed to deserialize response")
853853
}
@@ -938,7 +938,7 @@ QueryApi <- R6::R6Class(
938938
}
939939

940940
deserialized_resp_obj <- tryCatch(
941-
self$api_client$deserialize(local_var_resp$response, "character", loadNamespace("openapi")),
941+
self$api_client$deserialize(local_var_resp$response_as_text(), "character", loadNamespace("openapi")),
942942
error = function(e) {
943943
stop("Failed to deserialize response")
944944
}
@@ -1029,7 +1029,7 @@ QueryApi <- R6::R6Class(
10291029
}
10301030

10311031
deserialized_resp_obj <- tryCatch(
1032-
self$api_client$deserialize(local_var_resp$response, "character", loadNamespace("openapi")),
1032+
self$api_client$deserialize(local_var_resp$response_as_text(), "character", loadNamespace("openapi")),
10331033
error = function(e) {
10341034
stop("Failed to deserialize response")
10351035
}

0 commit comments

Comments
 (0)