Skip to content

Commit

Permalink
Merge pull request #2 from onesky/update-sample-app-info
Browse files Browse the repository at this point in the history
Update sample app info
  • Loading branch information
jacquetwong authored Dec 31, 2018
2 parents f6ae63d + 22dd2cb commit 02a9c12
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 11 deletions.
6 changes: 3 additions & 3 deletions examples/onesky-helloworld/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ buildscript {
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.0'
classpath 'app.onesky.android:onesky-conductor:0.0.1'
classpath 'app.onesky.android:onesky-conductor:0.0.2'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand All @@ -30,7 +30,7 @@ task clean(type: Delete) {
apply plugin: 'app.onesky'

OneSky {
appId = "94a3ecf8-0134-4c3b-a3a8-b6c90f14d57a"
apiKey = "1234"
appId = "aa339d82-7365-406b-af92-f3d1f4c77651"
apiKey = "06f7f71f85040b3ca951ecfb2e53b340"
resourceDirectoryRelativePath = "app/src/main/res/"
}
2 changes: 1 addition & 1 deletion onesky-conductor/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
group 'app.onesky.android'
version '0.0.1'
version '0.0.2'

apply plugin: 'java'
apply plugin: 'java-gradle-plugin'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package app.onesky.android;

import org.apache.http.HttpHeaders;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
Expand Down Expand Up @@ -32,7 +33,7 @@ public ApiConsumer(String appId, String apiKey) {

public String getAppConfigContent() throws Exception {

return getContent(INVOKE_URL + "apps/" + this.appId + "?platformId=android");
return getContent(INVOKE_URL + "apps/" + this.appId);
}

public String getStringFileContent(String languageId) throws Exception {
Expand All @@ -49,7 +50,7 @@ public boolean isTrusted(X509Certificate[] arg0, String arg1) throws Certificate
return true;
}
}).build();
b.setSslcontext( sslContext);
b.setSslcontext(sslContext);

HostnameVerifier hostnameVerifier = SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER;

Expand All @@ -59,12 +60,15 @@ public boolean isTrusted(X509Certificate[] arg0, String arg1) throws Certificate
.register("https", sslSocketFactory)
.build();

PoolingHttpClientConnectionManager connMgr = new PoolingHttpClientConnectionManager( socketFactoryRegistry);
b.setConnectionManager( connMgr);
PoolingHttpClientConnectionManager connMgr = new PoolingHttpClientConnectionManager(socketFactoryRegistry);
b.setConnectionManager(connMgr);

HttpClient httpClient = b.build();

HttpResponse response = httpClient.execute(new HttpGet(uri));
HttpGet request = new HttpGet(uri);
request.setHeader(HttpHeaders.AUTHORIZATION, "Bearer " + this.apiKey);
request.setHeader("Platform", "android");
HttpResponse response = httpClient.execute(request);

return EntityUtils.toString(response.getEntity());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ public void taskAction() throws Exception {

ApiConsumer apiConsumer = new ApiConsumer(OneSkyPlugin.oneSkyPluginExtension.appId, OneSkyPlugin.oneSkyPluginExtension.apiKey);
String appConfigContent = apiConsumer.getAppConfigContent();
checkResponse(appConfigContent);
writeStringFiles(appConfigContent);
}

private void writeStringFiles(String appConfigContent) throws Exception {

JsonParser jsonParser = new JsonParser();
JsonElement rootConfigElement = jsonParser.parse(appConfigContent);
JsonArray selectors = rootConfigElement.getAsJsonObject().getAsJsonObject("app").getAsJsonArray("selectors");
Expand Down Expand Up @@ -77,4 +79,16 @@ private void writeStringFile(String stringFileContent, String filePath) throws E
fileOutputStream.write(stringFileContent.getBytes());
fileOutputStream.close();
}

private void checkResponse(String appConfigContent) throws Exception {

JsonParser jsonParser = new JsonParser();
JsonElement rootConfigElement = jsonParser.parse(appConfigContent);
JsonArray errors = rootConfigElement.getAsJsonObject().getAsJsonArray("errors");
if (errors != null) {
for (JsonElement error : errors) {
throw new Exception(error.getAsJsonObject().get("message").getAsString());
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

public class ApiConsumerTest {

private String appId = "94a3ecf8-0134-4c3b-a3a8-b6c90f14d57a";
private String apiKey = "1234";
private String appId = "aa339d82-7365-406b-af92-f3d1f4c77651";
private String apiKey = "06f7f71f85040b3ca951ecfb2e53b340";

@Test
public void getAppConfig() throws Exception {
Expand Down

0 comments on commit 02a9c12

Please sign in to comment.