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". fixes #328 @30m
  • Loading branch information
みぞ@CrazyBeatCoder committed Feb 19, 2018
1 parent 9180cbd commit 6c1fe51
Show file tree
Hide file tree
Showing 5 changed files with 64 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 IsSubscribedServlet extends HttpServlet {

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

/**
* Provides a way to determine if a webhook configuration is subscribed to the provided user’s All
* events. If the provided user context has an active subscription with provided app, returns 204
* OK. If the response code is not 204, then the user does not have an active subscription. See
* HTTP Response code and error messages below for details.
*
* <p>Webhook設定が、提供されたユーザのすべてのイベントに登録されているかどうかを判断する方法を提供します。
* 提供されたユーザーコンテキストに、提供されたアプリケーションによるアクティブなサブスクリプションがある場合は、204 OKを返します。
* 応答コードが204でない場合、ユーザーにはアクティブなサブスクリプションがありません。 詳細については、下記の「HTTPレスポンスコードとエラーメッセージ」を参照してください。
*/
public void isSubscribed() {
mTwitterClient.isSubscribed();
}

/**
* 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 @@ -71,6 +71,27 @@ public void subscriptions() {
}
}

/**
* Provides a way to determine if a webhook configuration is subscribed to the provided user’s All
* events. If the provided user context has an active subscription with provided app, returns 204
* OK. If the response code is not 204, then the user does not have an active subscription. See
* HTTP Response code and error messages below for details.
*
* <p>Webhook設定が、提供されたユーザのすべてのイベントに登録されているかどうかを判断する方法を提供します。
* 提供されたユーザーコンテキストに、提供されたアプリケーションによるアクティブなサブスクリプションがある場合は、204 OKを返します。
* 応答コードが204でない場合、ユーザーにはアクティブなサブスクリプションがありません。 詳細については、下記の「HTTPレスポンスコードとエラーメッセージ」を参照してください。
*/
public void isSubscribed() {
try {
HttpResponse ret =
mTwitter4JUtil.get(TWITTER_API_ACCOUNT_ACTIVITY_SUBSCRIPTIONS_ENV_NAME_URL_STR);
LOG.log(Level.INFO, "isSubscribed ret.toString(): " + ret.toString());
LOG.log(Level.INFO, "isSubscribed 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
8 changes: 8 additions & 0 deletions src/main/webapp/WEB-INF/web.xml
Expand Up @@ -19,6 +19,14 @@
<servlet-name>subscriptions</servlet-name>
<url-pattern>/admin/subscriptions</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>is_subscribed</servlet-name>
<servlet-class>com.mizo0203.twitter.account.activity.api.beta.samples.IsSubscribedServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>is_subscribed</servlet-name>
<url-pattern>/admin/is_subscribed</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>returns_all_urls</servlet-name>
<servlet-class>com.mizo0203.twitter.account.activity.api.beta.samples.ReturnsAllUrlsServlet</servlet-class>
Expand Down
3 changes: 3 additions & 0 deletions src/main/webapp/index.html
Expand Up @@ -28,6 +28,9 @@ <h1>Hello App Engine!</h1>
<tr>
<td><a href="admin/subscriptions">subscriptions</a></td>
</tr>
<tr>
<td><a href="admin/is_subscribed">is_subscribed</a></td>
</tr>
<tr>
<td><a href="admin/deactivates_subscriptions">deactivates_subscriptions</a></td>
</tr>
Expand Down

0 comments on commit 6c1fe51

Please sign in to comment.