Skip to content

Commit 63ebcc2

Browse files
author
jonschmidt
committed
consolidated and moved around constants
1 parent 3b1ece8 commit 63ebcc2

File tree

4 files changed

+28
-45
lines changed

4 files changed

+28
-45
lines changed

src/main/java/com/soundcloud/api/ApiWrapper.java

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
11
package com.soundcloud.api;
22

3-
import static com.soundcloud.api.AuthParams.CLIENT_ID;
4-
import static com.soundcloud.api.AuthParams.CLIENT_SECRET;
5-
import static com.soundcloud.api.AuthParams.CODE;
6-
import static com.soundcloud.api.AuthParams.GRANT_TYPE;
7-
import static com.soundcloud.api.AuthParams.REDIRECT_URI;
8-
import static com.soundcloud.api.AuthParams.RESPONSE_TYPE;
9-
import static com.soundcloud.api.AuthParams.USERNAME;
10-
113
import org.apache.http.ConnectionReuseStrategy;
124
import org.apache.http.Header;
135
import org.apache.http.HeaderElement;
@@ -147,11 +139,11 @@ public ApiWrapper(String clientId,
147139
throw new IllegalArgumentException("username or password is null");
148140
}
149141
final Request request = addScope(Request.to(Endpoints.TOKEN).with(
150-
GRANT_TYPE, CloudAPI.PASSWORD,
142+
GRANT_TYPE, PASSWORD,
151143
CLIENT_ID, mClientId,
152144
CLIENT_SECRET, mClientSecret,
153145
USERNAME, username,
154-
AuthParams.PASSWORD, password), scopes);
146+
PASSWORD, password), scopes);
155147
mToken = requestToken(request);
156148
return mToken;
157149
}
@@ -205,20 +197,20 @@ public Token extensionGrantType(String grantType, String... scopes) throws IOExc
205197
@Override public Token refreshToken() throws IOException {
206198
if (mToken == null || mToken.refresh == null) throw new IllegalStateException("no refresh token available");
207199
mToken = requestToken(Request.to(Endpoints.TOKEN).with(
208-
GRANT_TYPE, CloudAPI.REFRESH_TOKEN,
200+
GRANT_TYPE, REFRESH_TOKEN,
209201
CLIENT_ID, mClientId,
210202
CLIENT_SECRET, mClientSecret,
211-
AuthParams.REFRESH_TOKEN, mToken.refresh));
203+
REFRESH_TOKEN, mToken.refresh));
212204
return mToken;
213205
}
214206

215207
@Override public Token exchangeOAuth1Token(String oauth1AccessToken) throws IOException {
216208
if (oauth1AccessToken == null) throw new IllegalArgumentException("need access token");
217209
mToken = requestToken(Request.to(Endpoints.TOKEN).with(
218-
GRANT_TYPE, OAUTH1_TOKEN,
210+
GRANT_TYPE, OAUTH1_TOKEN_GRANT_TYPE,
219211
CLIENT_ID, mClientId,
220212
CLIENT_SECRET, mClientSecret,
221-
AuthParams.REFRESH_TOKEN, oauth1AccessToken));
213+
REFRESH_TOKEN, oauth1AccessToken));
222214
return mToken;
223215
}
224216

@@ -241,8 +233,8 @@ public Token extensionGrantType(String grantType, String... scopes) throws IOExc
241233
final Request req = Request.to(options.length == 0 ? Endpoints.CONNECT : options[0]).with(
242234
REDIRECT_URI, mRedirectUri,
243235
CLIENT_ID, mClientId,
244-
RESPONSE_TYPE, "code");
245-
if (options.length == 2) req.add("scope", options[1]);
236+
RESPONSE_TYPE, CODE);
237+
if (options.length == 2) req.add(SCOPE, options[1]);
246238
return getURI(req, false, true);
247239
}
248240

@@ -677,7 +669,7 @@ public void setDefaultAcceptEncoding(String encoding) {
677669
scope.append(scopes[i]);
678670
if (i < scopes.length-1) scope.append(" ");
679671
}
680-
request.add("scope", scope.toString());
672+
request.add(SCOPE, scope.toString());
681673
}
682674
return request;
683675
}

src/main/java/com/soundcloud/api/AuthParams.java

Lines changed: 0 additions & 16 deletions
This file was deleted.

src/main/java/com/soundcloud/api/CloudAPI.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,32 @@
1515
* @see ApiWrapper
1616
*/
1717
public interface CloudAPI {
18+
// OAuth2 parameters
19+
String GRANT_TYPE = "grant_type";
20+
String CLIENT_ID = "client_id";
21+
String CLIENT_SECRET = "client_secret";
22+
String USERNAME = "username";
23+
String REDIRECT_URI = "redirect_uri";
24+
String CODE = "code";
25+
String RESPONSE_TYPE = "response_type";
26+
String SCOPE = "scope";
27+
1828
// standard oauth2 grant types
1929
String PASSWORD = "password";
2030
String AUTHORIZATION_CODE = "authorization_code";
2131
String REFRESH_TOKEN = "refresh_token";
2232
String CLIENT_CREDENTIALS = "client_credentials";
2333

24-
// custom soundcloud
25-
String OAUTH1_TOKEN = "oauth1_token";
26-
27-
// oauth2 extension grant types
28-
String FACEBOOK_GRANT_TYPE = "urn:soundcloud:oauth2:grant-type:facebook&access_token=";
34+
// custom
35+
String OAUTH1_TOKEN_GRANT_TYPE = "oauth1_token"; // soundcloud
36+
String FACEBOOK_GRANT_TYPE = "urn:soundcloud:oauth2:grant-type:facebook&access_token="; // oauth2 extension
2937

3038
// other constants
3139
String REALM = "SoundCloud";
3240
String OAUTH_SCHEME = "oauth";
3341
String VERSION = "1.2.1";
3442
String USER_AGENT = "SoundCloud Java Wrapper ("+VERSION+")";
3543

36-
3744
/**
3845
* Request a token using <a href="http://tools.ietf.org/html/draft-ietf-oauth-v2-10#section-4.1.2">
3946
* Resource Owner Password Credentials</a>.

src/main/java/com/soundcloud/api/Token.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,20 @@
1616
public class Token implements Serializable {
1717
private static final long serialVersionUID = 766168501082045382L;
1818

19-
public static final String ACCESS_TOKEN = "access_token";
20-
public static final String REFRESH_TOKEN = "refresh_token";
21-
public static final String SCOPE = "scope";
22-
public static final String EXPIRES_IN = "expires_in";
23-
2419
public static final String SCOPE_DEFAULT = "*";
2520

2621
/** Special scope for signup / password recovery */
2722
public static final String SCOPE_SIGNUP = "signup";
28-
public static final String SCOPE_PLAYCOUNT = "playcount";
2923

24+
public static final String SCOPE_PLAYCOUNT = "playcount";
3025
/** Don't expire access token - returned tokens won't include a refresh token */
3126
public static final String SCOPE_NON_EXPIRING = "non-expiring";
3227

28+
private static final String ACCESS_TOKEN = "access_token";
29+
private static final String REFRESH_TOKEN = "refresh_token";
30+
private static final String SCOPE = "scope";
31+
private static final String EXPIRES_IN = "expires_in";
32+
3333
// XXX these should be private
3434
public String access, refresh, scope;
3535
public long expiresIn;

0 commit comments

Comments
 (0)