jsonからキーを読み込めるようにした(#50)

This commit is contained in:
keita
2021-02-17 16:51:26 +09:00
parent 94ccbe00dd
commit ad9591147a
2 changed files with 18 additions and 0 deletions
+15
View File
@@ -0,0 +1,15 @@
#include "cocoatweet/oauth/key.h"
#include "nlohmann/json.hpp"
#include <fstream>
#include <string>
namespace CocoaTweet::OAuth{
Key Key::fromJsonFile(const std::string _jsonFile){
std::ifstream ifs(_jsonFile);
std::string str((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>());
auto j = nlohmann::json::parse(str);
return Key(j["consumer_key"], j["consumer_secret"], j["access_token"], j["access_token_secret"]);
}
}
+3
View File
@@ -2,6 +2,7 @@
#define COCOATWEET_OAUTH_KEY_H_
#include <map>
namespace CocoaTweet::OAuth {
class Key {
const std::string consumerKey_;
@@ -37,6 +38,8 @@ public:
return std::map<std::string, std::string>{{"oauth_consumer_key", consumerSecret_},
{"oauth_token", accessTokenSecret_}};
}
static Key fromJsonFile(const std::string _jsonFile);
};
} // namespace CocoaTweet::OAuth