Skip to content

Commit 360b236

Browse files
committed
Add back legacy SDK
1 parent a502150 commit 360b236

File tree

1,064 files changed

+13099
-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

+13099
-0
lines changed

legacy-sdk/build.gradle

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
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+
// Configure maven publishing for Central Portal
37+
mavenPublishing {
38+
publishToMavenCentral()
39+
signAllPublications()
40+
41+
coordinates("com.squareup", "square-legacy", "$version")
42+
43+
pom {
44+
name = "Square Legacy Java SDK"
45+
description = "Official Square Legacy Java SDK"
46+
inceptionYear = "2019"
47+
url = "https://github.com/square/square-java-sdk"
48+
49+
licenses {
50+
license {
51+
name = "MIT License"
52+
url = "https://opensource.org/licenses/MIT"
53+
distribution = "repo"
54+
}
55+
}
56+
57+
developers {
58+
developer {
59+
id = "square"
60+
name = "Square"
61+
url = "https://github.com/square"
62+
}
63+
}
64+
65+
scm {
66+
url = "https://github.com/square/square-java-sdk"
67+
connection = "scm:git:git://github.com/square/square-java-sdk.git"
68+
developerConnection = "scm:git:ssh://[email protected]/square/square-java-sdk.git"
69+
}
70+
}
71+
}
72+
73+
java {
74+
withSourcesJar()
75+
withJavadocJar()
76+
77+
toolchain {
78+
languageVersion = JavaLanguageVersion.of(8)
79+
}
80+
}
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 {}

legacy-sdk/src/main/java/com/squareup/square/legacy/BearerAuthCredentials.java

Whitespace-only changes.
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+
}

legacy-sdk/src/main/java/com/squareup/square/legacy/Configuration.java

Whitespace-only changes.
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+
}

legacy-sdk/src/main/java/com/squareup/square/legacy/Server.java

Whitespace-only changes.

0 commit comments

Comments
 (0)