Merge pull request #2 from milkcocoa0902/develop

merge branch develop into master
This commit is contained in:
Keita.S
2021-02-25 18:33:15 +09:00
35 changed files with 3100 additions and 70 deletions
+16
View File
@@ -0,0 +1,16 @@
FROM ubuntu:20.04
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y tzdata && apt-get clean
ENV TZ=Asia/Tokyo
RUN apt-get update && \
apt-get install -y clang \
cmake \
doxygen \
git \
graphviz \
libboost-dev \
libcurl4-openssl-dev \
libssl-dev \
ninja-build \
pkg-config && \
apt-get clean
+2580
View File
File diff suppressed because it is too large Load Diff
Vendored
+58
View File
@@ -0,0 +1,58 @@
pipeline {
agent {
dockerfile true
}
stages{
stage("parallel execution"){
parallel{
stage("doxygen"){
steps{
sh 'doxygen'
}
}
stage("validation"){
steps{
sh 'tools/validate/includeGuard.sh'
}
}
stage("build and test"){
stages{
stage("prepare"){
steps{
sh '''
mkdir -p build
cd build
cmake .. -G Ninja
'''
}
}
stage("build"){
steps{
sh '''
cd build
ninja
'''
}
}
stage("test"){
steps{
echo "test"
}
}
}
}
}
}
stage("upload artifact"){
steps{
archiveArtifacts allowEmptyArchive: true, artifacts: 'help/**/*.*', onlyIfSuccessful: true
}
}
}
}
+15 -4
View File
@@ -6,9 +6,11 @@ This is a library for using Twitter API from C++
- libssl
# Features
you can use these endpoint
- statuses/update
Now, only post a tweet.
- statuses/destroy/:id
- favorites/create
- favorites/destroy
# How
## API Key Registration
@@ -56,8 +58,17 @@ CocoaTweet::API::API api(key);
```
## Post Tweet
post tweet
## Use API
```
// Post a tweet
api.status().Update("Hello, World!!\nTweet from Cocoa Twitter Library");
// Delete a tweet
api.status().Destroy("tweet id");
// Fav. a tweet
api.favorite().Create("tweet id");
// un Fav. a tweet
api.favorite().Destroy("tweet id");
```
+5
View File
@@ -4,9 +4,14 @@ 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_);
}
Statuses::Status API::status() const {
return status_;
}
Favorites::Favorite API::favorite() const {
return favorite_;
}
} // namespace CocoaTweet::API
+16 -4
View File
@@ -1,17 +1,29 @@
#ifndef COCOATWEET_API_H_
#define COCOATWEET_API_H_
#ifndef COCOATWEET_API_API_H_
#define COCOATWEET_API_API_H_
#include "cocoatweet/api/status/status.h"
#include "cocoatweet/oauth/oauth.h"
#include <cocoatweet/api/status/status.h>
#include <cocoatweet/api/favorite/favorite.h>
#include <cocoatweet/oauth/oauth.h>
namespace CocoaTweet::API {
/// @brief Twitter API Entry Point
class API {
public:
/// @brief primary constructor
/// @param[in] _key Twitter API Key typed CocoaTweet::OAuth::Key
API(CocoaTweet::OAuth::Key _key);
/// @brief Getter for Grouped by Statuses/*
/// @param[out] Status object typed CocoaTweet::API::Statuses::Status
Statuses::Status status() const;
/// @brief Getter for Grouped by Favorites/*
/// @param[out] Favorite object typed CococaTweet::API::Favorites::Favorite
Favorites::Favorite favorite() const;
private:
Statuses::Status status_;
Favorites::Favorite favorite_;
std::shared_ptr<CocoaTweet::OAuth::OAuth1> oauth_;
};
} // namespace CocoaTweet::API
+18
View File
@@ -0,0 +1,18 @@
#include <cocoatweet/api/favorite/create.h>
#include <iostream>
namespace CocoaTweet::API::Favorites {
Create::Create() {
contentType_ = "application/x-www-form-urlencoded";
url_ = "https://api.twitter.com/1.1/favorites/create.json";
}
void Create::id(const std::string& _id) {
bodyParam_.insert_or_assign("id", _id);
}
void Create::process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth) {
HttpPost::process(_oauth, [](const unsigned int _, const std::string& _srv) {
std::cout << _srv << std::endl;
});
}
} // namespace CocoaTweet::API::Favorites
+17
View File
@@ -0,0 +1,17 @@
#ifndef COCOATWEET_API_FAVORITE_CREATE_H_
#define COCOATWEET_API_FAVORITE_CREATE_H_
#include <cocoatweet/api/interface/httpPost.h>
namespace CocoaTweet::API::Favorites {
class Create : public CocoaTweet::API::Interface::HttpPost {
public:
Create();
void id(const std::string& _id);
void process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth);
private:
};
} // namespace CocoaTweet::API::Favorites
#endif
+18
View File
@@ -0,0 +1,18 @@
#include <cocoatweet/api/favorite/destroy.h>
#include <iostream>
namespace CocoaTweet::API::Favorites {
Destroy::Destroy() {
contentType_ = "application/x-www-form-urlencoded";
url_ = "https://api.twitter.com/1.1/favorites/destroy.json";
}
void Destroy::id(const std::string& _id) {
bodyParam_.insert_or_assign("id", _id);
}
void Destroy::process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth) {
HttpPost::process(_oauth, [](const unsigned int _, const std::string& _srv) {
std::cout << _srv << std::endl;
});
}
} // namespace CocoaTweet::API::Favorites
+17
View File
@@ -0,0 +1,17 @@
#ifndef COCOATWEET_API_FAVORITE_DESTROY_H_
#define COCOATWEET_API_FAVORITE_DESTROY_H_
#include <cocoatweet/api/interface/httpPost.h>
namespace CocoaTweet::API::Favorites {
class Destroy : public CocoaTweet::API::Interface::HttpPost {
public:
Destroy();
void id(const std::string& _id);
void process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth);
private:
};
} // namespace CocoaTweet::API::Favorites
#endif
+23
View File
@@ -0,0 +1,23 @@
#include <iostream>
#include "cocoatweet/api/favorite/favorite.h"
#include "cocoatweet/api/favorite/create.h"
#include "cocoatweet/api/favorite/destroy.h"
namespace CocoaTweet::API::Favorites {
Favorite::Favorite(std::shared_ptr<CocoaTweet::OAuth::OAuth1> _oauth) {
oauth_ = _oauth;
}
void Favorite::Create(const std::string& _id) const {
CocoaTweet::API::Favorites::Create create;
create.id(_id);
create.process(oauth_);
}
void Favorite::Destroy(const std::string& _id) const {
CocoaTweet::API::Favorites::Destroy destroy;
destroy.id(_id);
destroy.process(oauth_);
}
} // namespace CocoaTweet::API::Favorites
+17
View File
@@ -0,0 +1,17 @@
#ifndef COCOATWEET_API_FAVORITE_FAVORITE_H_
#define COCOATWEET_API_FAVORITE_FAVORITE_H_
#include "cocoatweet/api/interface/groupInterface.h"
#include "cocoatweet/oauth/oauth.h"
namespace CocoaTweet::API::Favorites {
class Favorite : public groupInterface {
public:
Favorite() = default;
Favorite(std::shared_ptr<CocoaTweet::OAuth::OAuth1> _oauth);
void Create(const std::string& _id) const;
void Destroy(const std::string& _id) const;
};
} // namespace CocoaTweet::API::Favorites
#endif
@@ -1,5 +1,5 @@
#ifndef COCOATWEET_API_GROUPINTERFACE_H_
#define COCOATWEET_API_GROUPINTERFACE_H_
#ifndef COCOATWEET_API_INTERFACE_GROUPINTERFACE_H_
#define COCOATWEET_API_INTERFACE_GROUPINTERFACE_H_
#include <memory>
#include "cocoatweet/oauth/oauth.h"
@@ -1,4 +1,4 @@
#include <cocoatweet/api/interface/postInterface.h>
#include <cocoatweet/api/interface/httpPost.h>
#include "cocoatweet/util/util.h"
#include <iterator>
#include <memory>
@@ -10,22 +10,23 @@ extern "C" {
}
namespace CocoaTweet::API::Interface {
size_t postInterface::curlCallback_(char* _ptr, size_t _size, size_t _nmemb,
std::string* _stream) {
size_t HttpPost::curlCallback_(char* _ptr, size_t _size, size_t _nmemb, std::string* _stream) {
int realsize = _size * _nmemb;
_stream->append(_ptr, realsize);
return realsize;
}
void postInterface::process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth,
std::function<void(std::string)> _callback) {
void HttpPost::process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth,
std::function<void(const unsigned int, const std::string&)> _callback) {
// エンドポイントへのパラメータにOAuthパラメータを付加して署名作成
auto oauth = _oauth.lock();
auto oauthParam = oauth->oauthParam();
auto sigingParam = oauthParam;
if (contentType_ == "application/x-www-form-urlencoded") {
for (const auto [k, v] : bodyParam_) {
sigingParam.insert_or_assign(k, v);
}
}
auto signature = oauth->signature(sigingParam, "POST", url_);
@@ -40,10 +41,7 @@ void postInterface::process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth,
for (const auto& [key, value] : bodyParam_) {
tmp.push_back(key + "=" + value);
}
std::stringstream os;
std::copy(tmp.begin(), tmp.end(), std::ostream_iterator<std::string>(os, "&"));
requestBody = os.str();
requestBody.erase(requestBody.size() - std::char_traits<char>::length("&"));
requestBody = CocoaTweet::Util::join(tmp, "&");
}
std::cout << "request Body -> " << requestBody << std::endl;
@@ -54,10 +52,7 @@ void postInterface::process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth,
for (const auto& [key, value] : oauthParam) {
tmp.push_back(key + "=" + CocoaTweet::Util::urlEncode(value));
}
std::stringstream os;
std::copy(tmp.begin(), tmp.end(), std::ostream_iterator<std::string>(os, ","));
oauthHeader += os.str();
oauthHeader.erase(oauthHeader.size() - std::char_traits<char>::length(","));
oauthHeader += CocoaTweet::Util::join(tmp, ",");
}
std::cout << "OAuth Header -> " << oauthHeader << std::endl;
@@ -65,8 +60,9 @@ void postInterface::process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth,
CURL* curl;
CURLcode res;
std::string rcv;
long responseCode;
curl = curl_easy_init();
url_ = url_; // + "?status=" + status_;
url_ = url_;
std::cout << "URL : " << url_ << std::endl;
if (curl) {
curl_easy_setopt(curl, CURLOPT_URL, url_.c_str());
@@ -80,18 +76,19 @@ void postInterface::process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth,
struct curl_slist* headers = NULL;
// Authorizationをヘッダに追加
headers = curl_slist_append(headers, oauthHeader.c_str());
// headers = curl_slist_append(headers, "Content-Type: application/x-www-form-urlencoded");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
res = curl_easy_perform(curl);
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &responseCode);
curl_easy_cleanup(curl);
}
if (res != CURLE_OK) {
std::cout << "curl error : " << res << std::endl;
exit(1);
}
if (_callback) {
_callback(rcv);
_callback(responseCode, rcv);
}
}
} // namespace CocoaTweet::API::Interface
@@ -1,19 +1,19 @@
#ifndef COCOATWEET_API_INTERFACE_POSTINTERFACE_H_
#define COCOATWEET_API_INTERFACE_POSTINTERFACE_H_
#ifndef COCOATWEET_API_INTERFACE_HTTPPOST_H_
#define COCOATWEET_API_INTERFACE_HTTPPOST_H_
#include <functional>
#include "cocoatweet/oauth/oauth.h"
namespace CocoaTweet::API::Interface {
class postInterface {
class HttpPost {
public:
void process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth,
std::function<void(std::string)> _callback);
protected:
std::weak_ptr<CocoaTweet::OAuth::OAuth1> oauth_;
std::map<std::string, std::string> bodyParam_;
std::string url_;
std::string contentType_;
void process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth,
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
View File
+22
View File
@@ -0,0 +1,22 @@
#ifndef COCOATWEET_API_MEDIA_UPLOAD_H_
#define COCOATWEET_API_MEDIA_UPLOAD_H_
#include <cocoatweet/api/interface/postInterface.h>
namespace CocoaTweet::API::Medias {
class Upload : public postInterface {
public:
enum Command : class st::string {
INIT = "INIT",
APPEND = "APPEND",
FINALIZE = "FINALIZE",
};
Upload::Upload();
void media(const std::string& _media);
void mediaId(const std::string _mediaId);
void process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth, Command _command);
}
} // namespace CocoaTweet::API::Medias
#endif
+35
View File
@@ -0,0 +1,35 @@
#include <cocoatweet/api/model/tweet.h>
#include <cocoatweet/exception/tweetNotFoundException.h>
#include <cocoatweet/exception/authenticateException.h>
#include "nlohmann/json.hpp"
#include <iostream>
namespace CocoaTweet::API::Model {
Tweet Tweet::parse(const unsigned int _responseCode, const std::string& _json) {
auto j = nlohmann::json::parse(_json);
Tweet tweet;
if (_responseCode == 200) {
tweet.id(j["id_str"]);
} else {
auto error = j["errors"][0]["code"];
auto message = j["errors"][0]["message"];
if (error.get<int>() == 144) {
throw CocoaTweet::Exception::TweetNotFoundException(message.get<std::string>().c_str());
}else if(error.get<int>() == 32){
throw CocoaTweet::Exception::AuthenticateException(message.get<std::string>().c_str());
}
}
return tweet;
}
void Tweet::id(const std::string _id) {
id_ = _id;
}
const std::string Tweet::id() const {
return id_;
}
} // namespace CocoaTweet::API::Model
+22
View File
@@ -0,0 +1,22 @@
#ifndef COCOATWEET_API_MODEL_TWEET_H_
#define COCOATWEET_API_MODEL_TWEET_H_
#include <string>
namespace CocoaTweet::API::Model {
class Tweet final {
public:
Tweet() = default;
Tweet(const Tweet&) = default;
Tweet(const unsigned int _responseCode, const std::string& _json)
: Tweet(Tweet::parse(_responseCode, _json)) {}
static Tweet parse(const unsigned int _responseCode, const std::string& _json);
void id(const std::string _id);
const std::string id() const;
private:
std::string id_;
};
} // namespace CocoaTweet::API::Model
#endif
+21
View File
@@ -0,0 +1,21 @@
#include "cocoatweet/api/status/destroy.h"
#include <cocoatweet/api/model/tweet.h>
#include <iostream>
namespace CocoaTweet::API::Statuses {
Destroy::Destroy() {}
void Destroy::id(const std::string _id) {
contentType_ = "application/x-www-form-urlencoded";
url_ = "https://api.twitter.com/1.1/statuses/destroy/" + _id + ".json";
}
CocoaTweet::API::Model::Tweet Destroy::process(
std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth) {
CocoaTweet::API::Model::Tweet tweet;
HttpPost::process(_oauth,
[&tweet](const unsigned int _responseCode, const std::string& _rsv) {
tweet = CocoaTweet::API::Model::Tweet::parse(_responseCode, _rsv);
});
return tweet;
}
} // namespace CocoaTweet::API::Statuses
+27
View File
@@ -0,0 +1,27 @@
#ifndef COCOATWEET_API_STATUS_DESTROY_H_
#define COCOATWEET_API_STATUS_DESTROY_H_
#include <memory>
#include <cocoatweet/api/interface/httpPost.h>
#include <cocoatweet/api/model/tweet.h>
namespace CocoaTweet::API::Statuses {
/// @brief class for using status/destroy:id endpoint
class Destroy : public CocoaTweet::API::Interface::HttpPost {
public:
/// @brief primary constructor
Destroy();
/// @brief set tweet id to destroy
/// @param[in] std::string _id : tweet id which should be destroy
/// @param[out] none
void id(const std::string _id);
/// @brief process request for endpoint
/// @param[in] std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth : pointer to oauth object
/// @param[out] none
CocoaTweet::API::Model::Tweet process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth);
};
} // namespace CocoaTweet::API::Statuses
#endif
+9 -2
View File
@@ -2,15 +2,22 @@
#include "cocoatweet/api/status/status.h"
#include "cocoatweet/api/status/update.h"
#include "cocoatweet/api/status/destroy.h"
namespace CocoaTweet::API::Statuses {
Status::Status(std::shared_ptr<CocoaTweet::OAuth::OAuth1> _oauth) {
oauth_ = _oauth;
}
void Status::Update(const std::string& _status) const {
CocoaTweet::API::Model::Tweet Status::Update(const std::string& _status) const {
CocoaTweet::API::Statuses::Update update;
update.status(_status);
update.process(oauth_, [](std::string _rcv) { std::cout << _rcv << std::endl; });
return update.process(oauth_);
}
CocoaTweet::API::Model::Tweet Status::Destroy(const std::string& _id) const {
CocoaTweet::API::Statuses::Destroy destroy;
destroy.id(_id);
return destroy.process(oauth_);
}
} // namespace CocoaTweet::API::Statuses
+5 -3
View File
@@ -1,15 +1,17 @@
#ifndef COCOATWEET_API_STATUSED_H_
#define COCOATWEET_API_STATUSED_H_
#ifndef COCOATWEET_API_STATUS_STATUS_H_
#define COCOATWEET_API_STATUS_STATUS_H_
#include "cocoatweet/api/interface/groupInterface.h"
#include "cocoatweet/oauth/oauth.h"
#include <cocoatweet/api/model/tweet.h>
namespace CocoaTweet::API::Statuses {
class Status : public groupInterface {
public:
Status() = default;
Status(std::shared_ptr<CocoaTweet::OAuth::OAuth1> _oauth);
void Update(const std::string& _status) const;
CocoaTweet::API::Model::Tweet Update(const std::string& _status) const;
CocoaTweet::API::Model::Tweet Destroy(const std::string& _id) const;
private:
};
+12
View File
@@ -1,12 +1,24 @@
#include "cocoatweet/api/status/update.h"
#include <iostream>
namespace CocoaTweet::API::Statuses {
Update::Update() {
contentType_ = "application/x-www-form-urlencoded";
url_ = "https://api.twitter.com/1.1/statuses/update.json";
}
void Update::status(const std::string _status) {
status_ = _status;
bodyParam_.insert_or_assign("status", status_);
}
CocoaTweet::API::Model::Tweet Update::process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth) {
CocoaTweet::API::Model::Tweet tweet;
HttpPost::process(_oauth,
[&tweet](const unsigned int _responseCode, const std::string& _rsv) {
tweet = CocoaTweet::API::Model::Tweet::parse(_responseCode, _rsv);
});
return tweet;
}
} // namespace CocoaTweet::API::Statuses
+6 -6
View File
@@ -1,16 +1,16 @@
#ifndef COCOATWEET_API_STATUSES_UPDATE_H_
#define COCOATWEET_API_STATUSES_UPDATE_H_
#ifndef COCOATWEET_API_STATUS_UPDATE_H_
#define COCOATWEET_API_STATUS_UPDATE_H_
#include <memory>
#include "cocoatweet/api/interface/postInterface.h"
//#include "cocoatweet/oauth/oauth.h"
#include <cocoatweet/api/interface/httpPost.h>
#include <cocoatweet/api/model/tweet.h>
namespace CocoaTweet::API::Statuses {
class Update : public CocoaTweet::API::Interface::postInterface {
class Update : public CocoaTweet::API::Interface::HttpPost {
public:
Update();
void status(const std::string _status);
CocoaTweet::API::Model::Tweet process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth);
private:
std::string status_;
@@ -0,0 +1,12 @@
#ifndef COCOATWEET_EXCEPTION_AUTHENTICATEEXCEPTION_H_
#define COCOATWEET_EXCEPTION_AUTHENTICATEEXCEPTION_H_
#include <cocoatweet/exception/exception.h>
namespace CocoaTweet::Exception {
class AuthenticateException final : Exception {
using Exception::Exception;
};
} // namespace CocoaTweet::Exception
#endif
+21
View File
@@ -0,0 +1,21 @@
#ifndef COCOATWEET_EXCEPTION_EXCEPTION_H_
#define COCOATWEET_EXCEPTION_EXCEPTION_H_
#include <string>
#include <exception>
namespace CocoaTweet::Exception {
class Exception : public std::exception {
public:
Exception(const char* _msg) : msg_(std::string(_msg)) {}
const std::string& what() {
return msg_;
}
virtual ~Exception() = default;
protected:
std::string msg_;
};
} // namespace CocoaTweet::Exception
#endif
@@ -0,0 +1,12 @@
#ifndef COCOATWEET_EXCEPTION_RATELIMITEXCEPTION_H_
#define COCOATWEET_EXCEPTION_RATELIMITEXCEPTION_H_
#include <cocoatweet/exception/exception.h>
namespace CocoaTweet::Exception {
class RateLimitException final : Exception {
using Exception::Exception;
};
} // namespace CocoaTweet::Exception
#endif
@@ -0,0 +1,12 @@
#ifndef COCOATWEET_EXCEPTION_TWEETDUPLICATEEXCEPTION_H_
#define COCOATWEET_EXCEPTION_TWEETDUPLICATEEXCEPTION_H_
#include <cocoatweet/exception/exception.h>
namespace CocoaTweet::Exception {
class TweetDuplicateException final : Exception {
using Exception::Exception;
};
} // namespace CocoaTweet::Exception
#endif
@@ -0,0 +1,12 @@
#ifndef COCOATWEET_EXCEPTION_TWEETNOTFOUNDEXCEPTION_H_
#define COCOATWEET_EXCEPTION_TWEETNOTFOUNDEXCEPTION_H_
#include <cocoatweet/exception/exception.h>
namespace CocoaTweet::Exception {
class TweetNotFoundException final : Exception {
using Exception::Exception;
};
} // namespace CocoaTweet::Exception
#endif
@@ -0,0 +1,12 @@
#ifndef COCOATWEET_EXCEPTION_TWEETTOOLONGEXCEPTION_H_
#define COCOATWEET_EXCEPTION_TWEETTOOLONGEXCEPTION_H_
#include <cocoatweet/exception/exception.h>
namespace CocoaTweet::Exception {
class TweetTooLongException final : Exception {
using Exception::Exception;
};
} // namespace CocoaTweet::Exception
#endif
+2 -4
View File
@@ -28,10 +28,8 @@ std::map<std::string, std::string> OAuth1::signature(
tmp.push_back(key + "=" + value);
std::cout << (key + "=" + value) << std::endl;
}
std::ostringstream os;
std::copy(tmp.begin(), tmp.end(), std::ostream_iterator<std::string>(os, "&"));
std::string query = os.str();
query.erase(query.size() - std::char_traits<char>::length("&"));
std::string query = CocoaTweet::Util::join(tmp, "&");
auto significateKey = key().consumerSecret() + "&" + key().accessTokenSecret();
auto significateBase = _method + "&" + CocoaTweet::Util::urlEncode(_url) + "&" +
+13 -2
View File
@@ -19,6 +19,17 @@ std::string urlEncode(const std::string& _str) {
return out.str();
}
template <typename T>
std::string join(const std::vector<T> _vec) {}
std::string join(const std::vector<std::string> _vec, const std::string& _delim) {
std::string str("");
for (auto v : _vec) {
str += (v + _delim);
}
if (!str.empty()) {
str.pop_back();
}
return str;
}
} // namespace CocoaTweet::Util
+1 -2
View File
@@ -7,8 +7,7 @@
namespace CocoaTweet::Util {
std::string urlEncode(const std::string& _str);
template <typename T>
std::string join(const std::vector<T> _vec);
std::string join(const std::vector<std::string> _vec, const std::string& _delim);
} // namespace CocoaTweet::Util
#endif
+13 -9
View File
@@ -2,20 +2,24 @@
#include "cocoatweet/api/api.h"
auto main() -> int {
// キーオブジェクトを作成
// Generate Key object
// auto consumerKey = "your consumer key";
// auto consumerSecret = "your consumer secret";
// auto accessToken = "your access token";
// auto accessTokenSecret = "your access token secret";
// CocoaTweet::OAuth::Key key = CocoaTweet::OAuth::Key(consumerKey, consumerSecret,
// accessToken, accessTokenSecret);
// CocoaTweet::OAuth::Key key = CocoaTweet::OAuth::Key(consumerKey,
// consumerSecret,
// accessToken,
// accessTokenSecret);
// jsonファイルから各種キーを読み込むことも可能
CocoaTweet::OAuth::Key key = CocoaTweet::OAuth::Key::fromJsonFile("apikey.json");
// also can generate Key object from JSON file
// CocoaTweet::OAuth::Key key = CocoaTweet::OAuth::Key::fromJsonFile("api_key.json");
// 作成したキーオブジェクトを用いてAPIを立ち上げる.
// 内部的にはキーオブジェクトを使用してOAuth認証機を立ち上げている.
CocoaTweet::API::API api(key);
// Generate API Entry object using Key object
// CocoaTweet::API::API api(key);
api.status().Update("Hello Twitter World from Cocoa Twitter Library");
// Now, you can use a twitter api
// api.status().Update("Hello Twitter World from Cocoa Twitter Library");
// api.favorite().Create("tweet id you want to fav.");
// api.favorite().Destroy("tweet id you want to un_fav.");
}