Skip to content

Commit 456c973

Browse files
author
Sreeram Boyapati
committed
work in progress
1 parent dde11d4 commit 456c973

File tree

4 files changed

+51
-2
lines changed

4 files changed

+51
-2
lines changed

build.gradle

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
apply plugin: 'java'
2-
2+
apply plugin: 'idea'
33
version = '1.0'
44

55
repositories {
@@ -9,6 +9,8 @@ repositories {
99
dependencies {
1010
testCompile group: 'junit', name: 'junit', version: '4.11'
1111
compile 'com.google.code.gson:gson:2.2.4'
12+
compile 'org.apache.httpcomponents:httpclient:4.3.6'
13+
1214
}
1315

1416
jar {

src/main/java/com/hackerearth/heapi/sdk/options/BaseOptions.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ public class BaseOptions {
3737
@Expose
3838
public String language;
3939

40+
@SerializedName("client_secret")
41+
@Expose
42+
public String clientSecret;
43+
4044
@SerializedName("callback")
4145
@Expose
4246
public String callback;
@@ -70,6 +74,14 @@ public void setCompressed(String compressed) {
7074
this.compressed = compressed;
7175
}
7276

77+
public String getClientSecret() {
78+
return clientSecret;
79+
}
80+
81+
public void setClientSecret(String clientSecret) {
82+
this.clientSecret = clientSecret;
83+
}
84+
7385
public String getAsync() {
7486
return async;
7587
}

src/main/java/com/hackerearth/heapi/sdk/requests/BaseRequest.java

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,21 @@
2727
import com.hackerearth.heapi.sdk.options.BaseOptions;
2828
import com.hackerearth.heapi.sdk.responses.BaseResponse;
2929

30+
import org.apache.http.client.ClientProtocolException;
31+
import org.apache.http.client.methods.HttpPost;
32+
import org.apache.http.entity.StringEntity;
33+
import org.apache.http.impl.client.DefaultHttpClient;
34+
import org.apache.http.impl.client.HttpClientBuilder;
35+
import sun.net.www.http.HttpClient;
36+
37+
import java.io.IOException;
38+
import java.io.UnsupportedEncodingException;
39+
3040
public class BaseRequest {
3141

3242
public final BaseOptions options;
33-
private final String clientSecret;
43+
protected final String clientSecret;
44+
public final String USER_AGENT = "Mozilla/5.0";
3445

3546
public BaseRequest(String clientSecret, BaseOptions options){
3647
this.clientSecret = clientSecret;
@@ -41,6 +52,24 @@ public BaseResponse Execute(){
4152
return null;
4253
}
4354

55+
public String sendRequest(final String endpoint, final String jsonOptions){
56+
try {
57+
HttpPost httpPost = new HttpPost(endpoint);
58+
httpPost.setEntity(new StringEntity(jsonOptions));
59+
httpPost.setHeader("Accept", "application/json");
60+
httpPost.setHeader("Content-type", "application/json");
61+
HttpClient client = HttpClientBuilder.create().build();
62+
63+
new dexecute(httpPost);
64+
} catch (UnsupportedEncodingException e) {
65+
e.printStackTrace();
66+
} catch (ClientProtocolException e) {
67+
e.printStackTrace();
68+
} catch (IOException e) {
69+
e.printStackTrace();
70+
}
71+
return null;
72+
}
4473
//Blocking IO.
4574
public BaseResponse waitForResult(){
4675
return null;

src/main/java/com/hackerearth/heapi/sdk/requests/CompileRequest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
package com.hackerearth.heapi.sdk.requests;
2626

27+
import com.google.gson.Gson;
2728
import com.hackerearth.heapi.sdk.options.CompileOptions;
2829
import com.hackerearth.heapi.sdk.responses.CompileResponse;
2930

@@ -37,6 +38,11 @@ public CompileRequest(String clientSecret, CompileOptions params){
3738

3839
@Override
3940
public CompileResponse Execute(){
41+
Gson gson = new Gson();
42+
this.options.setClientSecret(this.clientSecret);
43+
44+
String jsonOptions = gson.toJson(this.options, CompileOptions.class);
45+
sendRequest(COMPILE_ENDPOINT, jsonOptions);
4046
return null;
4147
}
4248
}

0 commit comments

Comments
 (0)