Skip to content

Commit bcbcca1

Browse files
committed
1 parent e1f9be5 commit bcbcca1

File tree

6 files changed

+17
-14
lines changed

6 files changed

+17
-14
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ ScribeJava support out-of-box several HTTP clients:
9797
* Salesforce (https://www.salesforce.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceExample.java), [example with Async Ning HTTP Client](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SalesforceNingAsyncExample.java)
9898
* Sina (http://www.sina.com.cn/ http://weibo.com/login.php) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeibo2Example.java), [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SinaWeiboExample.java)
9999
* Skyrock (http://skyrock.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SkyrockExample.java)
100+
* Slack (https://slack.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SlackExample.java)
100101
* StackExchange (http://stackexchange.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/StackExchangeExample.java)
101102
* The Things Network (v1-staging and v2-preview) (https://www.thethingsnetwork.org/) [example v1](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV1StagingExample.java), [example v2 preview](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TheThingsNetworkV2PreviewExample.java)
102103
* Trello (https://trello.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/TrelloExample.java)

changelog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[SNAPSHOT]
22
* add raw Response (with HTTP repsponse code and body) as member to the OAuth2AccessTokenErrorResponse
33
* add possibility to set "" (empty string) as apiSecret
4+
* add Slack API (https://slack.com/) (thanks to https://github.com/petrkopotev)
45

56
[8.0.0]
67
* add Kakao API (https://kakao.com/) (thanks to https://github.com/v0o0v)

scribejava-apis/src/main/java/com/github/scribejava/apis/SlackApi.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
package com.github.scribejava.apis;
22

3-
import com.github.scribejava.apis.fitbit.FitBitJsonTokenExtractor;
43
import com.github.scribejava.apis.slack.SlackJsonTokenExtractor;
5-
import com.github.scribejava.apis.slack.SlackOAuth2AccessToken;
64
import com.github.scribejava.core.builder.api.DefaultApi20;
75

86
/**
9-
* Slack.com api
7+
* Slack.com API
108
*/
119
public class SlackApi extends DefaultApi20 {
1210

scribejava-apis/src/main/java/com/github/scribejava/apis/slack/SlackJsonTokenExtractor.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,16 @@ public static SlackJsonTokenExtractor instance() {
1919

2020
@Override
2121
protected SlackOAuth2AccessToken createToken(String accessToken, String tokenType, Integer expiresIn,
22-
String refreshToken, String scope, JsonNode response, String rawResponse) {
23-
String userAccessToken = "";
22+
String refreshToken, String scope, JsonNode response, String rawResponse) {
23+
final String userAccessToken;
2424
final JsonNode userAccessTokenNode = response.get("authed_user").get("access_token");
25-
if (userAccessTokenNode != null) {
26-
userAccessToken = userAccessTokenNode.asText();
25+
if (userAccessTokenNode == null) {
26+
userAccessToken = "";
27+
} else {
28+
userAccessToken = userAccessTokenNode.asText();
2729
}
2830

29-
return new SlackOAuth2AccessToken(accessToken, tokenType, expiresIn, refreshToken, scope,
30-
userAccessToken, rawResponse);
31+
return new SlackOAuth2AccessToken(accessToken, tokenType, expiresIn, refreshToken, scope, userAccessToken,
32+
rawResponse);
3133
}
3234
}

scribejava-apis/src/main/java/com/github/scribejava/apis/slack/SlackOAuth2AccessToken.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@
66

77
public class SlackOAuth2AccessToken extends OAuth2AccessToken {
88

9+
private static final long serialVersionUID = 1L;
10+
911
private final String userAccessToken;
1012

11-
public SlackOAuth2AccessToken(String accessToken, String tokenType, Integer expiresIn, String refreshToken, String scope, String userAccessToken, String rawResponse) {
13+
public SlackOAuth2AccessToken(String accessToken, String tokenType, Integer expiresIn, String refreshToken,
14+
String scope, String userAccessToken, String rawResponse) {
1215
super(accessToken, tokenType, expiresIn, refreshToken, scope, rawResponse);
1316
this.userAccessToken = userAccessToken;
1417
}
@@ -41,5 +44,4 @@ public boolean equals(Object obj) {
4144

4245
return Objects.equals(userAccessToken, ((SlackOAuth2AccessToken) obj).getUserAccessToken());
4346
}
44-
4547
}

scribejava-apis/src/test/java/com/github/scribejava/apis/examples/SlackExample.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class SlackExample {
1919

2020
private static final String NETWORK_NAME = "Slack.com";
2121
private static final String BOT_RESOURCE_URL = "https://slack.com/api/channels.list";
22-
private static final String BOT_SCOPE = "channels:read"
22+
private static final String BOT_SCOPE = "channels:read";
2323
private static final String USER_RESOURCE_URL = "https://slack.com/api/users.list";
2424
private static final String USER_SCOPE = "users:read";
2525
private static final String PAYLOAD = "null";
@@ -86,7 +86,7 @@ public static void main(String... args) throws IOException, InterruptedException
8686
final OAuthRequest userRequest = new OAuthRequest(Verb.GET, USER_RESOURCE_URL);
8787
userRequest.addHeader(CONTENT_TYPE_NAME, CONTENT_TYPE_VALUE);
8888
userRequest.setPayload(PAYLOAD);
89-
SlackOAuth2AccessToken token = (SlackOAuth2AccessToken)accessToken;
89+
final SlackOAuth2AccessToken token = (SlackOAuth2AccessToken) accessToken;
9090
service.signRequest(token.getUserAccessToken(), userRequest);
9191

9292
try (Response response = service.execute(userRequest)) {
@@ -96,7 +96,6 @@ public static void main(String... args) throws IOException, InterruptedException
9696
System.out.println(response.getBody());
9797
}
9898

99-
10099
System.out.println();
101100
System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)");
102101
}

0 commit comments

Comments
 (0)