Merge pull request #8 from milkcocoa0902/develop
merge branch develop into master
This commit is contained in:
+13
-2
@@ -22,7 +22,10 @@ set(CXX_STANDARD_REQUIRED ON)
|
|||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic")
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic")
|
||||||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g -DDEBUG")
|
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g -DDEBUG")
|
||||||
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2 -march=native -DNDEBUG")
|
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2 -march=native -DNDEBUG")
|
||||||
if(UNIX)
|
|
||||||
|
|
||||||
|
if(UNIX AND (NOT APPLE))
|
||||||
|
message(STATUS "afiejanfonw")
|
||||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-O1,--sort-common,--as-needed,-z,relro")
|
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-O1,--sort-common,--as-needed,-z,relro")
|
||||||
elseif(WIN32 OR APPLE)
|
elseif(WIN32 OR APPLE)
|
||||||
#set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-O1,--sort-common,--as-needed")
|
#set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-O1,--sort-common,--as-needed")
|
||||||
@@ -65,7 +68,15 @@ endif()
|
|||||||
|
|
||||||
|
|
||||||
# Search OpenSSL
|
# Search OpenSSL
|
||||||
if(UNIX OR APPLE)
|
if (APPLE)
|
||||||
|
# This is a bug in CMake that causes it to prefer the system version over
|
||||||
|
# the one in the specified ROOT folder.
|
||||||
|
find_package(PkgConfig REQUIRED)
|
||||||
|
find_package(OpenSSL REQUIRED)
|
||||||
|
set(OPENSSL_CRYPTO_LIBRARY ${OPENSSL_ROOT_DIR}/lib/libcrypto.dylib CACHE FILEPATH "" FORCE)
|
||||||
|
set(OPENSSL_SSL_LIBRARY ${OPENSSL_ROOT_DIR}/lib/libssl.dylib CACHE FILEPATH "" FORCE)
|
||||||
|
set(OPENSSL_LIBRARIES ${OPENSSL_CRYPTO_LIBRARY} ${OPENSSL_SSL_LIBRARY})
|
||||||
|
elseif(UNIX)
|
||||||
find_package(PkgConfig REQUIRED)
|
find_package(PkgConfig REQUIRED)
|
||||||
find_package(OpenSSL REQUIRED)
|
find_package(OpenSSL REQUIRED)
|
||||||
if(NOT OPENSSL_FOUND)
|
if(NOT OPENSSL_FOUND)
|
||||||
|
|||||||
@@ -935,6 +935,7 @@ EXCLUDE_SYMLINKS = NO
|
|||||||
|
|
||||||
EXCLUDE_PATTERNS = */third/*
|
EXCLUDE_PATTERNS = */third/*
|
||||||
EXCLUDE_PATTERNS += */build/*
|
EXCLUDE_PATTERNS += */build/*
|
||||||
|
EXCLUDE_PATTERNS += */test/*
|
||||||
|
|
||||||
# The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names
|
# The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names
|
||||||
# (namespaces, classes, functions, etc.) that should be excluded from the
|
# (namespaces, classes, functions, etc.) that should be excluded from the
|
||||||
|
|||||||
@@ -10,14 +10,16 @@ This is a library for using Twitter API from C++
|
|||||||
you can use these endpoint
|
you can use these endpoint
|
||||||
- statuses/update
|
- statuses/update
|
||||||
- statuses/destroy/:id
|
- statuses/destroy/:id
|
||||||
|
- statuses/retweet/:id
|
||||||
- favorites/create
|
- favorites/create
|
||||||
- favorites/destroy
|
- favorites/destroy
|
||||||
|
- media/upload(support: jpg, jpeg, png, gif, mp4)
|
||||||
|
|
||||||
# Dependency
|
# Dependency
|
||||||
- libcurl(openssl version)
|
- libcurl(openssl version)
|
||||||
- libssl
|
- libssl
|
||||||
|
|
||||||
# Instllation
|
# Installation
|
||||||
## Ubuntu
|
## Ubuntu
|
||||||
```
|
```
|
||||||
# apt install clang cmake git libboost-dev libboost-test-dev libcurl4-openssl-dev libssl-dev nunja-build
|
# apt install clang cmake git libboost-dev libboost-test-dev libcurl4-openssl-dev libssl-dev nunja-build
|
||||||
@@ -29,6 +31,17 @@ $ cmake .. -G Ninja
|
|||||||
$ ninja
|
$ ninja
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## macOS
|
||||||
|
```
|
||||||
|
$ brew install cmake curl git ninja openssl pkg-config
|
||||||
|
$ git clone https://github.com/koron0902/CocoaTweet
|
||||||
|
$ cd CocoaTweet
|
||||||
|
$ mkdir build
|
||||||
|
$ cd build
|
||||||
|
$ cmake .. -G ninja -DOPENSSL_ROOT_DIR=<path/to/openssl/install> # CANNOT detect libssl automatically with homebrew and cmake bug
|
||||||
|
$ ninja
|
||||||
|
```
|
||||||
|
|
||||||
## Windows
|
## Windows
|
||||||
- Get MinGW32 from [here](https://osdn.net/projects/mingw/downloads/68260/mingw-get-setup.exe/)(start download automatically at open link)
|
- Get MinGW32 from [here](https://osdn.net/projects/mingw/downloads/68260/mingw-get-setup.exe/)(start download automatically at open link)
|
||||||
- Install `mingw32-base-bin` and `mingw32-gcc-g+-bin` via MinGW32
|
- Install `mingw32-base-bin` and `mingw32-gcc-g+-bin` via MinGW32
|
||||||
@@ -103,6 +116,14 @@ CocoaTweet::API::API api(key);
|
|||||||
// Post a tweet
|
// Post a tweet
|
||||||
api.status().Update("Hello, World!!\nTweet from Cocoa Twitter Library");
|
api.status().Update("Hello, World!!\nTweet from Cocoa Twitter Library");
|
||||||
|
|
||||||
|
// Upload a media
|
||||||
|
auto media1 = api.media().Upload("path/to/file/image.jpeg");
|
||||||
|
auto media2 = api.media().Upload("path/to/file/image2.png");
|
||||||
|
api.status().Update("Upload media from Cocoa Twitter Library", std::vector<std::string>{media1.id(), media2.id()});
|
||||||
|
|
||||||
|
// Retweet a tweet
|
||||||
|
api.status().Retweet("tweet id");
|
||||||
|
|
||||||
// Delete a tweet
|
// Delete a tweet
|
||||||
api.status().Destroy("tweet id");
|
api.status().Destroy("tweet id");
|
||||||
|
|
||||||
@@ -112,3 +133,5 @@ api.favorite().Create("tweet id");
|
|||||||
// un Fav. a tweet
|
// un Fav. a tweet
|
||||||
api.favorite().Destroy("tweet id");
|
api.favorite().Destroy("tweet id");
|
||||||
```
|
```
|
||||||
|
|
||||||
|
donate by BitCoin : bc1qhpm8tmq72scqpl2ccemcf0ktfjg4rsu73e99tz
|
||||||
@@ -5,6 +5,7 @@ API::API(CocoaTweet::OAuth::Key _key) {
|
|||||||
oauth_ = std::make_shared<CocoaTweet::OAuth::OAuth1>(_key);
|
oauth_ = std::make_shared<CocoaTweet::OAuth::OAuth1>(_key);
|
||||||
status_ = Statuses::Status(oauth_);
|
status_ = Statuses::Status(oauth_);
|
||||||
favorite_ = Favorites::Favorite(oauth_);
|
favorite_ = Favorites::Favorite(oauth_);
|
||||||
|
media_ = Medias::Media(oauth_);
|
||||||
}
|
}
|
||||||
|
|
||||||
Statuses::Status API::status() const {
|
Statuses::Status API::status() const {
|
||||||
@@ -14,4 +15,8 @@ Statuses::Status API::status() const {
|
|||||||
Favorites::Favorite API::favorite() const {
|
Favorites::Favorite API::favorite() const {
|
||||||
return favorite_;
|
return favorite_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Medias::Media API::media() const {
|
||||||
|
return media_;
|
||||||
|
}
|
||||||
} // namespace CocoaTweet::API
|
} // namespace CocoaTweet::API
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#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/api/media/media.h>
|
||||||
#include <cocoatweet/oauth/oauth.h>
|
#include <cocoatweet/oauth/oauth.h>
|
||||||
|
|
||||||
namespace CocoaTweet::API {
|
namespace CocoaTweet::API {
|
||||||
@@ -21,9 +22,12 @@ public:
|
|||||||
/// @param[out] Favorite object typed CococaTweet::API::Favorites::Favorite
|
/// @param[out] Favorite object typed CococaTweet::API::Favorites::Favorite
|
||||||
Favorites::Favorite favorite() const;
|
Favorites::Favorite favorite() const;
|
||||||
|
|
||||||
|
Medias::Media media() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Statuses::Status status_;
|
Statuses::Status status_;
|
||||||
Favorites::Favorite favorite_;
|
Favorites::Favorite favorite_;
|
||||||
|
Medias::Media media_;
|
||||||
std::shared_ptr<CocoaTweet::OAuth::OAuth1> oauth_;
|
std::shared_ptr<CocoaTweet::OAuth::OAuth1> oauth_;
|
||||||
};
|
};
|
||||||
} // namespace CocoaTweet::API
|
} // namespace CocoaTweet::API
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
#ifndef COCOATWEET_API_INTERFACE_HTTPBASE_H_
|
||||||
|
#define COCOATWEET_API_INTERFACE_HTTPBASE_H_
|
||||||
|
|
||||||
|
#include <functional>
|
||||||
|
#include "cocoatweet/oauth/oauth.h"
|
||||||
|
|
||||||
|
namespace CocoaTweet::API::Interface {
|
||||||
|
class HttpBase {
|
||||||
|
public:
|
||||||
|
protected:
|
||||||
|
std::weak_ptr<CocoaTweet::OAuth::OAuth1> oauth_;
|
||||||
|
std::map<std::string, std::string> bodyParam_;
|
||||||
|
std::string url_;
|
||||||
|
std::string contentType_;
|
||||||
|
virtual void process(
|
||||||
|
std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth,
|
||||||
|
std::function<void(const unsigned int, const std::string&)> _callback) = 0;
|
||||||
|
static size_t curlCallback_(char* _ptr, size_t _size, size_t _nmemb, std::string* _stream) {
|
||||||
|
int realsize = _size * _nmemb;
|
||||||
|
_stream->append(_ptr, realsize);
|
||||||
|
return realsize;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
} // namespace CocoaTweet::API::Interface
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -9,13 +9,11 @@ extern "C" {
|
|||||||
#include <curl/curl.h>
|
#include <curl/curl.h>
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace CocoaTweet::API::Interface {
|
#ifndef NDEBUG
|
||||||
size_t HttpPost::curlCallback_(char* _ptr, size_t _size, size_t _nmemb, std::string* _stream) {
|
#include <iostream>
|
||||||
int realsize = _size * _nmemb;
|
#endif
|
||||||
_stream->append(_ptr, realsize);
|
|
||||||
return realsize;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
namespace CocoaTweet::API::Interface {
|
||||||
void HttpPost::process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth,
|
void HttpPost::process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth,
|
||||||
std::function<void(const unsigned int, const std::string&)> _callback) {
|
std::function<void(const unsigned int, const std::string&)> _callback) {
|
||||||
// エンドポイントへのパラメータにOAuthパラメータを付加して署名作成
|
// エンドポイントへのパラメータにOAuthパラメータを付加して署名作成
|
||||||
@@ -36,11 +34,20 @@ void HttpPost::process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth,
|
|||||||
// リクエストボディの構築
|
// リクエストボディの構築
|
||||||
std::string requestBody = "";
|
std::string requestBody = "";
|
||||||
{
|
{
|
||||||
std::vector<std::string> tmp;
|
if (contentType_ == "application/x-www-form-urlencoded") {
|
||||||
for (const auto& [key, value] : bodyParam_) {
|
std::vector<std::string> tmp;
|
||||||
tmp.push_back(key + "=" + value);
|
for (const auto& [key, value] : bodyParam_) {
|
||||||
|
tmp.push_back(key + "=" + value);
|
||||||
|
requestBody = CocoaTweet::Util::join(tmp, "&");
|
||||||
|
}
|
||||||
|
} else if (contentType_ == "multipart/form-data") {
|
||||||
|
for (const auto& [key, value] : bodyParam_) {
|
||||||
|
requestBody += (std::string("--") + "milkcocoa0902" + "\r\n");
|
||||||
|
requestBody +=
|
||||||
|
("Content-Disposition: form-data; name=\"" + key + "\";\r\n\r\n" + value + "\r\n");
|
||||||
|
}
|
||||||
|
requestBody += (std::string("--") + "milkcocoa0902" + "--" + "\r\n");
|
||||||
}
|
}
|
||||||
requestBody = CocoaTweet::Util::join(tmp, "&");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ヘッダの構築
|
// ヘッダの構築
|
||||||
@@ -69,12 +76,22 @@ void HttpPost::process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth,
|
|||||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, curlCallback_);
|
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, curlCallback_);
|
||||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (std::string*)&rcv);
|
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (std::string*)&rcv);
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
|
std::cout << "requestBody : " << requestBody << std::endl;
|
||||||
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
|
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
|
||||||
#endif
|
#endif
|
||||||
// Headerを保持するcurl_slist*を初期化
|
// Headerを保持するcurl_slist*を初期化
|
||||||
struct curl_slist* headers = NULL;
|
struct curl_slist* headers = NULL;
|
||||||
// Authorizationをヘッダに追加
|
// Authorizationをヘッダに追加
|
||||||
headers = curl_slist_append(headers, oauthHeader.c_str());
|
headers = curl_slist_append(headers, oauthHeader.c_str());
|
||||||
|
|
||||||
|
std::string contentType = "";
|
||||||
|
if (contentType_ == "application/x-www-form-urlencoded") {
|
||||||
|
contentType = contentType_;
|
||||||
|
} else if (contentType_ == "multipart/form-data") {
|
||||||
|
contentType = contentType_ + "; boundary=milkcocoa0902";
|
||||||
|
}
|
||||||
|
|
||||||
|
headers = curl_slist_append(headers, ("Content-Type: " + contentType).c_str());
|
||||||
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
|
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
|
||||||
res = curl_easy_perform(curl);
|
res = curl_easy_perform(curl);
|
||||||
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &responseCode);
|
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &responseCode);
|
||||||
|
|||||||
@@ -3,18 +3,20 @@
|
|||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include "cocoatweet/oauth/oauth.h"
|
#include "cocoatweet/oauth/oauth.h"
|
||||||
|
#include <cocoatweet/api/interface/httpBase.h>
|
||||||
|
|
||||||
namespace CocoaTweet::API::Interface {
|
namespace CocoaTweet::API::Interface {
|
||||||
class HttpPost {
|
/// @brief class for Send request with POST method
|
||||||
|
class HttpPost : public HttpBase {
|
||||||
public:
|
public:
|
||||||
protected:
|
protected:
|
||||||
std::weak_ptr<CocoaTweet::OAuth::OAuth1> oauth_;
|
/// @brief Send HTTP/POST using OAuth object
|
||||||
std::map<std::string, std::string> bodyParam_;
|
/// @param[in] std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth : pointer to OAuth object to
|
||||||
std::string url_;
|
/// authenticate
|
||||||
std::string contentType_;
|
/// @param[in] std::function<void(const unsigned int, const std::string&)> _callback :
|
||||||
|
/// callback method for processing to response
|
||||||
void process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth,
|
void process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth,
|
||||||
std::function<void(const unsigned int, const std::string&)> _callback);
|
std::function<void(const unsigned int, const std::string&)> _callback);
|
||||||
static size_t curlCallback_(char* _ptr, size_t _size, size_t _nmemb, std::string* _stream);
|
|
||||||
};
|
};
|
||||||
} // namespace CocoaTweet::API::Interface
|
} // namespace CocoaTweet::API::Interface
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
#include "cocoatweet/api/media/media.h"
|
||||||
|
|
||||||
|
namespace CocoaTweet::API::Medias {
|
||||||
|
Media::Media(std::shared_ptr<CocoaTweet::OAuth::OAuth1> _oauth) {
|
||||||
|
oauth_ = _oauth;
|
||||||
|
}
|
||||||
|
|
||||||
|
CocoaTweet::API::Model::MediaStore Media::Upload(const std::string& _media) const {
|
||||||
|
CocoaTweet::API::Medias::Upload upload;
|
||||||
|
upload.media(_media);
|
||||||
|
return upload.process(oauth_);
|
||||||
|
}
|
||||||
|
} // namespace CocoaTweet::API::Medias
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
#ifndef COCOATWEET_API_MEDIA_MEDIA_H_
|
||||||
|
#define COCOATWEET_API_MEDIA_MEDIA_H_
|
||||||
|
|
||||||
|
#include "cocoatweet/api/interface/groupInterface.h"
|
||||||
|
#include "cocoatweet/oauth/oauth.h"
|
||||||
|
#include <cocoatweet/api/model/mediaStore.h>
|
||||||
|
#include <cocoatweet/api/media/upload.h>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
namespace CocoaTweet::API::Medias {
|
||||||
|
|
||||||
|
/// @brief Entory point for statuses/*
|
||||||
|
class Media : public groupInterface {
|
||||||
|
public:
|
||||||
|
/// @brief primary constructor to allow for create NON-INITIALIZED object
|
||||||
|
Media() = default;
|
||||||
|
|
||||||
|
/// @brief constructor which finally should to be called.
|
||||||
|
/// @param[in] std::shared_ptr<CocoaTweet::OAuth::OAuth1> : pointer to OAuth object
|
||||||
|
Media(std::shared_ptr<CocoaTweet::OAuth::OAuth1> _oauth);
|
||||||
|
|
||||||
|
CocoaTweet::API::Model::MediaStore Upload(const std::string& _file) const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
};
|
||||||
|
} // namespace CocoaTweet::API::Medias
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,93 @@
|
|||||||
|
#include <cocoatweet/api/media/upload.h>
|
||||||
|
#include <cocoatweet/api/model/mediaStore.h>
|
||||||
|
#include <cocoatweet/exception/unsupportedMediaTypeException.h>
|
||||||
|
#include <fstream>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
namespace CocoaTweet::API::Medias {
|
||||||
|
const std::map<std::string, std::string> Upload::mimeType = {{".jpg", "image/jpeg"},
|
||||||
|
{".jpeg", "image/jpeg"},
|
||||||
|
{".png", "image/png"},
|
||||||
|
{".gif", "image/gif"},
|
||||||
|
{".mp4", "video/mp4"}};
|
||||||
|
Upload::Upload() {
|
||||||
|
url_ = "https://upload.twitter.com/1.1/media/upload.json";
|
||||||
|
}
|
||||||
|
|
||||||
|
void Upload::media(const std::string& _media) {
|
||||||
|
media_ = _media;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Upload::mediaId(const std::string& _mediaId) {}
|
||||||
|
|
||||||
|
CocoaTweet::API::Model::MediaStore Upload::process(
|
||||||
|
std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth) {
|
||||||
|
auto extension = std::filesystem::path(media_).extension().string<char>();
|
||||||
|
if (mimeType.count(extension) == 0) {
|
||||||
|
throw new CocoaTweet::Exception::UnsupportedMediaTypeException(
|
||||||
|
std::string("media type \"" + extension + "\" is not supported media type"));
|
||||||
|
}
|
||||||
|
|
||||||
|
auto backup = bodyParam_;
|
||||||
|
CocoaTweet::API::Model::MediaStore media;
|
||||||
|
std::ifstream ifs(media_, std::ios::binary);
|
||||||
|
std::string data((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>());
|
||||||
|
ifs.close();
|
||||||
|
|
||||||
|
bodyParam_.insert_or_assign("total_bytes", std::to_string(data.size()));
|
||||||
|
|
||||||
|
// INIT
|
||||||
|
{
|
||||||
|
contentType_ = "application/x-www-form-urlencoded";
|
||||||
|
bodyParam_.insert_or_assign("command", "INIT");
|
||||||
|
bodyParam_.insert_or_assign(
|
||||||
|
"media_type", mimeType.at(std::filesystem::path(media_).extension().string<char>()));
|
||||||
|
|
||||||
|
HttpPost::process(_oauth,
|
||||||
|
[&media](const unsigned int _responseCode, const std::string& _rsv) {
|
||||||
|
media = CocoaTweet::API::Model::MediaStore::parse(_responseCode, _rsv);
|
||||||
|
});
|
||||||
|
|
||||||
|
bodyParam_.insert_or_assign("media_id", media.id());
|
||||||
|
}
|
||||||
|
|
||||||
|
// APPEND
|
||||||
|
{
|
||||||
|
contentType_ = "multipart/form-data";
|
||||||
|
bodyParam_.erase("media_type");
|
||||||
|
bodyParam_.erase("total_bytes");
|
||||||
|
|
||||||
|
unsigned int segment = 0;
|
||||||
|
const unsigned long long chunk = 1024 * 512;
|
||||||
|
while (segment * chunk < data.size()) {
|
||||||
|
bodyParam_.insert_or_assign("command", "APPEND");
|
||||||
|
bodyParam_.insert_or_assign("segment_index", std::to_string(segment));
|
||||||
|
bodyParam_.insert_or_assign("media", data.substr(segment * chunk, chunk));
|
||||||
|
HttpPost::process(_oauth, [](const unsigned int _responseCode, const std::string& _rsv) {
|
||||||
|
// std::cout << _responseCode << std::endl << _rsv<< std::endl;
|
||||||
|
});
|
||||||
|
segment++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// FINALIZE
|
||||||
|
{
|
||||||
|
contentType_ = "application/x-www-form-urlencoded";
|
||||||
|
bodyParam_.insert_or_assign("command", "FINALIZE");
|
||||||
|
bodyParam_.erase("segment_index");
|
||||||
|
bodyParam_.erase("media");
|
||||||
|
HttpPost::process(_oauth,
|
||||||
|
[&media](const unsigned int _responseCode, const std::string& _rsv) {
|
||||||
|
std::cout << _responseCode << std::endl << _rsv << std::endl;
|
||||||
|
media = CocoaTweet::API::Model::MediaStore::parse(_responseCode, _rsv);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// STATUS if needed
|
||||||
|
{}
|
||||||
|
|
||||||
|
bodyParam_ = backup;
|
||||||
|
|
||||||
|
return media;
|
||||||
|
}
|
||||||
|
} // namespace CocoaTweet::API::Medias
|
||||||
|
|||||||
@@ -1,22 +1,37 @@
|
|||||||
#ifndef COCOATWEET_API_MEDIA_UPLOAD_H_
|
#ifndef COCOATWEET_API_MEDIA_UPLOAD_H_
|
||||||
#define COCOATWEET_API_MEDIA_UPLOAD_H_
|
#define COCOATWEET_API_MEDIA_UPLOAD_H_
|
||||||
|
|
||||||
#include <cocoatweet/api/interface/postInterface.h>
|
#include <cocoatweet/api/interface/httpPost.h>
|
||||||
|
#include <cocoatweet/api/model/mediaStore.h>
|
||||||
|
#include <string>
|
||||||
|
#include <filesystem>
|
||||||
|
|
||||||
namespace CocoaTweet::API::Medias {
|
namespace CocoaTweet::API::Medias {
|
||||||
class Upload : public postInterface {
|
/// @brief entry point for using media/upload endpoint
|
||||||
public:
|
class Upload : public CocoaTweet::API::Interface::HttpPost {
|
||||||
enum Command : class st::string {
|
private:
|
||||||
INIT = "INIT",
|
std::string media_;
|
||||||
APPEND = "APPEND",
|
static const std::map<std::string, std::string> mimeType;
|
||||||
FINALIZE = "FINALIZE",
|
|
||||||
};
|
|
||||||
|
|
||||||
Upload::Upload();
|
public:
|
||||||
|
/// @brief default constructor
|
||||||
|
Upload();
|
||||||
|
|
||||||
|
/// @brief set media file with absolute path
|
||||||
|
/// @param[in] const std::string& _media : absolute path to media should be uploaded
|
||||||
|
/// @param[out] none
|
||||||
void media(const std::string& _media);
|
void media(const std::string& _media);
|
||||||
void mediaId(const std::string _mediaId);
|
|
||||||
void process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth, Command _command);
|
/// @brief set media id(no affect to process. will be obsoleted)
|
||||||
}
|
void mediaId(const std::string& _mediaId);
|
||||||
|
|
||||||
|
/// @brief upload media
|
||||||
|
/// @param[in] std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth : pointer to OAuth object for
|
||||||
|
/// authenticate
|
||||||
|
/// @param[out] CocoaTweet::API::Model::MediaStore : media upload result. use id() for post
|
||||||
|
/// tweet.
|
||||||
|
CocoaTweet::API::Model::MediaStore process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth);
|
||||||
|
};
|
||||||
} // namespace CocoaTweet::API::Medias
|
} // namespace CocoaTweet::API::Medias
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -0,0 +1,71 @@
|
|||||||
|
#include <cocoatweet/api/model/mediaStore.h>
|
||||||
|
#include <cocoatweet/exception/exception.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 {
|
||||||
|
throw new CocoaTweet::Exception::Exception(j["error"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
@@ -0,0 +1,90 @@
|
|||||||
|
#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 MediaStore 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::MediaStore
|
||||||
|
static MediaStore parse(const unsigned int _responseCode, const std::string& _json);
|
||||||
|
|
||||||
|
/// @brief set id of tweet
|
||||||
|
/// @param[in] const std::string _id : media id to set
|
||||||
|
/// @param[out] none
|
||||||
|
void id(const std::string _id);
|
||||||
|
|
||||||
|
/// @brief set media size in byte
|
||||||
|
/// @param[in] const unsigned int _size : media size in byte
|
||||||
|
/// @param[out] none
|
||||||
|
void size(const unsigned int _size);
|
||||||
|
|
||||||
|
/// @brief set remaining time to expire the media
|
||||||
|
/// @param[in] const unsigned int : remaining time to expire the media ib sec
|
||||||
|
/// @param[out] none
|
||||||
|
void expires(const unsigned int _ex);
|
||||||
|
|
||||||
|
/// @brief set media processing status
|
||||||
|
/// @param[in] const std::string _state : media processed status
|
||||||
|
/// @param[out] none
|
||||||
|
void state(const std::string _state);
|
||||||
|
|
||||||
|
/// @brief set how second need for upload complete
|
||||||
|
/// @param[in] needed time to upload complete on server in second
|
||||||
|
/// @param[out] none
|
||||||
|
void remain(const unsigned int _remain);
|
||||||
|
|
||||||
|
/// @brief get media id
|
||||||
|
/// @param[in] none
|
||||||
|
/// @param[out] const std::string : media id
|
||||||
|
const std::string id() const;
|
||||||
|
|
||||||
|
/// @brief get media size
|
||||||
|
/// @param[in] none
|
||||||
|
/// @param[out] const unsigned int : media size in byte
|
||||||
|
const unsigned int size() const;
|
||||||
|
|
||||||
|
/// @brief get remaining time to expire the media
|
||||||
|
/// @param[in] none
|
||||||
|
/// @param[out] const unsigned int : remaining time to expire the media ib sec
|
||||||
|
const unsigned int expire() const;
|
||||||
|
|
||||||
|
/// @brief get media processing status
|
||||||
|
/// @param[in] none
|
||||||
|
/// @param[out] const std::string _state : media processed status
|
||||||
|
const std::string state() const;
|
||||||
|
|
||||||
|
/// @brief set how second need for upload complete
|
||||||
|
/// @param[in] none
|
||||||
|
/// @param[out] needed time to upload complete on server in second
|
||||||
|
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
|
||||||
@@ -4,20 +4,68 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace CocoaTweet::API::Model {
|
namespace CocoaTweet::API::Model {
|
||||||
|
|
||||||
|
/// @brief data class for tweet object
|
||||||
class Tweet final {
|
class Tweet final {
|
||||||
public:
|
public:
|
||||||
Tweet() = default;
|
/// @brief constructor
|
||||||
|
Tweet() = default;
|
||||||
|
|
||||||
|
/// @brief copy constructor
|
||||||
Tweet(const Tweet&) = default;
|
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(const unsigned int _responseCode, const std::string& _json)
|
||||||
: Tweet(Tweet::parse(_responseCode, _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);
|
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);
|
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);
|
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);
|
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);
|
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;
|
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;
|
const std::string createdAt() const;
|
||||||
|
|
||||||
|
/// @brief get tweet text
|
||||||
|
/// @param[in] none
|
||||||
|
/// @param[out] const std::string : tweet text
|
||||||
const std::string text() const;
|
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;
|
const std::string source() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ public:
|
|||||||
|
|
||||||
/// @brief process request for endpoint
|
/// @brief process request for endpoint
|
||||||
/// @param[in] std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth : pointer to oauth object
|
/// @param[in] std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth : pointer to oauth object
|
||||||
/// @param[out] none
|
/// @param[out] CocoaTweet::API::Model::Tweet : request result
|
||||||
CocoaTweet::API::Model::Tweet process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth);
|
CocoaTweet::API::Model::Tweet process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth);
|
||||||
};
|
};
|
||||||
} // namespace CocoaTweet::API::Statuses
|
} // namespace CocoaTweet::API::Statuses
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
#include <cocoatweet/api/status/retweet.h>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
namespace CocoaTweet::API::Statuses {
|
||||||
|
Retweet::Retweet(){}
|
||||||
|
|
||||||
|
void Retweet::id(const std::string& _id){
|
||||||
|
contentType_ = "application/x-www-form-urlencoded";
|
||||||
|
url_ = "https://api.twitter.com/1.1/statuses/retweet/" + _id + ".json";
|
||||||
|
}
|
||||||
|
|
||||||
|
CocoaTweet::API::Model::Tweet Retweet::process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth){
|
||||||
|
CocoaTweet::API::Model::Tweet tweet;
|
||||||
|
HttpPost::process(_oauth,
|
||||||
|
[&tweet](const unsigned int _responseCode, const std::string& _rcv) {
|
||||||
|
tweet = CocoaTweet::API::Model::Tweet(_responseCode, _rcv);
|
||||||
|
});
|
||||||
|
|
||||||
|
return tweet;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
#ifndef COCOATWEET_API_STATUS_RETWEET_H_
|
||||||
|
#define COCOATWEET_API_STATUS_RETWEET_H_
|
||||||
|
|
||||||
|
#include <cocoatweet/api/interface/httpPost.h>
|
||||||
|
#include <cocoatweet/api/model/tweet.h>
|
||||||
|
|
||||||
|
namespace CocoaTweet::API::Statuses {
|
||||||
|
class Retweet : public CocoaTweet::API::Interface::HttpPost{
|
||||||
|
public:
|
||||||
|
Retweet();
|
||||||
|
|
||||||
|
void id(const std::string& _id);
|
||||||
|
|
||||||
|
CocoaTweet::API::Model::Tweet process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
#include "cocoatweet/api/status/status.h"
|
#include "cocoatweet/api/status/status.h"
|
||||||
#include "cocoatweet/api/status/update.h"
|
#include "cocoatweet/api/status/update.h"
|
||||||
#include "cocoatweet/api/status/destroy.h"
|
#include "cocoatweet/api/status/destroy.h"
|
||||||
|
#include "cocoatweet/api/status/retweet.h"
|
||||||
|
|
||||||
namespace CocoaTweet::API::Statuses {
|
namespace CocoaTweet::API::Statuses {
|
||||||
Status::Status(std::shared_ptr<CocoaTweet::OAuth::OAuth1> _oauth) {
|
Status::Status(std::shared_ptr<CocoaTweet::OAuth::OAuth1> _oauth) {
|
||||||
@@ -13,9 +14,67 @@ CocoaTweet::API::Model::Tweet Status::Update(const std::string& _status) const {
|
|||||||
return update.process(oauth_);
|
return update.process(oauth_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CocoaTweet::API::Model::Tweet Status::Update(const std::string& _status,
|
||||||
|
const Options _options) const {
|
||||||
|
CocoaTweet::API::Statuses::Update update;
|
||||||
|
update.status(_status);
|
||||||
|
|
||||||
|
if (_options.replyToStatusId != defaultOpt_.replyToStatusId) {
|
||||||
|
update.replyToStatusId(_options.replyToStatusId);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_options.autoPopulateReplyMetaData != defaultOpt_.autoPopulateReplyMetaData) {
|
||||||
|
update.autoPopulateReplyMetaData(_options.autoPopulateReplyMetaData);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_options.excludeReplyUserId != defaultOpt_.excludeReplyUserId) {
|
||||||
|
update.excludeReplyUserId(_options.excludeReplyUserId);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_options.attachmentUrl != defaultOpt_.attachmentUrl) {
|
||||||
|
update.attachmentUrl(_options.attachmentUrl);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_options.coord != defaultOpt_.coord) {
|
||||||
|
update.coord(_options.coord);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_options.displayCoord != defaultOpt_.displayCoord) {
|
||||||
|
update.displayCoord(_options.displayCoord);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_options.trimUser != defaultOpt_.trimUser) {
|
||||||
|
update.trimUser(_options.trimUser);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_options.enableDMCommands != defaultOpt_.enableDMCommands) {
|
||||||
|
update.enableDMCommands(_options.enableDMCommands);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_options.failDMCommands != defaultOpt_.failDMCommands) {
|
||||||
|
update.failDMCommands(_options.failDMCommands);
|
||||||
|
}
|
||||||
|
|
||||||
|
return update.process(oauth_);
|
||||||
|
}
|
||||||
|
|
||||||
|
CocoaTweet::API::Model::Tweet Status::Update(const std::string& _status,
|
||||||
|
std::vector<std::string> _mediaId) const {
|
||||||
|
CocoaTweet::API::Statuses::Update update;
|
||||||
|
update.status(_status);
|
||||||
|
update.mediaId(_mediaId);
|
||||||
|
return update.process(oauth_);
|
||||||
|
}
|
||||||
|
|
||||||
CocoaTweet::API::Model::Tweet Status::Destroy(const std::string& _id) const {
|
CocoaTweet::API::Model::Tweet Status::Destroy(const std::string& _id) const {
|
||||||
CocoaTweet::API::Statuses::Destroy destroy;
|
CocoaTweet::API::Statuses::Destroy destroy;
|
||||||
destroy.id(_id);
|
destroy.id(_id);
|
||||||
return destroy.process(oauth_);
|
return destroy.process(oauth_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CocoaTweet::API::Model::Tweet Status::Retweet(const std::string& _id) const{
|
||||||
|
CocoaTweet::API::Statuses::Retweet retweet;
|
||||||
|
retweet.id(_id);
|
||||||
|
return retweet.process(oauth_);
|
||||||
|
}
|
||||||
} // namespace CocoaTweet::API::Statuses
|
} // namespace CocoaTweet::API::Statuses
|
||||||
|
|||||||
@@ -4,16 +4,66 @@
|
|||||||
#include "cocoatweet/api/interface/groupInterface.h"
|
#include "cocoatweet/api/interface/groupInterface.h"
|
||||||
#include "cocoatweet/oauth/oauth.h"
|
#include "cocoatweet/oauth/oauth.h"
|
||||||
#include <cocoatweet/api/model/tweet.h>
|
#include <cocoatweet/api/model/tweet.h>
|
||||||
|
#include <vector>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
namespace CocoaTweet::API::Statuses {
|
namespace CocoaTweet::API::Statuses {
|
||||||
|
|
||||||
|
/// @brief Entory point for statuses/*
|
||||||
class Status : public groupInterface {
|
class Status : public groupInterface {
|
||||||
public:
|
public:
|
||||||
|
struct Options {
|
||||||
|
std::string replyToStatusId;
|
||||||
|
bool autoPopulateReplyMetaData = false;
|
||||||
|
std::vector<std::string> excludeReplyUserId;
|
||||||
|
std::string attachmentUrl;
|
||||||
|
std::pair<std::string, std::string> coord;
|
||||||
|
bool displayCoord = false;
|
||||||
|
bool trimUser = false;
|
||||||
|
bool enableDMCommands = false;
|
||||||
|
bool failDMCommands = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
/// @brief primary constructor to allow for create NON-INITIALIZED object
|
||||||
Status() = default;
|
Status() = default;
|
||||||
|
|
||||||
|
/// @brief constructor which finally should to be called.
|
||||||
|
/// @param[in] std::shared_ptr<CocoaTweet::OAuth::OAuth1> : pointer to OAuth object
|
||||||
Status(std::shared_ptr<CocoaTweet::OAuth::OAuth1> _oauth);
|
Status(std::shared_ptr<CocoaTweet::OAuth::OAuth1> _oauth);
|
||||||
|
|
||||||
|
/// @brief send request to statuses/update with specified status
|
||||||
|
/// @details this function throws CocoaTweet::Exception::* if something happen
|
||||||
|
/// @param[in] const std::string& : tweet text
|
||||||
|
/// @param[out] CocoaTweet::API::Model::Tweet : Tweet result
|
||||||
CocoaTweet::API::Model::Tweet Update(const std::string& _status) const;
|
CocoaTweet::API::Model::Tweet Update(const std::string& _status) const;
|
||||||
|
|
||||||
|
/// @brief send request to statuses/update with specified status
|
||||||
|
/// @details this function throws CocoaTweet::Exception::* if something happen
|
||||||
|
/// @param[in] const std::string& : tweet text
|
||||||
|
/// @param[in] const CocoaTweet::API::Statuses::Status::Options option : status update options
|
||||||
|
/// for more parameters
|
||||||
|
/// @param[out] CocoaTweet::API::Model::Tweet : Tweet result
|
||||||
|
CocoaTweet::API::Model::Tweet Update(const std::string& _status,
|
||||||
|
const Options _options) const;
|
||||||
|
|
||||||
|
/// @brief send request to statuses/update with specified status
|
||||||
|
/// @details this function throws CocoaTweet::Exception::* if something happen
|
||||||
|
/// @param[in] const std::string& : tweet text
|
||||||
|
/// @param[in] std::vector<std::string> _mediaId : media id which posted with tweet
|
||||||
|
/// @param[out] CocoaTweet::API::Model::Tweet : Tweet result
|
||||||
|
CocoaTweet::API::Model::Tweet Update(const std::string& _status,
|
||||||
|
std::vector<std::string> _mediaId) const;
|
||||||
|
|
||||||
|
/// @brief send request to statuses/destroy with specified id
|
||||||
|
/// @details this function throws CocoaTweet::Exception::* if something happen
|
||||||
|
/// @param[in] const std::string& : tweet id which should be delete
|
||||||
|
/// @param[out] CocoaTweet::API::Model::Tweet : Destroy result
|
||||||
CocoaTweet::API::Model::Tweet Destroy(const std::string& _id) const;
|
CocoaTweet::API::Model::Tweet Destroy(const std::string& _id) const;
|
||||||
|
|
||||||
|
CocoaTweet::API::Model::Tweet Retweet(const std::string& _id) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Options defaultOpt_;
|
||||||
};
|
};
|
||||||
} // namespace CocoaTweet::API::Statuses
|
} // namespace CocoaTweet::API::Statuses
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#include "cocoatweet/api/status/update.h"
|
#include "cocoatweet/api/status/update.h"
|
||||||
|
#include <cocoatweet/util/util.h>
|
||||||
|
|
||||||
namespace CocoaTweet::API::Statuses {
|
namespace CocoaTweet::API::Statuses {
|
||||||
Update::Update() {
|
Update::Update() {
|
||||||
@@ -11,6 +12,47 @@ void Update::status(const std::string _status) {
|
|||||||
bodyParam_.insert_or_assign("status", status_);
|
bodyParam_.insert_or_assign("status", status_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Update::mediaId(const std::vector<std::string> _media) {
|
||||||
|
bodyParam_.insert_or_assign("media_ids", CocoaTweet::Util::join(_media, ","));
|
||||||
|
}
|
||||||
|
|
||||||
|
void Update::replyToStatusId(const std::string _reply) {
|
||||||
|
bodyParam_.insert_or_assign("in_reply_to_status_id", _reply);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Update::autoPopulateReplyMetaData(bool _meta) {
|
||||||
|
bodyParam_.insert_or_assign("auto_populate_reply_metadata", std::to_string(_meta));
|
||||||
|
}
|
||||||
|
|
||||||
|
void Update::excludeReplyUserId(const std::vector<std::string> _ex) {
|
||||||
|
bodyParam_.insert_or_assign("exclude_reply_user_ids", CocoaTweet::Util::join(_ex, ","));
|
||||||
|
}
|
||||||
|
|
||||||
|
void Update::attachmentUrl(const std::string _url) {
|
||||||
|
bodyParam_.insert_or_assign("attachment_url", _url);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Update::coord(std::pair<std::string, std::string> _coord) {
|
||||||
|
bodyParam_.insert_or_assign("lat", _coord.first);
|
||||||
|
bodyParam_.insert_or_assign("long", _coord.second);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Update::displayCoord(bool _disp) {
|
||||||
|
bodyParam_.insert_or_assign("display_coordinates", std::to_string(_disp));
|
||||||
|
}
|
||||||
|
|
||||||
|
void Update::trimUser(bool _trim) {
|
||||||
|
bodyParam_.insert_or_assign("trim_user", std::to_string(_trim));
|
||||||
|
}
|
||||||
|
|
||||||
|
void Update::enableDMCommands(bool _enable) {
|
||||||
|
bodyParam_.insert_or_assign("enable_dmcommands", std::to_string(_enable));
|
||||||
|
}
|
||||||
|
|
||||||
|
void Update::failDMCommands(bool _fail) {
|
||||||
|
bodyParam_.insert_or_assign("fail_dmcommands", std::to_string(_fail));
|
||||||
|
}
|
||||||
|
|
||||||
CocoaTweet::API::Model::Tweet Update::process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth) {
|
CocoaTweet::API::Model::Tweet Update::process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth) {
|
||||||
CocoaTweet::API::Model::Tweet tweet;
|
CocoaTweet::API::Model::Tweet tweet;
|
||||||
HttpPost::process(_oauth,
|
HttpPost::process(_oauth,
|
||||||
|
|||||||
@@ -1,15 +1,47 @@
|
|||||||
#ifndef COCOATWEET_API_STATUS_UPDATE_H_
|
#ifndef COCOATWEET_API_STATUS_UPDATE_H_
|
||||||
#define COCOATWEET_API_STATUS_UPDATE_H_
|
#define COCOATWEET_API_STATUS_UPDATE_H_
|
||||||
|
|
||||||
#include <memory>
|
|
||||||
#include <cocoatweet/api/interface/httpPost.h>
|
#include <cocoatweet/api/interface/httpPost.h>
|
||||||
#include <cocoatweet/api/model/tweet.h>
|
#include <cocoatweet/api/model/tweet.h>
|
||||||
|
#include <vector>
|
||||||
|
#include <utility>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
namespace CocoaTweet::API::Statuses {
|
namespace CocoaTweet::API::Statuses {
|
||||||
|
/// @brief class for using statuses/update endpoint
|
||||||
class Update : public CocoaTweet::API::Interface::HttpPost {
|
class Update : public CocoaTweet::API::Interface::HttpPost {
|
||||||
public:
|
public:
|
||||||
|
/// @brief primary constructor
|
||||||
Update();
|
Update();
|
||||||
|
|
||||||
|
/// @brief set tweet text for sending request to statuses/update
|
||||||
|
/// @param[in] const std::string _status : tweet text
|
||||||
|
/// @param[out] none
|
||||||
void status(const std::string _status);
|
void status(const std::string _status);
|
||||||
|
|
||||||
|
void mediaId(const std::vector<std::string> _media);
|
||||||
|
|
||||||
|
void replyToStatusId(const std::string _reply);
|
||||||
|
|
||||||
|
void autoPopulateReplyMetaData(bool _meta);
|
||||||
|
|
||||||
|
void excludeReplyUserId(const std::vector<std::string> _ex);
|
||||||
|
|
||||||
|
void attachmentUrl(const std::string _url);
|
||||||
|
|
||||||
|
void coord(std::pair<std::string, std::string> _coord);
|
||||||
|
|
||||||
|
void displayCoord(bool _disp);
|
||||||
|
|
||||||
|
void trimUser(bool _trim);
|
||||||
|
|
||||||
|
void enableDMCommands(bool _enable);
|
||||||
|
|
||||||
|
void failDMCommands(bool _fail);
|
||||||
|
|
||||||
|
/// @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
|
||||||
CocoaTweet::API::Model::Tweet process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth);
|
CocoaTweet::API::Model::Tweet process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ 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)) {}
|
||||||
|
Exception(const std::string& _msg) : msg_(std::string(_msg)) {}
|
||||||
const std::string& what() {
|
const std::string& what() {
|
||||||
return msg_;
|
return msg_;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
#ifndef COCOATWEET_EXCEPTION_UNSUPPORTEDMEDIATYPEEXCEPTION_H_
|
||||||
|
#define COCOATWEET_EXCEPTION_UNSUPPORTEDMEDIATYPEEXCEPTION_H_
|
||||||
|
|
||||||
|
#include <cocoatweet/exception/exception.h>
|
||||||
|
|
||||||
|
namespace CocoaTweet::Exception {
|
||||||
|
class UnsupportedMediaTypeException final : Exception {
|
||||||
|
using Exception::Exception;
|
||||||
|
};
|
||||||
|
} // namespace CocoaTweet::Exception
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
#ifndef COCOATWEET_OAUTH_KEY_H_
|
#ifndef COCOATWEET_OAUTH_KEY_H_
|
||||||
#define COCOATWEET_OAUTH_KEY_H_
|
#define COCOATWEET_OAUTH_KEY_H_
|
||||||
|
|
||||||
|
#include <string>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
namespace CocoaTweet::OAuth {
|
namespace CocoaTweet::OAuth {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#ifndef COCOATWEET_OAUTH_OAUTH_H_
|
#ifndef COCOATWEET_OAUTH_OAUTH_H_
|
||||||
#define COCOATWEET_OAUTH_OAUTH_H_
|
#define COCOATWEET_OAUTH_OAUTH_H_
|
||||||
|
|
||||||
|
#include <string>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include "key.h"
|
#include "key.h"
|
||||||
|
|||||||
Reference in New Issue
Block a user