Skip to content

Commit

Permalink
Upgrade sdk version
Browse files Browse the repository at this point in the history
  • Loading branch information
jacquetwong committed Dec 31, 2018
1 parent 6dfe38b commit 22dd2cb
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
2 changes: 1 addition & 1 deletion 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 Down
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());
}
}
}
}

0 comments on commit 22dd2cb

Please sign in to comment.