| 130 | } |
| 131 | |
| 132 | void GetEffects(std::function<void(std::vector<EffectsGroup>)> callback) |
| 133 | { |
| 134 | using namespace audacity::network_manager; |
| 135 | using rapidjson::StringRef; |
| 136 | |
| 137 | // TODO Get locale |
| 138 | const std::string locale = "en-EN"; |
| 139 | |
| 140 | rapidjson::Document jsonDoc; |
| 141 | jsonDoc.SetObject(); |
| 142 | auto& allocator = jsonDoc.GetAllocator(); |
| 143 | jsonDoc.AddMember("query", rapidjson::Value(getEffectsQuery.c_str(), allocator), allocator); |
| 144 | |
| 145 | rapidjson::Value variables(rapidjson::kObjectType); |
| 146 | variables.AddMember("locale", rapidjson::Value(locale.c_str(), allocator), allocator); |
| 147 | jsonDoc.AddMember("variables", variables, allocator); |
| 148 | |
| 149 | rapidjson::StringBuffer buffer; |
| 150 | rapidjson::Writer<rapidjson::StringBuffer> writer(buffer); |
| 151 | jsonDoc.Accept(writer); |
| 152 | |
| 153 | Request request(GetMusehubAPIEndpoint()); |
| 154 | request.setHeader(common_headers::ContentType, common_content_types::ApplicationJson); |
| 155 | request.setHeader(common_headers::Accept, common_content_types::ApplicationJson); |
| 156 | |
| 157 | auto response = NetworkManager::GetInstance().doPost(request, buffer.GetString(), buffer.GetSize()); |
| 158 | |
| 159 | response->setRequestFinishedCallback([response, callback](auto) { |
| 160 | const auto httpCode = response->getHTTPCode(); |
| 161 | const auto body = response->readAll<std::string>(); |
| 162 | |
| 163 | if(httpCode != HttpCode::OK) { |
| 164 | callback({}); |
| 165 | return; |
| 166 | } |
| 167 | |
| 168 | rapidjson::Document document; |
| 169 | document.Parse(body.c_str(), body.size()); |
| 170 | |
| 171 | if (document.HasParseError() || !document.IsObject()) { |
| 172 | callback({}); |
| 173 | return; |
| 174 | } |
| 175 | |
| 176 | auto groups = parseProductPages(document); |
| 177 | callback(groups); |
| 178 | }); |
| 179 | } |
| 180 | |
| 181 | std::string GetBecomeAPartnerUrl() |
| 182 | { |
no test coverage detected