Skip to content

Commit

Permalink
Add Account Activity API (beta) "GET account_activity/all/:env_name/s…
Browse files Browse the repository at this point in the history
…ubscriptions/list". fixes #329 @15m
  • Loading branch information
みぞ@CrazyBeatCoder committed Feb 22, 2018
1 parent 2d6f7a5 commit 0da3923
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 0 deletions.
@@ -0,0 +1,18 @@
package com.mizo0203.twitter.account.activity.api.beta.samples;

import com.mizo0203.twitter.account.activity.api.beta.samples.domain.UseCase;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class ListCurrentAllActivityTypeSubscriptionsServlet extends HttpServlet {

@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
try (UseCase useCase = new UseCase()) {
useCase.listCurrentAllActivityTypeSubscriptions();
}
}
}
Expand Up @@ -61,6 +61,18 @@ public void isSubscribed() {
mTwitterClient.isSubscribed();
}

/**
* Returns a list of the current All Activity type subscriptions. Note that the /list endpoint
* requires App-only Oauth, so requests should be made using a bearer token instead of app-user
* auth.
*
* <p>現在のAll Activity型サブスクリプションのリストを返します。 / listエンドポイントではApp-only Oauthが必要なので、app-user
* authの代わりにベアラトークンを使用してリクエストする必要があります。
*/
public void listCurrentAllActivityTypeSubscriptions() {
mTwitterClient.listCurrentAllActivityTypeSubscriptions();
}

/**
* Deactivates subscription(s) for the provided user context and app for all activities. After
* deactivation, all All events for the requesting user will no longer be sent to the webhook URL.
Expand Down
Expand Up @@ -21,6 +21,8 @@ public class TwitterClient {
"https://api.twitter.com/1.1/account_activity/all/env-beta/subscriptions.json";
private static final String TWITTER_API_ACCOUNT_ACTIVITY_COUNT_URL_STR =
"https://api.twitter.com/1.1/account_activity/all/count.json";
private static final String TWITTER_API_ACCOUNT_ACTIVITY_LIST_SUBSCRIPTIONS_URL_STR =
"https://api.twitter.com/1.1/account_activity/all/:env_name/subscriptions/list.json";
private final Twitter mTwitter;
private final Twitter4JUtil mTwitter4JUtil;

Expand Down Expand Up @@ -118,6 +120,29 @@ public void isSubscribed() {
}
}

/**
* Returns a list of the current All Activity type subscriptions. Note that the /list endpoint
* requires App-only Oauth, so requests should be made using a bearer token instead of app-user
* auth.
*
* <p>現在のAll Activity型サブスクリプションのリストを返します。 / listエンドポイントではApp-only Oauthが必要なので、app-user
* authの代わりにベアラトークンを使用してリクエストする必要があります。
*/
public void listCurrentAllActivityTypeSubscriptions() {
try {
HttpResponse ret =
mTwitter4JUtil
.getApplicationOnlyAuthentication()
.get(TWITTER_API_ACCOUNT_ACTIVITY_LIST_SUBSCRIPTIONS_URL_STR);
LOG.log(
Level.INFO, "listCurrentAllActivityTypeSubscriptions ret.toString(): " + ret.toString());
LOG.log(
Level.INFO, "listCurrentAllActivityTypeSubscriptions ret.asString(): " + ret.asString());
} catch (TwitterException e) {
e.printStackTrace();
}
}

/**
* Deactivates subscription(s) for the provided user context and app for all activities. After
* deactivation, all All events for the requesting user will no longer be sent to the webhook URL.
Expand Down
10 changes: 10 additions & 0 deletions src/main/webapp/WEB-INF/web.xml
Expand Up @@ -43,6 +43,16 @@
<servlet-name>returns_all_urls</servlet-name>
<url-pattern>/admin/returns_all_urls</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>list_current_all_activity_type_subscriptions</servlet-name>
<servlet-class>
com.mizo0203.twitter.account.activity.api.beta.samples.ListCurrentAllActivityTypeSubscriptionsServlet
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>list_current_all_activity_type_subscriptions</servlet-name>
<url-pattern>/admin/list_current_all_activity_type_subscriptions</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>deactivates_subscriptions</servlet-name>
<servlet-class>com.mizo0203.twitter.account.activity.api.beta.samples.DeactivatesSubscriptionsServlet
Expand Down
5 changes: 5 additions & 0 deletions src/main/webapp/index.html
Expand Up @@ -34,6 +34,11 @@ <h1>Hello App Engine!</h1>
<tr>
<td><a href="admin/is_subscribed">is_subscribed</a></td>
</tr>
<tr>
<td>
<a href="admin/list_current_all_activity_type_subscriptions">list_current_all_activity_type_subscriptions</a>
</td>
</tr>
<tr>
<td><a href="admin/deactivates_subscriptions">deactivates_subscriptions</a></td>
</tr>
Expand Down

0 comments on commit 0da3923

Please sign in to comment.