updated fully to Kotlin
This commit is contained in:
parent
7b13ab92c6
commit
47e5575417
@ -1,36 +0,0 @@
|
|||||||
package me.gilo.woodroid
|
|
||||||
|
|
||||||
import me.gilo.woodroid.data.ApiVersion
|
|
||||||
|
|
||||||
|
|
||||||
class Builder {
|
|
||||||
private lateinit var siteUrl: String
|
|
||||||
private lateinit var apiVerion: ApiVersion
|
|
||||||
private lateinit var consumerKey: String
|
|
||||||
private lateinit var consumerSecret: String
|
|
||||||
|
|
||||||
fun setSiteUrl(siteUrl: String): Builder {
|
|
||||||
this.siteUrl = siteUrl
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
fun setApiVersion(apiVerion: ApiVersion): Builder {
|
|
||||||
this.apiVerion = apiVerion
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
fun setConsumerKey(consumerKey: String): Builder {
|
|
||||||
this.consumerKey = consumerKey
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
fun setConsumerSecret(consumerSecret: String): Builder {
|
|
||||||
this.consumerSecret = consumerSecret
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
fun build(): Woocommerce {
|
|
||||||
return Woocommerce(siteUrl, apiVerion, consumerKey, consumerSecret)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,140 +0,0 @@
|
|||||||
package me.gilo.woodroid;
|
|
||||||
|
|
||||||
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;
|
|
||||||
import me.gilo.woodroid.repo.order.RefundRepository;
|
|
||||||
import me.gilo.woodroid.repo.product.*;
|
|
||||||
import org.json.JSONException;
|
|
||||||
import org.json.JSONObject;
|
|
||||||
|
|
||||||
public class Woocommerce {
|
|
||||||
|
|
||||||
public static final ApiVersion API_V1 = ApiVersion.API_VERSION1;
|
|
||||||
public static final ApiVersion API_V2 = ApiVersion.API_VERSION2;
|
|
||||||
public static final ApiVersion API_V3 = ApiVersion.API_VERSION3;
|
|
||||||
|
|
||||||
private final OrderNoteRepository orderNoteRepository;
|
|
||||||
private final RefundRepository refundRepository;
|
|
||||||
private final AttributeRepository attributeRepository;
|
|
||||||
private final AttributeTermRepository attributeTermRepository;
|
|
||||||
private final CategoryRepository categoryRepository;
|
|
||||||
private final ShippingClassRepository shippingClassRepository;
|
|
||||||
private final TagRepository tagRepository;
|
|
||||||
private final VariationRepository variationRepository;
|
|
||||||
private final CouponRepository couponRepository;
|
|
||||||
private final CustomerRepository customerRepository;
|
|
||||||
private final OrderRepository orderRepository;
|
|
||||||
private final ProductRepository productRepository;
|
|
||||||
private final ReviewRepository reviewRepository;
|
|
||||||
private final ReportsRepository reportsRepository;
|
|
||||||
private final CartRepository cartRepository;
|
|
||||||
private final PaymentGatewayRepository paymentGatewayRepository;
|
|
||||||
private final SettingsRepository settingsRepository;
|
|
||||||
private final ShippingMethodRepository shippingMethodRepository;
|
|
||||||
|
|
||||||
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);
|
|
||||||
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);
|
|
||||||
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 OrderNoteRepository OrderNoteRepository() {
|
|
||||||
return orderNoteRepository;
|
|
||||||
}
|
|
||||||
|
|
||||||
public RefundRepository RefundRepository() {
|
|
||||||
return refundRepository;
|
|
||||||
}
|
|
||||||
|
|
||||||
public AttributeRepository AttributeRepository() {
|
|
||||||
return attributeRepository;
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ReviewRepository ReviewRepository() {
|
|
||||||
return reviewRepository;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ReportsRepository ReportsRepository() {
|
|
||||||
return reportsRepository;
|
|
||||||
}
|
|
||||||
|
|
||||||
public PaymentGatewayRepository PaymentGatewayRepository() {
|
|
||||||
return paymentGatewayRepository;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SettingsRepository SettingsRepository() {
|
|
||||||
return settingsRepository;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ShippingMethodRepository ShippingMethodRepository() {
|
|
||||||
return shippingMethodRepository;
|
|
||||||
}
|
|
||||||
|
|
||||||
public CartRepository CartRepository(Context context) {
|
|
||||||
cartRepository.turnOnCookies(context);
|
|
||||||
return cartRepository;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
172
woodroid/src/main/java/me/gilo/woodroid/Woocommerce.kt
Normal file
172
woodroid/src/main/java/me/gilo/woodroid/Woocommerce.kt
Normal file
@ -0,0 +1,172 @@
|
|||||||
|
package me.gilo.woodroid
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import me.gilo.woodroid.data.ApiVersion
|
||||||
|
import me.gilo.woodroid.repo.*
|
||||||
|
import me.gilo.woodroid.repo.order.OrderNoteRepository
|
||||||
|
import me.gilo.woodroid.repo.order.RefundRepository
|
||||||
|
import me.gilo.woodroid.repo.product.*
|
||||||
|
|
||||||
|
class Woocommerce(siteUrl: String, apiVerion: ApiVersion, consumerKey: String, consumerSecret: String) {
|
||||||
|
companion object {
|
||||||
|
val API_V1 = ApiVersion.API_VERSION1
|
||||||
|
val API_V2 = ApiVersion.API_VERSION2
|
||||||
|
val API_V3 = ApiVersion.API_VERSION3
|
||||||
|
}
|
||||||
|
|
||||||
|
private val orderNoteRepository: OrderNoteRepository
|
||||||
|
private val refundRepository: RefundRepository
|
||||||
|
private val attributeRepository: AttributeRepository
|
||||||
|
private val attributeTermRepository: AttributeTermRepository
|
||||||
|
private val categoryRepository: CategoryRepository
|
||||||
|
private val shippingClassRepository: ShippingClassRepository
|
||||||
|
private val tagRepository: TagRepository
|
||||||
|
private val variationRepository: VariationRepository
|
||||||
|
private val couponRepository: CouponRepository
|
||||||
|
private val customerRepository: CustomerRepository
|
||||||
|
private val orderRepository: OrderRepository
|
||||||
|
private val productRepository: ProductRepository
|
||||||
|
private val reviewRepository: ReviewRepository
|
||||||
|
private val reportsRepository: ReportsRepository
|
||||||
|
private val cartRepository: CartRepository
|
||||||
|
private val paymentGatewayRepository: PaymentGatewayRepository
|
||||||
|
private val settingsRepository: SettingsRepository
|
||||||
|
private val shippingMethodRepository: ShippingMethodRepository
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
init {
|
||||||
|
val baseUrl = "$siteUrl/wp-json/wc/v$apiVerion/"
|
||||||
|
val cartBaseUrl = "$siteUrl/wp-json/wc/v2/"
|
||||||
|
|
||||||
|
orderNoteRepository = OrderNoteRepository(baseUrl, consumerKey, consumerSecret)
|
||||||
|
refundRepository = RefundRepository(baseUrl, consumerKey, consumerSecret)
|
||||||
|
attributeRepository = AttributeRepository(baseUrl, consumerKey, consumerSecret)
|
||||||
|
attributeTermRepository = AttributeTermRepository(baseUrl, consumerKey, consumerSecret)
|
||||||
|
categoryRepository = CategoryRepository(baseUrl, consumerKey, consumerSecret)
|
||||||
|
shippingClassRepository = ShippingClassRepository(baseUrl, consumerKey, consumerSecret)
|
||||||
|
tagRepository = TagRepository(baseUrl, consumerKey, consumerSecret)
|
||||||
|
variationRepository = VariationRepository(baseUrl, consumerKey, consumerSecret)
|
||||||
|
couponRepository = CouponRepository(baseUrl, consumerKey, consumerSecret)
|
||||||
|
customerRepository = CustomerRepository(baseUrl, consumerKey, consumerSecret)
|
||||||
|
orderRepository = OrderRepository(baseUrl, consumerKey, consumerSecret)
|
||||||
|
productRepository = ProductRepository(baseUrl, consumerKey, consumerSecret)
|
||||||
|
reportsRepository = ReportsRepository(baseUrl, consumerKey, consumerSecret)
|
||||||
|
cartRepository = CartRepository(cartBaseUrl, consumerKey, consumerSecret)
|
||||||
|
reviewRepository = ReviewRepository(baseUrl, consumerKey, consumerSecret)
|
||||||
|
paymentGatewayRepository = PaymentGatewayRepository(baseUrl, consumerKey, consumerSecret)
|
||||||
|
settingsRepository = SettingsRepository(baseUrl, consumerKey, consumerSecret)
|
||||||
|
shippingMethodRepository = ShippingMethodRepository(baseUrl, consumerKey, consumerSecret)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
fun OrderNoteRepository(): OrderNoteRepository {
|
||||||
|
return orderNoteRepository
|
||||||
|
}
|
||||||
|
|
||||||
|
fun RefundRepository(): RefundRepository {
|
||||||
|
return refundRepository
|
||||||
|
}
|
||||||
|
|
||||||
|
fun AttributeRepository(): AttributeRepository {
|
||||||
|
return attributeRepository
|
||||||
|
}
|
||||||
|
|
||||||
|
fun AttributeTermRepository(): AttributeTermRepository {
|
||||||
|
return attributeTermRepository
|
||||||
|
}
|
||||||
|
|
||||||
|
fun CategoryRepository(): CategoryRepository {
|
||||||
|
return categoryRepository
|
||||||
|
}
|
||||||
|
|
||||||
|
fun ShippingClassRepository(): ShippingClassRepository {
|
||||||
|
return shippingClassRepository
|
||||||
|
}
|
||||||
|
|
||||||
|
fun TagRepository(): TagRepository {
|
||||||
|
return tagRepository
|
||||||
|
}
|
||||||
|
|
||||||
|
fun VariationRepository(): VariationRepository {
|
||||||
|
return variationRepository
|
||||||
|
}
|
||||||
|
|
||||||
|
fun CouponRepository(): CouponRepository {
|
||||||
|
return couponRepository
|
||||||
|
}
|
||||||
|
|
||||||
|
fun CustomerRepository(): CustomerRepository {
|
||||||
|
return customerRepository
|
||||||
|
}
|
||||||
|
|
||||||
|
fun OrderRepository(): OrderRepository {
|
||||||
|
return orderRepository
|
||||||
|
}
|
||||||
|
|
||||||
|
fun ProductRepository(): ProductRepository {
|
||||||
|
return productRepository
|
||||||
|
}
|
||||||
|
|
||||||
|
fun ReviewRepository(): ReviewRepository {
|
||||||
|
return reviewRepository
|
||||||
|
}
|
||||||
|
|
||||||
|
fun ReportsRepository(): ReportsRepository {
|
||||||
|
return reportsRepository
|
||||||
|
}
|
||||||
|
|
||||||
|
fun PaymentGatewayRepository(): PaymentGatewayRepository {
|
||||||
|
return paymentGatewayRepository
|
||||||
|
}
|
||||||
|
|
||||||
|
fun SettingsRepository(): SettingsRepository {
|
||||||
|
return settingsRepository
|
||||||
|
}
|
||||||
|
|
||||||
|
fun ShippingMethodRepository(): ShippingMethodRepository {
|
||||||
|
return shippingMethodRepository
|
||||||
|
}
|
||||||
|
|
||||||
|
fun CartRepository(context: Context): CartRepository {
|
||||||
|
cartRepository.turnOnCookies(context)
|
||||||
|
return cartRepository
|
||||||
|
}
|
||||||
|
|
||||||
|
class Builder {
|
||||||
|
private lateinit var siteUrl: String
|
||||||
|
private lateinit var apiVersion: ApiVersion
|
||||||
|
private lateinit var consumerKey: String
|
||||||
|
private lateinit var consumerSecret: String
|
||||||
|
|
||||||
|
fun setSiteUrl(siteUrl: String): Builder {
|
||||||
|
this.siteUrl = siteUrl
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setApiVersion(apiVerion: ApiVersion): Builder {
|
||||||
|
this.apiVersion = apiVerion
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setConsumerKey(consumerKey: String): Builder {
|
||||||
|
this.consumerKey = consumerKey
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setConsumerSecret(consumerSecret: String): Builder {
|
||||||
|
this.consumerSecret = consumerSecret
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fun build(): Woocommerce {
|
||||||
|
return Woocommerce(siteUrl, apiVersion, consumerKey, consumerSecret)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user