Files
CocoaTweet/src/cocoatweet/api/model/tweet.cc
T
keita 1505b0b139 各種Exceptionの用意(#53)
Tweetオブジェクトを仮実装(#54)
Tweetオブジェクトのパースに当たり、httpPostのステータスコードを取得(#54)
各種オブジェクトにパースするためにhttpPostに渡すコールバックの引数を変更
2021-02-24 14:19:14 +09:00

33 lines
786 B
C++

#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.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