Skip to content

Commit 2a20a74

Browse files
authored
Add back legacy SDK and update gradle file to publish to central (#146)
1 parent a502150 commit 2a20a74

File tree

1,064 files changed

+252302
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,064 files changed

+252302
-0
lines changed

legacy-sdk/build.gradle

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
plugins {
2+
id 'java-library'
3+
id 'com.diffplug.spotless' version '6.11.0'
4+
id 'com.vanniktech.maven.publish' version '0.27.0'
5+
}
6+
7+
repositories {
8+
mavenCentral()
9+
}
10+
11+
dependencies {
12+
implementation 'io.apimatic:core-interfaces:0.3.1'
13+
implementation 'io.apimatic:core:0.6.6'
14+
implementation 'io.apimatic:okhttp-client-adapter:0.3.1'
15+
16+
testImplementation 'junit:junit:4.13.2'
17+
testImplementation 'org.junit.vintage:junit-vintage-engine:4.12.3'
18+
}
19+
20+
sourceCompatibility = 1.8
21+
targetCompatibility = 1.8
22+
23+
spotless {
24+
java {
25+
palantirJavaFormat()
26+
}
27+
}
28+
29+
group = 'com.squareup'
30+
version = rootProject.version
31+
32+
test {
33+
useJUnitPlatform()
34+
}
35+
36+
mavenPublishing {
37+
publishToMavenCentral()
38+
signAllPublications()
39+
40+
coordinates("com.squareup", "square-legacy", "$version")
41+
42+
pom {
43+
name = "Square Legacy Java SDK"
44+
description = "Official Square Legacy Java SDK"
45+
inceptionYear = "2019"
46+
url = "https://github.com/square/square-java-sdk"
47+
48+
licenses {
49+
license {
50+
name = "MIT License"
51+
url = "https://opensource.org/licenses/MIT"
52+
distribution = "repo"
53+
}
54+
}
55+
56+
developers {
57+
developer {
58+
id = "square"
59+
name = "Square"
60+
url = "https://github.com/square"
61+
}
62+
}
63+
64+
scm {
65+
url = "https://github.com/square/square-java-sdk"
66+
connection = "scm:git:git://github.com/square/square-java-sdk.git"
67+
developerConnection = "scm:git:ssh://[email protected]/square/square-java-sdk.git"
68+
}
69+
}
70+
}
71+
72+
java {
73+
withSourcesJar()
74+
withJavadocJar()
75+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.squareup.square.legacy;
2+
3+
import io.apimatic.core.utilities.CoreHelper;
4+
5+
/**
6+
* This is a Helper class with commonly used utilities for the SDK.
7+
*/
8+
public class ApiHelper extends CoreHelper {}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.squareup.square.legacy;
2+
3+
/**
4+
* Interface to access authentication credentials.
5+
*/
6+
public interface BearerAuthCredentials {
7+
8+
/**
9+
* String value for accessToken.
10+
* @return accessToken
11+
*/
12+
String getAccessToken();
13+
14+
/**
15+
* Checks if provided credentials matched with existing ones.
16+
* @param accessToken String value for credentials.
17+
* @return true if credentials matched.
18+
*/
19+
boolean equals(String accessToken);
20+
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
package com.squareup.square.legacy;
2+
3+
import com.squareup.square.legacy.http.Headers;
4+
import com.squareup.square.legacy.http.client.HttpContext;
5+
import com.squareup.square.legacy.http.request.HttpBodyRequest;
6+
import com.squareup.square.legacy.http.request.HttpMethod;
7+
import com.squareup.square.legacy.http.request.HttpRequest;
8+
import com.squareup.square.legacy.http.response.HttpResponse;
9+
import com.squareup.square.legacy.http.response.HttpStringResponse;
10+
import io.apimatic.coreinterfaces.compatibility.CompatibilityFactory;
11+
import io.apimatic.coreinterfaces.http.Context;
12+
import io.apimatic.coreinterfaces.http.HttpHeaders;
13+
import io.apimatic.coreinterfaces.http.Method;
14+
import io.apimatic.coreinterfaces.http.request.Request;
15+
import io.apimatic.coreinterfaces.http.response.ApiResponseType;
16+
import io.apimatic.coreinterfaces.http.response.DynamicType;
17+
import io.apimatic.coreinterfaces.http.response.Response;
18+
import java.io.InputStream;
19+
import java.util.AbstractMap.SimpleEntry;
20+
import java.util.List;
21+
import java.util.Map;
22+
23+
public class CompatibilityFactoryImpl implements CompatibilityFactory {
24+
25+
@Override
26+
public Context createHttpContext(Request request, Response response) {
27+
return new HttpContext((HttpRequest) request, (HttpResponse) response);
28+
}
29+
30+
@Override
31+
public Request createHttpRequest(
32+
Method httpMethod,
33+
StringBuilder queryUrlBuilder,
34+
HttpHeaders headers,
35+
Map<String, Object> queryParameters,
36+
List<SimpleEntry<String, Object>> formParameters) {
37+
return new HttpRequest(
38+
HttpMethod.valueOf(httpMethod.toString()),
39+
queryUrlBuilder,
40+
(Headers) headers,
41+
queryParameters,
42+
formParameters);
43+
}
44+
45+
@Override
46+
public Request createHttpRequest(
47+
Method httpMethod,
48+
StringBuilder queryUrlBuilder,
49+
HttpHeaders headers,
50+
Map<String, Object> queryParameters,
51+
Object body) {
52+
return new HttpBodyRequest(
53+
HttpMethod.valueOf(httpMethod.toString()), queryUrlBuilder, (Headers) headers, queryParameters, body);
54+
}
55+
56+
@Override
57+
public Response createHttpResponse(int code, HttpHeaders headers, InputStream rawBody) {
58+
return new HttpResponse(code, (Headers) headers, rawBody);
59+
}
60+
61+
@Override
62+
public Response createHttpResponse(int code, HttpHeaders headers, InputStream rawBody, String body) {
63+
return new HttpStringResponse(code, (Headers) headers, rawBody, body);
64+
}
65+
66+
@Override
67+
public HttpHeaders createHttpHeaders(Map<String, List<String>> headers) {
68+
return new Headers(headers);
69+
}
70+
71+
@Override
72+
public HttpHeaders createHttpHeaders(HttpHeaders headers) {
73+
return new Headers((Headers) headers);
74+
}
75+
76+
@Override
77+
public HttpHeaders createHttpHeaders() {
78+
return new Headers();
79+
}
80+
81+
@Override
82+
public DynamicType createDynamicResponse(Response httpResponse) {
83+
return null;
84+
}
85+
86+
@Override
87+
public <T> ApiResponseType<T> createApiResponse(int statusCode, HttpHeaders headers, T result) {
88+
return null;
89+
}
90+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
package com.squareup.square.legacy;
2+
3+
import com.squareup.square.legacy.authentication.BearerAuthModel;
4+
import com.squareup.square.legacy.http.Headers;
5+
import com.squareup.square.legacy.http.client.ReadonlyHttpClientConfiguration;
6+
7+
/**
8+
* Configuration Interface for the library.
9+
*/
10+
public interface Configuration {
11+
12+
/**
13+
* Current API environment.
14+
* @return a copy of environment
15+
*/
16+
Environment getEnvironment();
17+
18+
/**
19+
* Sets the base URL requests are made to. Defaults to `https://connect.squareup.com`
20+
* @return a copy of customUrl
21+
*/
22+
String getCustomUrl();
23+
24+
/**
25+
* Square Connect API versions.
26+
* @return a copy of squareVersion
27+
*/
28+
String getSquareVersion();
29+
30+
/**
31+
* Http Client Configuration instance.
32+
* @return a copy of httpClientConfig
33+
*/
34+
ReadonlyHttpClientConfiguration getHttpClientConfig();
35+
36+
/**
37+
* Additional headers to add to each API request.
38+
* @return a copy of additionalHeaders
39+
*/
40+
Headers getAdditionalHeaders();
41+
42+
/**
43+
* Additional detail which can be appended with User-Agent header.
44+
* @return a copy of userAgentDetail
45+
*/
46+
String getUserAgentDetail();
47+
48+
/**
49+
* The timeout to use for making HTTP requests. The timeout to use for making HTTP requests.
50+
* @return a copy of timeout
51+
*/
52+
long timeout();
53+
54+
/**
55+
* OAuth 2.0 Access Token.
56+
* @return accessToken
57+
*/
58+
String getAccessToken();
59+
60+
/**
61+
* The credentials to use with BearerAuth.
62+
* @return bearerAuthCredentials
63+
*/
64+
BearerAuthCredentials getBearerAuthCredentials();
65+
66+
/**
67+
* The auth credential model for BearerAuth.
68+
* @return the instance of BearerAuthModel
69+
*/
70+
BearerAuthModel getBearerAuthModel();
71+
72+
/**
73+
* Get base URI by current environment.
74+
* @param server Server for which to get the base URI
75+
* @return Processed base URI
76+
*/
77+
String getBaseUri(Server server);
78+
79+
/**
80+
* Get base URI by current environment.
81+
* @return Processed base URI
82+
*/
83+
String getBaseUri();
84+
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
package com.squareup.square.legacy;
2+
3+
import com.fasterxml.jackson.annotation.JsonCreator;
4+
import com.fasterxml.jackson.annotation.JsonValue;
5+
import java.io.IOException;
6+
import java.util.ArrayList;
7+
import java.util.List;
8+
import java.util.TreeMap;
9+
10+
/**
11+
* Environment to be used.
12+
*/
13+
public enum Environment {
14+
PRODUCTION,
15+
16+
SANDBOX,
17+
18+
CUSTOM;
19+
20+
private static TreeMap<String, Environment> valueMap = new TreeMap<>();
21+
private String value;
22+
23+
static {
24+
PRODUCTION.value = "production";
25+
SANDBOX.value = "sandbox";
26+
CUSTOM.value = "custom";
27+
28+
valueMap.put("production", PRODUCTION);
29+
valueMap.put("sandbox", SANDBOX);
30+
valueMap.put("custom", CUSTOM);
31+
}
32+
33+
/**
34+
* Returns the enum member associated with the given string value.
35+
* @param toConvert String value to get enum member.
36+
* @return The enum member against the given string value.
37+
* @throws IOException when provided value is not mapped to any enum member.
38+
*/
39+
@JsonCreator
40+
public static Environment constructFromString(String toConvert) throws IOException {
41+
Environment enumValue = fromString(toConvert);
42+
if (enumValue == null) {
43+
throw new IOException("Unable to create enum instance with value: " + toConvert);
44+
}
45+
return enumValue;
46+
}
47+
48+
/**
49+
* Returns the enum member associated with the given string value.
50+
* @param toConvert String value to get enum member.
51+
* @return The enum member against the given string value.
52+
*/
53+
public static Environment fromString(String toConvert) {
54+
return valueMap.get(toConvert);
55+
}
56+
57+
/**
58+
* Returns the string value associated with the enum member.
59+
* @return The string value against enum member.
60+
*/
61+
@JsonValue
62+
public String value() {
63+
return value;
64+
}
65+
66+
/**
67+
* Get string representation of this enum.
68+
*/
69+
@Override
70+
public String toString() {
71+
return value.toString();
72+
}
73+
74+
/**
75+
* Convert list of Environment values to list of string values.
76+
* @param toConvert The list of Environment values to convert.
77+
* @return List of representative string values.
78+
*/
79+
public static List<String> toValue(List<Environment> toConvert) {
80+
if (toConvert == null) {
81+
return null;
82+
}
83+
List<String> convertedValues = new ArrayList<>();
84+
for (Environment enumValue : toConvert) {
85+
convertedValues.add(enumValue.value);
86+
}
87+
return convertedValues;
88+
}
89+
}

0 commit comments

Comments
 (0)