|
2 | 2 | install.packages("petstore_1.0.0.tar.gz",repos=NULL, type="source") |
3 | 3 | library(petstore) |
4 | 4 |
|
5 | | -var_pet_id <- 56 # integer | ID of pet to return |
| 5 | +errorMsg <- "{\"code\":1,\"type\":\"error\",\"message\":\"Pet not found\"}" |
| 6 | +#errorMsg <- '{"code": 404, "message": "Not found"}' |
| 7 | +a <- ModelApiResponse$new()$fromJSONString(errorMsg) |
| 8 | +dput(a) |
6 | 9 |
|
7 | | -#Find pet by ID |
8 | | -#api_instance <- PetApi$new() |
9 | | -## Configure API key authorization: api_key |
10 | | -#api_instance$api_client$api_keys['api_key'] <- 'TODO_YOUR_API_KEY'; |
11 | | -#result <- tryCatch( |
12 | | -# api_instance$GetPetById(var_pet_id), |
13 | | -# ApiException = function(ex) ex |
14 | | -# ) |
15 | | -## In case of error, print the error object |
16 | | -#if(!is.null(result$ApiException)) { |
17 | | -# cat(result$ApiException$toString()) |
18 | | -#} else { |
19 | | -# # deserialized response object |
20 | | -# response.object <- result$content |
21 | | -# # response headers |
22 | | -# response.headers <- result$response$headers |
23 | | -# # response status code |
24 | | -# response.status.code <- result$response$status_code |
25 | | -#} |
26 | | - |
27 | | -json2 <- |
28 | | -'{"name": "pet", "photoUrls" : ["http://a.com", "http://b.com"]}' |
29 | | - |
30 | | -json <- |
31 | | -'[ |
32 | | - {"Name" : "Mario", "Age" : 32, "Occupation" : "Plumber"}, |
33 | | - {"Name" : "Peach", "Age" : 21, "Occupation" : "Princess"}, |
34 | | - {}, |
35 | | - {"Name" : "Bowser", "Occupation" : "Koopa"} |
36 | | -]' |
37 | | - |
38 | | - |
39 | | -#Pet$public_methods |
40 | | -#Pet$public_methods$fromJSON(json) |
41 | | -#Pet$public_methods$toJson() |
42 | | -#Pet$public_methods$validateJSON(json2) |
43 | | -#Pet$public_methods$validateJson(json) |
44 | | -#Pet$my_static_method <- function(x) { x + 2} |
45 | | -#Pet$public_methods$my_static_method(1) |
46 | | - |
47 | | - basque_pig_json <- |
48 | | - '{"className2": "BasquePig", "color": "red"}' |
49 | | - |
50 | | - danish_pig_json <- |
51 | | - '{"className2": "DanishPig", "size": 7}' |
52 | | - |
53 | | - wrong_json <- |
54 | | - '[ |
55 | | - {"Name" : "Tom", "Age" : 32, "Occupation" : "Consultant"}, |
56 | | - {}, |
57 | | - {"Name" : "Ada", "Occupation" : "Engineer"} |
58 | | - ]' |
59 | | - |
60 | | - print("==========") |
61 | | - pig <- Pig$new() |
62 | | - basque_pig <- pig$fromJSON(basque_pig_json) |
63 | | - #print(basque_pig$actual_instance$color) |
64 | | - #expect_equal(basque_pig$actual_type, "BasquePig") |
65 | | - pig$fromJSON(danish_pig_json) |
66 | | - #pig$fromJSON(wrong_json) |
67 | | - pig$toJSON() |
68 | | - |
69 | | - #d <- DanishPig$new() |
70 | | - #dp <- d$validateJSON(danish_pig_json) |
| 10 | +var_pet_id <- 1231256 # integer | ID of pet to return |
71 | 11 |
|
| 12 | +#Find pet by ID |
| 13 | +api_instance <- PetApi$new() |
| 14 | +# Configure API key authorization: api_key |
| 15 | +api_instance$api_client$api_keys['api_key'] <- 'TODO_YOUR_API_KEY'; |
| 16 | +result <- tryCatch( |
| 17 | + api_instance$GetPetById(var_pet_id), |
| 18 | + ApiException = function(ex) ex |
| 19 | + ) |
| 20 | +# In case of error, print the error object |
| 21 | +if(!is.null(result$ApiException)) { |
| 22 | + cat(result$ApiException$toString()) |
| 23 | +} else { |
| 24 | + # deserialized response object |
| 25 | + response.object <- result$content |
| 26 | + # response headers |
| 27 | + response.headers <- result$response$headers |
| 28 | + # response status code |
| 29 | + response.status.code <- result$response$status_code |
| 30 | +} |
72 | 31 |
|
| 32 | +#json2 <- |
| 33 | +#'{"name": "pet", "photoUrls" : ["http://a.com", "http://b.com"]}' |
| 34 | +# |
| 35 | +#json <- |
| 36 | +#'[ |
| 37 | +# {"Name" : "Mario", "Age" : 32, "Occupation" : "Plumber"}, |
| 38 | +# {"Name" : "Peach", "Age" : 21, "Occupation" : "Princess"}, |
| 39 | +# {}, |
| 40 | +# {"Name" : "Bowser", "Occupation" : "Koopa"} |
| 41 | +#]' |
| 42 | +# |
| 43 | +# |
| 44 | +##Pet$public_methods |
| 45 | +##Pet$public_methods$fromJSON(json) |
| 46 | +##Pet$public_methods$toJson() |
| 47 | +##Pet$public_methods$validateJSON(json2) |
| 48 | +##Pet$public_methods$validateJson(json) |
| 49 | +##Pet$my_static_method <- function(x) { x + 2} |
| 50 | +##Pet$public_methods$my_static_method(1) |
| 51 | +# |
| 52 | +# basque_pig_json <- |
| 53 | +# '{"className2": "BasquePig", "color": "red"}' |
| 54 | +# |
| 55 | +# danish_pig_json <- |
| 56 | +# '{"className2": "DanishPig", "size": 7}' |
| 57 | +# |
| 58 | +# wrong_json <- |
| 59 | +# '[ |
| 60 | +# {"Name" : "Tom", "Age" : 32, "Occupation" : "Consultant"}, |
| 61 | +# {}, |
| 62 | +# {"Name" : "Ada", "Occupation" : "Engineer"} |
| 63 | +# ]' |
| 64 | +# |
| 65 | +# print("==========") |
| 66 | +# pig <- Pig$new() |
| 67 | +# basque_pig <- pig$fromJSON(basque_pig_json) |
| 68 | +# #print(basque_pig$actual_instance$color) |
| 69 | +# #expect_equal(basque_pig$actual_type, "BasquePig") |
| 70 | +# pig$fromJSON(danish_pig_json) |
| 71 | +# #pig$fromJSON(wrong_json) |
| 72 | +# pig$toJSON() |
| 73 | +# |
| 74 | +# #d <- DanishPig$new() |
| 75 | +# #dp <- d$validateJSON(danish_pig_json) |
| 76 | +# |
| 77 | +# |
0 commit comments