1
1
package eu .bittrade .libs .steemj .plugins .apis .tags ;
2
2
3
- import java .text .ParseException ;
4
- import java .text .SimpleDateFormat ;
5
- import java .util .Date ;
6
3
import java .util .List ;
7
- import java .util .TimeZone ;
8
4
9
- import eu .bittrade .libs .steemj .base .models .Permlink ;
10
5
import eu .bittrade .libs .steemj .communication .CommunicationHandler ;
11
6
import eu .bittrade .libs .steemj .communication .jrpc .JsonRPCRequest ;
12
- import eu .bittrade .libs .steemj .configuration .SteemJConfig ;
13
7
import eu .bittrade .libs .steemj .enums .RequestMethods ;
14
8
import eu .bittrade .libs .steemj .enums .SteemApiType ;
15
9
import eu .bittrade .libs .steemj .exceptions .SteemCommunicationException ;
16
10
import eu .bittrade .libs .steemj .exceptions .SteemResponseException ;
17
- import eu .bittrade .libs .steemj .exceptions .SteemTransformationException ;
18
11
import eu .bittrade .libs .steemj .plugins .apis .tags .enums .DiscussionSortType ;
19
12
import eu .bittrade .libs .steemj .plugins .apis .tags .models .Discussion ;
13
+ import eu .bittrade .libs .steemj .plugins .apis .tags .models .DiscussionQuery ;
14
+ import eu .bittrade .libs .steemj .plugins .apis .tags .models .DiscussionQueryResult ;
15
+ import eu .bittrade .libs .steemj .plugins .apis .tags .models .GetActiveVotesArgs ;
16
+ import eu .bittrade .libs .steemj .plugins .apis .tags .models .GetActiveVotesReturn ;
17
+ import eu .bittrade .libs .steemj .plugins .apis .tags .models .GetDiscussionArgs ;
18
+ import eu .bittrade .libs .steemj .plugins .apis .tags .models .GetDiscussionsByAuthorBeforeDateArgs ;
19
+ import eu .bittrade .libs .steemj .plugins .apis .tags .models .GetRepliesByLastUpdateArgs ;
20
+ import eu .bittrade .libs .steemj .plugins .apis .tags .models .GetTagsUsedByAuthorArgs ;
21
+ import eu .bittrade .libs .steemj .plugins .apis .tags .models .GetTagsUsedByAuthorReturn ;
20
22
import eu .bittrade .libs .steemj .plugins .apis .tags .models .Tag ;
21
- import eu .bittrade .libs .steemj .plugins .apis .tags .models .VoteState ;
22
- import eu .bittrade .libs .steemj .protocol .AccountName ;
23
23
24
24
/**
25
25
* This class implements the tags api.
@@ -82,14 +82,43 @@ public static List<Tag> getTrendingTags(CommunicationHandler communicationHandle
82
82
return communicationHandler .performRequest (requestObject , Tag .class );
83
83
}
84
84
85
- public static void getTagsUsedByAuthor (CommunicationHandler communicationHandler ) {
86
-
85
+ /**
86
+ *
87
+ * @param communicationHandler
88
+ * @param getTagsUsedByAuthorArgs
89
+ * @return
90
+ * @throws SteemCommunicationException
91
+ * @throws SteemResponseException
92
+ */
93
+ public static GetTagsUsedByAuthorReturn getTagsUsedByAuthor (CommunicationHandler communicationHandler ,
94
+ GetTagsUsedByAuthorArgs getTagsUsedByAuthorArgs )
95
+ throws SteemCommunicationException , SteemResponseException {
96
+ JsonRPCRequest requestObject = new JsonRPCRequest ();
97
+ requestObject .setApiMethod (RequestMethods .GET_CONTENT_REPLIES );
98
+ requestObject .setSteemApi (SteemApiType .TAGS_API );
99
+ requestObject .setAdditionalParameters (getTagsUsedByAuthorArgs );
100
+
101
+ return communicationHandler .performRequest (requestObject , GetTagsUsedByAuthorReturn .class ).get (0 );
87
102
}
88
-
89
- public static void getDiscussion (CommunicationHandler communicationHandler ) {
90
-
103
+
104
+ /**
105
+ *
106
+ * @param communicationHandler
107
+ * @param getDiscussionArgs
108
+ * @return
109
+ * @throws SteemCommunicationException
110
+ * @throws SteemResponseException
111
+ */
112
+ public static Discussion getDiscussion (CommunicationHandler communicationHandler ,
113
+ GetDiscussionArgs getDiscussionArgs ) throws SteemCommunicationException , SteemResponseException {
114
+ JsonRPCRequest requestObject = new JsonRPCRequest ();
115
+ requestObject .setApiMethod (RequestMethods .GET_DISCUSSION );
116
+ requestObject .setSteemApi (SteemApiType .TAGS_API );
117
+ requestObject .setAdditionalParameters (getDiscussionArgs );
118
+
119
+ return communicationHandler .performRequest (requestObject , Discussion .class ).get (0 );
91
120
}
92
-
121
+
93
122
/**
94
123
* Get the replies of a specific post.
95
124
*
@@ -113,26 +142,52 @@ public static void getDiscussion(CommunicationHandler communicationHandler) {
113
142
* <li>If the Server returned an error object.</li>
114
143
* </ul>
115
144
*/
116
- public List < Discussion > getContentReplies (CommunicationHandler communicationHandler , AccountName author , Permlink permlink )
117
- throws SteemCommunicationException , SteemResponseException {
145
+ public DiscussionQueryResult getContentReplies (CommunicationHandler communicationHandler ,
146
+ DiscussionQuery discussionQuery ) throws SteemCommunicationException , SteemResponseException {
118
147
JsonRPCRequest requestObject = new JsonRPCRequest ();
119
148
requestObject .setApiMethod (RequestMethods .GET_CONTENT_REPLIES );
120
- requestObject .setSteemApi (SteemApiType .DATABASE_API );
121
- String [] parameters = { author .getName (), permlink .getLink () };
122
- requestObject .setAdditionalParameters (parameters );
149
+ requestObject .setSteemApi (SteemApiType .TAGS_API );
150
+ requestObject .setAdditionalParameters (discussionQuery );
123
151
124
- return communicationHandler .performRequest (requestObject , Discussion .class );
152
+ return communicationHandler .performRequest (requestObject , DiscussionQueryResult .class ). get ( 0 );
125
153
}
126
-
127
-
128
- public static void getPostDiscussionsByPayout () {
129
-
154
+
155
+ /**
156
+ *
157
+ * @param communicationHandler
158
+ * @param discussionQuery
159
+ * @return
160
+ * @throws SteemCommunicationException
161
+ * @throws SteemResponseException
162
+ */
163
+ public static DiscussionQueryResult getPostDiscussionsByPayout (CommunicationHandler communicationHandler ,
164
+ DiscussionQuery discussionQuery ) throws SteemCommunicationException , SteemResponseException {
165
+ JsonRPCRequest requestObject = new JsonRPCRequest ();
166
+ requestObject .setApiMethod (RequestMethods .GET_POST_DISCUSSIONS_BY_PAYOUT );
167
+ requestObject .setSteemApi (SteemApiType .TAGS_API );
168
+ requestObject .setAdditionalParameters (discussionQuery );
169
+
170
+ return communicationHandler .performRequest (requestObject , DiscussionQueryResult .class ).get (0 );
130
171
}
131
-
132
- public static void getCommentDiscussionsByPayout () {
133
-
172
+
173
+ /**
174
+ *
175
+ * @param communicationHandler
176
+ * @param discussionQuery
177
+ * @return
178
+ * @throws SteemCommunicationException
179
+ * @throws SteemResponseException
180
+ */
181
+ public static DiscussionQueryResult getCommentDiscussionsByPayout (CommunicationHandler communicationHandler ,
182
+ DiscussionQuery discussionQuery ) throws SteemCommunicationException , SteemResponseException {
183
+ JsonRPCRequest requestObject = new JsonRPCRequest ();
184
+ requestObject .setApiMethod (RequestMethods .GET_COMMENT_DISCUSSIONS_BY_PAYOUT );
185
+ requestObject .setSteemApi (SteemApiType .TAGS_API );
186
+ requestObject .setAdditionalParameters (discussionQuery );
187
+
188
+ return communicationHandler .performRequest (requestObject , DiscussionQueryResult .class ).get (0 );
134
189
}
135
-
190
+
136
191
/**
137
192
* Get active discussions for a specified tag.
138
193
*
@@ -156,30 +211,15 @@ public static void getCommentDiscussionsByPayout() {
156
211
* <li>If the Server returned an error object.</li>
157
212
* </ul>
158
213
*/
159
- public List <Discussion > getDiscussionsBy (CommunicationHandler communicationHandler , eu . bittrade . libs . steemj . plugins . apis . tags . models . DiscussionQuery discussionQuery , DiscussionSortType sortBy )
160
- throws SteemCommunicationException , SteemResponseException {
214
+ public List <Discussion > getDiscussionsBy (CommunicationHandler communicationHandler , DiscussionQuery discussionQuery ,
215
+ DiscussionSortType sortBy ) throws SteemCommunicationException , SteemResponseException {
161
216
JsonRPCRequest requestObject = new JsonRPCRequest ();
162
-
163
217
requestObject .setApiMethod (RequestMethods .valueOf (sortBy .name ()));
164
- requestObject .setSteemApi (SteemApiType .DATABASE_API );
165
- Object [] parameters = { discussionQuery };
166
- requestObject .setAdditionalParameters (parameters );
218
+ requestObject .setSteemApi (SteemApiType .TAGS_API );
219
+ requestObject .setAdditionalParameters (discussionQuery );
167
220
168
221
return communicationHandler .performRequest (requestObject , Discussion .class );
169
-
170
- /*(get_discussions_by_trending)
171
- (get_discussions_by_created)
172
- (get_discussions_by_active)
173
- (get_discussions_by_cashout)
174
- (get_discussions_by_votes)
175
- (get_discussions_by_children)
176
- (get_discussions_by_hot)
177
- (get_discussions_by_feed)
178
- (get_discussions_by_blog)
179
- (get_discussions_by_comments)
180
- (get_discussions_by_promoted)*/
181
222
}
182
-
183
223
184
224
/**
185
225
* /** Get a list of Content starting from the given post of the given user.
@@ -207,17 +247,17 @@ public List<Discussion> getDiscussionsBy(CommunicationHandler communicationHandl
207
247
* <li>If the Server returned an error object.</li>
208
248
* </ul>
209
249
*/
210
- public List <Discussion > getRepliesByLastUpdate (CommunicationHandler communicationHandler , AccountName username , Permlink permlink , int limit )
250
+ public List <Discussion > getRepliesByLastUpdate (CommunicationHandler communicationHandler ,
251
+ GetRepliesByLastUpdateArgs getRepliesByLastUpdateArgs )
211
252
throws SteemCommunicationException , SteemResponseException {
212
253
JsonRPCRequest requestObject = new JsonRPCRequest ();
213
254
requestObject .setApiMethod (RequestMethods .GET_REPLIES_BY_LAST_UPDATE );
214
- requestObject .setSteemApi (SteemApiType .DATABASE_API );
215
- Object [] parameters = { username , permlink .getLink (), String .valueOf (limit ) };
216
- requestObject .setAdditionalParameters (parameters );
255
+ requestObject .setSteemApi (SteemApiType .TAGS_API );
256
+ requestObject .setAdditionalParameters (getRepliesByLastUpdateArgs );
217
257
218
258
return communicationHandler .performRequest (requestObject , Discussion .class );
219
259
}
220
-
260
+
221
261
/**
222
262
* Get a list of discussion for a given author.
223
263
*
@@ -246,30 +286,17 @@ public List<Discussion> getRepliesByLastUpdate(CommunicationHandler communicatio
246
286
* <li>If the Server returned an error object.</li>
247
287
* </ul>
248
288
*/
249
- public List <Discussion > getDiscussionsByAuthorBeforeDate (CommunicationHandler communicationHandler , AccountName author , Permlink permlink , String date ,
250
- int limit ) throws SteemCommunicationException , SteemResponseException {
289
+ public DiscussionQueryResult getDiscussionsByAuthorBeforeDate (CommunicationHandler communicationHandler ,
290
+ GetDiscussionsByAuthorBeforeDateArgs getDiscussionsByAuthorBeforeDateArgs )
291
+ throws SteemCommunicationException , SteemResponseException {
251
292
JsonRPCRequest requestObject = new JsonRPCRequest ();
252
-
253
293
requestObject .setApiMethod (RequestMethods .GET_DISCUSSIONS_BY_AUTHOR_BEFORE_DATE );
254
- requestObject .setSteemApi (SteemApiType .DATABASE_API );
294
+ requestObject .setSteemApi (SteemApiType .TAGS_API );
295
+ requestObject .setAdditionalParameters (getDiscussionsByAuthorBeforeDateArgs );
255
296
256
- // Verify that the date has the correct format.
257
- SimpleDateFormat simpleDateFormat = new SimpleDateFormat (SteemJConfig .getInstance ().getDateTimePattern ());
258
- simpleDateFormat .setTimeZone (TimeZone .getTimeZone (SteemJConfig .getInstance ().getTimeZoneId ()));
259
- Date beforeDate ;
260
- try {
261
- beforeDate = simpleDateFormat .parse (date );
262
- } catch (ParseException e ) {
263
- throw new SteemTransformationException ("Could not parse the received date to a Date object." , e );
264
- }
265
-
266
- String [] parameters = { author .getName (), permlink .getLink (), simpleDateFormat .format (beforeDate ),
267
- String .valueOf (limit ) };
268
- requestObject .setAdditionalParameters (parameters );
269
-
270
- return communicationHandler .performRequest (requestObject , Discussion .class );
297
+ return communicationHandler .performRequest (requestObject , DiscussionQueryResult .class ).get (0 );
271
298
}
272
-
299
+
273
300
/**
274
301
* Get the active votes for a given post of a given author.
275
302
*
@@ -293,14 +320,13 @@ public List<Discussion> getDiscussionsByAuthorBeforeDate(CommunicationHandler co
293
320
* <li>If the Server returned an error object.</li>
294
321
* </ul>
295
322
*/
296
- public static List < VoteState > getActiveVotes (CommunicationHandler communicationHandler , AccountName author , Permlink permlink )
297
- throws SteemCommunicationException , SteemResponseException {
323
+ public static GetActiveVotesReturn getActiveVotes (CommunicationHandler communicationHandler ,
324
+ GetActiveVotesArgs getActiveVotesArgs ) throws SteemCommunicationException , SteemResponseException {
298
325
JsonRPCRequest requestObject = new JsonRPCRequest ();
299
326
requestObject .setApiMethod (RequestMethods .GET_ACTIVE_VOTES );
300
- requestObject .setSteemApi (SteemApiType .DATABASE_API );
301
- String [] parameters = { author .getName (), permlink .getLink () };
302
- requestObject .setAdditionalParameters (parameters );
327
+ requestObject .setSteemApi (SteemApiType .TAGS_API );
328
+ requestObject .setAdditionalParameters (getActiveVotesArgs );
303
329
304
- return communicationHandler .performRequest (requestObject , VoteState .class );
330
+ return communicationHandler .performRequest (requestObject , GetActiveVotesReturn .class ). get ( 0 );
305
331
}
306
332
}
0 commit comments