media/uploadを叩くやつ(#56)

This commit is contained in:
keita
2021-03-10 23:59:01 +09:00
parent a58903e9c0
commit 852a6bb1b3
5 changed files with 294 additions and 14 deletions
+74
View File
@@ -0,0 +1,74 @@
#include <cocoatweet/api/model/mediaStore.h>
#include <cocoatweet/exception/tweetNotFoundException.h>
#include <cocoatweet/exception/authenticateException.h>
#include <cocoatweet/exception/tweetDuplicateException.h>
#include <cocoatweet/exception/tweetTooLongException.h>
#include <cocoatweet/exception/rateLimitException.h>
#include "nlohmann/json.hpp"
namespace CocoaTweet::API::Model {
MediaStore MediaStore::parse(const unsigned int _responseCode, const std::string& _json) {
auto j = nlohmann::json::parse(_json);
MediaStore media;
if (_responseCode / 100 == 2) {
if(j.count("media_id_string") != 0){
media.id(j["media_id_string"]);
}
if(j.count("size") != 0){
media.size(j["size"]);
}
if(j.count("expires_after_secs") != 0){
media.expires(j["expires_after_secs"]);
}
if(j.count("processing_info") == 0){
media.state("succeeded");
}else{
media.state(j["processing_info"]["state"]);
media.remain(j["processing_info"]["check_after_secs"].get<unsigned int>());
}
} else {
}
return media;
}
void MediaStore::id(const std::string _id) {
id_ = _id;
}
void MediaStore::size(const unsigned int _size){
size_ = _size;
}
void MediaStore::expires(const unsigned int _ex) {
expires_ = _ex;
}
void MediaStore::state(const std::string _state) {
state_ = _state;
}
void MediaStore::remain(const unsigned int _remain){
remain_ = _remain;
}
const std::string MediaStore::id() const {
return id_;
}
const unsigned int MediaStore::size() const {
return size_;
}
const unsigned int MediaStore::expire() const {
return expires_;
}
const std::string MediaStore::state() const {
return state_;
}
const unsigned int MediaStore::remain() const{
return remain_;
}
} // namespace CocoaTweet::API::Model
+82
View File
@@ -0,0 +1,82 @@
#ifndef COCOATWEET_API_MODEL_MEDIASTORE_H_
#define COCOATWEET_API_MODEL_MEDIASTORE_H_
#include <string>
namespace CocoaTweet::API::Model {
/// @brief data class for tweet object
class MediaStore final {
public:
/// @brief constructor
MediaStore() = default;
/// @brief copy constructor
MediaStore(const MediaStore&) = default;
/// @brief constructor for create object from json response
/// @param[in] const unsigned int _responseCode : http status code which received when post request
/// @param[in] const std::string& _json : received content from twitter endpoint
MediaStore(const unsigned int _responseCode, const std::string& _json)
: MediaStore(MediaStore::parse(_responseCode, _json)) {}
/// @brief response parser for tweet object
/// @param[in] const unsigned int _responseCode : http status code which received when post request
/// @param[in] const std::string& _json : received content from twitter endpoint
/// @param[out] CocoaTweet::API::Model::Tweet
static MediaStore parse(const unsigned int _responseCode, const std::string& _json);
/// @brief set id of tweet
/// @param[in] const std::string _id : tweet id to set
/// @param[out] none
void id(const std::string _id);
/// @brief set created time of tweet
/// @param[in] const std::string _at : tweet created time to set
/// @param[out] none
void size(const unsigned int _size);
/// @brief set tweet text
/// @param[in] const std::string _text : text of tweet to set
/// @param[out] none
void expires(const unsigned int _ex);
/// @brief set tweet source
/// @param[in] const std::string _source : source information to set
/// @param[out] none
void state(const std::string _state);
void remain(const unsigned int _remain);
/// @brief get tweet id
/// @param[in] none
/// @param[out] const std::string : tweet id
const std::string id() const;
/// @brief get tweet create time
/// @param[in] none
/// @param[out] const std::string : time of tweet created time
const unsigned int size() const;
/// @brief get tweet text
/// @param[in] none
/// @param[out] const std::string : tweet text
const unsigned int expire() const;
/// @brief get tweet source information
/// @param[in] none
/// @param[out] const std::string : source information
const std::string state() const;
const unsigned int remain() const;
private:
std::string id_;
unsigned long long size_;
unsigned long long expires_;
std::string state_;
unsigned long long remain_;
};
} // namespace CocoaTweet::API::Model
#endif
+49 -1
View File
@@ -4,20 +4,68 @@
#include <string>
namespace CocoaTweet::API::Model {
/// @brief data class for tweet object
class Tweet final {
public:
Tweet() = default;
/// @brief constructor
Tweet() = default;
/// @brief copy constructor
Tweet(const Tweet&) = default;
/// @brief constructor for create object from json response
/// @param[in] const unsigned int _responseCode : http status code which received when post
/// request
/// @param[in] const std::string& _json : received content from twitter endpoint
Tweet(const unsigned int _responseCode, const std::string& _json)
: Tweet(Tweet::parse(_responseCode, _json)) {}
/// @brief response parser for tweet object
/// @param[in] const unsigned int _responseCode : http status code which received when post
/// request
/// @param[in] const std::string& _json : received content from twitter endpoint
/// @param[out] CocoaTweet::API::Model::Tweet
static Tweet parse(const unsigned int _responseCode, const std::string& _json);
/// @brief set id of tweet
/// @param[in] const std::string _id : tweet id to set
/// @param[out] none
void id(const std::string _id);
/// @brief set created time of tweet
/// @param[in] const std::string _at : tweet created time to set
/// @param[out] none
void createdAt(const std::string _at);
/// @brief set tweet text
/// @param[in] const std::string _text : text of tweet to set
/// @param[out] none
void text(const std::string _text);
/// @brief set tweet source
/// @param[in] const std::string _source : source information to set
/// @param[out] none
void source(const std::string _source);
/// @brief get tweet id
/// @param[in] none
/// @param[out] const std::string : tweet id
const std::string id() const;
/// @brief get tweet create time
/// @param[in] none
/// @param[out] const std::string : time of tweet created time
const std::string createdAt() const;
/// @brief get tweet text
/// @param[in] none
/// @param[out] const std::string : tweet text
const std::string text() const;
/// @brief get tweet source information
/// @param[in] none
/// @param[out] const std::string : source information
const std::string source() const;
private: