jsonからキーを読み込めるようにした(#50)
This commit is contained in:
@@ -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"]);
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user