This commit is contained in:
keita
2022-04-21 10:03:33 +09:00
parent 9dc7f35365
commit d43e04506b
15 changed files with 127 additions and 6 deletions
+34
View File
@@ -0,0 +1,34 @@
#include "cocoatweet/api/user/show.h"
#include <cocoatweet/util/util.h>
#include "nlohmann/json.hpp"
namespace CocoaTweet::API::Users {
Show::Show() {
contentType_ = "application/x-www-form-urlencoded";
url_ = "https://api.twitter.com/1.1/users/show.json";
}
void Show::screenName(const std::string& _screenName) {
if(bodyParam_.count("user_id") > 0){
bodyParam_.erase("user_id");
}
bodyParam_.insert_or_assign("screen_name", _screenName);
}
void Show::id(const std::string& _id) {
if(bodyParam_.count("screen_name") > 0){
bodyParam_.erase("screen_name");
}
bodyParam_.insert_or_assign("id", _id);
}
CocoaTweet::API::Model::User Show::process(
std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth) {
CocoaTweet::API::Model::User user;
HttpGet::process(_oauth, [&user](const std::string& _rcv) {
user = CocoaTweet::API::Model::User::parse(_rcv);
});
return user;
}
} // namespace CocoaTweet::API::Statuses
+36
View File
@@ -0,0 +1,36 @@
#ifndef COCOATWEET_API_USER_SHOW_H_
#define COCOATWEET_API_USER_SHOW_H_
#include <cocoatweet/api/interface/httpGet.h>
#include <cocoatweet/api/model/user.h>
#include <vector>
#include <utility>
#include <memory>
namespace CocoaTweet::API::Users {
/// @brief class for using users/show endpoint
class Show : public CocoaTweet::API::Interface::HttpGet {
public:
/// @brief primary constructor
Show();
/// @brief set screen name to get user information
/// @param[in] const std::string& _id : screen name for getting information
void id(const std::string& _id);
/// @brief set screen name to get user information
/// @param[in] const std::string& _screenName : screen name for getting information
void screenName(const std::string& _screenName);
/// @brief process request for endpoint
/// @param[in] std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth : pointer to oauth object
/// @param[out] CocoaTweet::API::Model::User : request result
CocoaTweet::API::Model::User process(
std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth);
private:
std::string status_;
};
} // namespace CocoaTweet::API::Statuses
#endif
+14
View File
@@ -0,0 +1,14 @@
#include <cocoatweet/api/user/user.h>
#include <cocoatweet/api/user/show.h>
namespace CocoaTweet::API::Users{
User::User(std::shared_ptr<CocoaTweet::OAuth::OAuth1> _oauth) {
oauth_ = _oauth;
}
CocoaTweet::API::Model::User User::show(const std::string& _screenName)const{
CocoaTweet::API::Users::Show show;
show.screenName(_screenName);
return show.process(oauth_);
}
}
+26
View File
@@ -0,0 +1,26 @@
#ifndef COCOATWEET_API_USER_USER_H_
#define COCOATWEET_API_USER_USER_H_
#include "cocoatweet/api/interface/groupInterface.h"
#include "cocoatweet/oauth/oauth.h"
#include <cocoatweet/api/model/user.h>
#include <vector>
#include <utility>
namespace CocoaTweet::API::Users {
/// @brief class for using users/show endpoint
class User : public groupInterface {
public:
/// @brief primary constructor
User() = default;
/// @brief constructor which finally should to be called.
/// @param[in] std::shared_ptr<CocoaTweet::OAuth::OAuth1> : pointer to OAuth object
User(std::shared_ptr<CocoaTweet::OAuth::OAuth1> _oauth);
CocoaTweet::API::Model::User show(const std::string& _screenName) const;
};
} // namespace CocoaTweet::API::Statuses
#endif