1 |
df4ee0a0
|
みぞ@CrazyBeatCoder
|
package com.mizo0203.twitter.timeline.talker;
|
2 |
|
|
|
3 |
|
|
import twitter4j.conf.Configuration;
|
4 |
|
|
import twitter4j.conf.ConfigurationBuilder;
|
5 |
|
|
|
6 |
|
|
/**
|
7 |
|
|
* Java アプリケーション起動時に実行されるクラス
|
8 |
|
|
*
|
9 |
|
|
* @author みぞ@CrazyBeatCoder
|
10 |
|
|
*/
|
11 |
|
|
public class Application {
|
12 |
|
|
|
13 |
|
|
public static void main(String[] args) {
|
14 |
|
|
TwitterTimelineTalker twitterTimelineTalker;
|
15 |
|
|
Talker talker;
|
16 |
|
|
|
17 |
|
|
try {
|
18 |
|
|
talker = new Talker();
|
19 |
|
|
twitterTimelineTalker =
|
20 |
|
|
new TwitterTimelineTalker(new Arguments(args).twitterConfiguration, talker);
|
21 |
|
|
} catch (IllegalArgumentException | IllegalStateException e) {
|
22 |
|
|
System.err.println(e.getMessage());
|
23 |
|
|
return;
|
24 |
|
|
}
|
25 |
|
|
|
26 |
|
|
twitterTimelineTalker.start();
|
27 |
|
|
talker.talkAsync("アプリケーションを起動しました", Talker.YukkuriVoice.REIMU);
|
28 |
|
|
}
|
29 |
|
|
|
30 |
|
|
/**
|
31 |
|
|
* Java アプリケーション起動時に指定する引数のデータクラス
|
32 |
|
|
*
|
33 |
|
|
* @author みぞ@CrazyBeatCoder
|
34 |
|
|
*/
|
35 |
|
|
private static class Arguments {
|
36 |
|
|
|
37 |
|
|
private final Configuration twitterConfiguration;
|
38 |
|
|
|
39 |
|
|
private Arguments(String[] args) throws IllegalArgumentException {
|
40 |
|
|
if (args.length < Argument.values().length) {
|
41 |
|
|
StringBuilder exceptionMessage = new StringBuilder();
|
42 |
|
|
exceptionMessage.append(Argument.values().length + " つの引数を指定してください。\n");
|
43 |
|
|
for (Argument arg : Argument.values()) {
|
44 |
|
|
exceptionMessage.append((arg.ordinal() + 1) + " つ目: " + arg.detail + "\n");
|
45 |
|
|
}
|
46 |
|
|
throw new IllegalArgumentException(exceptionMessage.toString());
|
47 |
|
|
}
|
48 |
|
|
|
49 |
|
|
String consumer_key = args[Argument.CONSUMER_KEY.ordinal()];
|
50 |
|
|
String consumer_secret = args[Argument.CONSUMER_SECRET.ordinal()];
|
51 |
|
|
String access_token = args[Argument.ACCESS_TOKEN.ordinal()];
|
52 |
|
|
String access_token_secret = args[Argument.ACCESS_TOKEN_SECRET.ordinal()];
|
53 |
|
|
|
54 |
|
|
twitterConfiguration = new ConfigurationBuilder().setOAuthConsumerKey(consumer_key)
|
55 |
|
|
.setOAuthConsumerSecret(consumer_secret).setOAuthAccessToken(access_token)
|
56 |
|
|
.setOAuthAccessTokenSecret(access_token_secret).build();
|
57 |
|
|
}
|
58 |
|
|
|
59 |
|
|
}
|
60 |
|
|
|
61 |
|
|
/**
|
62 |
|
|
* Java アプリケーション起動時に指定する引数の定義
|
63 |
|
|
*
|
64 |
|
|
* @author みぞ@CrazyBeatCoder
|
65 |
|
|
*/
|
66 |
|
|
private enum Argument {
|
67 |
|
|
CONSUMER_KEY("Twitter Application's Consumer Key (API Key)"), //
|
68 |
|
|
CONSUMER_SECRET("Twitter Application's Consumer Secret (API Secret)"), //
|
69 |
|
|
ACCESS_TOKEN("Twitter Account's Access Token"), //
|
70 |
|
|
ACCESS_TOKEN_SECRET("Twitter Account's Access Token Secret"), //
|
71 |
|
|
;
|
72 |
|
|
|
73 |
|
|
private final String detail;
|
74 |
|
|
|
75 |
|
|
private Argument(String detail) {
|
76 |
|
|
this.detail = detail;
|
77 |
|
|
}
|
78 |
|
|
}
|
79 |
|
|
}
|