forked from pocoproject/poco
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTweetApp.cpp
More file actions
153 lines (129 loc) · 3.71 KB
/
TweetApp.cpp
File metadata and controls
153 lines (129 loc) · 3.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
//
// TwitterApp.cpp
//
// A very simple command-line Twitter client.
//
// Copyright (c) 2009-2013, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#include "Poco/Util/Application.h"
#include "Poco/Util/Option.h"
#include "Poco/Util/OptionSet.h"
#include "Poco/Util/HelpFormatter.h"
#include "Twitter.h"
#include <iostream>
using Poco::Util::Application;
using Poco::Util::Option;
using Poco::Util::OptionSet;
using Poco::Util::HelpFormatter;
using Poco::Util::AbstractConfiguration;
using Poco::Util::OptionCallback;
class TweetApp: public Application
/// A very simple Twitter command-line client.
{
public:
TweetApp()
{
}
protected:
void defineOptions(OptionSet& options)
{
Application::defineOptions(options);
options.addOption(
Option("help", "h", "Display help information on command line arguments.")
.required(false)
.repeatable(false)
.callback(OptionCallback<TweetApp>(this, &TweetApp::handleHelp)));
options.addOption(
Option("message", "m", "Specify the status message to post.")
.required(true)
.repeatable(false)
.argument("message")
.callback(OptionCallback<TweetApp>(this, &TweetApp::handleMessage)));
options.addOption(
Option("ckey", "c", "Specify the Twitter consumer key.")
.required(true)
.repeatable(false)
.argument("consumer key")
.callback(OptionCallback<TweetApp>(this, &TweetApp::handleConsumerKey)));
options.addOption(
Option("csecret", "s", "Specify the Twitter consumer secret.")
.required(true)
.repeatable(false)
.argument("consumer secret")
.callback(OptionCallback<TweetApp>(this, &TweetApp::handleConsumerSecret)));
options.addOption(
Option("token", "t", "Specify the Twitter access token.")
.required(true)
.repeatable(true)
.argument("access token")
.callback(OptionCallback<TweetApp>(this, &TweetApp::handleAccessToken)));
options.addOption(
Option("tsecret", "S", "Specify the Twitter access token secret.")
.required(true)
.repeatable(true)
.argument("access token secret")
.callback(OptionCallback<TweetApp>(this, &TweetApp::handleAccessTokenSecret)));
}
void handleHelp(const std::string& name, const std::string& value)
{
displayHelp();
stopOptionsProcessing();
}
void handleConsumerKey(const std::string& name, const std::string& value)
{
_consumerKey = value;
}
void handleConsumerSecret(const std::string& name, const std::string& value)
{
_consumerSecret = value;
}
void handleAccessToken(const std::string& name, const std::string& value)
{
_accessToken = value;
}
void handleAccessTokenSecret(const std::string& name, const std::string& value)
{
_accessTokenSecret = value;
}
void handleMessage(const std::string& name, const std::string& value)
{
_message = value;
}
void displayHelp()
{
HelpFormatter helpFormatter(options());
helpFormatter.setCommand(commandName());
helpFormatter.setUsage("OPTIONS");
helpFormatter.setHeader("A simple Twitter command line client for posting status updates.");
helpFormatter.format(std::cout);
}
int main(const std::vector<std::string>& args)
{
try
{
if (!_message.empty())
{
Twitter twitter;
twitter.login(_consumerKey, _consumerSecret, _accessToken, _accessTokenSecret);
Poco::Int64 statusId = twitter.update(_message);
std::cout << statusId << std::endl;
}
}
catch (Poco::Exception& exc)
{
std::cerr << exc.displayText() << std::endl;
return Application::EXIT_SOFTWARE;
}
return Application::EXIT_OK;
}
private:
std::string _consumerKey;
std::string _consumerSecret;
std::string _accessToken;
std::string _accessTokenSecret;
std::string _message;
};
POCO_APP_MAIN(TweetApp)