blob: 63464ed8e82881c07ff34a7935e1fddc886975df (
plain) (
blame)
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
108
109
|
#include "configuration.h"
#include <json.hpp>
#include <cassert>
using nlohmann::json;
namespace twitter {
configuration::configuration()
{
_valid = false;
}
configuration::configuration(std::string data)
{
_valid = true;
auto _data = json::parse(data);
_characters_reserved_per_media = _data.at("characters_reserved_per_media");
_dm_text_character_limit = _data.at("dm_text_character_limit");
_max_media_per_upload = _data.at("max_media_per_upload");
_photo_size_limit = _data.at("photo_size_limit");
_short_url_length = _data.at("short_url_length");
_short_https_url_length = _data.at("short_url_length_https");
for (json::iterator sizedata = _data.at("photo_sizes").begin(); sizedata != _data.at("photo_sizes").end(); ++sizedata)
{
photosize size;
size.height = sizedata.value().at("h");
size.width = sizedata.value().at("w");
if (sizedata.value().at("resize") == "fit")
{
size.resize = resizetype::fit;
} else {
size.resize = resizetype::crop;
}
_photo_sizes[sizedata.key()] = size;
}
for (auto path : _data.at("non_username_paths"))
{
_non_username_paths.insert(path.get<std::string>());
}
}
size_t configuration::getCharactersReservedPerMedia() const
{
assert(_valid);
return _characters_reserved_per_media;
}
size_t configuration::getDirectMessageCharacterLimit() const
{
assert(_valid);
return _dm_text_character_limit;
}
size_t configuration::getMaxMediaPerUpload() const
{
assert(_valid);
return _max_media_per_upload;
}
size_t configuration::getPhotoSizeLimit() const
{
assert(_valid);
return _photo_size_limit;
}
std::map<std::string, configuration::photosize> configuration::getPhotoSizes() const
{
assert(_valid);
return _photo_sizes;
}
size_t configuration::getShortUrlLength() const
{
assert(_valid);
return _short_url_length;
}
size_t configuration::getShortHttpsUrlLength() const
{
assert(_valid);
return _short_https_url_length;
}
std::set<std::string> configuration::getNonUsernamePaths() const
{
assert(_valid);
return _non_username_paths;
}
configuration::operator bool() const
{
return _valid;
}
};
|