diff --git a/src/cocoatweet/oauth/key.cc b/src/cocoatweet/oauth/key.cc new file mode 100644 index 0000000..f6e9333 --- /dev/null +++ b/src/cocoatweet/oauth/key.cc @@ -0,0 +1,15 @@ +#include "cocoatweet/oauth/key.h" +#include "nlohmann/json.hpp" +#include +#include + +namespace CocoaTweet::OAuth{ +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); + return Key(j["consumer_key"], j["consumer_secret"], j["access_token"], j["access_token_secret"]); +} +} diff --git a/src/cocoatweet/oauth/key.h b/src/cocoatweet/oauth/key.h index 536dce8..425ba0b 100644 --- a/src/cocoatweet/oauth/key.h +++ b/src/cocoatweet/oauth/key.h @@ -2,6 +2,7 @@ #define COCOATWEET_OAUTH_KEY_H_ #include + namespace CocoaTweet::OAuth { class Key { const std::string consumerKey_; @@ -37,6 +38,8 @@ public: return std::map{{"oauth_consumer_key", consumerSecret_}, {"oauth_token", accessTokenSecret_}}; } + + static Key fromJsonFile(const std::string _jsonFile); }; } // namespace CocoaTweet::OAuth