MCPcopy Create free account
hub / github.com/CalcProgrammer1/OpenRGB / APIRequest

Function APIRequest

Controllers/NanoleafController/NanoleafController.cpp:13–85  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11#include "httplib.h"
12
13long APIRequest(std::string method, std::string location, std::string URI, json* request_data = nullptr, json* response_data = nullptr)
14{
15 /*-------------------------------------------------------------*\
16 | Append http:// to the location field to create the URL |
17 \*-------------------------------------------------------------*/
18 const std::string url("http://" + location);
19
20 /*-------------------------------------------------------------*\
21 | Create httplib Client and variables to hold result |
22 \*-------------------------------------------------------------*/
23 httplib::Client client(url.c_str());
24 int status = 0;
25 std::string body = "";
26
27 /*-------------------------------------------------------------*\
28 | Perform the appropriate call for the given method |
29 \*-------------------------------------------------------------*/
30 if(method == "GET")
31 {
32 httplib::Result result = client.Get(URI.c_str());
33
34 status = result->status;
35 body = result->body;
36 }
37 else if(method == "PUT")
38 {
39 if(request_data)
40 {
41 httplib::Result result = client.Put(URI.c_str(), request_data->dump(), "application/json");
42
43 status = result->status;
44 body = result->body;
45 }
46 else
47 {
48 httplib::Result result = client.Put(URI.c_str());
49
50 status = result->status;
51 body = result->body;
52 }
53 }
54 else if(method == "DELETE")
55 {
56 httplib::Result result = client.Delete(URI.c_str());
57
58 status = result->status;
59 body = result->body;
60 }
61 else if(method == "POST")
62 {
63 httplib::Result result = client.Post(URI.c_str());
64
65 status = result->status;
66 body = result->body;
67 }
68
69 /*-------------------------------------------------------------*\
70 | If status is in the 200 range the request was successful |

Callers 6

NanoleafControllerMethod · 0.85
PairMethod · 0.85
UnpairMethod · 0.85
StartExternalControlMethod · 0.85
SelectEffectMethod · 0.85
SetBrightnessMethod · 0.85

Calls 6

PutMethod · 0.80
DeleteMethod · 0.80
PostMethod · 0.80
parseFunction · 0.50
GetMethod · 0.45
dumpMethod · 0.45

Tested by

no test coverage detected