Restructured the API classes
This commit is contained in:
parent
58a8cd5f6a
commit
69277df89b
@ -25,7 +25,7 @@ public class AppModule {
|
|||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
Woocommerce providesWoocommerce() {
|
Woocommerce providesWoocommerce() {
|
||||||
Woocommerce woocommerce = new Woocommerce.Builder()
|
Woocommerce woocommerce = Woocommerce.Builder()
|
||||||
.setSiteUrl("http://157.230.131.179")
|
.setSiteUrl("http://157.230.131.179")
|
||||||
.setApiVersion(Woocommerce.API_V3)
|
.setApiVersion(Woocommerce.API_V3)
|
||||||
.setConsumerKey("ck_26c61abd7eeff238d87dc56585bf26cb2d1a1ec3")
|
.setConsumerKey("ck_26c61abd7eeff238d87dc56585bf26cb2d1a1ec3")
|
||||||
|
|||||||
39
woodroid/src/main/java/me/gilo/woodroid/Builder.java
Normal file
39
woodroid/src/main/java/me/gilo/woodroid/Builder.java
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
package me.gilo.woodroid;
|
||||||
|
|
||||||
|
import me.gilo.woodroid.data.ApiVersion;
|
||||||
|
|
||||||
|
public class Builder {
|
||||||
|
private String siteUrl;
|
||||||
|
private ApiVersion apiVerion;
|
||||||
|
private String consumerKey;
|
||||||
|
private String consumerSecret;
|
||||||
|
|
||||||
|
|
||||||
|
public Builder() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder setSiteUrl(String siteUrl) {
|
||||||
|
this.siteUrl = siteUrl;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder setApiVersion(ApiVersion apiVerion) {
|
||||||
|
this.apiVerion = apiVerion;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder setConsumerKey(String consumerKey) {
|
||||||
|
this.consumerKey = consumerKey;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder setConsumerSecret(String consumerSecret) {
|
||||||
|
this.consumerSecret = consumerSecret;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public Woocommerce build() {
|
||||||
|
return new Woocommerce(siteUrl, apiVerion, consumerKey, consumerSecret);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -2,6 +2,7 @@ package me.gilo.woodroid;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import me.gilo.woodroid.data.ApiVersion;
|
||||||
import me.gilo.woodroid.models.PaymentGateway;
|
import me.gilo.woodroid.models.PaymentGateway;
|
||||||
import me.gilo.woodroid.repo.*;
|
import me.gilo.woodroid.repo.*;
|
||||||
import me.gilo.woodroid.repo.order.OrderNoteRepository;
|
import me.gilo.woodroid.repo.order.OrderNoteRepository;
|
||||||
@ -35,31 +36,12 @@ public class Woocommerce {
|
|||||||
final SettingsRepository settingsRepository;
|
final SettingsRepository settingsRepository;
|
||||||
final ShippingMethodRepository shippingMethodRepository;
|
final ShippingMethodRepository shippingMethodRepository;
|
||||||
|
|
||||||
|
public static Builder Builder(){
|
||||||
enum ApiVersion {
|
return new Builder();
|
||||||
API_VERSION1{
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "1";
|
|
||||||
}
|
|
||||||
},
|
|
||||||
API_VERSION2{
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "2";
|
|
||||||
}
|
|
||||||
},
|
|
||||||
API_VERSION3{
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "3";
|
|
||||||
}
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Woocommerce(String siteUrl, ApiVersion apiVerion, String consumerKey, String consumerSecret) {
|
public Woocommerce(String siteUrl, ApiVersion apiVerion, String consumerKey, String consumerSecret) {
|
||||||
String baseUrl = siteUrl + "/wp-json/wc/v" + apiVerion + "/";
|
String baseUrl = siteUrl + "/wp-json/wc/v" + apiVerion + "/";
|
||||||
|
|
||||||
String cartBaseUrl = siteUrl + "/wp-json/wc/v" + 2 + "/";
|
String cartBaseUrl = siteUrl + "/wp-json/wc/v" + 2 + "/";
|
||||||
|
|
||||||
orderNoteRepository = new OrderNoteRepository(baseUrl, consumerKey, consumerSecret);
|
orderNoteRepository = new OrderNoteRepository(baseUrl, consumerKey, consumerSecret);
|
||||||
@ -74,11 +56,8 @@ public class Woocommerce {
|
|||||||
customerRepository = new CustomerRepository(baseUrl, consumerKey, consumerSecret);
|
customerRepository = new CustomerRepository(baseUrl, consumerKey, consumerSecret);
|
||||||
orderRepository = new OrderRepository(baseUrl, consumerKey, consumerSecret);
|
orderRepository = new OrderRepository(baseUrl, consumerKey, consumerSecret);
|
||||||
productRepository = new ProductRepository(baseUrl, consumerKey, consumerSecret);
|
productRepository = new ProductRepository(baseUrl, consumerKey, consumerSecret);
|
||||||
|
|
||||||
reportsRepository = new ReportsRepository(baseUrl, consumerKey, consumerSecret);
|
reportsRepository = new ReportsRepository(baseUrl, consumerKey, consumerSecret);
|
||||||
|
|
||||||
cartRepository = new CartRepository(cartBaseUrl, consumerKey, consumerSecret);
|
cartRepository = new CartRepository(cartBaseUrl, consumerKey, consumerSecret);
|
||||||
|
|
||||||
reviewRepository = new ReviewRepository(baseUrl, consumerKey, consumerSecret);
|
reviewRepository = new ReviewRepository(baseUrl, consumerKey, consumerSecret);
|
||||||
paymentGatewayRepository = new PaymentGatewayRepository(baseUrl, consumerKey, consumerSecret);
|
paymentGatewayRepository = new PaymentGatewayRepository(baseUrl, consumerKey, consumerSecret);
|
||||||
settingsRepository = new SettingsRepository(baseUrl, consumerKey, consumerSecret);
|
settingsRepository = new SettingsRepository(baseUrl, consumerKey, consumerSecret);
|
||||||
@ -86,43 +65,6 @@ public class Woocommerce {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static class Builder {
|
|
||||||
private String siteUrl;
|
|
||||||
private ApiVersion apiVerion;
|
|
||||||
private String consumerKey;
|
|
||||||
private String consumerSecret;
|
|
||||||
|
|
||||||
|
|
||||||
public Builder() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder setSiteUrl(String siteUrl) {
|
|
||||||
this.siteUrl = siteUrl;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder setApiVersion(ApiVersion apiVerion) {
|
|
||||||
this.apiVerion = apiVerion;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder setConsumerKey(String consumerKey) {
|
|
||||||
this.consumerKey = consumerKey;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder setConsumerSecret(String consumerSecret) {
|
|
||||||
this.consumerSecret = consumerSecret;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public Woocommerce build() {
|
|
||||||
return new Woocommerce(siteUrl, apiVerion, consumerKey, consumerSecret);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public OrderNoteRepository OrderNoteRepository() {
|
public OrderNoteRepository OrderNoteRepository() {
|
||||||
return orderNoteRepository;
|
return orderNoteRepository;
|
||||||
}
|
}
|
||||||
|
|||||||
22
woodroid/src/main/java/me/gilo/woodroid/data/ApiVersion.java
Normal file
22
woodroid/src/main/java/me/gilo/woodroid/data/ApiVersion.java
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
package me.gilo.woodroid.data;
|
||||||
|
|
||||||
|
public enum ApiVersion {
|
||||||
|
API_VERSION1{
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "1";
|
||||||
|
}
|
||||||
|
},
|
||||||
|
API_VERSION2{
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "2";
|
||||||
|
}
|
||||||
|
},
|
||||||
|
API_VERSION3{
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "3";
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user