コメント書いたり

This commit is contained in:
keita
2021-03-11 21:40:10 +09:00
parent 16daa46810
commit d2425d009d
11 changed files with 127 additions and 63 deletions
+2 -2
View File
@@ -1,7 +1,7 @@
#include "cocoatweet/api/media/media.h"
namespace CocoaTweet::API::Medias {
Media::Media(std::shared_ptr<CocoaTweet::OAuth::OAuth1> _oauth) {
Media::Media(std::shared_ptr<CocoaTweet::OAuth::OAuth1> _oauth) {
oauth_ = _oauth;
}
@@ -10,4 +10,4 @@ CocoaTweet::API::Model::MediaStore Media::Upload(const std::string& _media) cons
upload.media(_media);
return upload.process(oauth_);
}
} // namespace CocoaTweet::API::Statuses
} // namespace CocoaTweet::API::Medias
+1 -1
View File
@@ -23,6 +23,6 @@ public:
private:
};
} // namespace CocoaTweet::API::Statuses
} // namespace CocoaTweet::API::Medias
#endif
+6 -4
View File
@@ -21,15 +21,14 @@ void Upload::mediaId(const std::string& _mediaId) {}
CocoaTweet::API::Model::MediaStore Upload::process(
std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth) {
auto backup = bodyParam_;
CocoaTweet::API::Model::MediaStore media;
std::ifstream ifs(media_, std::ios::binary);
ifs.seekg(0, std::ios::end);
unsigned long long size = ifs.tellg();
bodyParam_.insert_or_assign("total_bytes", std::to_string(size));
ifs.seekg(0);
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";
@@ -72,6 +71,7 @@ CocoaTweet::API::Model::MediaStore Upload::process(
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);
});
}
@@ -79,6 +79,8 @@ CocoaTweet::API::Model::MediaStore Upload::process(
// STATUS if needed
{}
bodyParam_ = backup;
return media;
}
} // namespace CocoaTweet::API::Medias
+14 -1
View File
@@ -7,16 +7,29 @@
#include <filesystem>
namespace CocoaTweet::API::Medias {
/// @brief entry point for using media/upload endpoint
class Upload : public CocoaTweet::API::Interface::HttpPost {
private:
std::string media_;
static const std::map<std::string, std::string> mimeType;
;
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);
/// @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