@@ -27,36 +27,29 @@ namespace realm::app {
27
27
28
28
PushClient::~PushClient () = default ;
29
29
30
- namespace {
31
- util::UniqueFunction<void (const Response&)>
32
- wrap_completion (util::UniqueFunction<void (util::Optional<AppError>)>&& completion)
30
+ void PushClient::request (const std::shared_ptr<User>& user, HttpMethod method, std::string&& body,
31
+ util::UniqueFunction<void (util::Optional<AppError>)>&& completion)
33
32
{
34
- return [completion = std::move (completion)](const Response& response) {
35
- completion (AppUtils::check_for_errors (response));
36
- };
33
+ auto push_route = util::format (" /app/%1/push/providers/%2/registration" , m_app_id, m_service_name);
34
+ std::string route = m_auth_request_client->url_for_path (push_route);
35
+ m_auth_request_client->do_authenticated_request (method, std::move (route), std::move (body), user,
36
+ RequestTokenType::AccessToken,
37
+ [completion = std::move (completion)](const Response& response) {
38
+ completion (AppUtils::check_for_errors (response));
39
+ });
37
40
}
38
- } // anonymous namespace
39
41
40
- void PushClient::register_device (const std::string& registration_token, const std::shared_ptr<User>& sync_user ,
42
+ void PushClient::register_device (const std::string& registration_token, const std::shared_ptr<User>& user ,
41
43
util::UniqueFunction<void (util::Optional<AppError>)>&& completion)
42
44
{
43
- auto push_route = util::format (" /app/%1/push/providers/%2/registration" , m_app_id, m_service_name);
44
- std::string route = m_auth_request_client->url_for_path (push_route);
45
-
46
45
bson::BsonDocument args{{" registrationToken" , registration_token}};
47
- m_auth_request_client->do_authenticated_request (HttpMethod::put, std::move (route), bson::Bson (args).to_string (),
48
- sync_user, RequestTokenType::AccessToken,
49
- wrap_completion (std::move (completion)));
46
+ request (user, HttpMethod::put, bson::Bson (args).to_string (), std::move (completion));
50
47
}
51
48
52
- void PushClient::deregister_device (const std::shared_ptr<User>& sync_user ,
49
+ void PushClient::deregister_device (const std::shared_ptr<User>& user ,
53
50
util::UniqueFunction<void (util::Optional<AppError>)>&& completion)
54
51
{
55
- auto push_route = util::format (" /app/%1/push/providers/%2/registration" , m_app_id, m_service_name);
56
-
57
- m_auth_request_client->do_authenticated_request (HttpMethod::del, m_auth_request_client->url_for_path (push_route),
58
- " " , sync_user, RequestTokenType::AccessToken,
59
- wrap_completion (std::move (completion)));
52
+ request (user, HttpMethod::del, " " , std::move (completion));
60
53
}
61
54
62
55
} // namespace realm::app
0 commit comments