-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Account Activity API (beta) "DELETE account_activity/all/:env_nam…
…e/subscriptions". fixes #331 @2h
- Loading branch information
みぞ@CrazyBeatCoder
committed
Feb 18, 2018
1 parent
a83d285
commit 4b29455
Showing
6 changed files
with
139 additions
and
12 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
...m/mizo0203/twitter/account/activity/api/beta/samples/DeactivatesSubscriptionsServlet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright 2015 Google Inc. <p> Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. You may obtain a copy of the | ||
* License at <p> http://www.apache.org/licenses/LICENSE-2.0 <p> Unless required by applicable law | ||
* or agreed to in writing, software distributed under the License is distributed on an "AS IS" | ||
* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License | ||
* for the specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
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 DeactivatesSubscriptionsServlet extends HttpServlet { | ||
|
||
@Override | ||
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { | ||
try (UseCase useCase = new UseCase()) { | ||
useCase.deactivatesSubscriptions(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package twitter4j; | ||
|
||
import com.mizo0203.twitter.account.activity.api.beta.samples.domain.difine.KeysAndAccessTokens; | ||
import twitter4j.auth.AccessToken; | ||
|
||
import java.lang.reflect.Field; | ||
|
||
public class Twitter4JUtil { | ||
private final HttpParameter[] IMPLICIT_PARAMS; | ||
private final TwitterImpl mTwitter; | ||
|
||
public Twitter4JUtil() { | ||
mTwitter = createTwitterInstance(); | ||
IMPLICIT_PARAMS = createHttpParameterArray(mTwitter); | ||
} | ||
|
||
private static TwitterImpl createTwitterInstance() { | ||
TwitterImpl twitter = (TwitterImpl) new TwitterFactory().getInstance(); | ||
twitter.setOAuthConsumer(KeysAndAccessTokens.CONSUMER_KEY, KeysAndAccessTokens.CONSUMER_SECRET); | ||
twitter.setOAuthAccessToken( | ||
new AccessToken(KeysAndAccessTokens.TOKEN, KeysAndAccessTokens.TOKEN_SECRET)); | ||
return twitter; | ||
} | ||
|
||
private static HttpParameter[] createHttpParameterArray(TwitterImpl twitter) { | ||
try { | ||
Field field = twitter.getClass().getDeclaredField("IMPLICIT_PARAMS"); | ||
field.setAccessible(true); | ||
return (HttpParameter[]) field.get(twitter); | ||
} catch (NoSuchFieldException | IllegalAccessException e) { | ||
e.printStackTrace(); | ||
return null; | ||
} | ||
} | ||
|
||
public Twitter getTwitter() { | ||
return mTwitter; | ||
} | ||
|
||
private HttpResponse post(String url) throws TwitterException { | ||
mTwitter.ensureAuthorizationEnabled(); | ||
if (!mTwitter.conf.isMBeanEnabled()) { | ||
return mTwitter.http.post(url, IMPLICIT_PARAMS, mTwitter.auth, mTwitter); | ||
} else { | ||
// intercept HTTP call for monitoring purposes | ||
HttpResponse response = null; | ||
long start = System.currentTimeMillis(); | ||
try { | ||
response = mTwitter.http.post(url, IMPLICIT_PARAMS, mTwitter.auth, mTwitter); | ||
} finally { | ||
long elapsedTime = System.currentTimeMillis() - start; | ||
TwitterAPIMonitor.getInstance().methodCalled(url, elapsedTime, isOk(response)); | ||
} | ||
return response; | ||
} | ||
} | ||
|
||
public HttpResponse delete(String url) throws TwitterException { | ||
return mTwitter.http.delete(url, IMPLICIT_PARAMS, mTwitter.auth, mTwitter); | ||
} | ||
|
||
private boolean isOk(HttpResponse response) { | ||
return response != null && response.getStatusCode() < 300; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters