From e0c78cacbdfbabd1550c630e8913381dc5eac102 Mon Sep 17 00:00:00 2001 From: keita Date: Thu, 11 Mar 2021 13:42:10 +0900 Subject: [PATCH] =?UTF-8?q?media/upload=E3=82=92=E3=82=A8=E3=83=B3?= =?UTF-8?q?=E3=83=88=E3=83=AA=E3=83=BC=E3=83=9D=E3=82=A4=E3=83=B3=E3=83=88?= =?UTF-8?q?=E3=81=AB=E4=B9=97=E3=81=9B=E3=81=9F(#56)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/cocoatweet/api/media/media.cc | 13 +++++++++++++ src/cocoatweet/api/media/media.h | 28 ++++++++++++++++++++++++++++ src/cocoatweet/api/media/upload.cc | 18 +++++++++--------- src/cocoatweet/api/media/upload.h | 3 ++- 4 files changed, 52 insertions(+), 10 deletions(-) create mode 100644 src/cocoatweet/api/media/media.cc create mode 100644 src/cocoatweet/api/media/media.h diff --git a/src/cocoatweet/api/media/media.cc b/src/cocoatweet/api/media/media.cc new file mode 100644 index 0000000..8826915 --- /dev/null +++ b/src/cocoatweet/api/media/media.cc @@ -0,0 +1,13 @@ +#include "cocoatweet/api/media/media.h" + +namespace CocoaTweet::API::Medias { + Media::Media(std::shared_ptr _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::Statuses diff --git a/src/cocoatweet/api/media/media.h b/src/cocoatweet/api/media/media.h new file mode 100644 index 0000000..0cd46b0 --- /dev/null +++ b/src/cocoatweet/api/media/media.h @@ -0,0 +1,28 @@ +#ifndef COCOATWEET_API_MEDIAS_MEDIA_H_ +#define COCOATWEET_API_MEDIAS_MEDIA_H_ + +#include "cocoatweet/api/interface/groupInterface.h" +#include "cocoatweet/oauth/oauth.h" +#include +#include +#include + +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 : pointer to OAuth object + Media(std::shared_ptr _oauth); + + CocoaTweet::API::Model::MediaStore Upload(const std::string& _file) const; + +private: +}; +} // namespace CocoaTweet::API::Statuses + +#endif diff --git a/src/cocoatweet/api/media/upload.cc b/src/cocoatweet/api/media/upload.cc index 64d77c3..5a8694c 100644 --- a/src/cocoatweet/api/media/upload.cc +++ b/src/cocoatweet/api/media/upload.cc @@ -14,7 +14,9 @@ void Upload::media(const std::string& _media) { void Upload::mediaId(const std::string& _mediaId) {} -void Upload::process(std::weak_ptr _oauth) { +CocoaTweet::API::Model::MediaStore Upload::process( + std::weak_ptr _oauth) { + CocoaTweet::API::Model::MediaStore media; std::ifstream ifs(media_, std::ios::binary); ifs.seekg(0, std::ios::end); unsigned long long size = ifs.tellg(); @@ -26,14 +28,11 @@ void Upload::process(std::weak_ptr _oauth) { // INIT { contentType_ = "application/x-www-form-urlencoded"; - // contentType_ = "multipart/form-data"; bodyParam_.insert_or_assign("command", "INIT"); bodyParam_.insert_or_assign("media_type", "image/jpeg"); - CocoaTweet::API::Model::MediaStore media; HttpPost::process(_oauth, [&media](const unsigned int _responseCode, const std::string& _rsv) { - std::cout << _rsv << std::endl; media = CocoaTweet::API::Model::MediaStore::parse(_responseCode, _rsv); }); @@ -52,7 +51,6 @@ void Upload::process(std::weak_ptr _oauth) { 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)); - CocoaTweet::API::Model::MediaStore media; HttpPost::process(_oauth, [](const unsigned int _responseCode, const std::string& _rsv) { // std::cout << _responseCode << std::endl << _rsv<< std::endl; }); @@ -66,13 +64,15 @@ void Upload::process(std::weak_ptr _oauth) { bodyParam_.insert_or_assign("command", "FINALIZE"); bodyParam_.erase("segment_index"); bodyParam_.erase("media"); - CocoaTweet::API::Model::MediaStore media; - HttpPost::process(_oauth, [](const unsigned int _responseCode, const std::string& _rsv) { - std::cout << _rsv << std::endl; - }); + HttpPost::process(_oauth, + [&media](const unsigned int _responseCode, const std::string& _rsv) { + media = CocoaTweet::API::Model::MediaStore::parse(_responseCode, _rsv); + }); } // STATUS if needed {} + + return media; } } // namespace CocoaTweet::API::Medias diff --git a/src/cocoatweet/api/media/upload.h b/src/cocoatweet/api/media/upload.h index 4f19009..770b1b2 100644 --- a/src/cocoatweet/api/media/upload.h +++ b/src/cocoatweet/api/media/upload.h @@ -2,6 +2,7 @@ #define COCOATWEET_API_MEDIA_UPLOAD_H_ #include +#include #include namespace CocoaTweet::API::Medias { @@ -13,7 +14,7 @@ public: Upload(); void media(const std::string& _media); void mediaId(const std::string& _mediaId); - void process(std::weak_ptr _oauth); + CocoaTweet::API::Model::MediaStore process(std::weak_ptr _oauth); }; } // namespace CocoaTweet::API::Medias