diff options
Diffstat (limited to 'src/configuration.cpp')
-rw-r--r-- | src/configuration.cpp | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/src/configuration.cpp b/src/configuration.cpp new file mode 100644 index 0000000..63464ed --- /dev/null +++ b/src/configuration.cpp | |||
@@ -0,0 +1,109 @@ | |||
1 | #include "configuration.h" | ||
2 | #include <json.hpp> | ||
3 | #include <cassert> | ||
4 | |||
5 | using nlohmann::json; | ||
6 | |||
7 | namespace twitter { | ||
8 | |||
9 | configuration::configuration() | ||
10 | { | ||
11 | _valid = false; | ||
12 | } | ||
13 | |||
14 | configuration::configuration(std::string data) | ||
15 | { | ||
16 | _valid = true; | ||
17 | |||
18 | auto _data = json::parse(data); | ||
19 | |||
20 | _characters_reserved_per_media = _data.at("characters_reserved_per_media"); | ||
21 | _dm_text_character_limit = _data.at("dm_text_character_limit"); | ||
22 | _max_media_per_upload = _data.at("max_media_per_upload"); | ||
23 | _photo_size_limit = _data.at("photo_size_limit"); | ||
24 | _short_url_length = _data.at("short_url_length"); | ||
25 | _short_https_url_length = _data.at("short_url_length_https"); | ||
26 | |||
27 | for (json::iterator sizedata = _data.at("photo_sizes").begin(); sizedata != _data.at("photo_sizes").end(); ++sizedata) | ||
28 | { | ||
29 | photosize size; | ||
30 | size.height = sizedata.value().at("h"); | ||
31 | size.width = sizedata.value().at("w"); | ||
32 | if (sizedata.value().at("resize") == "fit") | ||
33 | { | ||
34 | size.resize = resizetype::fit; | ||
35 | } else { | ||
36 | size.resize = resizetype::crop; | ||
37 | } | ||
38 | |||
39 | _photo_sizes[sizedata.key()] = size; | ||
40 | } | ||
41 | |||
42 | for (auto path : _data.at("non_username_paths")) | ||
43 | { | ||
44 | _non_username_paths.insert(path.get<std::string>()); | ||
45 | } | ||
46 | } | ||
47 | |||
48 | size_t configuration::getCharactersReservedPerMedia() const | ||
49 | { | ||
50 | assert(_valid); | ||
51 | |||
52 | return _characters_reserved_per_media; | ||
53 | } | ||
54 | |||
55 | size_t configuration::getDirectMessageCharacterLimit() const | ||
56 | { | ||
57 | assert(_valid); | ||
58 | |||
59 | return _dm_text_character_limit; | ||
60 | } | ||
61 | |||
62 | size_t configuration::getMaxMediaPerUpload() const | ||
63 | { | ||
64 | assert(_valid); | ||
65 | |||
66 | return _max_media_per_upload; | ||
67 | } | ||
68 | |||
69 | size_t configuration::getPhotoSizeLimit() const | ||
70 | { | ||
71 | assert(_valid); | ||
72 | |||
73 | return _photo_size_limit; | ||
74 | } | ||
75 | |||
76 | std::map<std::string, configuration::photosize> configuration::getPhotoSizes() const | ||
77 | { | ||
78 | assert(_valid); | ||
79 | |||
80 | return _photo_sizes; | ||
81 | } | ||
82 | |||
83 | size_t configuration::getShortUrlLength() const | ||
84 | { | ||
85 | assert(_valid); | ||
86 | |||
87 | return _short_url_length; | ||
88 | } | ||
89 | |||
90 | size_t configuration::getShortHttpsUrlLength() const | ||
91 | { | ||
92 | assert(_valid); | ||
93 | |||
94 | return _short_https_url_length; | ||
95 | } | ||
96 | |||
97 | std::set<std::string> configuration::getNonUsernamePaths() const | ||
98 | { | ||
99 | assert(_valid); | ||
100 | |||
101 | return _non_username_paths; | ||
102 | } | ||
103 | |||
104 | configuration::operator bool() const | ||
105 | { | ||
106 | return _valid; | ||
107 | } | ||
108 | |||
109 | }; | ||