Skip to content

Commit 4acf8c6

Browse files
committed
Formatting changes
1 parent 6b5fbaa commit 4acf8c6

File tree

8 files changed

+934
-935
lines changed

8 files changed

+934
-935
lines changed

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
.idea/
22
automate-client-java.iml
3-
target/
3+
target/
4+
5+
.classpath
6+
.project
7+
.settings/
Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
11
package com.browserstack.appautomate;
22

33
import java.io.FileNotFoundException;
4-
54
import com.browserstack.automate.exception.AppAutomateException;
65
import com.browserstack.automate.exception.InvalidFileExtensionException;
76
import com.browserstack.automate.exception.SessionNotFound;
87
import com.browserstack.automate.model.Session;
98

10-
/**
11-
* @author Hitesh Raghuvanshi
12-
*/
139
public interface AppAutomate {
1410

15-
public Session getSession(String sessionId) throws SessionNotFound, AppAutomateException;
11+
public Session getSession(String sessionId) throws SessionNotFound, AppAutomateException;
1612

17-
public String uploadApp(String filePath)
18-
throws AppAutomateException, FileNotFoundException, InvalidFileExtensionException;
13+
public String uploadApp(String filePath)
14+
throws AppAutomateException, FileNotFoundException, InvalidFileExtensionException;
1915

20-
}
16+
}

src/main/java/com/browserstack/appautomate/AppAutomateClient.java

Lines changed: 42 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import java.io.File;
44
import java.io.FileNotFoundException;
5-
65
import com.browserstack.automate.exception.AppAutomateException;
76
import com.browserstack.automate.exception.InvalidFileExtensionException;
87
import com.browserstack.automate.exception.SessionNotFound;
@@ -17,66 +16,63 @@
1716
import com.google.api.client.http.HttpMediaType;
1817
import com.google.api.client.http.MultipartContent;
1918

20-
/**
21-
* @author Hitesh Raghuvanshi
22-
*/
2319
public class AppAutomateClient extends BrowserStackClient implements AppAutomate {
2420

25-
private static final String BASE_URL = "https://api-cloud.browserstack.com/app-automate";
21+
private static final String BASE_URL = "https://api-cloud.browserstack.com/app-automate";
2622

27-
public AppAutomateClient(String username, String accessKey) {
28-
super(BASE_URL, username, accessKey);
29-
}
23+
public AppAutomateClient(String username, String accessKey) {
24+
super(BASE_URL, username, accessKey);
25+
}
26+
27+
public Session getSession(String sessionId) throws SessionNotFound, AppAutomateException {
28+
try {
29+
SessionNode sessionNode = newRequest(Method.GET, "/sessions/{sessionId}.json")
30+
.routeParam("sessionId", sessionId).asObject(SessionNode.class);
31+
32+
if (sessionNode.getSession() == null) {
33+
throw new SessionNotFound("Session not found: " + sessionId);
34+
}
3035

31-
public Session getSession(String sessionId) throws SessionNotFound, AppAutomateException {
32-
try {
33-
SessionNode sessionNode = newRequest(Method.GET, "/sessions/{sessionId}.json")
34-
.routeParam("sessionId", sessionId).asObject(SessionNode.class);
35-
36-
if (sessionNode.getSession() == null) {
37-
throw new SessionNotFound("Session not found: " + sessionId);
38-
}
39-
40-
return sessionNode.getSession().setClient(this);
41-
} catch (BrowserStackObjectNotFound e) {
42-
throw new SessionNotFound("Session not found: " + sessionId);
43-
} catch (BrowserStackException e) {
44-
throw new AppAutomateException(e);
45-
}
36+
return sessionNode.getSession().setClient(this);
37+
} catch (BrowserStackObjectNotFound e) {
38+
throw new SessionNotFound("Session not found: " + sessionId);
39+
} catch (BrowserStackException e) {
40+
throw new AppAutomateException(e);
4641
}
42+
}
4743

48-
public String uploadApp(String filePath)
49-
throws AppAutomateException, FileNotFoundException, InvalidFileExtensionException {
50-
try {
51-
File file = new File(filePath);
44+
public String uploadApp(String filePath)
45+
throws AppAutomateException, FileNotFoundException, InvalidFileExtensionException {
46+
try {
47+
File file = new File(filePath);
5248

53-
if (!file.exists()) {
54-
throw new FileNotFoundException("File not found at " + filePath);
55-
}
49+
if (!file.exists()) {
50+
throw new FileNotFoundException("File not found at " + filePath);
51+
}
5652

57-
if (!filePath.endsWith(".apk") && !filePath.endsWith(".ipa")) {
58-
throw new InvalidFileExtensionException("File extension should be only .apk or .ipa.");
59-
}
53+
if (!filePath.endsWith(".apk") && !filePath.endsWith(".ipa")) {
54+
throw new InvalidFileExtensionException("File extension should be only .apk or .ipa.");
55+
}
6056

61-
MultipartContent content = new MultipartContent()
62-
.setMediaType(new HttpMediaType("multipart/form-data").setParameter("boundary", "__END_OF_PART__"));
57+
MultipartContent content = new MultipartContent().setMediaType(
58+
new HttpMediaType("multipart/form-data").setParameter("boundary", "__END_OF_PART__"));
6359

64-
FileContent fileContent = new FileContent("multipart/form-data", file);
60+
FileContent fileContent = new FileContent("multipart/form-data", file);
6561

66-
MultipartContent.Part part = new MultipartContent.Part(fileContent);
67-
part.setHeaders(new HttpHeaders().set("Content-Disposition",
68-
String.format("form-data; name=\"file\"; filename=\"%s\"", file.getName())));
69-
content.addPart(part);
62+
MultipartContent.Part part = new MultipartContent.Part(fileContent);
63+
part.setHeaders(new HttpHeaders().set("Content-Disposition",
64+
String.format("form-data; name=\"file\"; filename=\"%s\"", file.getName())));
65+
content.addPart(part);
7066

71-
ObjectNode response = newRequest(Method.POST, "/upload").body(content).asJsonObject();
67+
ObjectNode response = newRequest(Method.POST, "/upload").body(content).asJsonObject();
7268

73-
String appId = (response != null) ? response.path("app_url").asText() : null;
69+
String appId = (response != null) ? response.path("app_url").asText() : null;
7470

75-
return appId;
76-
} catch (BrowserStackException e) {
77-
throw new AppAutomateException(e);
78-
}
71+
return appId;
72+
} catch (BrowserStackException e) {
73+
throw new AppAutomateException(e);
7974
}
75+
}
8076

8177
}
8278

0 commit comments

Comments
 (0)