めんどくさくなったから一括でコミットするけど許してくれ

This commit is contained in:
keita
2021-02-23 16:37:15 +09:00
parent 5cebef5d9c
commit b4497728b1
18 changed files with 148 additions and 52 deletions
+33
View File
@@ -0,0 +1,33 @@
#include <cocoatweet/api/model/tweet.h>
#include <cocoatweet/exception/tweetNotFoundException.h>
#include "nlohmann/json.hpp"
#include <iostream>
namespace CocoaTweet::API::Model {
Tweet Tweet::parse(const unsigned int _responseCode, const std::string& _json) {
auto j = nlohmann::json::parse(_json);
Tweet tweet;
if (_responseCode == 200) {
Tweet tweet;
tweet.id(j["id_str"]);
} else {
auto error = j["errors"][0]["code"];
auto message = j["errors"][0]["message"];
if (error.get<int>() == 144) {
throw CocoaTweet::Exception::TweetNotFoundException(message.get<std::string>().c_str());
}
}
return tweet;
}
void Tweet::id(const std::string& _id) {
id_ = _id;
}
const std::string& Tweet::id() const {
return id_;
}
} // namespace CocoaTweet::API::Model
+22
View File
@@ -0,0 +1,22 @@
#ifndef COCOATWEET_API_MODEL_TWEET_H_
#define COCOATWEET_API_MODEL_TWEET_H_
#include <string>
namespace CocoaTweet::API::Model {
class Tweet final {
public:
Tweet() = default;
Tweet(const Tweet&) = default;
Tweet(const unsigned int _responseCode, const std::string& _json)
: Tweet(Tweet::parse(_responseCode, _json)) {}
static Tweet parse(const unsigned int _responseCode, const std::string& _json);
void id(const std::string& _id);
const std::string& id() const;
private:
std::string id_;
};
} // namespace CocoaTweet::API::Model
#endif