Skip to content

Commit 5c058f9

Browse files
committed
Initial commit of WooCommerce API client
1 parent b1e3ac3 commit 5c058f9

Some content is hidden

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

41 files changed

+10806
-0
lines changed

pom.xml

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>wtx.woocommerce</groupId>
7+
<artifactId>woocommerce-api-client</artifactId>
8+
<version>0.1.0</version>
9+
<packaging>jar</packaging>
10+
11+
<name>WooCommerce REST API Client</name>
12+
<description>The WooCommerce REST API Client for Java provides easy access to the features of the e-commerce platform's API.</description>
13+
<url>https://github.com/yourusername/my-java-project</url>
14+
15+
<properties>
16+
<java.version>17</java.version>
17+
<maven.compiler.source>17</maven.compiler.source>
18+
<maven.compiler.target>17</maven.compiler.target>
19+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
20+
</properties>
21+
22+
<dependencies>
23+
24+
<dependency>
25+
<groupId>com.fasterxml.jackson.core</groupId>
26+
<artifactId>jackson-annotations</artifactId>
27+
<version>2.18.2</version>
28+
</dependency>
29+
30+
<dependency>
31+
<groupId>javax.annotation</groupId>
32+
<artifactId>javax.annotation-api</artifactId>
33+
<version>1.3.2</version>
34+
</dependency>
35+
36+
<dependency>
37+
<groupId>com.squareup.okhttp3</groupId>
38+
<artifactId>okhttp</artifactId>
39+
<version>4.12.0</version>
40+
</dependency>
41+
42+
<dependency>
43+
<groupId>com.squareup.okhttp3</groupId>
44+
<artifactId>logging-interceptor</artifactId>
45+
<version>4.12.0</version>
46+
</dependency>
47+
48+
<dependency>
49+
<groupId>com.google.code.gson</groupId>
50+
<artifactId>gson</artifactId>
51+
<version>2.11.0</version>
52+
</dependency>
53+
54+
<dependency>
55+
<groupId>com.squareup.okio</groupId>
56+
<artifactId>okio</artifactId>
57+
<version>3.9.1</version>
58+
</dependency>
59+
60+
<dependency>
61+
<groupId>io.gsonfire</groupId>
62+
<artifactId>gson-fire</artifactId>
63+
<version>1.9.0</version>
64+
</dependency>
65+
66+
<dependency>
67+
<groupId>com.google.code.findbugs</groupId>
68+
<artifactId>jsr305</artifactId>
69+
<version>3.0.2</version>
70+
</dependency>
71+
72+
</dependencies>
73+
74+
<build>
75+
<plugins>
76+
77+
<plugin>
78+
<groupId>org.apache.maven.plugins</groupId>
79+
<artifactId>maven-compiler-plugin</artifactId>
80+
<version>3.11.0</version>
81+
<configuration>
82+
<source>${maven.compiler.source}</source>
83+
<target>${maven.compiler.target}</target>
84+
</configuration>
85+
</plugin>
86+
87+
<plugin>
88+
<groupId>org.apache.maven.plugins</groupId>
89+
<artifactId>maven-jar-plugin</artifactId>
90+
<version>3.3.0</version>
91+
<configuration>
92+
<archive>
93+
<manifest>
94+
<mainClass>com.example.MyApp</mainClass>
95+
</manifest>
96+
</archive>
97+
</configuration>
98+
</plugin>
99+
100+
</plugins>
101+
</build>
102+
103+
</project>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package wtx.woocommerce;
2+
3+
import wtx.woocommerce.api.client.config.OkHttpClientConfig;
4+
import wtx.woocommerce.api.client.config.GsonConfig;
5+
import wtx.woocommerce.api.client.invoker.ApiClient;
6+
7+
public class WooCommerceApiClient extends ApiClient {
8+
9+
// Default setup of the API Client to provide ignoring not recognized fields in the response.
10+
public WooCommerceApiClient() {
11+
getJSON().setGson(GsonConfig.createGson());
12+
setUserAgent("WooCommerceApiClient (by wtx-labs)");
13+
}
14+
15+
// Default configuration improved with logging API communication messages.
16+
public WooCommerceApiClient(boolean enableLoggingApiMessages) {
17+
18+
getJSON().setGson(GsonConfig.createGson());
19+
setUserAgent("WooCommerceApiClient (by wtx-labs)");
20+
21+
if (enableLoggingApiMessages) {
22+
setHttpClient(OkHttpClientConfig.configureClient(getHttpClient()));
23+
}
24+
25+
}
26+
27+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package wtx.woocommerce;
2+
3+
import java.util.List;
4+
5+
import wtx.woocommerce.api.client.CustomersApi;
6+
import wtx.woocommerce.api.client.invoker.ApiException;
7+
import wtx.woocommerce.api.client.model.Customer;
8+
9+
public class WooCommerceApiClientUsageDemo {
10+
11+
public static void main(String[] args) {
12+
13+
System.out.println(">>> Start running the WooCommerceApiClientUsageDemo...");
14+
15+
// Use WooCommerceApiClient(true) if you need to log API communication messages.
16+
WooCommerceApiClient apiClient = new WooCommerceApiClient();
17+
18+
// TODO: Set your host and credentials!
19+
apiClient.setBasePath("https://your-woocommerce-shop.com/wp-json/wc/v3");
20+
apiClient.setUsername("TODO_SET_API_USERNAME");
21+
apiClient.setPassword("TODO_SET_API_PASSWORD");
22+
23+
CustomersApi customersApi = new CustomersApi(apiClient);
24+
25+
try {
26+
27+
List<Customer> customers = customersApi.listAllCustomers(null, null, null, null, null, null, null, null, null, null, null, null, null);
28+
29+
// Example list of customer emails:
30+
for (Customer customer : customers) {
31+
System.out.println("Customer: " + customer.getEmail());
32+
}
33+
34+
} catch (ApiException e) {
35+
System.err.println("Error occurred during API call: " + e);
36+
}
37+
38+
System.out.println("<<< The WooCommerceApiClientUsageDemo has been finished.");
39+
40+
}
41+
42+
}

0 commit comments

Comments
 (0)