FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
openapi/cpp/src/http_client.cpp at main · kallydev/openapi · GitHub
kallydev
/
openapi
Public
forked from
longbridge/openapi
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
openapi
/
cpp
/
src
/
http_client.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
107 lines (95 loc) · 2.78 KB
Breadcrumbs
openapi
/
cpp
/
src
/
http_client.cpp
Copy path
File metadata and controls
107 lines (95 loc) · 2.78 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#
include
<
vector
>
#
include
"
callback.hpp
"
#
include
"
http_client.hpp
"
#
include
"
longbridge.h
"
#
include
"
oauth.hpp
"
namespace
longbridge
{
HttpClient::HttpClient
()
: http_client_(
nullptr
)
{
}
HttpClient::~HttpClient
()
{
if
(http_client_) {
lb_http_client_free
(http_client_);
}
}
HttpClient::HttpClient
(HttpClient&& other)
noexcept
: http_client_(other.http_client_)
{
other.
http_client_
=
nullptr
;
}
HttpClient
HttpClient::from_apikey
(
const
std::string& app_key,
const
std::string& app_secret,
const
std::string& access_token,
const
std::optional<std::string>& http_url)
{
HttpClient client;
client.
http_client_
=
lb_http_client_from_apikey
(http_url ? http_url->
c_str
() :
nullptr
,
app_key.
c_str
(),
app_secret.
c_str
(),
access_token.
c_str
());
return
client;
}
HttpClient
HttpClient::from_apikey_env
(Status& status)
{
lb_error_t
* err =
nullptr
;
lb_http_client_t
* http_client_ptr =
lb_http_client_from_apikey_env
(&err);
status =
std::move
(
Status
(err));
if
(status.
is_ok
()) {
HttpClient client;
client.
http_client_
= http_client_ptr;
return
client;
}
return
HttpClient
();
}
HttpClient
HttpClient::from_oauth
(
const
OAuth& oauth,
const
std::optional<std::string>& http_url)
{
HttpClient client;
client.
http_client_
=
lb_http_client_from_oauth
(oauth, http_url ? http_url->
c_str
() :
nullptr
);
return
client;
}
void
HttpClient::request
(
const
std::string& method,
const
std::string& path,
const
std::optional<std::map<std::string, std::string>>& headers,
const
std::optional<std::string>& body,
AsyncCallback<
void
*, HttpResult> callback)
{
std::vector<
lb_http_header_t
> c_headers;
if
(headers) {
for
(
auto
it = headers->
begin
(); it != headers->
end
(); it++) {
c_headers.
push_back
(
lb_http_header_t
{ it->
first
.
c_str
(), it->
second
.
c_str
() });
}
}
c_headers.
push_back
(
lb_http_header_t
{
nullptr
,
nullptr
});
lb_http_client_request
(
http_client_,
method.
c_str
(),
path.
c_str
(),
c_headers.
data
(),
body ? body->
c_str
() :
nullptr
,
[](
auto
res) {
auto
callback_ptr =
callback::get_async_callback<
void
*, HttpResult>(res->
userdata
);
Status
status
(res->
error
);
if
(status) {
const
lb_http_result_t
* result = (
const
lb_http_result_t
*)res->
data
;
HttpResult
http_res
(
lb_http_result_response_body
(result));
(*callback_ptr)(AsyncResult<
void
*, HttpResult>(
nullptr
,
std::move
(status), &http_res));
}
else
{
(*callback_ptr)(
AsyncResult<
void
*, HttpResult>(
nullptr
,
std::move
(status),
nullptr
));
}
},
new
AsyncCallback<
void
*, HttpResult>(callback));
}
}
//
namespace longbridge
Back
|
FazBrowse Home
|
New Git URL