Skip to content
This repository was archived by the owner on Oct 17, 2023. It is now read-only.

Commit adbdaea

Browse files
author
Chris Paul
committed
Add support for API app CRUD. Add tests. Update documentation.
1 parent c828d67 commit adbdaea

File tree

4 files changed

+95
-0
lines changed

4 files changed

+95
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package com.hellosign.sdk.http;
2+
3+
import java.net.HttpURLConnection;
4+
import java.net.URL;
5+
6+
import org.slf4j.Logger;
7+
import org.slf4j.LoggerFactory;
8+
9+
import com.hellosign.sdk.HelloSignException;
10+
11+
public class HttpDeleteRequest extends AbstractHttpRequest {
12+
13+
private static final Logger logger = LoggerFactory.getLogger(HttpDeleteRequest.class);
14+
15+
public HttpDeleteRequest(String url) throws HelloSignException {
16+
this(url, null);
17+
}
18+
19+
public HttpDeleteRequest(String url, Authentication auth) throws HelloSignException {
20+
if (url == null || "".equals(url)) {
21+
throw new HelloSignException("URL cannot be null or empty");
22+
}
23+
this.url = url;
24+
if (auth != null) {
25+
this.auth = new Authentication(auth);
26+
}
27+
}
28+
29+
public int getHttpResponseCode() throws HelloSignException {
30+
try {
31+
logger.debug("DELETE: " + url);
32+
HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
33+
connection.setRequestProperty("Accept-Charset", DEFAULT_ENCODING);
34+
connection.setRequestProperty("user-agent", USER_AGENT);
35+
if (auth != null) {
36+
logger.debug("Authenticating...");
37+
auth.authenticate(connection, url);
38+
}
39+
connection.setDoOutput(true);
40+
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
41+
connection.setRequestMethod("DELETE");
42+
connection.connect();
43+
return connection.getResponseCode();
44+
} catch (Exception e) {
45+
throw new HelloSignException(e);
46+
}
47+
}
48+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.hellosign.sdk.http;
2+
3+
import java.io.Serializable;
4+
import java.util.Map;
5+
6+
import com.hellosign.sdk.HelloSignException;
7+
8+
public class HttpPutRequest extends HttpPostRequest {
9+
10+
protected String method = "PUT";
11+
12+
public HttpPutRequest(String url) throws HelloSignException {
13+
super(url);
14+
}
15+
16+
public HttpPutRequest(String url, Authentication auth) throws HelloSignException {
17+
super(url, auth);
18+
}
19+
20+
public HttpPutRequest(String url, Map<String, Serializable> fields, Authentication auth) throws HelloSignException {
21+
super(url, fields, auth);
22+
}
23+
24+
public HttpPutRequest(String url, Map<String, Serializable> fields) throws HelloSignException {
25+
super(url, fields);
26+
}
27+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.hellosign.sdk.resource.support;
2+
3+
import org.json.JSONObject;
4+
5+
import com.hellosign.sdk.HelloSignException;
6+
import com.hellosign.sdk.resource.AbstractResourceList;
7+
import com.hellosign.sdk.resource.ApiApp;
8+
9+
public class ApiAppList extends AbstractResourceList<ApiApp> {
10+
11+
public ApiAppList(JSONObject json) throws HelloSignException {
12+
super(json, "api_apps");
13+
}
14+
15+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
name=My Production App
2+
domain=example.com
3+
callback_url=https://example.com/hello
4+
oauth[callback_url]=https://example.com/oauth
5+
oauth[scopes]=*

0 commit comments

Comments
 (0)