Skip to content

Commit 99df682

Browse files
committed
Move Env to toplevel
1 parent 8b0be19 commit 99df682

6 files changed

Lines changed: 32 additions & 27 deletions

File tree

src/examples/java/com/soundcloud/api/examples/CreateWrapper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.soundcloud.api.examples;
22

33
import com.soundcloud.api.ApiWrapper;
4-
import com.soundcloud.api.CloudAPI;
4+
import com.soundcloud.api.Env;
55
import com.soundcloud.api.Token;
66

77
import java.io.File;
@@ -24,7 +24,7 @@ public static void main(String[] args) throws Exception {
2424
args[1] /* client_secret */,
2525
null /* redirect URI */,
2626
null /* token */,
27-
args.length == 5 ? CloudAPI.Env.valueOf(args[4].toUpperCase()) : CloudAPI.Env.SANDBOX);
27+
args.length == 5 ? Env.valueOf(args[4].toUpperCase()) : Env.SANDBOX);
2828

2929
Token token = wrapper.login(args[2] /* login */, args[3] /* password */);
3030
System.out.println("got token from server: " + token);

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
* Example usage:
6565
* <code>
6666
* <pre>
67-
* ApiWrapper wrapper = new ApiWrapper("client_id", "client_secret", null, null, CloudAPI.Env.SANDBOX);
67+
* ApiWrapper wrapper = new ApiWrapper("client_id", "client_secret", null, null, Env.SANDBOX);
6868
* wrapper.login("login", "password");
6969
* HttpResponse response = wrapper.get(Request.to("/tracks"));
7070
* </pre>
@@ -194,6 +194,8 @@ public URI getURI(Request request, boolean ssl) {
194194

195195
/**
196196
* Request an OAuth2 token from SoundCloud
197+
* @param request the token request
198+
* @return the token
197199
* @throws java.io.IOException network error
198200
* @throws com.soundcloud.api.CloudAPI.InvalidTokenException unauthorized
199201
*/
@@ -245,16 +247,14 @@ protected SSLSocketFactory getSSLSocketFactory() {
245247

246248
/**
247249
* User-Agent to identify ourselves with - defaults to USER_AGENT
248-
*
249250
* @return the agent to use
250251
* @see CloudAPI#USER_AGENT
251252
*/
252253
protected String getUserAgent() {
253254
return USER_AGENT;
254255
}
255256

256-
257-
/** The HttpClient instance used to make the calls */
257+
/** @return The HttpClient instance used to make the calls */
258258
public HttpClient getHttpClient() {
259259
if (httpClient == null) {
260260
final HttpParams params = getParams();
@@ -372,6 +372,8 @@ public synchronized void addTokenStateListener(TokenStateListener listener) {
372372

373373
/**
374374
* Execute an API request, adds the necessary headers.
375+
* @param req the HTTP request
376+
* @return the HTTP response
375377
* @throws java.io.IOException network error etc.
376378
*/
377379
public HttpResponse execute(HttpRequest req) throws IOException {

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

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -153,24 +153,6 @@ public interface CloudAPI {
153153
*/
154154
URI loginViaFacebook();
155155

156-
/**
157-
* The environment to operate against.
158-
* Use SANDBOX for testing your app, and LIVE for production applications.
159-
*/
160-
enum Env {
161-
/** The main production site */
162-
@SuppressWarnings({"UnusedDeclaration"})
163-
LIVE("api.soundcloud.com"),
164-
/** sandbox-soundcloud.com */
165-
SANDBOX("api.sandbox-soundcloud.com");
166-
public final HttpHost host, sslHost;
167-
168-
Env(String hostname) {
169-
host = new HttpHost(hostname, -1, "http");
170-
sslHost = new HttpHost(hostname, -1, "https");
171-
}
172-
}
173-
174156
/**
175157
* Interested in changes to the current token.
176158
*/
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.soundcloud.api;
2+
3+
import org.apache.http.HttpHost;
4+
5+
/**
6+
* The environment to operate against.
7+
* Use SANDBOX for testing your app, and LIVE for production applications.
8+
*/
9+
@SuppressWarnings({"UnusedDeclaration"})
10+
public enum Env {
11+
/** The main production site, http://soundcloud.com */
12+
LIVE("api.soundcloud.com"),
13+
/** For testig, http://sandbox-soundcloud.com */
14+
SANDBOX("api.sandbox-soundcloud.com");
15+
16+
public final HttpHost host, sslHost;
17+
Env(String hostname) {
18+
host = new HttpHost(hostname, -1, "http");
19+
sslHost = new HttpHost(hostname, -1, "https");
20+
}
21+
}

src/test/java/com/soundcloud/api/ApiWrapperTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public class ApiWrapperTest {
4242
final FakeHttpLayer layer = new FakeHttpLayer();
4343
@Before
4444
public void setup() {
45-
api = new ApiWrapper("invalid", "invalid", URI.create("redirect://me"), null, CloudAPI.Env.SANDBOX) {
45+
api = new ApiWrapper("invalid", "invalid", URI.create("redirect://me"), null, Env.SANDBOX) {
4646
@Override
4747
protected RequestDirector getRequestDirector(HttpRequestExecutor requestExec,
4848
ClientConnectionManager conman,
@@ -315,7 +315,7 @@ public void shouldCallTokenStateListenerWhenTokenIsRefreshed() throws Exception
315315

316316
@Test
317317
public void shouldSerializeAndDeserializeWrapper() throws Exception {
318-
ApiWrapper wrapper = new ApiWrapper("client", "secret", null, new Token("1", "2"), CloudAPI.Env.SANDBOX);
318+
ApiWrapper wrapper = new ApiWrapper("client", "secret", null, new Token("1", "2"), Env.SANDBOX);
319319
File ser = File.createTempFile("serialized_wrapper", "ser");
320320
wrapper.toFile(ser);
321321
ApiWrapper other = ApiWrapper.fromFile(ser);

src/test/java/com/soundcloud/api/CloudAPIIntegrationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public void setUp() throws Exception {
3535
CLIENT_SECRET,
3636
null,
3737
null,
38-
CloudAPI.Env.SANDBOX);
38+
Env.SANDBOX);
3939

4040
api.login("api-testing", "testing");
4141
}

0 commit comments

Comments
 (0)