From 227742748d54c3870728c3a09ea3db66bc6a0dab Mon Sep 17 00:00:00 2001 From: keita Date: Thu, 1 Apr 2021 21:50:28 +0900 Subject: [PATCH] =?UTF-8?q?direct=5Fmaggages/event/new=E3=82=92=E3=81=9F?= =?UTF-8?q?=E3=81=9F=E3=81=8F=E3=82=84=E3=81=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/cocoatweet/api/directMessage/new.cc | 31 ++++++++++++++++++++++++ src/cocoatweet/api/directMessage/new.h | 32 +++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 src/cocoatweet/api/directMessage/new.cc create mode 100644 src/cocoatweet/api/directMessage/new.h diff --git a/src/cocoatweet/api/directMessage/new.cc b/src/cocoatweet/api/directMessage/new.cc new file mode 100644 index 0000000..34220e6 --- /dev/null +++ b/src/cocoatweet/api/directMessage/new.cc @@ -0,0 +1,31 @@ +#include +#include +#include + +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; + } + + + 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::process(std::weak_ptr _oauth){ + bodyParam_.insert_or_assign("data", json_.dump()); + HttpPost::process(_oauth, [](const std::string& _rcv){}); + } +} \ No newline at end of file diff --git a/src/cocoatweet/api/directMessage/new.h b/src/cocoatweet/api/directMessage/new.h new file mode 100644 index 0000000..2cb3647 --- /dev/null +++ b/src/cocoatweet/api/directMessage/new.h @@ -0,0 +1,32 @@ +#ifndef COCOATWEET_API_DIRECTMESSAGE_NEW_H_ +#define COCOATWEET_API_DIRECTMESSAGE_NEW_H_ + +#include +#include +#include +#include +#include +#include "nlohmann/json.hpp" + +namespace CocoaTweet::API::DirectMessages { +/// @brief class for using statuses/update endpoint +class New : public CocoaTweet::API::Interface::HttpPost { +public: + New(); + void recipient(const std::string& _id); + void message(const std::string& _message); + + + + /// @brief process request for endpoint + /// @param[in] std::weak_ptr _oauth : pointer to oauth object + /// @param[out] CocoaTweet::API::Model::Tweet : request result + void process(std::weak_ptr _oauth); + +private: + std::string status_; + nlohmann::json json_; +}; +} // namespace CocoaTweet::API::Statuses + +#endif