Compare commits
19 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 09139202dc | |||
| 41437fab52 | |||
| 397b6f3110 | |||
| 0fcff18726 | |||
| 2024368490 | |||
| dcb2565df6 | |||
| 9aa3fe1c9a | |||
| 75b2599b6b | |||
| 30e010226c | |||
| ea4cf6f562 | |||
| 7aca42a994 | |||
| 9742f20199 | |||
| c88923291e | |||
| 948613c794 | |||
| 3f6d4f3415 | |||
| 3d64272c9e | |||
| 5f230937af | |||
| 489c17f30f | |||
| c545b546b7 |
+15
-4
@@ -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)
|
||||||
@@ -108,8 +119,8 @@ include_directories(${CURL_INCLUDE_DIRS})
|
|||||||
|
|
||||||
|
|
||||||
include_directories(
|
include_directories(
|
||||||
${PROJECT_SOURCE_DIR}/src
|
${CMAKE_SOURCE_DIR}/src
|
||||||
${PROJECT_SOURCE_DIR}/third
|
${CMAKE_SOURCE_DIR}/third
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Vendored
+2
-2
@@ -26,7 +26,7 @@ pipeline {
|
|||||||
sh '''
|
sh '''
|
||||||
mkdir -p build
|
mkdir -p build
|
||||||
cd build
|
cd build
|
||||||
cmake .. -G Ninja
|
cmake .. -G Ninja -DENABLE_TEST=TRUE
|
||||||
'''
|
'''
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -47,7 +47,7 @@ pipeline {
|
|||||||
try{
|
try{
|
||||||
sh '''
|
sh '''
|
||||||
cd build
|
cd build
|
||||||
ctest --output_on_failure
|
ctest --output-on-failure
|
||||||
'''
|
'''
|
||||||
unittestBadge.setStatus('passing')
|
unittestBadge.setStatus('passing')
|
||||||
}catch(Exception error){
|
}catch(Exception error){
|
||||||
|
|||||||
@@ -6,22 +6,40 @@
|
|||||||
# CocoaTweet
|
# CocoaTweet
|
||||||
This is a library for using Twitter API from C++
|
This is a library for using Twitter API from C++
|
||||||
|
|
||||||
|
# Features
|
||||||
|
you can use these endpoint
|
||||||
|
- statuses/update
|
||||||
|
- statuses/destroy/:id
|
||||||
|
- favorites/create
|
||||||
|
- favorites/destroy
|
||||||
|
|
||||||
# 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
|
||||||
$ git clone https://github.com/koron0902/CocoaTweet
|
$ git clone https://github.com/koron0902/CocoaTweet
|
||||||
$ cd CocoaTweet // HINT : see bellow for more build faster
|
$ cd CocoaTweet
|
||||||
$ mkdir build
|
$ mkdir build
|
||||||
$ cd build
|
$ cd build
|
||||||
$ cmake .. -G Ninja
|
$ 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
|
||||||
@@ -29,10 +47,10 @@ $ ninja
|
|||||||
- Get libcurl-32bit and OpenSSL-32bit from [here](https://curl.se/windows/)
|
- Get libcurl-32bit and OpenSSL-32bit from [here](https://curl.se/windows/)
|
||||||
- Get ninja from [here](https://github.com/ninja-build/ninja/releases) and add PATH(Optional, but build faster)
|
- Get ninja from [here](https://github.com/ninja-build/ninja/releases) and add PATH(Optional, but build faster)
|
||||||
|
|
||||||
and ....
|
and then....
|
||||||
```
|
```
|
||||||
$ git clone https://github.com/koron0902/CocoaTweet
|
$ git clone https://github.com/koron0902/CocoaTweet
|
||||||
$ cd CocoaTweet // HINT : see bellow for more build faster
|
$ cd CocoaTweet
|
||||||
$ mkdir build
|
$ mkdir build
|
||||||
$ cd build
|
$ cd build
|
||||||
|
|
||||||
@@ -45,27 +63,6 @@ $ cmake .. -G "MinGW Makefiles" -DOPENSSL_ROOT_DIR=<path/to/openssl/install> -DC
|
|||||||
$ mingw32-make
|
$ mingw32-make
|
||||||
```
|
```
|
||||||
|
|
||||||
## -- HINT --
|
|
||||||
in the default, test code also linked when build.
|
|
||||||
you can build more faster modifing CMakeLists.txt
|
|
||||||
```
|
|
||||||
$ vi CMakeLists.txt (or other editor you like)
|
|
||||||
|
|
||||||
// line 73
|
|
||||||
# enable_testing()
|
|
||||||
|
|
||||||
// line 76
|
|
||||||
# add_subdirectory(test)
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
# Features
|
|
||||||
you can use these endpoint
|
|
||||||
- statuses/update
|
|
||||||
- statuses/destroy/:id
|
|
||||||
- favorites/create
|
|
||||||
- favorites/destroy
|
|
||||||
|
|
||||||
# How
|
# How
|
||||||
## API Key Registration
|
## API Key Registration
|
||||||
### 1.Write Key into code
|
### 1.Write Key into code
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#include <cocoatweet/api/favorite/create.h>
|
#include <cocoatweet/api/favorite/create.h>
|
||||||
#include <iostream>
|
#include <cocoatweet/api/model/tweet.h>
|
||||||
|
|
||||||
namespace CocoaTweet::API::Favorites {
|
namespace CocoaTweet::API::Favorites {
|
||||||
Create::Create() {
|
Create::Create() {
|
||||||
contentType_ = "application/x-www-form-urlencoded";
|
contentType_ = "application/x-www-form-urlencoded";
|
||||||
@@ -10,9 +11,13 @@ void Create::id(const std::string& _id) {
|
|||||||
bodyParam_.insert_or_assign("id", _id);
|
bodyParam_.insert_or_assign("id", _id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Create::process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth) {
|
CocoaTweet::API::Model::Tweet Create::process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth) {
|
||||||
HttpPost::process(_oauth, [](const unsigned int _, const std::string& _srv) {
|
CocoaTweet::API::Model::Tweet tweet;
|
||||||
std::cout << _srv << std::endl;
|
HttpPost::process(_oauth,
|
||||||
});
|
[&tweet](const unsigned int _responseCode, const std::string& _rcv) {
|
||||||
|
tweet = CocoaTweet::API::Model::Tweet(_responseCode, _rcv);
|
||||||
|
});
|
||||||
|
|
||||||
|
return tweet;
|
||||||
}
|
}
|
||||||
} // namespace CocoaTweet::API::Favorites
|
} // namespace CocoaTweet::API::Favorites
|
||||||
|
|||||||
@@ -2,13 +2,14 @@
|
|||||||
#define COCOATWEET_API_FAVORITE_CREATE_H_
|
#define COCOATWEET_API_FAVORITE_CREATE_H_
|
||||||
|
|
||||||
#include <cocoatweet/api/interface/httpPost.h>
|
#include <cocoatweet/api/interface/httpPost.h>
|
||||||
|
#include <cocoatweet/api/model/tweet.h>
|
||||||
|
|
||||||
namespace CocoaTweet::API::Favorites {
|
namespace CocoaTweet::API::Favorites {
|
||||||
class Create : public CocoaTweet::API::Interface::HttpPost {
|
class Create : public CocoaTweet::API::Interface::HttpPost {
|
||||||
public:
|
public:
|
||||||
Create();
|
Create();
|
||||||
void id(const std::string& _id);
|
void id(const std::string& _id);
|
||||||
void process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth);
|
CocoaTweet::API::Model::Tweet process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#include <cocoatweet/api/favorite/destroy.h>
|
#include <cocoatweet/api/favorite/destroy.h>
|
||||||
#include <iostream>
|
#include <cocoatweet/api/model/tweet.h>
|
||||||
|
|
||||||
namespace CocoaTweet::API::Favorites {
|
namespace CocoaTweet::API::Favorites {
|
||||||
Destroy::Destroy() {
|
Destroy::Destroy() {
|
||||||
contentType_ = "application/x-www-form-urlencoded";
|
contentType_ = "application/x-www-form-urlencoded";
|
||||||
@@ -10,9 +11,14 @@ void Destroy::id(const std::string& _id) {
|
|||||||
bodyParam_.insert_or_assign("id", _id);
|
bodyParam_.insert_or_assign("id", _id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Destroy::process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth) {
|
CocoaTweet::API::Model::Tweet Destroy::process(
|
||||||
HttpPost::process(_oauth, [](const unsigned int _, const std::string& _srv) {
|
std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth) {
|
||||||
std::cout << _srv << std::endl;
|
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;
|
||||||
}
|
}
|
||||||
} // namespace CocoaTweet::API::Favorites
|
} // namespace CocoaTweet::API::Favorites
|
||||||
|
|||||||
@@ -2,13 +2,14 @@
|
|||||||
#define COCOATWEET_API_FAVORITE_DESTROY_H_
|
#define COCOATWEET_API_FAVORITE_DESTROY_H_
|
||||||
|
|
||||||
#include <cocoatweet/api/interface/httpPost.h>
|
#include <cocoatweet/api/interface/httpPost.h>
|
||||||
|
#include <cocoatweet/api/model/tweet.h>
|
||||||
|
|
||||||
namespace CocoaTweet::API::Favorites {
|
namespace CocoaTweet::API::Favorites {
|
||||||
class Destroy : public CocoaTweet::API::Interface::HttpPost {
|
class Destroy : public CocoaTweet::API::Interface::HttpPost {
|
||||||
public:
|
public:
|
||||||
Destroy();
|
Destroy();
|
||||||
void id(const std::string& _id);
|
void id(const std::string& _id);
|
||||||
void process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth);
|
CocoaTweet::API::Model::Tweet process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
#include <iostream>
|
|
||||||
|
|
||||||
#include "cocoatweet/api/favorite/favorite.h"
|
#include "cocoatweet/api/favorite/favorite.h"
|
||||||
#include "cocoatweet/api/favorite/create.h"
|
#include "cocoatweet/api/favorite/create.h"
|
||||||
#include "cocoatweet/api/favorite/destroy.h"
|
#include "cocoatweet/api/favorite/destroy.h"
|
||||||
@@ -9,15 +7,15 @@ Favorite::Favorite(std::shared_ptr<CocoaTweet::OAuth::OAuth1> _oauth) {
|
|||||||
oauth_ = _oauth;
|
oauth_ = _oauth;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Favorite::Create(const std::string& _id) const {
|
CocoaTweet::API::Model::Tweet Favorite::Create(const std::string& _id) const {
|
||||||
CocoaTweet::API::Favorites::Create create;
|
CocoaTweet::API::Favorites::Create create;
|
||||||
create.id(_id);
|
create.id(_id);
|
||||||
create.process(oauth_);
|
return create.process(oauth_);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Favorite::Destroy(const std::string& _id) const {
|
CocoaTweet::API::Model::Tweet Favorite::Destroy(const std::string& _id) const {
|
||||||
CocoaTweet::API::Favorites::Destroy destroy;
|
CocoaTweet::API::Favorites::Destroy destroy;
|
||||||
destroy.id(_id);
|
destroy.id(_id);
|
||||||
destroy.process(oauth_);
|
return destroy.process(oauth_);
|
||||||
}
|
}
|
||||||
} // namespace CocoaTweet::API::Favorites
|
} // namespace CocoaTweet::API::Favorites
|
||||||
|
|||||||
@@ -3,14 +3,15 @@
|
|||||||
|
|
||||||
#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>
|
||||||
|
|
||||||
namespace CocoaTweet::API::Favorites {
|
namespace CocoaTweet::API::Favorites {
|
||||||
class Favorite : public groupInterface {
|
class Favorite : public groupInterface {
|
||||||
public:
|
public:
|
||||||
Favorite() = default;
|
Favorite() = default;
|
||||||
Favorite(std::shared_ptr<CocoaTweet::OAuth::OAuth1> _oauth);
|
Favorite(std::shared_ptr<CocoaTweet::OAuth::OAuth1> _oauth);
|
||||||
void Create(const std::string& _id) const;
|
CocoaTweet::API::Model::Tweet Create(const std::string& _id) const;
|
||||||
void Destroy(const std::string& _id) const;
|
CocoaTweet::API::Model::Tweet Destroy(const std::string& _id) const;
|
||||||
};
|
};
|
||||||
} // namespace CocoaTweet::API::Favorites
|
} // namespace CocoaTweet::API::Favorites
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <iostream>
|
#include <stdexcept>
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include <curl/curl.h>
|
#include <curl/curl.h>
|
||||||
}
|
}
|
||||||
@@ -31,7 +31,6 @@ void HttpPost::process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth,
|
|||||||
auto signature = oauth->signature(sigingParam, "POST", url_);
|
auto signature = oauth->signature(sigingParam, "POST", url_);
|
||||||
|
|
||||||
// 作成した署名をエンドポイントへのパラメータ及びOAuthパラメータに登録
|
// 作成した署名をエンドポイントへのパラメータ及びOAuthパラメータに登録
|
||||||
std::cout << "signature : " << signature["oauth_signature"] << std::endl;
|
|
||||||
oauthParam.merge(signature);
|
oauthParam.merge(signature);
|
||||||
|
|
||||||
// リクエストボディの構築
|
// リクエストボディの構築
|
||||||
@@ -43,7 +42,6 @@ void HttpPost::process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth,
|
|||||||
}
|
}
|
||||||
requestBody = CocoaTweet::Util::join(tmp, "&");
|
requestBody = CocoaTweet::Util::join(tmp, "&");
|
||||||
}
|
}
|
||||||
std::cout << "request Body -> " << requestBody << std::endl;
|
|
||||||
|
|
||||||
// ヘッダの構築
|
// ヘッダの構築
|
||||||
std::string oauthHeader = "authorization: OAuth ";
|
std::string oauthHeader = "authorization: OAuth ";
|
||||||
@@ -54,7 +52,6 @@ void HttpPost::process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth,
|
|||||||
}
|
}
|
||||||
oauthHeader += CocoaTweet::Util::join(tmp, ",");
|
oauthHeader += CocoaTweet::Util::join(tmp, ",");
|
||||||
}
|
}
|
||||||
std::cout << "OAuth Header -> " << oauthHeader << std::endl;
|
|
||||||
|
|
||||||
// do post
|
// do post
|
||||||
CURL* curl;
|
CURL* curl;
|
||||||
@@ -63,15 +60,17 @@ void HttpPost::process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth,
|
|||||||
long responseCode;
|
long responseCode;
|
||||||
curl = curl_easy_init();
|
curl = curl_easy_init();
|
||||||
url_ = url_;
|
url_ = url_;
|
||||||
std::cout << "URL : " << url_ << std::endl;
|
|
||||||
if (curl) {
|
if (curl) {
|
||||||
curl_easy_setopt(curl, CURLOPT_URL, url_.c_str());
|
curl_easy_setopt(curl, CURLOPT_URL, url_.c_str());
|
||||||
curl_easy_setopt(curl, CURLOPT_POST, 1);
|
curl_easy_setopt(curl, CURLOPT_POST, 1);
|
||||||
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, requestBody.c_str());
|
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, requestBody.c_str());
|
||||||
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, requestBody.length());
|
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, requestBody.length());
|
||||||
|
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
|
||||||
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
|
||||||
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
|
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
|
||||||
|
#endif
|
||||||
// Headerを保持するcurl_slist*を初期化
|
// Headerを保持するcurl_slist*を初期化
|
||||||
struct curl_slist* headers = NULL;
|
struct curl_slist* headers = NULL;
|
||||||
// Authorizationをヘッダに追加
|
// Authorizationをヘッダに追加
|
||||||
@@ -83,7 +82,7 @@ void HttpPost::process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (res != CURLE_OK) {
|
if (res != CURLE_OK) {
|
||||||
std::cout << "curl error : " << res << std::endl;
|
throw std::runtime_error(std::string("INTERNAL ERROR : curl(") + std::to_string(res) + ")");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
#include <cocoatweet/api/model/tweet.h>
|
#include <cocoatweet/api/model/tweet.h>
|
||||||
#include <cocoatweet/exception/tweetNotFoundException.h>
|
#include <cocoatweet/exception/tweetNotFoundException.h>
|
||||||
#include <cocoatweet/exception/authenticateException.h>
|
#include <cocoatweet/exception/authenticateException.h>
|
||||||
|
#include <cocoatweet/exception/tweetDuplicateException.h>
|
||||||
|
#include <cocoatweet/exception/tweetTooLongException.h>
|
||||||
|
#include <cocoatweet/exception/rateLimitException.h>
|
||||||
#include "nlohmann/json.hpp"
|
#include "nlohmann/json.hpp"
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
namespace CocoaTweet::API::Model {
|
namespace CocoaTweet::API::Model {
|
||||||
Tweet Tweet::parse(const unsigned int _responseCode, const std::string& _json) {
|
Tweet Tweet::parse(const unsigned int _responseCode, const std::string& _json) {
|
||||||
auto j = nlohmann::json::parse(_json);
|
auto j = nlohmann::json::parse(_json);
|
||||||
@@ -12,13 +13,22 @@ Tweet Tweet::parse(const unsigned int _responseCode, const std::string& _json) {
|
|||||||
|
|
||||||
if (_responseCode == 200) {
|
if (_responseCode == 200) {
|
||||||
tweet.id(j["id_str"]);
|
tweet.id(j["id_str"]);
|
||||||
|
tweet.createdAt(j["created_at"]);
|
||||||
|
tweet.text(j["text"]);
|
||||||
|
tweet.source(j["source"]);
|
||||||
} else {
|
} else {
|
||||||
auto error = j["errors"][0]["code"];
|
auto error = j["errors"][0]["code"];
|
||||||
auto message = j["errors"][0]["message"];
|
auto message = j["errors"][0]["message"];
|
||||||
if (error.get<int>() == 144) {
|
if (error.get<int>() == 144) {
|
||||||
throw CocoaTweet::Exception::TweetNotFoundException(message.get<std::string>().c_str());
|
throw CocoaTweet::Exception::TweetNotFoundException(message.get<std::string>().c_str());
|
||||||
}else if(error.get<int>() == 32){
|
} else if (error.get<int>() == 32) {
|
||||||
throw CocoaTweet::Exception::AuthenticateException(message.get<std::string>().c_str());
|
throw CocoaTweet::Exception::AuthenticateException(message.get<std::string>().c_str());
|
||||||
|
} else if (error.get<int>() == 187) {
|
||||||
|
throw CocoaTweet::Exception::TweetDuplicateException(message.get<std::string>().c_str());
|
||||||
|
} else if (error.get<int>() == 88 || error.get<int>() == 185) {
|
||||||
|
throw CocoaTweet::Exception::RateLimitException(message.get<std::string>().c_str());
|
||||||
|
} else if (error.get<int>() == 186) {
|
||||||
|
throw CocoaTweet::Exception::TweetTooLongException(message.get<std::string>().c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29,7 +39,27 @@ void Tweet::id(const std::string _id) {
|
|||||||
id_ = _id;
|
id_ = _id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Tweet::createdAt(const std::string _at) {
|
||||||
|
createdAt_ = _at;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Tweet::text(const std::string _text) {
|
||||||
|
text_ = _text;
|
||||||
|
}
|
||||||
|
void Tweet::source(const std::string _source) {
|
||||||
|
source_ = _source;
|
||||||
|
}
|
||||||
|
|
||||||
const std::string Tweet::id() const {
|
const std::string Tweet::id() const {
|
||||||
return id_;
|
return id_;
|
||||||
}
|
}
|
||||||
|
const std::string Tweet::createdAt() const {
|
||||||
|
return createdAt_;
|
||||||
|
}
|
||||||
|
const std::string Tweet::text() const {
|
||||||
|
return text_;
|
||||||
|
}
|
||||||
|
const std::string Tweet::source() const {
|
||||||
|
return source_;
|
||||||
|
}
|
||||||
} // namespace CocoaTweet::API::Model
|
} // namespace CocoaTweet::API::Model
|
||||||
|
|||||||
@@ -12,10 +12,19 @@ public:
|
|||||||
: Tweet(Tweet::parse(_responseCode, _json)) {}
|
: Tweet(Tweet::parse(_responseCode, _json)) {}
|
||||||
static Tweet parse(const unsigned int _responseCode, const std::string& _json);
|
static Tweet parse(const unsigned int _responseCode, const std::string& _json);
|
||||||
void id(const std::string _id);
|
void id(const std::string _id);
|
||||||
|
void createdAt(const std::string _at);
|
||||||
|
void text(const std::string _text);
|
||||||
|
void source(const std::string _source);
|
||||||
const std::string id() const;
|
const std::string id() const;
|
||||||
|
const std::string createdAt() const;
|
||||||
|
const std::string text() const;
|
||||||
|
const std::string source() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string id_;
|
std::string id_;
|
||||||
|
std::string createdAt_;
|
||||||
|
std::string text_;
|
||||||
|
std::string source_;
|
||||||
};
|
};
|
||||||
} // namespace CocoaTweet::API::Model
|
} // namespace CocoaTweet::API::Model
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#include "cocoatweet/api/status/destroy.h"
|
#include "cocoatweet/api/status/destroy.h"
|
||||||
#include <cocoatweet/api/model/tweet.h>
|
#include <cocoatweet/api/model/tweet.h>
|
||||||
#include <iostream>
|
|
||||||
namespace CocoaTweet::API::Statuses {
|
namespace CocoaTweet::API::Statuses {
|
||||||
Destroy::Destroy() {}
|
Destroy::Destroy() {}
|
||||||
void Destroy::id(const std::string _id) {
|
void Destroy::id(const std::string _id) {
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
#include <iostream>
|
|
||||||
|
|
||||||
#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"
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
#include "cocoatweet/api/status/update.h"
|
#include "cocoatweet/api/status/update.h"
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
namespace CocoaTweet::API::Statuses {
|
namespace CocoaTweet::API::Statuses {
|
||||||
Update::Update() {
|
Update::Update() {
|
||||||
|
|||||||
@@ -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 {
|
||||||
@@ -11,11 +12,7 @@ class Key {
|
|||||||
const std::string accessTokenSecret_;
|
const std::string accessTokenSecret_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Key()
|
Key() : consumerKey_(""), consumerSecret_(""), accessToken_(""), accessTokenSecret_("") {}
|
||||||
: consumerKey_(""),
|
|
||||||
consumerSecret_(""),
|
|
||||||
accessToken_(""),
|
|
||||||
accessTokenSecret_("") {}
|
|
||||||
Key(const std::string& _consumerKey, const std::string& _consumerSecret,
|
Key(const std::string& _consumerKey, const std::string& _consumerSecret,
|
||||||
const std::string& _accessToken, const std::string& _accessTokenSecret)
|
const std::string& _accessToken, const std::string& _accessTokenSecret)
|
||||||
: consumerKey_(_consumerKey),
|
: consumerKey_(_consumerKey),
|
||||||
|
|||||||
@@ -7,7 +7,6 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include <openssl/hmac.h>
|
#include <openssl/hmac.h>
|
||||||
@@ -26,7 +25,6 @@ std::map<std::string, std::string> OAuth1::signature(
|
|||||||
std::vector<std::string> tmp;
|
std::vector<std::string> tmp;
|
||||||
for (const auto& [key, value] : _param) {
|
for (const auto& [key, value] : _param) {
|
||||||
tmp.push_back(key + "=" + value);
|
tmp.push_back(key + "=" + value);
|
||||||
std::cout << (key + "=" + value) << std::endl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string query = CocoaTweet::Util::join(tmp, "&");
|
std::string query = CocoaTweet::Util::join(tmp, "&");
|
||||||
@@ -36,10 +34,6 @@ std::map<std::string, std::string> OAuth1::signature(
|
|||||||
CocoaTweet::Util::urlEncode(query);
|
CocoaTweet::Util::urlEncode(query);
|
||||||
auto k64Sha1 = hmacSha1(significateKey, significateBase);
|
auto k64Sha1 = hmacSha1(significateKey, significateBase);
|
||||||
|
|
||||||
std::cout << "significate key : " << significateKey << std::endl;
|
|
||||||
std::cout << "significate base : " << significateBase << std::endl;
|
|
||||||
std::cout << "hmac-sha1 : " << k64Sha1 << std::endl;
|
|
||||||
|
|
||||||
auto ret = std::map<std::string, std::string>{{"oauth_signature", k64Sha1}};
|
auto ret = std::map<std::string, std::string>{{"oauth_signature", k64Sha1}};
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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"
|
||||||
|
|||||||
+4
-3
@@ -19,7 +19,8 @@ auto main() -> int {
|
|||||||
// CocoaTweet::API::API api(key);
|
// CocoaTweet::API::API api(key);
|
||||||
|
|
||||||
// Now, you can use a twitter api
|
// Now, you can use a twitter api
|
||||||
// api.status().Update("Hello Twitter World from Cocoa Twitter Library");
|
// auto status = api.status().Update("Hello Twitter World via Cocoa Twitter Library");
|
||||||
// api.favorite().Create("tweet id you want to fav.");
|
// api.favorite().Create(status.id());
|
||||||
// api.favorite().Destroy("tweet id you want to un_fav.");
|
// api.favorite().Destroy(status.id());
|
||||||
|
// api.status().Destroy(status.id());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
file(GLOB_RECURSE SOURCES ./*.cc)
|
file(GLOB_RECURSE SOURCES ./*.cc)
|
||||||
|
include_directories(${CMAKE_SOURCE_DIR}/third)
|
||||||
|
|
||||||
foreach(TEST_SOURCE_FILE ${SOURCES})
|
foreach(TEST_SOURCE_FILE ${SOURCES})
|
||||||
file(RELATIVE_PATH SRC_RELPATH ${CMAKE_CURRENT_LIST_DIR} ${TEST_SOURCE_FILE})
|
file(RELATIVE_PATH SRC_RELPATH ${CMAKE_CURRENT_LIST_DIR} ${TEST_SOURCE_FILE})
|
||||||
|
|||||||
@@ -0,0 +1,96 @@
|
|||||||
|
#define BOOST_TEST_DYN_LINK
|
||||||
|
|
||||||
|
#include <boost/test/included/unit_test.hpp>
|
||||||
|
|
||||||
|
#include "nlohmann/json.hpp"
|
||||||
|
#include "cocoatweet/api/model/tweet.h"
|
||||||
|
#include "cocoatweet/exception/authenticateException.h"
|
||||||
|
#include "cocoatweet/exception/rateLimitException.h"
|
||||||
|
#include "cocoatweet/exception/tweetTooLongException.h"
|
||||||
|
#include "cocoatweet/exception/tweetDuplicateException.h"
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_SUITE(tweet_object)
|
||||||
|
BOOST_AUTO_TEST_CASE(test01) {
|
||||||
|
CocoaTweet::API::Model::Tweet tweet;
|
||||||
|
|
||||||
|
BOOST_TEST(tweet.id() == "");
|
||||||
|
BOOST_TEST(tweet.createdAt() == "");
|
||||||
|
BOOST_TEST(tweet.text() == "");
|
||||||
|
BOOST_TEST(tweet.source() == "");
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(test02) {
|
||||||
|
std::string json = R"({
|
||||||
|
"id_str" : "1234567890",
|
||||||
|
"created_at" : "Thu Mar 04 00:00:00 +0000 2021",
|
||||||
|
"text" : "tweet",
|
||||||
|
"source" : "Twitter for Android"
|
||||||
|
})";
|
||||||
|
|
||||||
|
CocoaTweet::API::Model::Tweet tweet(200, json);
|
||||||
|
BOOST_TEST(tweet.id() == "1234567890");
|
||||||
|
BOOST_TEST(tweet.createdAt() == "Thu Mar 04 00:00:00 +0000 2021");
|
||||||
|
BOOST_TEST(tweet.text() == "tweet");
|
||||||
|
BOOST_TEST(tweet.source() == "Twitter for Android");
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(test03) {
|
||||||
|
std::string json = R"({
|
||||||
|
"errors" : [{
|
||||||
|
"code" : 32,
|
||||||
|
"message" : "Could not authenticate you."
|
||||||
|
}]
|
||||||
|
})";
|
||||||
|
|
||||||
|
BOOST_CHECK_THROW(CocoaTweet::API::Model::Tweet(401, json),
|
||||||
|
CocoaTweet::Exception::AuthenticateException);
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(test04) {
|
||||||
|
std::string json = R"({
|
||||||
|
"errors" : [{
|
||||||
|
"code" : 88,
|
||||||
|
"message" : "Rate limit exceeded."
|
||||||
|
}]
|
||||||
|
})";
|
||||||
|
|
||||||
|
BOOST_CHECK_THROW(CocoaTweet::API::Model::Tweet(429, json),
|
||||||
|
CocoaTweet::Exception::RateLimitException);
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(test05) {
|
||||||
|
std::string json = R"({
|
||||||
|
"errors" : [{
|
||||||
|
"code" : 185,
|
||||||
|
"message" : "User is over daily status update limit."
|
||||||
|
}]
|
||||||
|
})";
|
||||||
|
|
||||||
|
BOOST_CHECK_THROW(CocoaTweet::API::Model::Tweet(403, json),
|
||||||
|
CocoaTweet::Exception::RateLimitException);
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(test06) {
|
||||||
|
std::string json = R"({
|
||||||
|
"errors" : [{
|
||||||
|
"code" : 186,
|
||||||
|
"message" : "Tweet needs to be a bit shorter."
|
||||||
|
}]
|
||||||
|
})";
|
||||||
|
|
||||||
|
BOOST_CHECK_THROW(CocoaTweet::API::Model::Tweet(403, json),
|
||||||
|
CocoaTweet::Exception::TweetTooLongException);
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(test07) {
|
||||||
|
std::string json = R"({
|
||||||
|
"errors" : [{
|
||||||
|
"code" : 187,
|
||||||
|
"message" : "Status is a duplicate."
|
||||||
|
}]
|
||||||
|
})";
|
||||||
|
|
||||||
|
BOOST_CHECK_THROW(CocoaTweet::API::Model::Tweet(403, json),
|
||||||
|
CocoaTweet::Exception::TweetDuplicateException);
|
||||||
|
}
|
||||||
|
BOOST_AUTO_TEST_SUITE_END()
|
||||||
+3
-3
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
BOOST_AUTO_TEST_SUITE(oauth_key)
|
BOOST_AUTO_TEST_SUITE(oauth_key)
|
||||||
BOOST_AUTO_TEST_CASE(test01) {
|
BOOST_AUTO_TEST_CASE(test01) {
|
||||||
CocoaTweet::OAuth::Key key;
|
CocoaTweet::OAuth::Key key;
|
||||||
|
|
||||||
BOOST_TEST(key.consumerKey() == "");
|
BOOST_TEST(key.consumerKey() == "");
|
||||||
BOOST_TEST(key.consumerSecret() == "");
|
BOOST_TEST(key.consumerSecret() == "");
|
||||||
@@ -15,7 +15,8 @@ BOOST_AUTO_TEST_CASE(test01) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(test02) {
|
BOOST_AUTO_TEST_CASE(test02) {
|
||||||
CocoaTweet::OAuth::Key key("consumerKey", "consumerSecret", "accessToken", "accessTokenSecret");
|
CocoaTweet::OAuth::Key key("consumerKey", "consumerSecret", "accessToken",
|
||||||
|
"accessTokenSecret");
|
||||||
|
|
||||||
BOOST_TEST(key.consumerKey() == "consumerKey");
|
BOOST_TEST(key.consumerKey() == "consumerKey");
|
||||||
BOOST_TEST(key.consumerSecret() == "consumerSecret");
|
BOOST_TEST(key.consumerSecret() == "consumerSecret");
|
||||||
@@ -31,5 +32,4 @@ BOOST_AUTO_TEST_CASE(test02) {
|
|||||||
BOOST_TEST(secret.at("oauth_token") == "accessTokenSecret");
|
BOOST_TEST(secret.at("oauth_token") == "accessTokenSecret");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
BOOST_AUTO_TEST_SUITE_END()
|
BOOST_AUTO_TEST_SUITE_END()
|
||||||
|
|||||||
Reference in New Issue
Block a user