Merge pull request #10 from milkcocoa0902/develop
merge branch develop into master
This commit is contained in:
@@ -17,6 +17,7 @@ you can use these endpoint
|
||||
- favorites/create
|
||||
- favorites/destroy
|
||||
- media/upload(support: jpg, jpeg, png, gif, mp4)
|
||||
- direct_messages/events/new (message_create)
|
||||
|
||||
# Dependency
|
||||
- libcurl(openssl version)
|
||||
@@ -142,6 +143,10 @@ api.favorite().Destroy("tweet id");
|
||||
// get a timeline with screen name
|
||||
auto timeline = api.status().UserTimeline("milkcocoa0902");
|
||||
|
||||
// send a direct message
|
||||
// you cau get recipient_id using https://idtwi.com/
|
||||
api.directMessage().messageCreate("<recipient_id>", "Sent message using Cocoa Twitter Library");
|
||||
|
||||
```
|
||||
|
||||
# More Information
|
||||
|
||||
@@ -2,10 +2,11 @@
|
||||
|
||||
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_);
|
||||
}
|
||||
|
||||
Statuses::Status API::status() const {
|
||||
@@ -19,4 +20,8 @@ Favorites::Favorite API::favorite() const {
|
||||
Medias::Media API::media() const {
|
||||
return media_;
|
||||
}
|
||||
|
||||
DirectMessages::DirectMessage API::directMessage() const {
|
||||
return directMessage_;
|
||||
}
|
||||
} // namespace CocoaTweet::API
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <cocoatweet/api/status/status.h>
|
||||
#include <cocoatweet/api/favorite/favorite.h>
|
||||
#include <cocoatweet/api/media/media.h>
|
||||
#include <cocoatweet/api/directMessage/directMessage.h>
|
||||
#include <cocoatweet/oauth/oauth.h>
|
||||
|
||||
namespace CocoaTweet::API {
|
||||
@@ -24,10 +25,13 @@ public:
|
||||
|
||||
Medias::Media media() const;
|
||||
|
||||
DirectMessages::DirectMessage directMessage() const;
|
||||
|
||||
private:
|
||||
Statuses::Status status_;
|
||||
Favorites::Favorite favorite_;
|
||||
Medias::Media media_;
|
||||
DirectMessages::DirectMessage directMessage_;
|
||||
std::shared_ptr<CocoaTweet::OAuth::OAuth1> oauth_;
|
||||
};
|
||||
} // namespace CocoaTweet::API
|
||||
|
||||
@@ -0,0 +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
|
||||
@@ -0,0 +1,27 @@
|
||||
#ifndef COCOATWEET_API_DIRECTMESSAGE_DIRECTMESSAGE_H_
|
||||
#define COCOATWEET_API_DIRECTMESSAGE_DIRECTMESSAGE_H_
|
||||
|
||||
#include "cocoatweet/api/interface/groupInterface.h"
|
||||
#include "cocoatweet/oauth/oauth.h"
|
||||
#include <cocoatweet/api/model/tweet.h>
|
||||
#include <vector>
|
||||
#include <utility>
|
||||
|
||||
namespace CocoaTweet::API::DirectMessages {
|
||||
|
||||
/// @brief Entory point for statuses/*
|
||||
class DirectMessage : public groupInterface {
|
||||
public:
|
||||
DirectMessage() = default;
|
||||
|
||||
/// @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::DirectMessages
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,30 @@
|
||||
#include <cocoatweet/api/directMessage/new.h>
|
||||
#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";
|
||||
|
||||
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<CocoaTweet::OAuth::OAuth1> _oauth) {
|
||||
bodyParam_.insert_or_assign("data", json_.dump());
|
||||
HttpPost::process(_oauth, [](const std::string& _rcv) {});
|
||||
}
|
||||
} // namespace CocoaTweet::API::DirectMessages
|
||||
@@ -0,0 +1,30 @@
|
||||
#ifndef COCOATWEET_API_DIRECTMESSAGE_NEW_H_
|
||||
#define COCOATWEET_API_DIRECTMESSAGE_NEW_H_
|
||||
|
||||
#include <cocoatweet/api/interface/httpPost.h>
|
||||
#include <cocoatweet/api/model/tweet.h>
|
||||
#include <vector>
|
||||
#include <utility>
|
||||
#include <memory>
|
||||
#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<CocoaTweet::OAuth::OAuth1> _oauth : pointer to oauth object
|
||||
/// @param[out] CocoaTweet::API::Model::Tweet : request result
|
||||
void process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth);
|
||||
|
||||
private:
|
||||
std::string status_;
|
||||
nlohmann::json json_;
|
||||
};
|
||||
} // namespace CocoaTweet::API::DirectMessages
|
||||
|
||||
#endif
|
||||
@@ -53,6 +53,8 @@ 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") {
|
||||
requestBody = bodyParam_["data"];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,6 +97,8 @@ 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") {
|
||||
contentType_ = "application/json";
|
||||
}
|
||||
|
||||
headers = curl_slist_append(headers, ("Content-Type: " + contentType).c_str());
|
||||
|
||||
Reference in New Issue
Block a user