forked from organicmaps/organicmaps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathremote_file.hpp
59 lines (50 loc) · 1.51 KB
/
remote_file.hpp
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
#pragma once
#include "platform/http_client.hpp"
#include <functional>
#include <memory>
#include <string>
namespace platform
{
class RemoteFile
{
public:
enum class Status
{
Ok,
Forbidden,
NotFound,
NetworkError,
DiskError
};
struct Result
{
std::string const m_url;
Status const m_status;
int const m_httpCode;
std::string const m_description;
Result(std::string url, Status status, int httpCode, std::string description)
: m_url(std::move(url))
, m_status(status)
, m_httpCode(httpCode)
, m_description(std::move(description))
{}
Result(std::string url, Status status, std::string description)
: Result(std::move(url), status, 0, std::move(description))
{}
};
explicit RemoteFile(std::string url, std::string accessToken = {},
HttpClient::Headers const & defaultHeaders = {},
bool allowRedirection = true);
Result Download(std::string const & filePath) const;
using StartDownloadingHandler = std::function<void(std::string const & filePath)>;
using ResultHandler = std::function<void(Result &&, std::string const & filePath)>;
void DownloadAsync(std::string const & filePath,
StartDownloadingHandler && startDownloadingHandler,
ResultHandler && resultHandler) const;
private:
std::string const m_url;
std::string const m_accessToken;
HttpClient::Headers const m_defaultHeaders;
bool const m_allowRedirection;
};
} // namespace platform