From ad9591147a5c71c3fd14f04cc58aeb9ae9bdb57f Mon Sep 17 00:00:00 2001 From: keita Date: Wed, 17 Feb 2021 16:51:26 +0900 Subject: [PATCH] =?UTF-8?q?json=E3=81=8B=E3=82=89=E3=82=AD=E3=83=BC?= =?UTF-8?q?=E3=82=92=E8=AA=AD=E3=81=BF=E8=BE=BC=E3=82=81=E3=82=8B=E3=82=88?= =?UTF-8?q?=E3=81=86=E3=81=AB=E3=81=97=E3=81=9F(#50)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/cocoatweet/oauth/key.cc | 15 +++++++++++++++ src/cocoatweet/oauth/key.h | 3 +++ 2 files changed, 18 insertions(+) create mode 100644 src/cocoatweet/oauth/key.cc 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