media/uploadをエントリーポイントに乗せた(#56)
This commit is contained in:
@@ -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::Statuses
|
||||||
@@ -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 <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::Statuses
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -14,7 +14,9 @@ void Upload::media(const std::string& _media) {
|
|||||||
|
|
||||||
void Upload::mediaId(const std::string& _mediaId) {}
|
void Upload::mediaId(const std::string& _mediaId) {}
|
||||||
|
|
||||||
void Upload::process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth) {
|
CocoaTweet::API::Model::MediaStore Upload::process(
|
||||||
|
std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth) {
|
||||||
|
CocoaTweet::API::Model::MediaStore media;
|
||||||
std::ifstream ifs(media_, std::ios::binary);
|
std::ifstream ifs(media_, std::ios::binary);
|
||||||
ifs.seekg(0, std::ios::end);
|
ifs.seekg(0, std::ios::end);
|
||||||
unsigned long long size = ifs.tellg();
|
unsigned long long size = ifs.tellg();
|
||||||
@@ -26,14 +28,11 @@ void Upload::process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth) {
|
|||||||
// INIT
|
// INIT
|
||||||
{
|
{
|
||||||
contentType_ = "application/x-www-form-urlencoded";
|
contentType_ = "application/x-www-form-urlencoded";
|
||||||
// contentType_ = "multipart/form-data";
|
|
||||||
bodyParam_.insert_or_assign("command", "INIT");
|
bodyParam_.insert_or_assign("command", "INIT");
|
||||||
bodyParam_.insert_or_assign("media_type", "image/jpeg");
|
bodyParam_.insert_or_assign("media_type", "image/jpeg");
|
||||||
|
|
||||||
CocoaTweet::API::Model::MediaStore media;
|
|
||||||
HttpPost::process(_oauth,
|
HttpPost::process(_oauth,
|
||||||
[&media](const unsigned int _responseCode, const std::string& _rsv) {
|
[&media](const unsigned int _responseCode, const std::string& _rsv) {
|
||||||
std::cout << _rsv << std::endl;
|
|
||||||
media = CocoaTweet::API::Model::MediaStore::parse(_responseCode, _rsv);
|
media = CocoaTweet::API::Model::MediaStore::parse(_responseCode, _rsv);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -52,7 +51,6 @@ void Upload::process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth) {
|
|||||||
bodyParam_.insert_or_assign("command", "APPEND");
|
bodyParam_.insert_or_assign("command", "APPEND");
|
||||||
bodyParam_.insert_or_assign("segment_index", std::to_string(segment));
|
bodyParam_.insert_or_assign("segment_index", std::to_string(segment));
|
||||||
bodyParam_.insert_or_assign("media", data.substr(segment * chunk, chunk));
|
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) {
|
HttpPost::process(_oauth, [](const unsigned int _responseCode, const std::string& _rsv) {
|
||||||
// std::cout << _responseCode << std::endl << _rsv<< std::endl;
|
// std::cout << _responseCode << std::endl << _rsv<< std::endl;
|
||||||
});
|
});
|
||||||
@@ -66,13 +64,15 @@ void Upload::process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth) {
|
|||||||
bodyParam_.insert_or_assign("command", "FINALIZE");
|
bodyParam_.insert_or_assign("command", "FINALIZE");
|
||||||
bodyParam_.erase("segment_index");
|
bodyParam_.erase("segment_index");
|
||||||
bodyParam_.erase("media");
|
bodyParam_.erase("media");
|
||||||
CocoaTweet::API::Model::MediaStore media;
|
HttpPost::process(_oauth,
|
||||||
HttpPost::process(_oauth, [](const unsigned int _responseCode, const std::string& _rsv) {
|
[&media](const unsigned int _responseCode, const std::string& _rsv) {
|
||||||
std::cout << _rsv << std::endl;
|
media = CocoaTweet::API::Model::MediaStore::parse(_responseCode, _rsv);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// STATUS if needed
|
// STATUS if needed
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
return media;
|
||||||
}
|
}
|
||||||
} // namespace CocoaTweet::API::Medias
|
} // namespace CocoaTweet::API::Medias
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
#define COCOATWEET_API_MEDIA_UPLOAD_H_
|
#define COCOATWEET_API_MEDIA_UPLOAD_H_
|
||||||
|
|
||||||
#include <cocoatweet/api/interface/httpPost.h>
|
#include <cocoatweet/api/interface/httpPost.h>
|
||||||
|
#include <cocoatweet/api/model/mediaStore.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace CocoaTweet::API::Medias {
|
namespace CocoaTweet::API::Medias {
|
||||||
@@ -13,7 +14,7 @@ public:
|
|||||||
Upload();
|
Upload();
|
||||||
void media(const std::string& _media);
|
void media(const std::string& _media);
|
||||||
void mediaId(const std::string& _mediaId);
|
void mediaId(const std::string& _mediaId);
|
||||||
void process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth);
|
CocoaTweet::API::Model::MediaStore process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth);
|
||||||
};
|
};
|
||||||
} // namespace CocoaTweet::API::Medias
|
} // namespace CocoaTweet::API::Medias
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user