#include "cocoatweet/authentication/key.h" #include "nlohmann/json.hpp" #include #include #include namespace CocoaTweet::Authentication { Key Key::fromJsonFile(const std::string _jsonFile) { std::ifstream ifs(_jsonFile); std::string str((std::istreambuf_iterator(ifs)), std::istreambuf_iterator()); auto j = nlohmann::json::parse(str); Key key; key.authType(Key::AUTH_TYPE::OAUTH10A); if (j.contains("consumer_key")) { key.consumerKey(j["consumer_key"].get()); } if (j.contains("consumer_secret")) { key.consumerSecret(j["consumer_secret"].get()); } if (j.contains("access_token")) { key.accessToken(j["access_token"].get()); } if (j.contains("access_token_secret")) { key.accessTokenSecret(j["access_token_secret"].get()); } return key; } } // namespace CocoaTweet::Authentication