format
This commit is contained in:
@@ -2,10 +2,10 @@
|
||||
|
||||
namespace CocoaTweet::API {
|
||||
API::API(CocoaTweet::OAuth::Key _key) {
|
||||
oauth_ = std::make_shared<CocoaTweet::OAuth::OAuth1>(_key);
|
||||
status_ = Statuses::Status(oauth_);
|
||||
favorite_ = Favorites::Favorite(oauth_);
|
||||
media_ = Medias::Media(oauth_);
|
||||
oauth_ = std::make_shared<CocoaTweet::OAuth::OAuth1>(_key);
|
||||
status_ = Statuses::Status(oauth_);
|
||||
favorite_ = Favorites::Favorite(oauth_);
|
||||
media_ = Medias::Media(oauth_);
|
||||
directMessage_ = DirectMessages::DirectMessage(oauth_);
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ Medias::Media API::media() const {
|
||||
return media_;
|
||||
}
|
||||
|
||||
DirectMessages::DirectMessage API::directMessage() const{
|
||||
DirectMessages::DirectMessage API::directMessage() const {
|
||||
return directMessage_;
|
||||
}
|
||||
} // namespace CocoaTweet::API
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
#include <cocoatweet/api/directMessage/directMessage.h>
|
||||
#include <cocoatweet/api/directMessage/new.h>
|
||||
|
||||
namespace CocoaTweet::API::DirectMessages{
|
||||
DirectMessage::DirectMessage(std::shared_ptr<CocoaTweet::OAuth::OAuth1> _oauth){
|
||||
oauth_ = _oauth;
|
||||
}
|
||||
|
||||
void DirectMessage::messageCreate(const std::string& _recipient, const std::string& _message){
|
||||
CocoaTweet::API::DirectMessages::New dm;
|
||||
dm.recipient(_recipient);
|
||||
dm.message(_message);
|
||||
dm.process(oauth_);
|
||||
}
|
||||
}
|
||||
namespace CocoaTweet::API::DirectMessages {
|
||||
DirectMessage::DirectMessage(std::shared_ptr<CocoaTweet::OAuth::OAuth1> _oauth) {
|
||||
oauth_ = _oauth;
|
||||
}
|
||||
|
||||
void DirectMessage::messageCreate(const std::string& _recipient, const std::string& _message) {
|
||||
CocoaTweet::API::DirectMessages::New dm;
|
||||
dm.recipient(_recipient);
|
||||
dm.message(_message);
|
||||
dm.process(oauth_);
|
||||
}
|
||||
} // namespace CocoaTweet::API::DirectMessages
|
||||
@@ -17,10 +17,11 @@ public:
|
||||
/// @brief constructor which finally should to be called.
|
||||
/// @param[in] std::shared_ptr<CocoaTweet::OAuth::OAuth1> : pointer to OAuth object
|
||||
DirectMessage(std::shared_ptr<CocoaTweet::OAuth::OAuth1> _oauth);
|
||||
|
||||
|
||||
void messageCreate(const std::string& _recipient, const std::string& _message);
|
||||
|
||||
private:
|
||||
};
|
||||
} // namespace CocoaTweet::API::Statuses
|
||||
} // namespace CocoaTweet::API::DirectMessages
|
||||
|
||||
#endif
|
||||
|
||||
@@ -2,30 +2,29 @@
|
||||
#include <cocoatweet/util/util.h>
|
||||
#include <string>
|
||||
|
||||
namespace CocoaTweet::API::DirectMessages{
|
||||
New::New(){
|
||||
url_ = "https://api.twitter.com/1.1/direct_messages/events/new.json";
|
||||
contentType_ = "application/json";
|
||||
namespace CocoaTweet::API::DirectMessages {
|
||||
New::New() {
|
||||
url_ = "https://api.twitter.com/1.1/direct_messages/events/new.json";
|
||||
contentType_ = "application/json";
|
||||
|
||||
nlohmann::json tmp;
|
||||
tmp["type"] = "message_create";
|
||||
tmp["message_create"] = nlohmann::json::object();
|
||||
tmp["message_create"]["target"] = nlohmann::json::object();
|
||||
tmp["message_create"]["message_data"] = nlohmann::json::object();
|
||||
json_["event"] = tmp;
|
||||
}
|
||||
nlohmann::json tmp;
|
||||
tmp["type"] = "message_create";
|
||||
tmp["message_create"] = nlohmann::json::object();
|
||||
tmp["message_create"]["target"] = nlohmann::json::object();
|
||||
tmp["message_create"]["message_data"] = nlohmann::json::object();
|
||||
json_["event"] = tmp;
|
||||
}
|
||||
|
||||
void New::recipient(const std::string& _id) {
|
||||
json_["event"]["message_create"]["target"]["recipient_id"] = std::stol(_id);
|
||||
}
|
||||
|
||||
void New::recipient(const std::string& _id){
|
||||
json_["event"]["message_create"]["target"]["recipient_id"] = std::stol(_id);
|
||||
}
|
||||
void New::message(const std::string& _message) {
|
||||
json_["event"]["message_create"]["message_data"]["text"] = _message;
|
||||
}
|
||||
|
||||
void New::message(const std::string& _message){
|
||||
json_["event"]["message_create"]["message_data"]["text"] = _message;
|
||||
}
|
||||
|
||||
void New::process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth){
|
||||
bodyParam_.insert_or_assign("data", json_.dump());
|
||||
HttpPost::process(_oauth, [](const std::string& _rcv){});
|
||||
}
|
||||
}
|
||||
void New::process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth) {
|
||||
bodyParam_.insert_or_assign("data", json_.dump());
|
||||
HttpPost::process(_oauth, [](const std::string& _rcv) {});
|
||||
}
|
||||
} // namespace CocoaTweet::API::DirectMessages
|
||||
@@ -16,8 +16,6 @@ public:
|
||||
void recipient(const std::string& _id);
|
||||
void message(const std::string& _message);
|
||||
|
||||
|
||||
|
||||
/// @brief process request for endpoint
|
||||
/// @param[in] std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth : pointer to oauth object
|
||||
/// @param[out] CocoaTweet::API::Model::Tweet : request result
|
||||
@@ -27,6 +25,6 @@ private:
|
||||
std::string status_;
|
||||
nlohmann::json json_;
|
||||
};
|
||||
} // namespace CocoaTweet::API::Statuses
|
||||
} // namespace CocoaTweet::API::DirectMessages
|
||||
|
||||
#endif
|
||||
|
||||
@@ -53,7 +53,7 @@ void HttpPost::process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth,
|
||||
("Content-Disposition: form-data; name=\"" + key + "\";\r\n\r\n" + value + "\r\n");
|
||||
}
|
||||
requestBody += (std::string("--") + "milkcocoa0902" + "--" + "\r\n");
|
||||
}else if(contentType_ == "application/json"){
|
||||
} else if (contentType_ == "application/json") {
|
||||
requestBody = bodyParam_["data"];
|
||||
}
|
||||
}
|
||||
@@ -97,7 +97,7 @@ void HttpPost::process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth,
|
||||
contentType = contentType_;
|
||||
} else if (contentType_ == "multipart/form-data") {
|
||||
contentType = contentType_ + "; boundary=milkcocoa0902";
|
||||
}else if(contentType_ == "application/json"){
|
||||
} else if (contentType_ == "application/json") {
|
||||
contentType_ = "application/json";
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user