Skip to content

Commit

Permalink
Restructured the API classes
Browse files Browse the repository at this point in the history
  • Loading branch information
gilokimu committed Apr 17, 2019
1 parent 58a8cd5 commit 69277df
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 62 deletions.
2 changes: 1 addition & 1 deletion app/src/main/java/me/gilo/wc/di/AppModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ WcApp providesApplication() {
@Provides
@Singleton
Woocommerce providesWoocommerce() {
Woocommerce woocommerce = new Woocommerce.Builder()
Woocommerce woocommerce = Woocommerce.Builder()
.setSiteUrl("http://157.230.131.179")
.setApiVersion(Woocommerce.API_V3)
.setConsumerKey("ck_26c61abd7eeff238d87dc56585bf26cb2d1a1ec3")
Expand Down
39 changes: 39 additions & 0 deletions woodroid/src/main/java/me/gilo/woodroid/Builder.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
64 changes: 3 additions & 61 deletions woodroid/src/main/java/me/gilo/woodroid/Woocommerce.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.content.Context;
import android.util.Log;
import me.gilo.woodroid.data.ApiVersion;
import me.gilo.woodroid.models.PaymentGateway;
import me.gilo.woodroid.repo.*;
import me.gilo.woodroid.repo.order.OrderNoteRepository;
Expand Down Expand Up @@ -35,31 +36,12 @@ public class Woocommerce {
final SettingsRepository settingsRepository;
final ShippingMethodRepository shippingMethodRepository;


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";
}
},
public static Builder Builder(){
return new Builder();
}

public Woocommerce(String siteUrl, ApiVersion apiVerion, String consumerKey, String consumerSecret) {
String baseUrl = siteUrl + "/wp-json/wc/v" + apiVerion + "/";

String cartBaseUrl = siteUrl + "/wp-json/wc/v" + 2 + "/";

orderNoteRepository = new OrderNoteRepository(baseUrl, consumerKey, consumerSecret);
Expand All @@ -74,55 +56,15 @@ public Woocommerce(String siteUrl, ApiVersion apiVerion, String consumerKey, Str
customerRepository = new CustomerRepository(baseUrl, consumerKey, consumerSecret);
orderRepository = new OrderRepository(baseUrl, consumerKey, consumerSecret);
productRepository = new ProductRepository(baseUrl, consumerKey, consumerSecret);

reportsRepository = new ReportsRepository(baseUrl, consumerKey, consumerSecret);

cartRepository = new CartRepository(cartBaseUrl, consumerKey, consumerSecret);

reviewRepository = new ReviewRepository(baseUrl, consumerKey, consumerSecret);
paymentGatewayRepository = new PaymentGatewayRepository(baseUrl, consumerKey, consumerSecret);
settingsRepository = new SettingsRepository(baseUrl, consumerKey, consumerSecret);
shippingMethodRepository = new ShippingMethodRepository(baseUrl, consumerKey, consumerSecret);

}


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() {
return orderNoteRepository;
}
Expand Down
22 changes: 22 additions & 0 deletions woodroid/src/main/java/me/gilo/woodroid/data/ApiVersion.java
Original file line number Diff line number Diff line change
@@ -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";
}
},
}

0 comments on commit 69277df

Please sign in to comment.