|
@@ -0,0 +1,142 @@
|
|
1
|
+/*
|
|
2
|
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
|
|
3
|
+ *
|
|
4
|
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+ * of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+ * in the Software without restriction, including without limitation the rights
|
|
7
|
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+ * copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+ * furnished to do so, subject to the following conditions:
|
|
10
|
+ *
|
|
11
|
+ * The above copyright notice and this permission notice shall be included in
|
|
12
|
+ * all copies or substantial portions of the Software.
|
|
13
|
+ *
|
|
14
|
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+ * SOFTWARE.
|
|
21
|
+ */
|
|
22
|
+
|
|
23
|
+package com.dmdirc.addons.parser_twitter.actions;
|
|
24
|
+
|
|
25
|
+import com.dmdirc.Server;
|
|
26
|
+import com.dmdirc.ServerManager;
|
|
27
|
+import com.dmdirc.actions.interfaces.ActionComponent;
|
|
28
|
+import com.dmdirc.addons.parser_twitter.Twitter;
|
|
29
|
+import com.dmdirc.addons.parser_twitter.api.TwitterStatus;
|
|
30
|
+import com.dmdirc.addons.parser_twitter.api.TwitterUser;
|
|
31
|
+import com.dmdirc.parser.interfaces.Parser;
|
|
32
|
+
|
|
33
|
+/**
|
|
34
|
+ * Action components which expose Twitter functionality.
|
|
35
|
+ *
|
|
36
|
+ * @since 0.6.4
|
|
37
|
+ * @author chris
|
|
38
|
+ */
|
|
39
|
+public enum TwitterActionComponents implements ActionComponent {
|
|
40
|
+
|
|
41
|
+ /** Takes a twitter channel name (&12345) and returns the status. */
|
|
42
|
+ TWITTER_CHANNEL_NAME_STATUS {
|
|
43
|
+
|
|
44
|
+ /** {@inheritDoc} */
|
|
45
|
+ @Override
|
|
46
|
+ public Object get(final Object argument) {
|
|
47
|
+ final long id = Long.parseLong(((String) argument).substring(1));
|
|
48
|
+
|
|
49
|
+ for (Server server : ServerManager.getServerManager().getServers()) {
|
|
50
|
+ final Parser parser = server.getParser();
|
|
51
|
+
|
|
52
|
+ if (parser instanceof Twitter) {
|
|
53
|
+ final TwitterStatus status = ((Twitter) parser).getApi().getStatus(id);
|
|
54
|
+
|
|
55
|
+ if (status != null) {
|
|
56
|
+ return status;
|
|
57
|
+ }
|
|
58
|
+ }
|
|
59
|
+ }
|
|
60
|
+
|
|
61
|
+ return null;
|
|
62
|
+ }
|
|
63
|
+
|
|
64
|
+ /** {@inheritDoc} */
|
|
65
|
+ @Override
|
|
66
|
+ public Class<?> appliesTo() {
|
|
67
|
+ return String.class;
|
|
68
|
+ }
|
|
69
|
+
|
|
70
|
+ /** {@inheritDoc} */
|
|
71
|
+ @Override
|
|
72
|
+ public Class<?> getType() {
|
|
73
|
+ return TwitterStatus.class;
|
|
74
|
+ }
|
|
75
|
+
|
|
76
|
+ /** {@inheritDoc} */
|
|
77
|
+ @Override
|
|
78
|
+ public String getName() {
|
|
79
|
+ return "twitter status (if a Twitter channel link)";
|
|
80
|
+ }
|
|
81
|
+
|
|
82
|
+ },
|
|
83
|
+
|
|
84
|
+ /** Returns the user who created a tweet. */
|
|
85
|
+ TWITTER_STATUS_USER {
|
|
86
|
+
|
|
87
|
+ /** {@inheritDoc} */
|
|
88
|
+ @Override
|
|
89
|
+ public Object get(final Object argument) {
|
|
90
|
+ return ((TwitterStatus) argument).getUser();
|
|
91
|
+ }
|
|
92
|
+
|
|
93
|
+ /** {@inheritDoc} */
|
|
94
|
+ @Override
|
|
95
|
+ public Class<?> appliesTo() {
|
|
96
|
+ return TwitterStatus.class;
|
|
97
|
+ }
|
|
98
|
+
|
|
99
|
+ /** {@inheritDoc} */
|
|
100
|
+ @Override
|
|
101
|
+ public Class<?> getType() {
|
|
102
|
+ return TwitterUser.class;
|
|
103
|
+ }
|
|
104
|
+
|
|
105
|
+ /** {@inheritDoc} */
|
|
106
|
+ @Override
|
|
107
|
+ public String getName() {
|
|
108
|
+ return "user";
|
|
109
|
+ }
|
|
110
|
+
|
|
111
|
+ },
|
|
112
|
+
|
|
113
|
+ /** Returns the screen name of a twitter user. */
|
|
114
|
+ TWITTER_USER_SCREENNAME {
|
|
115
|
+
|
|
116
|
+ /** {@inheritDoc} */
|
|
117
|
+ @Override
|
|
118
|
+ public Object get(final Object argument) {
|
|
119
|
+ return ((TwitterUser) argument).getScreenName();
|
|
120
|
+ }
|
|
121
|
+
|
|
122
|
+ /** {@inheritDoc} */
|
|
123
|
+ @Override
|
|
124
|
+ public Class<?> appliesTo() {
|
|
125
|
+ return TwitterUser.class;
|
|
126
|
+ }
|
|
127
|
+
|
|
128
|
+ /** {@inheritDoc} */
|
|
129
|
+ @Override
|
|
130
|
+ public Class<?> getType() {
|
|
131
|
+ return String.class;
|
|
132
|
+ }
|
|
133
|
+
|
|
134
|
+ /** {@inheritDoc} */
|
|
135
|
+ @Override
|
|
136
|
+ public String getName() {
|
|
137
|
+ return "screen name";
|
|
138
|
+ }
|
|
139
|
+
|
|
140
|
+ };
|
|
141
|
+
|
|
142
|
+}
|