Resorted to using Repo over service and exposed all the repos available
This commit is contained in:
parent
b56ac5f17d
commit
939afd1d9a
@ -47,7 +47,7 @@ class ShopActivity : BaseActivity() {
|
||||
.setConsumerSecret("cs_062e8e3a7ae0ce08fdebc0c39f8f834d5e87598e")
|
||||
.build()
|
||||
|
||||
woocommerce.Product().products().enqueue(object : Callback<List<Product>> {
|
||||
woocommerce.ProductRepository().products().enqueue(object : Callback<List<Product>> {
|
||||
override fun onResponse(call: Call<List<Product>>, response: Response<List<Product>>) {
|
||||
val productsResponse = response.body()
|
||||
for (product in productsResponse!!) {
|
||||
@ -62,7 +62,6 @@ class ShopActivity : BaseActivity() {
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -42,7 +42,7 @@ class AddCouponActivity : BaseActivity() {
|
||||
private fun createCoupon(coupon: Coupon) {
|
||||
showLoading("Loading", "This won't take long")
|
||||
|
||||
woocommerce.Coupon().create(coupon).enqueue(object : Callback<Coupon> {
|
||||
woocommerce.CouponRepository().create(coupon).enqueue(object : Callback<Coupon> {
|
||||
override fun onResponse(call: Call<Coupon>, response: Response<Coupon>) {
|
||||
val couponResponse = response.body()
|
||||
stopShowingLoading()
|
||||
|
||||
@ -46,7 +46,7 @@ class CouponActivity : BaseActivity() {
|
||||
private fun getCoupon(couponId: Int) {
|
||||
showLoading()
|
||||
|
||||
woocommerce.Coupon().coupon(couponId).enqueue(object : Callback<Coupon> {
|
||||
woocommerce.CouponRepository().coupon(couponId).enqueue(object : Callback<Coupon> {
|
||||
override fun onResponse(call: Call<Coupon>, response: Response<Coupon>) {
|
||||
val coupon = response.body()!!
|
||||
|
||||
@ -65,7 +65,7 @@ class CouponActivity : BaseActivity() {
|
||||
private fun delete(couponId: Int) {
|
||||
showLoading()
|
||||
|
||||
woocommerce.Coupon().delete(couponId).enqueue(object : Callback<Coupon> {
|
||||
woocommerce.CouponRepository().delete(couponId).enqueue(object : Callback<Coupon> {
|
||||
override fun onResponse(call: Call<Coupon>, response: Response<Coupon>) {
|
||||
if (response.isSuccessful) {
|
||||
val coupon = response.body()!!
|
||||
@ -91,7 +91,7 @@ class CouponActivity : BaseActivity() {
|
||||
private fun update(coupon: Coupon) {
|
||||
showLoading()
|
||||
|
||||
woocommerce.Coupon().update(coupon.id, coupon).enqueue(object : Callback<Coupon> {
|
||||
woocommerce.CouponRepository().update(coupon.id, coupon).enqueue(object : Callback<Coupon> {
|
||||
override fun onResponse(call: Call<Coupon>, response: Response<Coupon>) {
|
||||
val coupon = response.body()!!
|
||||
|
||||
|
||||
@ -46,7 +46,7 @@ class CouponsActivity : BaseActivity() {
|
||||
|
||||
//Not best practise, but works for purposes of demo
|
||||
private fun coupons() {
|
||||
woocommerce.Coupon().coupons().enqueue(object : Callback<List<Coupon>> {
|
||||
woocommerce.CouponRepository().coupons().enqueue(object : Callback<List<Coupon>> {
|
||||
override fun onResponse(call: Call<List<Coupon>>, response: Response<List<Coupon>>) {
|
||||
val couponResponse = response.body()
|
||||
for (coupon in couponResponse!!) {
|
||||
|
||||
@ -1,19 +1,33 @@
|
||||
package me.gilo.woodroid;
|
||||
|
||||
import me.gilo.woodroid.services.CouponService;
|
||||
import me.gilo.woodroid.services.CustomerService;
|
||||
import me.gilo.woodroid.services.OrderService;
|
||||
import me.gilo.woodroid.services.ProductService;
|
||||
import me.gilo.woodroid.repo.CouponRepository;
|
||||
import me.gilo.woodroid.repo.CustomerRepository;
|
||||
import me.gilo.woodroid.repo.OrderRepository;
|
||||
import me.gilo.woodroid.repo.ProductRepository;
|
||||
import me.gilo.woodroid.repo.order.OrderNoteRepository;
|
||||
import me.gilo.woodroid.repo.order.RefundRepository;
|
||||
import me.gilo.woodroid.repo.product.*;
|
||||
|
||||
public class Woocommerce {
|
||||
|
||||
public static final ApiVersion API_V1 = ApiVersion.API_VERSION1;
|
||||
public static final ApiVersion API_V2 = ApiVersion.API_VERSION2;
|
||||
|
||||
final CouponService couponService;
|
||||
final CustomerService customerService;
|
||||
final OrderService orderService;
|
||||
final ProductService productService;
|
||||
final OrderNoteRepository orderNoteRepository;
|
||||
final RefundRepository refundRepository;
|
||||
final AttributeRepository attributeRepository;
|
||||
final AttributeTermRepository attributeTermRepository;
|
||||
final CategoryRepository categoryRepository;
|
||||
|
||||
final ShippingClassRepository shippingClassRepository;
|
||||
final TagRepository tagRepository;
|
||||
final VariationRepository variationRepository;
|
||||
final CouponRepository couponRepository;
|
||||
final CustomerRepository customerRepository;
|
||||
|
||||
final OrderRepository orderRepository;
|
||||
final ProductRepository productRepository;
|
||||
|
||||
|
||||
enum ApiVersion {
|
||||
API_VERSION1{
|
||||
@ -38,10 +52,20 @@ public class Woocommerce {
|
||||
|
||||
public Woocommerce(String siteUrl, ApiVersion apiVerion, String consumerKey, String consumerSecret) {
|
||||
String baseUrl = siteUrl + "/wp-json/wc/v" + apiVerion + "/";
|
||||
couponService = new CouponService(baseUrl, consumerKey, consumerSecret);
|
||||
customerService = new CustomerService(baseUrl, consumerKey, consumerSecret);
|
||||
orderService = new OrderService(baseUrl, consumerKey, consumerSecret);
|
||||
productService = new ProductService(baseUrl, consumerKey, consumerSecret);
|
||||
|
||||
orderNoteRepository = new OrderNoteRepository(baseUrl, consumerKey, consumerSecret);
|
||||
refundRepository = new RefundRepository(baseUrl, consumerKey, consumerSecret);
|
||||
attributeRepository = new AttributeRepository(baseUrl, consumerKey, consumerSecret);
|
||||
attributeTermRepository = new AttributeTermRepository(baseUrl, consumerKey, consumerSecret);
|
||||
categoryRepository = new CategoryRepository(baseUrl, consumerKey, consumerSecret);
|
||||
shippingClassRepository = new ShippingClassRepository(baseUrl, consumerKey, consumerSecret);
|
||||
tagRepository = new TagRepository(baseUrl, consumerKey, consumerSecret);
|
||||
variationRepository = new VariationRepository(baseUrl, consumerKey, consumerSecret);
|
||||
couponRepository = new CouponRepository(baseUrl, consumerKey, consumerSecret);
|
||||
customerRepository = new CustomerRepository(baseUrl, consumerKey, consumerSecret);
|
||||
orderRepository = new OrderRepository(baseUrl, consumerKey, consumerSecret);
|
||||
productRepository = new ProductRepository(baseUrl, consumerKey, consumerSecret);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -81,19 +105,51 @@ public class Woocommerce {
|
||||
}
|
||||
}
|
||||
|
||||
public CouponService Coupon() {
|
||||
return couponService;
|
||||
public OrderNoteRepository OrderNoteRepository() {
|
||||
return orderNoteRepository;
|
||||
}
|
||||
|
||||
public CustomerService Customer() {
|
||||
return customerService;
|
||||
public RefundRepository RefundRepository() {
|
||||
return refundRepository;
|
||||
}
|
||||
|
||||
public OrderService Order() {
|
||||
return orderService;
|
||||
public AttributeRepository AttributeRepository() {
|
||||
return attributeRepository;
|
||||
}
|
||||
|
||||
public ProductService Product() {
|
||||
return productService;
|
||||
public AttributeTermRepository AttributeTermRepository() {
|
||||
return attributeTermRepository;
|
||||
}
|
||||
|
||||
public CategoryRepository CategoryRepository() {
|
||||
return categoryRepository;
|
||||
}
|
||||
|
||||
public ShippingClassRepository ShippingClassRepository() {
|
||||
return shippingClassRepository;
|
||||
}
|
||||
|
||||
public TagRepository TagRepository() {
|
||||
return tagRepository;
|
||||
}
|
||||
|
||||
public VariationRepository VariationRepository() {
|
||||
return variationRepository;
|
||||
}
|
||||
|
||||
public CouponRepository CouponRepository() {
|
||||
return couponRepository;
|
||||
}
|
||||
|
||||
public CustomerRepository CustomerRepository() {
|
||||
return customerRepository;
|
||||
}
|
||||
|
||||
public OrderRepository OrderRepository() {
|
||||
return orderRepository;
|
||||
}
|
||||
|
||||
public ProductRepository ProductRepository() {
|
||||
return productRepository;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,9 +1,7 @@
|
||||
package me.gilo.woodroid.data.api;
|
||||
|
||||
|
||||
import me.gilo.woodroid.models.Attribute;
|
||||
import me.gilo.woodroid.models.AttributeTerm;
|
||||
import me.gilo.woodroid.models.Coupon;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.http.*;
|
||||
|
||||
@ -15,7 +13,7 @@ public interface ProductAttributeTermAPI {
|
||||
|
||||
@Headers("Content-Type: application/json")
|
||||
@POST("products/attributes/{id}/terms")
|
||||
Call<AttributeTerm> create(@Body AttributeTerm body);
|
||||
Call<AttributeTerm> create(@Path("id") int attribute_id, @Body AttributeTerm body);
|
||||
|
||||
@GET("products/attributes/{id}/terms/[term_id]")
|
||||
Call<AttributeTerm> view(@Path("id") int attribute_id, @Path("term_id") int term_id);
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
package me.gilo.woodroid.repo.product;
|
||||
|
||||
import me.gilo.woodroid.data.api.ProductAttributeTermAPI;
|
||||
import me.gilo.woodroid.models.Attribute;
|
||||
import me.gilo.woodroid.models.AttributeTerm;
|
||||
import me.gilo.woodroid.repo.WooRepository;
|
||||
import retrofit2.Call;
|
||||
@ -12,41 +11,33 @@ public class AttributeTermRepository extends WooRepository {
|
||||
|
||||
private final ProductAttributeTermAPI apiService;
|
||||
|
||||
Attribute attribute;
|
||||
|
||||
public AttributeTermRepository(String baseUrl, String consumerKey, String consumerSecret, Attribute attribute) {
|
||||
public AttributeTermRepository(String baseUrl, String consumerKey, String consumerSecret) {
|
||||
super(baseUrl, consumerKey, consumerSecret);
|
||||
apiService = retrofit.create(ProductAttributeTermAPI.class);
|
||||
|
||||
this.attribute = attribute;
|
||||
}
|
||||
|
||||
public Call<AttributeTerm> create(AttributeTerm term) {
|
||||
return apiService.create(term);
|
||||
public Call<AttributeTerm> create(int attribute_id, AttributeTerm term) {
|
||||
return apiService.create(attribute_id, term);
|
||||
}
|
||||
|
||||
public void setAttribute(Attribute attribute) {
|
||||
this.attribute = attribute;
|
||||
public Call<AttributeTerm> term(int attribute_id, int id) {
|
||||
return apiService.view(attribute_id, id);
|
||||
}
|
||||
|
||||
public Call<AttributeTerm> term(int id) {
|
||||
return apiService.view(attribute.getId(), id);
|
||||
public Call<List<AttributeTerm>> terms(int attribute_id) {
|
||||
return apiService.list(attribute_id);
|
||||
}
|
||||
|
||||
public Call<List<AttributeTerm>> terms() {
|
||||
return apiService.list(attribute.getId());
|
||||
public Call<AttributeTerm> update(int attribute_id, int id, AttributeTerm term) {
|
||||
return apiService.update(attribute_id, id, term);
|
||||
}
|
||||
|
||||
public Call<AttributeTerm> update(int id, AttributeTerm term) {
|
||||
return apiService.update(attribute.getId(), id, term);
|
||||
public Call<AttributeTerm> delete(int attribute_id, int id) {
|
||||
return apiService.delete(attribute_id, id);
|
||||
}
|
||||
|
||||
public Call<AttributeTerm> delete(int id) {
|
||||
return apiService.delete(attribute.getId(), id);
|
||||
}
|
||||
|
||||
public Call<AttributeTerm> delete(int id, boolean force) {
|
||||
return apiService.delete(attribute.getId(), id, force);
|
||||
public Call<AttributeTerm> delete(int attribute_id, int id, boolean force) {
|
||||
return apiService.delete(attribute_id, id, force);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
package me.gilo.woodroid.repo.product;
|
||||
|
||||
import me.gilo.woodroid.data.api.ProductVariationAPI;
|
||||
import me.gilo.woodroid.models.Product;
|
||||
import me.gilo.woodroid.models.Variation;
|
||||
import me.gilo.woodroid.repo.WooRepository;
|
||||
import retrofit2.Call;
|
||||
@ -11,38 +10,35 @@ import java.util.List;
|
||||
public class VariationRepository extends WooRepository {
|
||||
|
||||
private final ProductVariationAPI apiService;
|
||||
Product product;
|
||||
|
||||
public VariationRepository(String baseUrl, String consumerKey, String consumerSecret, Product product) {
|
||||
public VariationRepository(String baseUrl, String consumerKey, String consumerSecret) {
|
||||
super(baseUrl, consumerKey, consumerSecret);
|
||||
apiService = retrofit.create(ProductVariationAPI.class);
|
||||
|
||||
this.product = product;
|
||||
}
|
||||
|
||||
public Call<Variation> create(Variation variation) {
|
||||
return apiService.create(product.getId(), variation);
|
||||
public Call<Variation> create(int product_id, Variation variation) {
|
||||
return apiService.create(product_id, variation);
|
||||
}
|
||||
|
||||
|
||||
public Call<Variation> variation(int id) {
|
||||
return apiService.view(product.getId(), id);
|
||||
public Call<Variation> variation(int product_id, int id) {
|
||||
return apiService.view(product_id, id);
|
||||
}
|
||||
|
||||
public Call<List<Variation>> variations() {
|
||||
return apiService.list(product.getId());
|
||||
public Call<List<Variation>> variations(int product_id) {
|
||||
return apiService.list(product_id);
|
||||
}
|
||||
|
||||
public Call<Variation> update(int id, Variation variation) {
|
||||
return apiService.update(product.getId(), id, variation);
|
||||
public Call<Variation> update(int product_id, int id, Variation variation) {
|
||||
return apiService.update(product_id, id, variation);
|
||||
}
|
||||
|
||||
public Call<Variation> delete(int id) {
|
||||
return apiService.delete(product.getId(), id);
|
||||
public Call<Variation> delete(int product_id, int id) {
|
||||
return apiService.delete(product_id, id);
|
||||
}
|
||||
|
||||
public Call<Variation> delete(int id, boolean force) {
|
||||
return apiService.delete(product.getId(), id, force);
|
||||
public Call<Variation> delete(int product_id, int id, boolean force) {
|
||||
return apiService.delete(product_id, id, force);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -1,42 +0,0 @@
|
||||
package me.gilo.woodroid.services;
|
||||
|
||||
import me.gilo.woodroid.models.Coupon;
|
||||
import me.gilo.woodroid.repo.CouponRepository;
|
||||
import retrofit2.Call;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class CouponService {
|
||||
|
||||
final CouponRepository couponRepository;
|
||||
|
||||
public CouponService(String baseUrl, String consumerKey, String consumerSecret) {
|
||||
couponRepository = new CouponRepository(baseUrl, consumerKey, consumerSecret);
|
||||
}
|
||||
|
||||
public Call<Coupon> create(Coupon coupon) {
|
||||
return couponRepository.create(coupon);
|
||||
}
|
||||
|
||||
|
||||
public Call<Coupon> coupon(int id) {
|
||||
return couponRepository.coupon(id);
|
||||
}
|
||||
|
||||
public Call<List<Coupon>> coupons() {
|
||||
return couponRepository.coupons();
|
||||
}
|
||||
|
||||
public Call<Coupon> update(int id, Coupon coupon) {
|
||||
return couponRepository.update(id, coupon);
|
||||
}
|
||||
|
||||
public Call<Coupon> delete(int id) {
|
||||
return couponRepository.delete(id);
|
||||
}
|
||||
|
||||
public Call<Coupon> delete(int id, boolean force) {
|
||||
return couponRepository.delete(id, force);
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,42 +0,0 @@
|
||||
package me.gilo.woodroid.services;
|
||||
|
||||
import me.gilo.woodroid.models.Customer;
|
||||
import me.gilo.woodroid.repo.CustomerRepository;
|
||||
import retrofit2.Call;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class CustomerService {
|
||||
|
||||
final CustomerRepository customerRepository;
|
||||
|
||||
public CustomerService(String baseUrl, String consumerKey, String consumerSecret) {
|
||||
customerRepository = new CustomerRepository(baseUrl, consumerKey, consumerSecret);
|
||||
}
|
||||
|
||||
public Call<Customer> create(Customer customer) {
|
||||
return customerRepository.create(customer);
|
||||
}
|
||||
|
||||
|
||||
public Call<Customer> customer(int id) {
|
||||
return customerRepository.customer(id);
|
||||
}
|
||||
|
||||
public Call<List<Customer>> customers() {
|
||||
return customerRepository.customers();
|
||||
}
|
||||
|
||||
public Call<Customer> update(int id, Customer customer) {
|
||||
return customerRepository.update(id, customer);
|
||||
}
|
||||
|
||||
public Call<Customer> delete(int id) {
|
||||
return customerRepository.delete(id);
|
||||
}
|
||||
|
||||
public Call<Customer> delete(int id, boolean force) {
|
||||
return customerRepository.delete(id, force);
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,42 +0,0 @@
|
||||
package me.gilo.woodroid.services;
|
||||
|
||||
import me.gilo.woodroid.models.Order;
|
||||
import me.gilo.woodroid.repo.OrderRepository;
|
||||
import retrofit2.Call;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class OrderService {
|
||||
|
||||
final OrderRepository orderRepository;
|
||||
|
||||
public OrderService(String baseUrl, String consumerKey, String consumerSecret) {
|
||||
orderRepository = new OrderRepository(baseUrl, consumerKey, consumerSecret);
|
||||
}
|
||||
|
||||
public Call<Order> create(Order order) {
|
||||
return orderRepository.create(order);
|
||||
}
|
||||
|
||||
|
||||
public Call<Order> order(int id) {
|
||||
return orderRepository.order(id);
|
||||
}
|
||||
|
||||
public Call<List<Order>> orders() {
|
||||
return orderRepository.orders();
|
||||
}
|
||||
|
||||
public Call<Order> update(int id, Order order) {
|
||||
return orderRepository.update(id, order);
|
||||
}
|
||||
|
||||
public Call<Order> delete(int id) {
|
||||
return orderRepository.delete(id);
|
||||
}
|
||||
|
||||
public Call<Order> delete(int id, boolean force) {
|
||||
return orderRepository.delete(id, force);
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,42 +0,0 @@
|
||||
package me.gilo.woodroid.services;
|
||||
|
||||
import me.gilo.woodroid.models.Product;
|
||||
import me.gilo.woodroid.repo.ProductRepository;
|
||||
import retrofit2.Call;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ProductService {
|
||||
|
||||
final ProductRepository productRepository;
|
||||
|
||||
public ProductService(String baseUrl, String consumerKey, String consumerSecret) {
|
||||
productRepository = new ProductRepository(baseUrl, consumerKey, consumerSecret);
|
||||
}
|
||||
|
||||
public Call<Product> create(Product product) {
|
||||
return productRepository.create(product);
|
||||
}
|
||||
|
||||
|
||||
public Call<Product> product(int id) {
|
||||
return productRepository.product(id);
|
||||
}
|
||||
|
||||
public Call<List<Product>> products() {
|
||||
return productRepository.products();
|
||||
}
|
||||
|
||||
public Call<Product> update(int id, Product product) {
|
||||
return productRepository.update(id, product);
|
||||
}
|
||||
|
||||
public Call<Product> delete(int id) {
|
||||
return productRepository.delete(id);
|
||||
}
|
||||
|
||||
public Call<Product> delete(int id, boolean force) {
|
||||
return productRepository.delete(id, force);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user