めんどくさくなったから一括でコミットするけど許してくれ
This commit is contained in:
@@ -1,15 +1,24 @@
|
|||||||
#ifndef COCOATWEET_API_H_
|
#ifndef COCOATWEET_API_H_
|
||||||
#define COCOATWEET_API_H_
|
#define COCOATWEET_API_H_
|
||||||
|
|
||||||
#include "cocoatweet/api/status/status.h"
|
#include <cocoatweet/api/status/status.h>
|
||||||
#include "cocoatweet/api/favorite/favorite.h"
|
#include <cocoatweet/api/favorite/favorite.h>
|
||||||
#include "cocoatweet/oauth/oauth.h"
|
#include <cocoatweet/oauth/oauth.h>
|
||||||
|
|
||||||
namespace CocoaTweet::API {
|
namespace CocoaTweet::API {
|
||||||
|
/// @brief Twitter API Entry Point
|
||||||
class API {
|
class API {
|
||||||
public:
|
public:
|
||||||
|
/// @brief primary constructor
|
||||||
|
/// @param[in] _key Twitter API Key typed CocoaTweet::OAuth::Key
|
||||||
API(CocoaTweet::OAuth::Key _key);
|
API(CocoaTweet::OAuth::Key _key);
|
||||||
|
|
||||||
|
/// @brief Getter for Grouped by Statuses/*
|
||||||
|
/// @param[out] Status object typed CocoaTweet::API::Statuses::Status
|
||||||
Statuses::Status status() const;
|
Statuses::Status status() const;
|
||||||
|
|
||||||
|
/// @brief Getter for Grouped by Favorites/*
|
||||||
|
/// @param[out] Favorite object typed CococaTweet::API::Favorites::Favorite
|
||||||
Favorites::Favorite favorite() const;
|
Favorites::Favorite favorite() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ void Create::id(const std::string& _id) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Create::process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth) {
|
void Create::process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth) {
|
||||||
HttpPost::process(_oauth,
|
HttpPost::process(_oauth, [](const std::string& _srv) { std::cout << _srv << std::endl; });
|
||||||
[](const std::string& _srv) { std::cout << _srv << std::endl; });
|
|
||||||
}
|
}
|
||||||
} // namespace CocoaTweet::API::Favorites
|
} // namespace CocoaTweet::API::Favorites
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ void Destroy::id(const std::string& _id) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Destroy::process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth) {
|
void Destroy::process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth) {
|
||||||
HttpPost::process(_oauth,
|
HttpPost::process(_oauth, [](const std::string& _srv) { std::cout << _srv << std::endl; });
|
||||||
[](const std::string& _srv) { std::cout << _srv << std::endl; });
|
|
||||||
}
|
}
|
||||||
} // namespace CocoaTweet::API::Favorites
|
} // namespace CocoaTweet::API::Favorites
|
||||||
|
|||||||
@@ -10,8 +10,7 @@ extern "C" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
namespace CocoaTweet::API::Interface {
|
namespace CocoaTweet::API::Interface {
|
||||||
size_t HttpPost::curlCallback_(char* _ptr, size_t _size, size_t _nmemb,
|
size_t HttpPost::curlCallback_(char* _ptr, size_t _size, size_t _nmemb, std::string* _stream) {
|
||||||
std::string* _stream) {
|
|
||||||
int realsize = _size * _nmemb;
|
int realsize = _size * _nmemb;
|
||||||
_stream->append(_ptr, realsize);
|
_stream->append(_ptr, realsize);
|
||||||
return realsize;
|
return realsize;
|
||||||
|
|||||||
@@ -7,7 +7,6 @@
|
|||||||
namespace CocoaTweet::API::Interface {
|
namespace CocoaTweet::API::Interface {
|
||||||
class HttpPost {
|
class HttpPost {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::weak_ptr<CocoaTweet::OAuth::OAuth1> oauth_;
|
std::weak_ptr<CocoaTweet::OAuth::OAuth1> oauth_;
|
||||||
std::map<std::string, std::string> bodyParam_;
|
std::map<std::string, std::string> bodyParam_;
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
#ifndef COCOATWEET_API_MEDIA_UPLOAD_H_
|
||||||
|
#define COCOATWEET_API_MEDIA_UPLOAD_H_
|
||||||
|
|
||||||
|
#include <cocoatweet/api/interface/postInterface.h>
|
||||||
|
|
||||||
|
namespace CocoaTweet::API::Medias {
|
||||||
|
class Upload : public postInterface {
|
||||||
|
public:
|
||||||
|
enum Command : class st::string {
|
||||||
|
INIT = "INIT",
|
||||||
|
APPEND = "APPEND",
|
||||||
|
FINALIZE = "FINALIZE",
|
||||||
|
};
|
||||||
|
|
||||||
|
Upload::Upload();
|
||||||
|
void media(const std::string& _media);
|
||||||
|
void mediaId(const std::string _mediaId);
|
||||||
|
void process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth, Command _command);
|
||||||
|
}
|
||||||
|
} // namespace CocoaTweet::API::Medias
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -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
|
||||||
@@ -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
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
#include "cocoatweet/api/status/destroy.h"
|
#include "cocoatweet/api/status/destroy.h"
|
||||||
|
#include <cocoatweet/api/model/tweet.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
namespace CocoaTweet::API::Statuses {
|
namespace CocoaTweet::API::Statuses {
|
||||||
Destroy::Destroy() {}
|
Destroy::Destroy() {}
|
||||||
@@ -8,8 +9,11 @@ void Destroy::id(const std::string _id) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Destroy::process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth) {
|
void Destroy::process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth) {
|
||||||
HttpPost::process(_oauth,
|
CocoaTweet::API::Model::Tweet tweet;
|
||||||
[](const std::string& _srv) { std::cout << _srv << std::endl; });
|
HttpPost::process(_oauth, [&tweet](const std::string& _srv) {
|
||||||
|
tweet = CocoaTweet::API::Model::Tweet::parse(100, _srv);
|
||||||
|
});
|
||||||
|
std::cout << "afw" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace CocoaTweet::API::Statuses
|
} // namespace CocoaTweet::API::Statuses
|
||||||
|
|||||||
@@ -2,15 +2,23 @@
|
|||||||
#define COCOATWEET_API_STATUSES_DESTROY_H_
|
#define COCOATWEET_API_STATUSES_DESTROY_H_
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <cocoatweet/api/interface/httpPost.h>
|
||||||
#include "cocoatweet/api/interface/httpPost.h"
|
|
||||||
//#include "cocoatweet/oauth/oauth.h"
|
|
||||||
|
|
||||||
namespace CocoaTweet::API::Statuses {
|
namespace CocoaTweet::API::Statuses {
|
||||||
|
/// @brief class for using status/destroy:id endpoint
|
||||||
class Destroy : public CocoaTweet::API::Interface::HttpPost {
|
class Destroy : public CocoaTweet::API::Interface::HttpPost {
|
||||||
public:
|
public:
|
||||||
|
/// @brief primary constructor
|
||||||
Destroy();
|
Destroy();
|
||||||
|
|
||||||
|
/// @brief set tweet id to destroy
|
||||||
|
/// @param[in] std::string _id : tweet id which should be destroy
|
||||||
|
/// @param[out] none
|
||||||
void id(const std::string _id);
|
void id(const std::string _id);
|
||||||
|
|
||||||
|
/// @brief process request for endpoint
|
||||||
|
/// @param[in] std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth : pointer to oauth object
|
||||||
|
/// @param[out] none
|
||||||
void process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth);
|
void process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth);
|
||||||
};
|
};
|
||||||
} // namespace CocoaTweet::API::Statuses
|
} // namespace CocoaTweet::API::Statuses
|
||||||
|
|||||||
@@ -12,8 +12,7 @@ void Update::status(const std::string _status) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Update::process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth) {
|
void Update::process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth) {
|
||||||
HttpPost::process(_oauth,
|
HttpPost::process(_oauth, [](const std::string& _srv) { std::cout << _srv << std::endl; });
|
||||||
[](const std::string& _srv) { std::cout << _srv << std::endl; });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace CocoaTweet::API::Statuses
|
} // namespace CocoaTweet::API::Statuses
|
||||||
|
|||||||
@@ -3,10 +3,10 @@
|
|||||||
|
|
||||||
#include <cocoatweet/exception/exception.h>
|
#include <cocoatweet/exception/exception.h>
|
||||||
|
|
||||||
namespace CocoaTweet::Exception{
|
namespace CocoaTweet::Exception {
|
||||||
class AuthenticateException final: Exception{
|
class AuthenticateException final : Exception {
|
||||||
using Exception::Exception;
|
using Exception::Exception;
|
||||||
};
|
};
|
||||||
}
|
} // namespace CocoaTweet::Exception
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -4,15 +4,18 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <exception>
|
#include <exception>
|
||||||
|
|
||||||
namespace CocoaTweet::Exception{
|
namespace CocoaTweet::Exception {
|
||||||
class Exception: public std::exception{
|
class Exception : public std::exception {
|
||||||
public:
|
public:
|
||||||
Exception(const char* _msg):msg_(std::string(_msg)){}
|
Exception(const char* _msg) : msg_(std::string(_msg)) {}
|
||||||
const std::string& what(){return msg_;}
|
const std::string& what() {
|
||||||
|
return msg_;
|
||||||
|
}
|
||||||
virtual ~Exception() = default;
|
virtual ~Exception() = default;
|
||||||
protected:
|
|
||||||
|
protected:
|
||||||
std::string msg_;
|
std::string msg_;
|
||||||
};
|
};
|
||||||
}
|
} // namespace CocoaTweet::Exception
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -3,10 +3,10 @@
|
|||||||
|
|
||||||
#include <cocoatweet/exception/exception.h>
|
#include <cocoatweet/exception/exception.h>
|
||||||
|
|
||||||
namespace CocoaTweet::Exception{
|
namespace CocoaTweet::Exception {
|
||||||
class RateLimitException final: Exception{
|
class RateLimitException final : Exception {
|
||||||
using Exception::Exception;
|
using Exception::Exception;
|
||||||
};
|
};
|
||||||
}
|
} // namespace CocoaTweet::Exception
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -3,10 +3,10 @@
|
|||||||
|
|
||||||
#include <cocoatweet/exception/exception.h>
|
#include <cocoatweet/exception/exception.h>
|
||||||
|
|
||||||
namespace CocoaTweet::Exception{
|
namespace CocoaTweet::Exception {
|
||||||
class TweetDuplicateException final: Exception{
|
class TweetDuplicateException final : Exception {
|
||||||
using Exception::Exception;
|
using Exception::Exception;
|
||||||
};
|
};
|
||||||
}
|
} // namespace CocoaTweet::Exception
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -3,10 +3,10 @@
|
|||||||
|
|
||||||
#include <cocoatweet/exception/exception.h>
|
#include <cocoatweet/exception/exception.h>
|
||||||
|
|
||||||
namespace CocoaTweet::Exception{
|
namespace CocoaTweet::Exception {
|
||||||
class TweetNotFoundException final: Exception{
|
class TweetNotFoundException final : Exception {
|
||||||
using Exception::Exception;
|
using Exception::Exception;
|
||||||
};
|
};
|
||||||
}
|
} // namespace CocoaTweet::Exception
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -3,10 +3,10 @@
|
|||||||
|
|
||||||
#include <cocoatweet/exception/exception.h>
|
#include <cocoatweet/exception/exception.h>
|
||||||
|
|
||||||
namespace CocoaTweet::Exception{
|
namespace CocoaTweet::Exception {
|
||||||
class TweetTooLongException final: Exception{
|
class TweetTooLongException final : Exception {
|
||||||
using Exception::Exception;
|
using Exception::Exception;
|
||||||
};
|
};
|
||||||
}
|
} // namespace CocoaTweet::Exception
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user