Merge pull request #8 from gilokimu/kotlin_refactor

Kotlin refactor
This commit is contained in:
Gilbert Kimutai 2019-06-08 12:13:38 +03:00 committed by GitHub
commit 7b13ab92c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
294 changed files with 4313 additions and 8233 deletions

2
.idea/gradle.xml generated
View File

@ -9,10 +9,12 @@
<set> <set>
<option value="$PROJECT_DIR$" /> <option value="$PROJECT_DIR$" />
<option value="$PROJECT_DIR$/app" /> <option value="$PROJECT_DIR$/app" />
<option value="$PROJECT_DIR$/firebasecart" />
<option value="$PROJECT_DIR$/woodroid" /> <option value="$PROJECT_DIR$/woodroid" />
</set> </set>
</option> </option>
<option name="resolveModulePerSourceSet" value="false" /> <option name="resolveModulePerSourceSet" value="false" />
<option name="testRunner" value="PLATFORM" />
</GradleProjectSettings> </GradleProjectSettings>
</option> </option>
</component> </component>

View File

@ -1,9 +1,6 @@
apply plugin: 'com.android.application' apply plugin: 'com.android.application'
apply plugin: 'kotlin-android' apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions' apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt' apply plugin: 'kotlin-kapt'
android { android {

View File

@ -17,7 +17,7 @@ class CouponViewHolder(val context: Context, itemView: View) :
val tvTitle = itemView.findViewById<TextView>(R.id.tvTitle) val tvTitle = itemView.findViewById<TextView>(R.id.tvTitle)
val tvDescription = itemView.findViewById<TextView>(R.id.tvDescription) val tvDescription = itemView.findViewById<TextView>(R.id.tvDescription)
tvTitle.text = coupon.code.toUpperCase() tvTitle.text = coupon.code?.toUpperCase()
tvDescription.text = Html.fromHtml(coupon.description) tvDescription.text = Html.fromHtml(coupon.description)
itemView.setOnClickListener{ itemView.setOnClickListener{

View File

@ -26,7 +26,7 @@ class OrderViewHolder(val context: Context, itemView: View) :
tvTitle.text = "#" + order.orderNumber tvTitle.text = "#" + order.orderNumber
tvStatus.text = order.status tvStatus.text = order.status
tvDate.text = DateUtils.getDateString_shortAndSmart(order.getDateCreated()) tvDate.text = DateUtils.getDateString_shortAndSmart(order.dateCreated)
tvPrice.text = SpannableString("Ksh${order.total}") tvPrice.text = SpannableString("Ksh${order.total}")

View File

@ -25,7 +25,7 @@ constructor() {
private val cart: CollectionReference = FirebaseFirestore.getInstance() private val cart: CollectionReference = FirebaseFirestore.getInstance()
.collection("users") .collection("users")
.document(FirebaseAuth.getInstance().currentUser!!.uid) .document(FirebaseAuth.getInstance().currentUser?.uid ?: "0")
.collection("cart") .collection("cart")
fun cart(): QueryLiveData<CartLineItem> { fun cart(): QueryLiveData<CartLineItem> {

View File

@ -17,57 +17,57 @@ constructor() {
fun create(customer: Customer): WooLiveData<Customer> { fun create(customer: Customer): WooLiveData<Customer> {
val callBack = WooLiveData<Customer>() val callBack = WooLiveData<Customer>()
woocommerce!!.CustomerRepository().create(customer).enqueue(callBack) woocommerce.CustomerRepository().create(customer).enqueue(callBack)
return callBack return callBack
} }
fun currentCustomer(): WooLiveData<List<Customer>> { fun currentCustomer(): WooLiveData<List<Customer>> {
val callBack = WooLiveData<List<Customer>>() val callBack = WooLiveData<List<Customer>>()
val customerFilter = CustomerFilter() val customerFilter = CustomerFilter()
customerFilter.email = FirebaseAuth.getInstance().currentUser!!.email customerFilter.setEmail(FirebaseAuth.getInstance().currentUser!!.email!!)
woocommerce!!.CustomerRepository().customers(customerFilter).enqueue(callBack) woocommerce.CustomerRepository().customers(customerFilter).enqueue(callBack)
return callBack return callBack
} }
fun customer(id: Int): WooLiveData<Customer> { fun customer(id: Int): WooLiveData<Customer> {
val callBack = WooLiveData<Customer>() val callBack = WooLiveData<Customer>()
woocommerce!!.CustomerRepository().customer(id).enqueue(callBack) woocommerce.CustomerRepository().customer(id).enqueue(callBack)
return callBack return callBack
} }
fun customers(): WooLiveData<List<Customer>> { fun customers(): WooLiveData<List<Customer>> {
val callBack = WooLiveData<List<Customer>>() val callBack = WooLiveData<List<Customer>>()
woocommerce!!.CustomerRepository().customers().enqueue(callBack) woocommerce.CustomerRepository().customers().enqueue(callBack)
return callBack return callBack
} }
fun customers(customerFilter: CustomerFilter): WooLiveData<List<Customer>> { fun customers(customerFilter: CustomerFilter): WooLiveData<List<Customer>> {
val callBack = WooLiveData<List<Customer>>() val callBack = WooLiveData<List<Customer>>()
woocommerce!!.CustomerRepository().customers(customerFilter).enqueue(callBack) woocommerce.CustomerRepository().customers(customerFilter).enqueue(callBack)
return callBack return callBack
} }
fun update(id: Int, customer: Customer): WooLiveData<Customer> { fun update(id: Int, customer: Customer): WooLiveData<Customer> {
val callBack = WooLiveData<Customer>() val callBack = WooLiveData<Customer>()
woocommerce!!.CustomerRepository().update(id, customer).enqueue(callBack) woocommerce.CustomerRepository().update(id, customer).enqueue(callBack)
return callBack return callBack
} }
fun delete(id: Int): WooLiveData<Customer> { fun delete(id: Int): WooLiveData<Customer> {
val callBack = WooLiveData<Customer>() val callBack = WooLiveData<Customer>()
woocommerce!!.CustomerRepository().delete(id).enqueue(callBack) woocommerce.CustomerRepository().delete(id).enqueue(callBack)
return callBack return callBack
} }
fun delete(id: Int, force: Boolean): WooLiveData<Customer> { fun delete(id: Int, force: Boolean): WooLiveData<Customer> {
val callBack = WooLiveData<Customer>() val callBack = WooLiveData<Customer>()
woocommerce!!.CustomerRepository().delete(id, force).enqueue(callBack) woocommerce.CustomerRepository().delete(id, force).enqueue(callBack)
return callBack return callBack
} }

View File

@ -50,7 +50,7 @@ class CouponActivity : BaseActivity() {
override fun onResponse(call: Call<Coupon>, response: Response<Coupon>) { override fun onResponse(call: Call<Coupon>, response: Response<Coupon>) {
val coupon = response.body()!! val coupon = response.body()!!
etCode.setText(coupon.code.toUpperCase()) etCode.setText(coupon.code?.toUpperCase())
etDescription.setText(coupon.description) etDescription.setText(coupon.description)
stopShowingLoading() stopShowingLoading()
@ -70,7 +70,7 @@ class CouponActivity : BaseActivity() {
if (response.isSuccessful) { if (response.isSuccessful) {
val coupon = response.body()!! val coupon = response.body()!!
etCode.setText(coupon.code.toUpperCase()) etCode.setText(coupon.code?.toUpperCase())
etDescription.setText(coupon.description) etDescription.setText(coupon.description)
finish() finish()
@ -95,7 +95,7 @@ class CouponActivity : BaseActivity() {
override fun onResponse(call: Call<Coupon>, response: Response<Coupon>) { override fun onResponse(call: Call<Coupon>, response: Response<Coupon>) {
val coupon = response.body()!! val coupon = response.body()!!
etCode.setText(coupon.code.toUpperCase()) etCode.setText(coupon.code?.toUpperCase())
etDescription.setText(coupon.description) etDescription.setText(coupon.description)
stopShowingLoading() stopShowingLoading()

View File

@ -48,7 +48,7 @@ class CouponsActivity : BaseActivity() {
//Not best practise, but works for purposes of demo //Not best practise, but works for purposes of demo
private fun coupons() { private fun coupons() {
val filter = CouponFilter() val filter = CouponFilter()
filter.search = "FEB" filter.setSearch("FEB")
woocommerce.CouponRepository().coupons(filter).enqueue(object : Callback<List<Coupon>> { woocommerce.CouponRepository().coupons(filter).enqueue(object : Callback<List<Coupon>> {
override fun onResponse(call: Call<List<Coupon>>, response: Response<List<Coupon>>) { override fun onResponse(call: Call<List<Coupon>>, response: Response<List<Coupon>>) {

View File

@ -106,7 +106,7 @@ class BillingAddressActivity : WooDroidActivity<CustomerViewModel>() {
customer.billingAddress.country = country customer.billingAddress.country = country
customer.billingAddress.phone = phone customer.billingAddress.phone = phone
customer.billingAddress.email = FirebaseAuth.getInstance().currentUser!!.email customer.billingAddress.email = FirebaseAuth.getInstance().currentUser!!.email!!
viewModel.update(customer.id, customer).observe(this, Observer { viewModel.update(customer.id, customer).observe(this, Observer {
response-> response->

View File

@ -62,7 +62,7 @@ class CategoryFragment : Fragment() {
private fun categories() { private fun categories() {
val filter = ProductCategoryFilter() val filter = ProductCategoryFilter()
filter.per_page = 50 filter.setPer_page(50)
viewModel.categories(filter).observe(this, android.arch.lifecycle.Observer { response -> viewModel.categories(filter).observe(this, android.arch.lifecycle.Observer { response ->
when (response!!.status()) { when (response!!.status()) {

View File

@ -173,13 +173,13 @@ class CartActivity : WooDroidActivity<CartViewModel>() {
lineItem.productId = cartitem.productId lineItem.productId = cartitem.productId
lineItem.quantity = cartitem.quantity lineItem.quantity = cartitem.quantity
lineitems.add(lineItem); lineitems.add(lineItem)
} }
order.setLineItems(lineitems); order.lineItems = lineitems
order.setBillingAddress(customer.billingAddress) order.billingAddress = customer.billingAddress
order.setShippingAddress(customer.shippingAddress) order.shippingAddress = customer.shippingAddress
order.setCustomer(customer) order.customer = customer
createOrder(order) createOrder(order)
} }

View File

@ -78,7 +78,7 @@ class ShopActivity : BaseActivity() {
val filter = ProductFilter() val filter = ProductFilter()
if (etSearch.text.toString().isNotEmpty()){ if (etSearch.text.toString().isNotEmpty()){
filter.search = etSearch.text.toString() filter.setSearch(etSearch.text.toString())
} }
if (etMinPrice.text.toString().isNotEmpty()){ if (etMinPrice.text.toString().isNotEmpty()){

View File

@ -67,7 +67,7 @@ class RelatedProductsFragment : Fragment() {
rvShop.adapter = adapter rvShop.adapter = adapter
val filter = ProductFilter() val filter = ProductFilter()
filter.include = product.related_ids.toIntArray() filter.setInclude(product.related_ids.toIntArray())
viewModel.products(filter).observe(this, android.arch.lifecycle.Observer { response -> viewModel.products(filter).observe(this, android.arch.lifecycle.Observer { response ->
when (response!!.status()) { when (response!!.status()) {

View File

@ -1,6 +1,8 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules. // Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript { buildscript {
ext.kotlin_version = '1.3.21'
ext.kotlin_version = '1.3.31' ext.kotlin_version = '1.3.31'
ext.kotlin_version = '1.3.31' ext.kotlin_version = '1.3.31'
repositories { repositories {
@ -9,7 +11,7 @@ buildscript {
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:3.4.1' classpath 'com.android.tools.build:gradle:3.5.0-alpha08'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.2.0' classpath 'com.google.gms:google-services:4.2.0'
// NOTE: Do not place your application dependencies here; they belong // NOTE: Do not place your application dependencies here; they belong

1
firebasecart/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/build

34
firebasecart/build.gradle Normal file
View File

@ -0,0 +1,34 @@
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 28
defaultConfig {
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:28.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

21
firebasecart/proguard-rules.pro vendored Normal file
View File

@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile

View File

@ -0,0 +1,24 @@
package me.gilo.woodroid.firebasecart
import android.support.test.InstrumentationRegistry
import android.support.test.runner.AndroidJUnit4
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.Assert.*
/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("me.gilo.woodroid.firebasecart.test", appContext.packageName)
}
}

View File

@ -0,0 +1,2 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="me.gilo.woodroid.firebasecart"/>

View File

@ -0,0 +1,3 @@
<resources>
<string name="app_name">FirebaseCart</string>
</resources>

View File

@ -0,0 +1,17 @@
package me.gilo.woodroid.firebasecart
import org.junit.Test
import org.junit.Assert.*
/**
* Example local unit test, which will execute on the development machine (host).
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
class ExampleUnitTest {
@Test
fun addition_isCorrect() {
assertEquals(4, 2 + 2)
}
}

View File

@ -1 +1 @@
include ':app', ':woodroid' include ':app', ':woodroid', ':firebasecart'

View File

@ -1,39 +0,0 @@
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);
}
}

View File

@ -0,0 +1,36 @@
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)
}
}

View File

@ -1,39 +0,0 @@
package me.gilo.woodroid.callback;
import android.arch.lifecycle.LiveData;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import java.io.IOException;
public class CallBackLiveData<T> extends LiveData<Resource<T>> implements Callback<T> {
public CallBackLiveData() {
setValue(new Resource<>(Status.LOADING));
}
@Override
public void onResponse(Call<T> call, Response<T> response) {
if (response.isSuccessful()){
setValue(new Resource<>(response.body()));
}else{
String error = null;
try {
error = response.errorBody().string();
} catch (IOException e) {
e.printStackTrace();
}
if (error == null){
error = "Something went wrong";
}
setValue(new Resource<>(new NetworkException(error)));
}
}
@Override
public void onFailure(Call<T> call, Throwable t) {
setValue(new Resource<>( new NetworkException(t)));
}
}

View File

@ -0,0 +1,36 @@
package me.gilo.woodroid.callback
import android.arch.lifecycle.LiveData
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response
import java.io.IOException
class CallBackLiveData<T> : LiveData<Resource<T>>(), Callback<T> {
init {
value = Resource(Status.LOADING)
}
override fun onResponse(call: Call<T>, response: Response<T>) {
if (response.isSuccessful) {
setValue(Resource(response.body()!!))
} else {
var error: String? = null
try {
error = response.errorBody()!!.string()
} catch (e: IOException) {
e.printStackTrace()
}
if (error == null) {
error = "Something went wrong"
}
setValue(Resource(NetworkException(error)))
}
}
override fun onFailure(call: Call<T>, t: Throwable) {
value = Resource(NetworkException(t))
}
}

View File

@ -1,20 +0,0 @@
package me.gilo.woodroid.callback;
public class NetworkException extends Exception{
public NetworkException() {
super();
}
public NetworkException(String message) {
super(message);
}
public NetworkException(String message, Throwable cause) {
super(message, cause);
}
public NetworkException(Throwable cause) {
super(cause);
}
}

View File

@ -0,0 +1,12 @@
package me.gilo.woodroid.callback
class NetworkException : Exception {
constructor() : super() {}
constructor(message: String) : super(message) {}
constructor(message: String, cause: Throwable) : super(message, cause) {}
constructor(cause: Throwable) : super(cause) {}
}

View File

@ -1,79 +0,0 @@
package me.gilo.woodroid.callback;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.Log;
import java.util.List;
@SuppressWarnings({"WeakerAccess", "ConstantConditions"})
public final class Resource<T> {
@Nullable
private final T data;
@Nullable
private final Exception error;
Status status = Status.LOADING;
public Resource(@NonNull T data) {
this(data, null);
}
public Resource(@NonNull Status status) {
this(null, null);
this.status = status;
}
public Resource(@NonNull Exception exception) {
this(null, exception);
this.status = Status.ERROR;
}
private Resource(@Nullable T value, @Nullable Exception error) {
this.data = value;
this.error = error;
if (error != null){
status = Status.ERROR;
}else if (data != null){
if (data instanceof List){
if (((List) data).size() == 0){
status = Status.EMPTY;
}else {
status = status.SUCCESS;
}
}else {
status = Status.SUCCESS;
}
}else {
status = Status.LOADING;
}
}
public boolean isSuccessful() {
return data != null && error == null;
}
@NonNull
public T data() {
if (error != null) {
throw new IllegalStateException("error is not null. Call isSuccessful() first.");
}
return data;
}
@NonNull
public Exception error() {
if (data != null) {
throw new IllegalStateException("data is not null. Call isSuccessful() first.");
}
return error;
}
@NonNull
public Status status() {
return status;
}
}

View File

@ -0,0 +1,60 @@
package me.gilo.woodroid.callback
import android.util.Log
class Resource<T> private constructor(private val data: T?, private val error: Exception?) {
internal var status = Status.LOADING
val isSuccessful: Boolean
get() = data != null && error == null
constructor(data: T) : this(data, null) {}
constructor(status: Status) : this(null, null) {
this.status = status
}
constructor(exception: Exception) : this(null, exception) {
this.status = Status.ERROR
}
init {
if (error != null) {
status = Status.ERROR
} else if (data != null) {
if (data is List<*>) {
if ((data as List<*>).size == 0) {
status = Status.EMPTY
} else {
status = Status.SUCCESS
}
} else {
status = Status.SUCCESS
}
} else {
status = Status.LOADING
}
}
fun data(): T? {
if (error != null) {
throw IllegalStateException("error is not null. Call isSuccessful() first.")
}
return data
}
fun error(): Exception? {
if (data != null) {
throw IllegalStateException("data is not null. Call isSuccessful() first.")
}
return error
}
fun status(): Status {
return status
}
}

View File

@ -1,12 +0,0 @@
package me.gilo.woodroid.callback;
public enum Status {
EMPTY,
SUCCESS,
ERROR,
LOADING;
public Status isLoading(){
return LOADING;
}
}

View File

@ -0,0 +1,11 @@
package me.gilo.woodroid.callback
enum class Status {
EMPTY,
SUCCESS,
ERROR,
LOADING;
val isLoading: Status
get() = LOADING
}

View File

@ -1,7 +0,0 @@
package me.gilo.woodroid.callback;
import retrofit2.Call;
public interface WooCall<T> extends Call<T> {
}

View File

@ -0,0 +1,5 @@
package me.gilo.woodroid.callback
import retrofit2.Call
interface WooCall<T> : Call<T>

View File

@ -1,22 +0,0 @@
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";
}
},
}

View File

@ -0,0 +1,19 @@
package me.gilo.woodroid.data
enum class ApiVersion {
API_VERSION1 {
override fun toString(): String {
return "1"
}
},
API_VERSION2 {
override fun toString(): String {
return "2"
}
},
API_VERSION3 {
override fun toString(): String {
return "3"
}
}
}

View File

@ -1,28 +0,0 @@
package me.gilo.woodroid.data;
import org.apache.http.NameValuePair;
import java.util.ArrayList;
public class RestAdapter {
static String oauth_nonce = "";
static String oauth_timestamp = "";
static String oauth_signature_method = "HMAC-SHA1";
static ArrayList<NameValuePair> params;
private String baseUrl;
private String consumerKey;
private String consumerSecret;
public RestAdapter(String baseUrl, String consumerKey, String consumerSecret) {
this.baseUrl = baseUrl;
this.consumerKey = consumerKey;
this.consumerSecret = consumerSecret;
}
}

View File

@ -0,0 +1,18 @@
package me.gilo.woodroid.data
import org.apache.http.NameValuePair
import java.util.ArrayList
class RestAdapter(private val baseUrl: String, private val consumerKey: String, private val consumerSecret: String) {
companion object {
internal var oauth_nonce = ""
internal var oauth_timestamp = ""
internal var oauth_signature_method = "HMAC-SHA1"
internal var params: ArrayList<NameValuePair>? = null
}
}

View File

@ -1,38 +0,0 @@
package me.gilo.woodroid.data.api;
import retrofit2.Call;
import me.gilo.woodroid.models.LineItem;
import me.gilo.woodroid.models.filters.CartFilter;
import retrofit2.http.*;
import java.util.Map;
public interface CartAPI {
@Headers("Content-Type: application/json")
@POST("clear")
Call<String> clear();
@GET("count-items")
Call<Integer> count();
@GET("cart")
Call<Map<String, LineItem>> list();
@Headers("Content-Type: application/json")
@POST("cart/add")
Call<Map<String, LineItem>> addToCart(@Body LineItem body);
@DELETE("cart/cart-item")
Call<String> delete(@Body CartFilter body);
@GET("cart/cart-item")
Call<String> restore(@Body CartFilter body);
@Headers("Content-Type: application/json")
@POST("cart/cart-item")
Call<String> update(@Body CartFilter body);
}

View File

@ -0,0 +1,36 @@
package me.gilo.woodroid.data.api
import retrofit2.Call
import me.gilo.woodroid.models.LineItem
import me.gilo.woodroid.models.filters.CartFilter
import retrofit2.http.*
interface CartAPI {
@Headers("Content-Type: application/json")
@POST("clear")
fun clear(): Call<String>
@GET("count-items")
fun count(): Call<Int>
@GET("cart")
fun list(): Call<Map<String, LineItem>>
@Headers("Content-Type: application/json")
@POST("cart/add")
fun addToCart(@Body body: LineItem): Call<Map<String, LineItem>>
@DELETE("cart/cart-item")
fun delete(@Body body: CartFilter): Call<String>
@GET("cart/cart-item")
fun restore(@Body body: CartFilter): Call<String>
@Headers("Content-Type: application/json")
@POST("cart/cart-item")
fun update(@Body body: CartFilter): Call<String>
}

View File

@ -1,39 +0,0 @@
package me.gilo.woodroid.data.api;
import me.gilo.woodroid.models.Coupon;
import retrofit2.Call;
import retrofit2.http.*;
import java.util.List;
import java.util.Map;
public interface CouponAPI{
@Headers("Content-Type: application/json")
@POST("coupons")
Call<Coupon> create(@Body Coupon body);
@GET("coupons/{id}")
Call<Coupon> view(@Path("id") int id);
@GET("coupons")
Call<List<Coupon>> list();
@GET("coupons")
Call<List<Coupon>> filter(@QueryMap Map<String, String> filter);
@Headers("Content-Type: application/json")
@PUT("coupons/{id}")
Call<Coupon> update(@Path("id") int id, @Body Coupon body);
@DELETE("coupons/{id}")
Call<Coupon> delete(@Path("id") int id);
@DELETE("coupons/{id}")
Call<Coupon> delete(@Path("id") int id, @Query("force") boolean force);
@POST("coupons/batch")
Call<String> batch(@Body Coupon body);
}

View File

@ -0,0 +1,36 @@
package me.gilo.woodroid.data.api
import me.gilo.woodroid.models.Coupon
import retrofit2.Call
import retrofit2.http.*
interface CouponAPI {
@Headers("Content-Type: application/json")
@POST("coupons")
fun create(@Body body: Coupon): Call<Coupon>
@GET("coupons/{id}")
fun view(@Path("id") id: Int): Call<Coupon>
@GET("coupons")
fun list(): Call<List<Coupon>>
@GET("coupons")
fun filter(@QueryMap filter: Map<String, String>): Call<List<Coupon>>
@Headers("Content-Type: application/json")
@PUT("coupons/{id}")
fun update(@Path("id") id: Int, @Body body: Coupon): Call<Coupon>
@DELETE("coupons/{id}")
fun delete(@Path("id") id: Int): Call<Coupon>
@DELETE("coupons/{id}")
fun delete(@Path("id") id: Int, @Query("force") force: Boolean): Call<Coupon>
@POST("coupons/batch")
fun batch(@Body body: Coupon): Call<String>
}

View File

@ -1,43 +0,0 @@
package me.gilo.woodroid.data.api;
import me.gilo.woodroid.models.Customer;
import me.gilo.woodroid.models.Download;
import retrofit2.Call;
import retrofit2.http.*;
import java.util.List;
import java.util.Map;
public interface CustomerAPI {
@Headers("Content-Type: application/json")
@POST("customers")
Call<Customer> create(@Body Customer body);
@GET("customers/{id}")
Call<Customer> view(@Path("id") int id);
@GET("customers")
Call<List<Customer>> list();
@Headers("Content-Type: application/json")
@PUT("customers/{id}")
Call<Customer> update(@Path("id") int id, @Body Customer body);
@DELETE("customers/{id}")
Call<Customer> delete(@Path("id") int id);
@DELETE("customers/{id}")
Call<Customer> delete(@Path("id") int id, @Query("force") boolean force);
@POST("customers/batch")
Call<String> batch(@Body Customer body);
@POST("customers/{id}/downloads")
Call<List<Download>> downloads(@Path("id") int id);
@GET("customers")
Call<List<Customer>> filter(@QueryMap Map<String, String> filter);
}

View File

@ -0,0 +1,40 @@
package me.gilo.woodroid.data.api
import me.gilo.woodroid.models.Customer
import me.gilo.woodroid.models.Download
import retrofit2.Call
import retrofit2.http.*
interface CustomerAPI {
@Headers("Content-Type: application/json")
@POST("customers")
fun create(@Body body: Customer): Call<Customer>
@GET("customers/{id}")
fun view(@Path("id") id: Int): Call<Customer>
@GET("customers")
fun list(): Call<List<Customer>>
@Headers("Content-Type: application/json")
@PUT("customers/{id}")
fun update(@Path("id") id: Int, @Body body: Customer): Call<Customer>
@DELETE("customers/{id}")
fun delete(@Path("id") id: Int): Call<Customer>
@DELETE("customers/{id}")
fun delete(@Path("id") id: Int, @Query("force") force: Boolean): Call<Customer>
@POST("customers/batch")
fun batch(@Body body: Customer): Call<String>
@POST("customers/{id}/downloads")
fun downloads(@Path("id") id: Int): Call<List<Download>>
@GET("customers")
fun filter(@QueryMap filter: Map<String, String>): Call<List<Customer>>
}

View File

@ -1,39 +0,0 @@
package me.gilo.woodroid.data.api;
import me.gilo.woodroid.models.Order;
import retrofit2.Call;
import retrofit2.http.*;
import java.util.List;
import java.util.Map;
public interface OrderAPI {
@Headers("Content-Type: application/json")
@POST("orders")
Call<Order> create(@Body Order body);
@GET("orders/{id}")
Call<Order> view(@Path("id") int id);
@GET("orders")
Call<List<Order>> list();
@Headers("Content-Type: application/json")
@PUT("orders/{id}")
Call<Order> update(@Path("id") int id, @Body Order body);
@DELETE("orders/{id}")
Call<Order> delete(@Path("id") int id);
@DELETE("orders/{id}")
Call<Order> delete(@Path("id") int id, @Query("force") boolean force);
@POST("orders/batch")
Call<String> batch(@Body Order body);
@GET("orders")
Call<List<Order>> filter(@QueryMap Map<String, String> filter);
}

View File

@ -0,0 +1,36 @@
package me.gilo.woodroid.data.api
import me.gilo.woodroid.models.Order
import retrofit2.Call
import retrofit2.http.*
interface OrderAPI {
@Headers("Content-Type: application/json")
@POST("orders")
fun create(@Body body: Order): Call<Order>
@GET("orders/{id}")
fun view(@Path("id") id: Int): Call<Order>
@GET("orders")
fun list(): Call<List<Order>>
@Headers("Content-Type: application/json")
@PUT("orders/{id}")
fun update(@Path("id") id: Int, @Body body: Order): Call<Order>
@DELETE("orders/{id}")
fun delete(@Path("id") id: Int): Call<Order>
@DELETE("orders/{id}")
fun delete(@Path("id") id: Int, @Query("force") force: Boolean): Call<Order>
@POST("orders/batch")
fun batch(@Body body: Order): Call<String>
@GET("orders")
fun filter(@QueryMap filter: Map<String, String>): Call<List<Order>>
}

View File

@ -1,32 +0,0 @@
package me.gilo.woodroid.data.api;
import me.gilo.woodroid.models.OrderNote;
import retrofit2.Call;
import retrofit2.http.*;
import java.util.List;
import java.util.Map;
public interface OrderNoteAPI {
@Headers("Content-Type: application/json")
@POST("orders/{id}/notes")
Call<OrderNote> create(@Path("id") int order_id, @Body OrderNote body);
@GET("orders/{id}/notes/{note_id}")
Call<OrderNote> view(@Path("id") int order_id, @Path("note_id") int note_id);
@GET("orders/{id}/notes")
Call<List<OrderNote>> list(@Path("id") int order_id);
@DELETE("orders/{id}/notes/{note_id}")
Call<OrderNote> delete(@Path("id") int order_id, @Path("note_id") int note_id);
@DELETE("orders/{id}/notes/{note_id}")
Call<OrderNote> delete(@Path("id") int order_id, @Path("note_id") int note_id, @Query("force") boolean force);
@GET("orders/{id}/notes")
Call<List<OrderNote>> filter(@Path("id") int order_id, @QueryMap Map<String, String> filter);
}

View File

@ -0,0 +1,29 @@
package me.gilo.woodroid.data.api
import me.gilo.woodroid.models.OrderNote
import retrofit2.Call
import retrofit2.http.*
interface OrderNoteAPI {
@Headers("Content-Type: application/json")
@POST("orders/{id}/notes")
fun create(@Path("id") order_id: Int, @Body body: OrderNote): Call<OrderNote>
@GET("orders/{id}/notes/{note_id}")
fun view(@Path("id") order_id: Int, @Path("note_id") note_id: Int): Call<OrderNote>
@GET("orders/{id}/notes")
fun list(@Path("id") order_id: Int): Call<List<OrderNote>>
@DELETE("orders/{id}/notes/{note_id}")
fun delete(@Path("id") order_id: Int, @Path("note_id") note_id: Int): Call<OrderNote>
@DELETE("orders/{id}/notes/{note_id}")
fun delete(@Path("id") order_id: Int, @Path("note_id") note_id: Int, @Query("force") force: Boolean): Call<OrderNote>
@GET("orders/{id}/notes")
fun filter(@Path("id") order_id: Int, @QueryMap filter: Map<String, String>): Call<List<OrderNote>>
}

View File

@ -1,23 +0,0 @@
package me.gilo.woodroid.data.api;
import retrofit2.Call;
import me.gilo.woodroid.models.PaymentGateway;
import retrofit2.http.*;
import java.util.List;
public interface PaymentGatewayAPI {
@GET("payment_gateways/{id}")
Call<PaymentGateway> view(@Path("id") int id);
@GET("payment_gateways")
Call<List<PaymentGateway>> list();
@Headers("Content-Type: application/json")
@PUT("payment_gateways")
Call<PaymentGateway> update(@Path("id") String id, @Body PaymentGateway body);
}

View File

@ -0,0 +1,21 @@
package me.gilo.woodroid.data.api
import retrofit2.Call
import me.gilo.woodroid.models.PaymentGateway
import retrofit2.http.*
interface PaymentGatewayAPI {
@GET("payment_gateways/{id}")
fun view(@Path("id") id: Int): Call<PaymentGateway>
@GET("payment_gateways")
fun list(): Call<List<PaymentGateway>>
@Headers("Content-Type: application/json")
@PUT("payment_gateways")
fun update(@Path("id") id: String, @Body body: PaymentGateway): Call<PaymentGateway>
}

View File

@ -1,57 +0,0 @@
package me.gilo.woodroid.data.api;
import me.gilo.woodroid.models.Product;
import retrofit2.Call;
import retrofit2.http.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public interface ProductAPI {
@GET("products")
Call<ArrayList<Product>> getProducts();
@GET("products/{id}")
Call<Product> getProduct(@Path("id") int id);
@GET("products")
Call<ArrayList<Product>> getProducts(@Query("filter[category]") String category);
@GET("products")
Call<ArrayList<Product>> search(@Query("search") String search);
@GET("products")
Call<List<Product>> filter(@QueryMap Map<String, String> filter);
@GET("products/count")
Call<List<Product>> getProductsCount();
@Headers("Content-Type: application/json")
@POST("products")
Call<Product> create(@Body Product body);
@GET("products/{id}")
Call<Product> view(@Path("id") int id);
@GET("products")
Call<List<Product>> list();
@Headers("Content-Type: application/json")
@PUT("products/{id}")
Call<Product> update(@Path("id") int id, @Body Product body);
@DELETE("products/{id}")
Call<Product> delete(@Path("id") int id);
@DELETE("products/{id}")
Call<Product> delete(@Path("id") int id, @Query("force") boolean force);
@POST("products/batch")
Call<String> batch(@Body Product body);
}

View File

@ -0,0 +1,55 @@
package me.gilo.woodroid.data.api
import me.gilo.woodroid.models.Product
import retrofit2.Call
import retrofit2.http.*
import java.util.ArrayList
interface ProductAPI {
@get:GET("products")
val products: Call<ArrayList<Product>>
@get:GET("products/count")
val productsCount: Call<List<Product>>
@GET("products/{id}")
fun getProduct(@Path("id") id: Int): Call<Product>
@GET("products")
fun getProducts(@Query("filter[category]") category: String): Call<ArrayList<Product>>
@GET("products")
fun search(@Query("search") search: String): Call<ArrayList<Product>>
@GET("products")
fun filter(@QueryMap filter: Map<String, String>): Call<List<Product>>
@Headers("Content-Type: application/json")
@POST("products")
fun create(@Body body: Product): Call<Product>
@GET("products/{id}")
fun view(@Path("id") id: Int): Call<Product>
@GET("products")
fun list(): Call<List<Product>>
@Headers("Content-Type: application/json")
@PUT("products/{id}")
fun update(@Path("id") id: Int, @Body body: Product): Call<Product>
@DELETE("products/{id}")
fun delete(@Path("id") id: Int): Call<Product>
@DELETE("products/{id}")
fun delete(@Path("id") id: Int, @Query("force") force: Boolean): Call<Product>
@POST("products/batch")
fun batch(@Body body: Product): Call<String>
}

View File

@ -1,39 +0,0 @@
package me.gilo.woodroid.data.api;
import me.gilo.woodroid.models.Attribute;
import retrofit2.Call;
import retrofit2.http.*;
import java.util.List;
import java.util.Map;
public interface ProductAttributeAPI {
@Headers("Content-Type: application/json")
@POST("products/attributes")
Call<Attribute> create(@Body Attribute body);
@GET("products/attributes/{id}")
Call<Attribute> view(@Path("id") int id);
@GET("products/attributes")
Call<List<Attribute>> list();
@Headers("Content-Type: application/json")
@PUT("products/attributes/{id}")
Call<Attribute> update(@Path("id") int id, @Body Attribute body);
@DELETE("products/attributes/{id}")
Call<Attribute> delete(@Path("id") int id);
@DELETE("products/attributes/{id}")
Call<Attribute> delete(@Path("id") int id, @Query("force") boolean force);
@POST("products/attributes/batch")
Call<String> batch(@Body Attribute body);
@GET("products/attributes")
Call<List<Attribute>> filter(@QueryMap Map<String, String> filter);
}

View File

@ -0,0 +1,36 @@
package me.gilo.woodroid.data.api
import me.gilo.woodroid.models.Attribute
import retrofit2.Call
import retrofit2.http.*
interface ProductAttributeAPI {
@Headers("Content-Type: application/json")
@POST("products/attributes")
fun create(@Body body: Attribute): Call<Attribute>
@GET("products/attributes/{id}")
fun view(@Path("id") id: Int): Call<Attribute>
@GET("products/attributes")
fun list(): Call<List<Attribute>>
@Headers("Content-Type: application/json")
@PUT("products/attributes/{id}")
fun update(@Path("id") id: Int, @Body body: Attribute): Call<Attribute>
@DELETE("products/attributes/{id}")
fun delete(@Path("id") id: Int): Call<Attribute>
@DELETE("products/attributes/{id}")
fun delete(@Path("id") id: Int, @Query("force") force: Boolean): Call<Attribute>
@POST("products/attributes/batch")
fun batch(@Body body: Attribute): Call<String>
@GET("products/attributes")
fun filter(@QueryMap filter: Map<String, String>): Call<List<Attribute>>
}

View File

@ -1,39 +0,0 @@
package me.gilo.woodroid.data.api;
import me.gilo.woodroid.models.AttributeTerm;
import retrofit2.Call;
import retrofit2.http.*;
import java.util.List;
import java.util.Map;
public interface ProductAttributeTermAPI {
@Headers("Content-Type: application/json")
@POST("products/attributes/{id}/terms")
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);
@GET("products/attributes/{id}/terms")
Call<List<AttributeTerm>> list(@Path("id") int attribute_id);
@Headers("Content-Type: application/json")
@PUT("products/attributes/{id}/terms/[term_id]")
Call<AttributeTerm> update(@Path("id") int attribute_id, @Path("term_id") int term_id, @Body AttributeTerm body);
@DELETE("products/attributes/{id}/terms/[term_id]")
Call<AttributeTerm> delete(@Path("id") int attribute_id, @Path("term_id") int term_id);
@DELETE("products/attributes/{id}/terms/[term_id]")
Call<AttributeTerm> delete(@Path("id") int attribute_id, @Path("term_id") int term_id, @Query("force") boolean force);
@POST("products/attributes/batch")
Call<String> batch(@Body AttributeTerm body);
@GET("products/attributes/{id}/terms")
Call<List<AttributeTerm>> filter(@Path("id") int attribute_id, @QueryMap Map<String, String> filter);
}

View File

@ -0,0 +1,36 @@
package me.gilo.woodroid.data.api
import me.gilo.woodroid.models.AttributeTerm
import retrofit2.Call
import retrofit2.http.*
interface ProductAttributeTermAPI {
@Headers("Content-Type: application/json")
@POST("products/attributes/{id}/terms")
fun create(@Path("id") attribute_id: Int, @Body body: AttributeTerm): Call<AttributeTerm>
@GET("products/attributes/{id}/terms/[term_id]")
fun view(@Path("id") attribute_id: Int, @Path("term_id") term_id: Int): Call<AttributeTerm>
@GET("products/attributes/{id}/terms")
fun list(@Path("id") attribute_id: Int): Call<List<AttributeTerm>>
@Headers("Content-Type: application/json")
@PUT("products/attributes/{id}/terms/[term_id]")
fun update(@Path("id") attribute_id: Int, @Path("term_id") term_id: Int, @Body body: AttributeTerm): Call<AttributeTerm>
@DELETE("products/attributes/{id}/terms/[term_id]")
fun delete(@Path("id") attribute_id: Int, @Path("term_id") term_id: Int): Call<AttributeTerm>
@DELETE("products/attributes/{id}/terms/[term_id]")
fun delete(@Path("id") attribute_id: Int, @Path("term_id") term_id: Int, @Query("force") force: Boolean): Call<AttributeTerm>
@POST("products/attributes/batch")
fun batch(@Body body: AttributeTerm): Call<String>
@GET("products/attributes/{id}/terms")
fun filter(@Path("id") attribute_id: Int, @QueryMap filter: Map<String, String>): Call<List<AttributeTerm>>
}

View File

@ -1,39 +0,0 @@
package me.gilo.woodroid.data.api;
import me.gilo.woodroid.models.Category;
import retrofit2.Call;
import retrofit2.http.*;
import java.util.List;
import java.util.Map;
public interface ProductCategoryAPI {
@Headers("Content-Type: application/json")
@POST("products/categories")
Call<Category> create(@Body Category body);
@GET("products/categories/{id}")
Call<Category> view(@Path("id") int id);
@GET("products/categories")
Call<List<Category>> list();
@Headers("Content-Type: application/json")
@PUT("products/categories/{id}")
Call<Category> update(@Path("id") int id, @Body Category body);
@DELETE("products/categories/{id}")
Call<Category> delete(@Path("id") int id);
@DELETE("products/categories/{id}")
Call<Category> delete(@Path("id") int id, @Query("force") boolean force);
@POST("products/categories/batch")
Call<String> batch(@Body Category body);
@GET("products/categories")
Call<List<Category>> filter(@QueryMap Map<String, String> filter);
}

View File

@ -0,0 +1,36 @@
package me.gilo.woodroid.data.api
import me.gilo.woodroid.models.Category
import retrofit2.Call
import retrofit2.http.*
interface ProductCategoryAPI {
@Headers("Content-Type: application/json")
@POST("products/categories")
fun create(@Body body: Category): Call<Category>
@GET("products/categories/{id}")
fun view(@Path("id") id: Int): Call<Category>
@GET("products/categories")
fun list(): Call<List<Category>>
@Headers("Content-Type: application/json")
@PUT("products/categories/{id}")
fun update(@Path("id") id: Int, @Body body: Category): Call<Category>
@DELETE("products/categories/{id}")
fun delete(@Path("id") id: Int): Call<Category>
@DELETE("products/categories/{id}")
fun delete(@Path("id") id: Int, @Query("force") force: Boolean): Call<Category>
@POST("products/categories/batch")
fun batch(@Body body: Category): Call<String>
@GET("products/categories")
fun filter(@QueryMap filter: Map<String, String>): Call<List<Category>>
}

View File

@ -1,39 +0,0 @@
package me.gilo.woodroid.data.api;
import me.gilo.woodroid.models.ProductReview;
import retrofit2.Call;
import retrofit2.http.*;
import java.util.List;
import java.util.Map;
public interface ProductReviewAPI {
@Headers("Content-Type: application/json")
@POST("products/reviews")
Call<ProductReview> create(@Body ProductReview body);
@GET("products/reviews/{id}")
Call<ProductReview> view(@Path("id") int id);
@GET("products/reviews")
Call<List<ProductReview>> list();
@Headers("Content-Type: application/json")
@PUT("products/reviews/{id}")
Call<ProductReview> update(@Path("id") int id, @Body ProductReview body);
@DELETE("products/reviews/{id}")
Call<ProductReview> delete(@Path("id") int id);
@DELETE("products/reviews/{id}")
Call<ProductReview> delete(@Path("id") int id, @Query("force") boolean force);
@POST("products/reviews/batch")
Call<String> batch(@Body ProductReview body);
@GET("products/reviews")
Call<List<ProductReview>> filter(@QueryMap Map<String, String> filter);
}

View File

@ -0,0 +1,36 @@
package me.gilo.woodroid.data.api
import me.gilo.woodroid.models.ProductReview
import retrofit2.Call
import retrofit2.http.*
interface ProductReviewAPI {
@Headers("Content-Type: application/json")
@POST("products/reviews")
fun create(@Body body: ProductReview): Call<ProductReview>
@GET("products/reviews/{id}")
fun view(@Path("id") id: Int): Call<ProductReview>
@GET("products/reviews")
fun list(): Call<List<ProductReview>>
@Headers("Content-Type: application/json")
@PUT("products/reviews/{id}")
fun update(@Path("id") id: Int, @Body body: ProductReview): Call<ProductReview>
@DELETE("products/reviews/{id}")
fun delete(@Path("id") id: Int): Call<ProductReview>
@DELETE("products/reviews/{id}")
fun delete(@Path("id") id: Int, @Query("force") force: Boolean): Call<ProductReview>
@POST("products/reviews/batch")
fun batch(@Body body: ProductReview): Call<String>
@GET("products/reviews")
fun filter(@QueryMap filter: Map<String, String>): Call<List<ProductReview>>
}

View File

@ -1,39 +0,0 @@
package me.gilo.woodroid.data.api;
import me.gilo.woodroid.models.Tag;
import retrofit2.Call;
import retrofit2.http.*;
import java.util.List;
import java.util.Map;
public interface ProductTagAPI {
@Headers("Content-Type: application/json")
@POST("products/tags")
Call<Tag> create(@Body Tag body);
@GET("products/tags/{id}")
Call<Tag> view(@Path("id") int id);
@GET("products/tags")
Call<List<Tag>> list();
@Headers("Content-Type: application/json")
@PUT("products/tags/{id}")
Call<Tag> update(@Path("id") int id, @Body Tag body);
@DELETE("products/tags/{id}")
Call<Tag> delete(@Path("id") int id);
@DELETE("products/tags/{id}")
Call<Tag> delete(@Path("id") int id, @Query("force") boolean force);
@POST("products/tags/batch")
Call<String> batch(@Body Tag body);
@GET("products/tags")
Call<List<Tag>> filter(@QueryMap Map<String, String> filter);
}

View File

@ -0,0 +1,36 @@
package me.gilo.woodroid.data.api
import me.gilo.woodroid.models.Tag
import retrofit2.Call
import retrofit2.http.*
interface ProductTagAPI {
@Headers("Content-Type: application/json")
@POST("products/tags")
fun create(@Body body: Tag): Call<Tag>
@GET("products/tags/{id}")
fun view(@Path("id") id: Int): Call<Tag>
@GET("products/tags")
fun list(): Call<List<Tag>>
@Headers("Content-Type: application/json")
@PUT("products/tags/{id}")
fun update(@Path("id") id: Int, @Body body: Tag): Call<Tag>
@DELETE("products/tags/{id}")
fun delete(@Path("id") id: Int): Call<Tag>
@DELETE("products/tags/{id}")
fun delete(@Path("id") id: Int, @Query("force") force: Boolean): Call<Tag>
@POST("products/tags/batch")
fun batch(@Body body: Tag): Call<String>
@GET("products/tags")
fun filter(@QueryMap filter: Map<String, String>): Call<List<Tag>>
}

View File

@ -1,41 +0,0 @@
package me.gilo.woodroid.data.api;
import me.gilo.woodroid.models.Product;
import me.gilo.woodroid.models.Variation;
import retrofit2.Call;
import retrofit2.http.*;
import java.util.List;
import java.util.Map;
public interface ProductVariationAPI {
@Headers("Content-Type: application/json")
@POST("products/{id}/variations")
Call<Variation> create(@Path("id") int product_id, @Body Variation body);
@GET("products/{id}/variations/{variation_id}")
Call<Variation> view(@Path("id") int product_id, @Path("variation_id") int variation_id);
@GET("products/{id}/variations")
Call<List<Variation>> list(@Path("id") int product_id);
@Headers("Content-Type: application/json")
@PUT("products/{id}/variations/{variation_id}")
Call<Variation> update(@Path("id") int product_id, @Path("variation_id") int variation_id, @Body Variation body);
@DELETE("products/{id}/variations/{variation_id}")
Call<Variation> delete(@Path("id") int product_id, @Path("variation_id") int variation_id);
@DELETE("products/{id}/variations/{variation_id}")
Call<Variation> delete(@Path("id") int product_id, @Path("variation_id") int variation_id, @Query("force") boolean force);
@Headers("Content-Type: application/json")
@PUT("products/{id}/variations/{variation_id}")
Call<Variation> batch(@Path("id") int product_id, @Path("variation_id") int variation_id, @Body Product body);
@GET("products/{id}/variations")
Call<List<Variation>> filter(@Path("id") int product_id, @QueryMap Map<String, String> filter);
}

View File

@ -0,0 +1,38 @@
package me.gilo.woodroid.data.api
import me.gilo.woodroid.models.Product
import me.gilo.woodroid.models.Variation
import retrofit2.Call
import retrofit2.http.*
interface ProductVariationAPI {
@Headers("Content-Type: application/json")
@POST("products/{id}/variations")
fun create(@Path("id") product_id: Int, @Body body: Variation): Call<Variation>
@GET("products/{id}/variations/{variation_id}")
fun view(@Path("id") product_id: Int, @Path("variation_id") variation_id: Int): Call<Variation>
@GET("products/{id}/variations")
fun list(@Path("id") product_id: Int): Call<List<Variation>>
@Headers("Content-Type: application/json")
@PUT("products/{id}/variations/{variation_id}")
fun update(@Path("id") product_id: Int, @Path("variation_id") variation_id: Int, @Body body: Variation): Call<Variation>
@DELETE("products/{id}/variations/{variation_id}")
fun delete(@Path("id") product_id: Int, @Path("variation_id") variation_id: Int): Call<Variation>
@DELETE("products/{id}/variations/{variation_id}")
fun delete(@Path("id") product_id: Int, @Path("variation_id") variation_id: Int, @Query("force") force: Boolean): Call<Variation>
@Headers("Content-Type: application/json")
@PUT("products/{id}/variations/{variation_id}")
fun batch(@Path("id") product_id: Int, @Path("variation_id") variation_id: Int, @Body body: Product): Call<Variation>
@GET("products/{id}/variations")
fun filter(@Path("id") product_id: Int, @QueryMap filter: Map<String, String>): Call<List<Variation>>
}

View File

@ -1,32 +0,0 @@
package me.gilo.woodroid.data.api;
import me.gilo.woodroid.models.Refund;
import retrofit2.Call;
import retrofit2.http.*;
import java.util.List;
import java.util.Map;
public interface RefundAPI {
@Headers("Content-Type: application/json")
@POST("orders/{id}/refunds")
Call<Refund> create(@Path("id") int order_id, @Body Refund body);
@GET("orders/{id}/refunds/{refund_id}")
Call<Refund> view(@Path("id") int order_id, @Path("refund_id") int refund_id);
@GET("orders/{id}/refunds")
Call<List<Refund>> list(@Path("id") int order_id);
@DELETE("orders/{id}/refunds/{refund_id}")
Call<Refund> delete(@Path("id") int order_id, @Path("refund_id") int refund_id);
@DELETE("orders/{id}/refunds/{refund_id}")
Call<Refund> delete(@Path("id") int order_id, @Path("refund_id") int refund_id, @Query("force") boolean force);
@GET("orders/{id}/refunds")
Call<List<Refund>> filter(@Path("id") int order_id, @QueryMap Map<String, String> filter);
}

View File

@ -0,0 +1,29 @@
package me.gilo.woodroid.data.api
import me.gilo.woodroid.models.Refund
import retrofit2.Call
import retrofit2.http.*
interface RefundAPI {
@Headers("Content-Type: application/json")
@POST("orders/{id}/refunds")
fun create(@Path("id") order_id: Int, @Body body: Refund): Call<Refund>
@GET("orders/{id}/refunds/{refund_id}")
fun view(@Path("id") order_id: Int, @Path("refund_id") refund_id: Int): Call<Refund>
@GET("orders/{id}/refunds")
fun list(@Path("id") order_id: Int): Call<List<Refund>>
@DELETE("orders/{id}/refunds/{refund_id}")
fun delete(@Path("id") order_id: Int, @Path("refund_id") refund_id: Int): Call<Refund>
@DELETE("orders/{id}/refunds/{refund_id}")
fun delete(@Path("id") order_id: Int, @Path("refund_id") refund_id: Int, @Query("force") force: Boolean): Call<Refund>
@GET("orders/{id}/refunds")
fun filter(@Path("id") order_id: Int, @QueryMap filter: Map<String, String>): Call<List<Refund>>
}

View File

@ -1,45 +0,0 @@
package me.gilo.woodroid.data.api;
import me.gilo.woodroid.models.report.*;
import retrofit2.Call;
import retrofit2.http.GET;
import retrofit2.http.QueryMap;
import java.util.List;
import java.util.Map;
public interface ReportAPI {
@GET("reports/sales")
Call<List<SalesTotal>> sales();
@GET("reports/sales")
Call<List<SalesTotal>> sales(@QueryMap Map<String, String> filter);
@GET("reports/top_sellers")
Call<List<TopSellerProducts>> top_sellers();
@GET(" /wp-json/wc/v3/reports/top_sellers")
Call<List<TopSellerProducts>> top_sellers(@QueryMap Map<String, String> filter);
@GET("reports/coupons/totals")
Call<List<CouponsTotal>> coupons_totals();
@GET("reports/customers/totals")
Call<List<CustomersTotal>> customers_totals();
@GET("reports/orders/totals")
Call<List<OrdersTotal>> orders_totals();
@GET("reports/products/totals")
Call<List<ProductsTotal>> products_totals();
@GET("reports/reviews/totals")
Call<List<ReviewsTotal>> reviews_totals();
}

View File

@ -0,0 +1,42 @@
package me.gilo.woodroid.data.api
import me.gilo.woodroid.models.report.*
import retrofit2.Call
import retrofit2.http.GET
import retrofit2.http.QueryMap
interface ReportAPI {
@GET("reports/sales")
fun sales(): Call<List<SalesTotal>>
@GET("reports/sales")
fun sales(@QueryMap filter: Map<String, String>): Call<List<SalesTotal>>
@GET("reports/top_sellers")
fun top_sellers(): Call<List<TopSellerProducts>>
@GET(" /wp-json/wc/v3/reports/top_sellers")
fun top_sellers(@QueryMap filter: Map<String, String>): Call<List<TopSellerProducts>>
@GET("reports/coupons/totals")
fun coupons_totals(): Call<List<CouponsTotal>>
@GET("reports/customers/totals")
fun customers_totals(): Call<List<CustomersTotal>>
@GET("reports/orders/totals")
fun orders_totals(): Call<List<OrdersTotal>>
@GET("reports/products/totals")
fun products_totals(): Call<List<ProductsTotal>>
@GET("reports/reviews/totals")
fun reviews_totals(): Call<List<ReviewsTotal>>
}

View File

@ -1,32 +0,0 @@
package me.gilo.woodroid.data.api;
import retrofit2.Call;
import me.gilo.woodroid.models.SettingGroup;
import me.gilo.woodroid.models.SettingOption;
import retrofit2.http.*;
import java.util.List;
public interface SettingsAPI {
@GET("settings")
Call<List<SettingGroup>> settings();
@GET("settings/{group_id}/{id}")
Call<SettingOption> option(@Path("group_id") String group_id, @Path("id") String option_id);
@GET("settings/{id}")
Call<List<SettingOption>> options(@Path("id") String group_id);
@Headers("Content-Type: application/json")
@PUT("settings/{group_id}/{id}")
Call<SettingOption> update(
@Path("group_id") String group_id,
@Path("id") String option_id,
@Body SettingOption body
);
}

View File

@ -0,0 +1,29 @@
package me.gilo.woodroid.data.api
import retrofit2.Call
import me.gilo.woodroid.models.SettingGroup
import me.gilo.woodroid.models.SettingOption
import retrofit2.http.*
interface SettingsAPI {
@GET("settings")
fun settings(): Call<List<SettingGroup>>
@GET("settings/{group_id}/{id}")
fun option(@Path("group_id") group_id: String, @Path("id") option_id: String): Call<SettingOption>
@GET("settings/{id}")
fun options(@Path("id") group_id: String): Call<List<SettingOption>>
@Headers("Content-Type: application/json")
@PUT("settings/{group_id}/{id}")
fun update(
@Path("group_id") group_id: String,
@Path("id") option_id: String,
@Body body: SettingOption
): Call<SettingOption>
}

View File

@ -1,39 +0,0 @@
package me.gilo.woodroid.data.api;
import me.gilo.woodroid.models.ShippingClass;
import retrofit2.Call;
import retrofit2.http.*;
import java.util.List;
import java.util.Map;
public interface ShippingClassAPI {
@Headers("Content-Type: application/json")
@POST("products/shipping_classes")
Call<ShippingClass> create(@Body ShippingClass body);
@GET("products/shipping_classes/{id}")
Call<ShippingClass> view(@Path("id") int id);
@GET("products/shipping_classes")
Call<List<ShippingClass>> list();
@Headers("Content-Type: application/json")
@PUT("products/shipping_classes/{id}")
Call<ShippingClass> update(@Path("id") int id, @Body ShippingClass body);
@DELETE("products/shipping_classes/{id}")
Call<ShippingClass> delete(@Path("id") int id);
@DELETE("products/shipping_classes/{id}")
Call<ShippingClass> delete(@Path("id") int id, @Query("force") boolean force);
@POST("products/shipping_classes/batch")
Call<String> batch(@Body ShippingClass body);
@GET("products/shipping_classes")
Call<List<ShippingClass>> filter(@QueryMap Map<String, String> filter);
}

View File

@ -0,0 +1,36 @@
package me.gilo.woodroid.data.api
import me.gilo.woodroid.models.ShippingClass
import retrofit2.Call
import retrofit2.http.*
interface ShippingClassAPI {
@Headers("Content-Type: application/json")
@POST("products/shipping_classes")
fun create(@Body body: ShippingClass): Call<ShippingClass>
@GET("products/shipping_classes/{id}")
fun view(@Path("id") id: Int): Call<ShippingClass>
@GET("products/shipping_classes")
fun list(): Call<List<ShippingClass>>
@Headers("Content-Type: application/json")
@PUT("products/shipping_classes/{id}")
fun update(@Path("id") id: Int, @Body body: ShippingClass): Call<ShippingClass>
@DELETE("products/shipping_classes/{id}")
fun delete(@Path("id") id: Int): Call<ShippingClass>
@DELETE("products/shipping_classes/{id}")
fun delete(@Path("id") id: Int, @Query("force") force: Boolean): Call<ShippingClass>
@POST("products/shipping_classes/batch")
fun batch(@Body body: ShippingClass): Call<String>
@GET("products/shipping_classes")
fun filter(@QueryMap filter: Map<String, String>): Call<List<ShippingClass>>
}

View File

@ -1,19 +0,0 @@
package me.gilo.woodroid.data.api;
import retrofit2.Call;
import me.gilo.woodroid.models.ShippingMethod;
import retrofit2.http.GET;
import retrofit2.http.Path;
import java.util.List;
public interface ShippingMethodAPI {
@GET("shipping_methods/{id}")
Call<ShippingMethod> view(@Path("id") String id);
@GET("shipping_methods")
Call<List<ShippingMethod>> list();
}

View File

@ -0,0 +1,17 @@
package me.gilo.woodroid.data.api
import retrofit2.Call
import me.gilo.woodroid.models.ShippingMethod
import retrofit2.http.GET
import retrofit2.http.Path
interface ShippingMethodAPI {
@GET("shipping_methods/{id}")
fun view(@Path("id") id: String): Call<ShippingMethod>
@GET("shipping_methods")
fun list(): Call<List<ShippingMethod>>
}

View File

@ -1,40 +0,0 @@
package me.gilo.woodroid.data.api;
import me.gilo.woodroid.models.ShippingZone;
import retrofit2.Call;
import retrofit2.http.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public interface ShippingZoneAPI {
@Headers("Content-Type: application/json")
@POST("shipping/zones")
Call<ShippingZone> create(@Body ShippingZone body);
@GET("shipping/zones/{id}")
Call<ShippingZone> view(@Path("id") int id);
@GET("shipping/zones")
Call<List<ShippingZone>> list();
@Headers("Content-Type: application/json")
@PUT("shipping/zones/{id}")
Call<ShippingZone> update(@Path("id") int id, @Body ShippingZone body);
@DELETE("shipping/zones/{id}")
Call<ShippingZone> delete(@Path("id") int id);
@DELETE("shipping/zones/{id}")
Call<ShippingZone> delete(@Path("id") int id, @Query("force") boolean force);
@POST("shipping/zones/batch")
Call<String> batch(@Body ShippingZone body);
@GET("coupons")
Call<ArrayList<ShippingZone>> filter(@QueryMap Map<String, String> filter);
}

View File

@ -0,0 +1,38 @@
package me.gilo.woodroid.data.api
import me.gilo.woodroid.models.ShippingZone
import retrofit2.Call
import retrofit2.http.*
import java.util.ArrayList
interface ShippingZoneAPI {
@Headers("Content-Type: application/json")
@POST("shipping/zones")
fun create(@Body body: ShippingZone): Call<ShippingZone>
@GET("shipping/zones/{id}")
fun view(@Path("id") id: Int): Call<ShippingZone>
@GET("shipping/zones")
fun list(): Call<List<ShippingZone>>
@Headers("Content-Type: application/json")
@PUT("shipping/zones/{id}")
fun update(@Path("id") id: Int, @Body body: ShippingZone): Call<ShippingZone>
@DELETE("shipping/zones/{id}")
fun delete(@Path("id") id: Int): Call<ShippingZone>
@DELETE("shipping/zones/{id}")
fun delete(@Path("id") id: Int, @Query("force") force: Boolean): Call<ShippingZone>
@POST("shipping/zones/batch")
fun batch(@Body body: ShippingZone): Call<String>
@GET("coupons")
fun filter(@QueryMap filter: Map<String, String>): Call<ArrayList<ShippingZone>>
}

View File

@ -1,40 +0,0 @@
package me.gilo.woodroid.data.api;
import me.gilo.woodroid.models.Coupon;
import retrofit2.Call;
import retrofit2.http.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public interface ShippingZoneLocationAPI {
@Headers("Content-Type: application/json")
@POST("coupons")
Call<Coupon> create(@Body Coupon body);
@GET("coupons/{id}")
Call<Coupon> view(@Path("id") int id);
@GET("coupons")
Call<List<Coupon>> list();
@Headers("Content-Type: application/json")
@PUT("coupons/{id}")
Call<Coupon> update(@Path("id") int id, @Body Coupon body);
@DELETE("coupons/{id}")
Call<Coupon> delete(@Path("id") int id);
@DELETE("coupons/{id}")
Call<Coupon> delete(@Path("id") int id, @Query("force") boolean force);
@POST("coupons/batch")
Call<String> batch(@Body Coupon body);
@GET("coupons")
Call<ArrayList<ShippingZoneLocationAPI>> filter(@QueryMap Map<String, String> filter);
}

View File

@ -0,0 +1,38 @@
package me.gilo.woodroid.data.api
import me.gilo.woodroid.models.Coupon
import retrofit2.Call
import retrofit2.http.*
import java.util.ArrayList
interface ShippingZoneLocationAPI {
@Headers("Content-Type: application/json")
@POST("coupons")
fun create(@Body body: Coupon): Call<Coupon>
@GET("coupons/{id}")
fun view(@Path("id") id: Int): Call<Coupon>
@GET("coupons")
fun list(): Call<List<Coupon>>
@Headers("Content-Type: application/json")
@PUT("coupons/{id}")
fun update(@Path("id") id: Int, @Body body: Coupon): Call<Coupon>
@DELETE("coupons/{id}")
fun delete(@Path("id") id: Int): Call<Coupon>
@DELETE("coupons/{id}")
fun delete(@Path("id") id: Int, @Query("force") force: Boolean): Call<Coupon>
@POST("coupons/batch")
fun batch(@Body body: Coupon): Call<String>
@GET("coupons")
fun filter(@QueryMap filter: Map<String, String>): Call<ArrayList<ShippingZoneLocationAPI>>
}

View File

@ -1,30 +0,0 @@
package me.gilo.woodroid.data.api;
import me.gilo.woodroid.models.TaxClass;
import retrofit2.Call;
import retrofit2.http.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public interface TaxClassAPI {
@Headers("Content-Type: application/json")
@POST("taxes/classes")
Call<TaxClass> create(@Body TaxClass body);
@GET("taxes/classes")
Call<List<TaxClass>> list();
@DELETE("taxes/classes/{id}")
Call<TaxClass> delete(@Path("id") int id);
@DELETE("taxes/classes/{id}")
Call<TaxClass> delete(@Path("id") int id, @Query("force") boolean force);
@GET("coupons")
Call<ArrayList<TaxClass>> filter(@QueryMap Map<String, String> filter);
}

View File

@ -0,0 +1,28 @@
package me.gilo.woodroid.data.api
import me.gilo.woodroid.models.TaxClass
import retrofit2.Call
import retrofit2.http.*
import java.util.ArrayList
interface TaxClassAPI {
@Headers("Content-Type: application/json")
@POST("taxes/classes")
fun create(@Body body: TaxClass): Call<TaxClass>
@GET("taxes/classes")
fun list(): Call<List<TaxClass>>
@DELETE("taxes/classes/{id}")
fun delete(@Path("id") id: Int): Call<TaxClass>
@DELETE("taxes/classes/{id}")
fun delete(@Path("id") id: Int, @Query("force") force: Boolean): Call<TaxClass>
@GET("coupons")
fun filter(@QueryMap filter: Map<String, String>): Call<ArrayList<TaxClass>>
}

View File

@ -1,40 +0,0 @@
package me.gilo.woodroid.data.api;
import me.gilo.woodroid.models.TaxRate;
import retrofit2.Call;
import retrofit2.http.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public interface TaxRateAPI {
@Headers("Content-Type: application/json")
@POST("taxes")
Call<TaxRate> create(@Body TaxRate body);
@GET("taxes/{id}")
Call<TaxRate> view(@Path("id") int id);
@GET("taxes")
Call<List<TaxRate>> list();
@Headers("Content-Type: application/json")
@PUT("taxes/{id}")
Call<TaxRate> update(@Path("id") int id, @Body TaxRate body);
@DELETE("taxes/{id}")
Call<TaxRate> delete(@Path("id") int id);
@DELETE("taxes/{id}")
Call<TaxRate> delete(@Path("id") int id, @Query("force") boolean force);
@POST("taxes/batch")
Call<String> batch(@Body TaxRate body);
@GET("coupons")
Call<ArrayList<TaxRate>> filter(@QueryMap Map<String, String> filter);
}

View File

@ -0,0 +1,38 @@
package me.gilo.woodroid.data.api
import me.gilo.woodroid.models.TaxRate
import retrofit2.Call
import retrofit2.http.*
import java.util.ArrayList
interface TaxRateAPI {
@Headers("Content-Type: application/json")
@POST("taxes")
fun create(@Body body: TaxRate): Call<TaxRate>
@GET("taxes/{id}")
fun view(@Path("id") id: Int): Call<TaxRate>
@GET("taxes")
fun list(): Call<List<TaxRate>>
@Headers("Content-Type: application/json")
@PUT("taxes/{id}")
fun update(@Path("id") id: Int, @Body body: TaxRate): Call<TaxRate>
@DELETE("taxes/{id}")
fun delete(@Path("id") id: Int): Call<TaxRate>
@DELETE("taxes/{id}")
fun delete(@Path("id") id: Int, @Query("force") force: Boolean): Call<TaxRate>
@POST("taxes/batch")
fun batch(@Body body: TaxRate): Call<String>
@GET("coupons")
fun filter(@QueryMap filter: Map<String, String>): Call<ArrayList<TaxRate>>
}

View File

@ -1,44 +0,0 @@
package me.gilo.woodroid.data.api;
import me.gilo.woodroid.models.Webhook;
import me.gilo.woodroid.models.WebhookDelivery;
import retrofit2.Call;
import retrofit2.http.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public interface WebhookAPI {
@Headers("Content-Type: application/json")
@POST("webhooks")
Call<Webhook> create(@Body Webhook body);
@GET("webhooks")
Call<List<Webhook>> list();
@GET("webhooks/{id}")
Call<Webhook> view(@Path("id") int id);
@GET("webhooks/{id}/deliveries/{delivery_id}")
Call<WebhookDelivery> delivery(@Path("id") int webhook_id, @Path("delivery_id") int delivery_id);
@GET("webhooks/{id}/deliveries")
Call<List<WebhookDelivery>> deliveries(@Path("id") int webhook_id);
@Headers("Content-Type: application/json")
@PUT("webhooks/{id}")
Call<Webhook> update(@Path("id") int id, @Body Webhook body);
@DELETE("webhooks/{id}")
Call<Webhook> delete(@Path("id") int id);
@DELETE("webhooks/{id}")
Call<Webhook> delete(@Path("id") int id, @Query("force") boolean force);
@GET("webhooks")
Call<ArrayList<Webhook>> filter(@QueryMap Map<String, String> filter);
}

View File

@ -0,0 +1,42 @@
package me.gilo.woodroid.data.api
import me.gilo.woodroid.models.Webhook
import me.gilo.woodroid.models.WebhookDelivery
import retrofit2.Call
import retrofit2.http.*
import java.util.ArrayList
interface WebhookAPI {
@Headers("Content-Type: application/json")
@POST("webhooks")
fun create(@Body body: Webhook): Call<Webhook>
@GET("webhooks")
fun list(): Call<List<Webhook>>
@GET("webhooks/{id}")
fun view(@Path("id") id: Int): Call<Webhook>
@GET("webhooks/{id}/deliveries/{delivery_id}")
fun delivery(@Path("id") webhook_id: Int, @Path("delivery_id") delivery_id: Int): Call<WebhookDelivery>
@GET("webhooks/{id}/deliveries")
fun deliveries(@Path("id") webhook_id: Int): Call<List<WebhookDelivery>>
@Headers("Content-Type: application/json")
@PUT("webhooks/{id}")
fun update(@Path("id") id: Int, @Body body: Webhook): Call<Webhook>
@DELETE("webhooks/{id}")
fun delete(@Path("id") id: Int): Call<Webhook>
@DELETE("webhooks/{id}")
fun delete(@Path("id") id: Int, @Query("force") force: Boolean): Call<Webhook>
@GET("webhooks")
fun filter(@QueryMap filter: Map<String, String>): Call<ArrayList<Webhook>>
}

View File

@ -1,13 +0,0 @@
package me.gilo.woodroid.data.auth;
import org.apache.http.NameValuePair;
import java.util.Comparator;
public class AlphabeticSorter implements Comparator<NameValuePair> {
@Override
public int compare(NameValuePair nameValuePair1, NameValuePair nameValuePair2) {
return nameValuePair1.getName().compareTo(nameValuePair2.getName());
}
}

View File

@ -0,0 +1,12 @@
package me.gilo.woodroid.data.auth
import org.apache.http.NameValuePair
import java.util.Comparator
class AlphabeticSorter : Comparator<NameValuePair> {
override fun compare(nameValuePair1: NameValuePair, nameValuePair2: NameValuePair): Int {
return nameValuePair1.name.compareTo(nameValuePair2.name)
}
}

View File

@ -1,173 +0,0 @@
package me.gilo.woodroid.data.auth;
import android.util.Base64;
import android.util.Log;
import okhttp3.HttpUrl;
import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;
import org.apache.http.NameValuePair;
import org.apache.http.client.utils.URLEncodedUtils;
import org.apache.http.message.BasicNameValuePair;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.*;
public class AuthIntercepter implements Interceptor {
static String oauth_nonce = "";
static String oauth_timestamp = "";
static String oauth_signature_method = "HMAC-SHA1";
private String oauth_signature = "";
private String consumerKey;
private String consumerSecret;
public AuthIntercepter(String consumerKey, String consumerSecret) {
this.consumerKey = consumerKey;
this.consumerSecret = consumerSecret;
}
@Override
public Response intercept(Chain chain) throws IOException {
ArrayList<NameValuePair> params = getOauthParams(chain);
HttpUrl.Builder builder = chain.request().url().newBuilder();
for (NameValuePair entry : params) {
builder.addQueryParameter(entry.getName(), entry.getValue());
}
Request newRequest = chain.request()
.newBuilder()
.url(builder.build())
.header("Accept", "application/json")
.build();
return chain.proceed(newRequest);
}
public ArrayList<NameValuePair> getOauthParams(Chain chain) {
ArrayList<NameValuePair> params = new ArrayList<>();
String request_url = chain.request().url().toString();
Iterator iterator = getQueryParams(request_url).entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry pair = (Map.Entry)iterator.next();
String key = (String) pair.getKey();
List<String> values = (List<String>) pair.getValue();
String value = "";
//why there would be multiple values for single key is not so clear to me, will keep this here though
if (values.size() == 1){
value = values.get(0);
}
params.add(new BasicNameValuePair(key, value));
iterator.remove();
}
if (request_url.contains("?")){
int request_url_end = request_url.indexOf("?");
request_url = request_url.substring(0, request_url_end);
}
oauth_nonce = getOauth_nonce();
oauth_timestamp = getOauth_timestamp();
params.add(new BasicNameValuePair("oauth_consumer_key", consumerKey));
params.add(new BasicNameValuePair("oauth_nonce", oauth_nonce));
params.add(new BasicNameValuePair("oauth_timestamp", oauth_timestamp));
params.add(new BasicNameValuePair("oauth_signature_method", oauth_signature_method));
Collections.sort(params, new AlphabeticSorter());
String encodedParams = URLEncodedUtils.format(params, "utf-8");
oauth_signature = getOauth_signature(chain.request().method(), request_url, consumerSecret, encodedParams );
params.add(new BasicNameValuePair("oauth_signature", oauth_signature));
return params;
}
public String getOauth_nonce() {
return (new StringBuilder(String.valueOf(Math.random() * 100000000D))).toString();
}
public String getStringToSign(String method, String url, String parameters) {
String string_to_sign = "";
try {
string_to_sign = (new StringBuilder(method + "&"))
.append(URLEncoder.encode(url, "utf-8")).append("&")
.append(URLEncoder.encode(parameters, "utf-8"))
.toString();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return string_to_sign;
}
public String getOauth_signature(String method, String url, String consumerSecret, String parameters) {
String signature = "";
String string_to_sign = getStringToSign(method, url, parameters);
try {
Mac mac = Mac.getInstance(oauth_signature_method);
String secret = consumerSecret + "&";
mac.init(new SecretKeySpec(secret.getBytes("utf-8"), oauth_signature_method));
signature = Base64.encodeToString(mac.doFinal(string_to_sign.getBytes("utf-8")), 0).trim();
} catch (NoSuchAlgorithmException | InvalidKeyException | UnsupportedEncodingException e) {
e.printStackTrace();
}
return signature;
}
public String getOauth_timestamp() {
long stamp = (long) (System.currentTimeMillis() / 1000D);
return (new StringBuilder(String.valueOf(stamp))).toString();
}
public static Map<String, List<String>> getQueryParams(String url) {
try {
Map<String, List<String>> params = new HashMap<String, List<String>>();
String[] urlParts = url.split("\\?");
if (urlParts.length > 1) {
String query = urlParts[1];
for (String param : query.split("&")) {
String[] pair = param.split("=");
String key = URLDecoder.decode(pair[0], "UTF-8");
String value = "";
if (pair.length > 1) {
value = URLDecoder.decode(pair[1], "UTF-8");
}
List<String> values = params.get(key);
if (values == null) {
values = new ArrayList<String>();
params.put(key, values);
}
values.add(value);
}
}
return params;
} catch (UnsupportedEncodingException ex) {
throw new AssertionError(ex);
}
}
}

View File

@ -0,0 +1,174 @@
package me.gilo.woodroid.data.auth
import android.util.Base64
import android.util.Log
import okhttp3.HttpUrl
import okhttp3.Interceptor
import okhttp3.Request
import okhttp3.Response
import org.apache.http.NameValuePair
import org.apache.http.client.utils.URLEncodedUtils
import org.apache.http.message.BasicNameValuePair
import javax.crypto.Mac
import javax.crypto.spec.SecretKeySpec
import java.io.IOException
import java.io.UnsupportedEncodingException
import java.net.URLDecoder
import java.net.URLEncoder
import java.security.InvalidKeyException
import java.security.NoSuchAlgorithmException
import java.util.*
import java.util.Map
class AuthIntercepter(private val consumerKey: String, private val consumerSecret: String) : Interceptor {
private var oauth_signature = ""
@Throws(IOException::class)
override fun intercept(chain: Interceptor.Chain): Response {
val params = getOauthParams(chain)
val builder = chain.request().url().newBuilder()
for (entry in params) {
builder.addQueryParameter(entry.name, entry.value)
}
val newRequest = chain.request()
.newBuilder()
.url(builder.build())
.header("Accept", "application/json")
.build()
return chain.proceed(newRequest)
}
fun getOauthParams(chain: Interceptor.Chain): ArrayList<NameValuePair> {
val params = ArrayList<NameValuePair>()
var request_url = chain.request().url().toString()
val iterator = getQueryParams(request_url).entries.iterator()
while (iterator.hasNext()) {
val pair = iterator.next() as Map.Entry<*, *>
val key = pair.key as String
val values = pair.value as List<String>
var value = ""
//why there would be multiple values for single key is not so clear to me, will keep this here though
if (values.size == 1) {
value = values[0]
}
params.add(BasicNameValuePair(key, value))
iterator.remove()
}
if (request_url.contains("?")) {
val request_url_end = request_url.indexOf("?")
request_url = request_url.substring(0, request_url_end)
}
oauth_nonce = getOauth_nonce()
oauth_timestamp = getOauth_timestamp()
params.add(BasicNameValuePair("oauth_consumer_key", consumerKey))
params.add(BasicNameValuePair("oauth_nonce", oauth_nonce))
params.add(BasicNameValuePair("oauth_timestamp", oauth_timestamp))
params.add(BasicNameValuePair("oauth_signature_method", oauth_signature_method))
Collections.sort(params, AlphabeticSorter())
val encodedParams = URLEncodedUtils.format(params, "utf-8")
oauth_signature = getOauth_signature(chain.request().method(), request_url, consumerSecret, encodedParams)
params.add(BasicNameValuePair("oauth_signature", oauth_signature))
return params
}
fun getOauth_nonce(): String {
return StringBuilder((Math.random() * 100000000.0).toString()).toString()
}
fun getStringToSign(method: String, url: String, parameters: String): String {
var string_to_sign = ""
try {
string_to_sign = StringBuilder("$method&")
.append(URLEncoder.encode(url, "utf-8")).append("&")
.append(URLEncoder.encode(parameters, "utf-8"))
.toString()
} catch (e: UnsupportedEncodingException) {
e.printStackTrace()
}
return string_to_sign
}
fun getOauth_signature(method: String, url: String, consumerSecret: String, parameters: String): String {
var signature = ""
val string_to_sign = getStringToSign(method, url, parameters)
try {
val mac = Mac.getInstance(oauth_signature_method)
val secret = "$consumerSecret&"
mac.init(SecretKeySpec(secret.toByteArray(charset("utf-8")), oauth_signature_method))
signature =
Base64.encodeToString(mac.doFinal(string_to_sign.toByteArray(charset("utf-8"))), 0).trim { it <= ' ' }
} catch (e: NoSuchAlgorithmException) {
e.printStackTrace()
} catch (e: InvalidKeyException) {
e.printStackTrace()
} catch (e: UnsupportedEncodingException) {
e.printStackTrace()
}
return signature
}
fun getOauth_timestamp(): String {
val stamp = (System.currentTimeMillis() / 1000.0).toLong()
return StringBuilder(stamp.toString()).toString()
}
companion object {
internal var oauth_nonce = ""
internal var oauth_timestamp = ""
internal var oauth_signature_method = "HMAC-SHA1"
fun getQueryParams(url: String): MutableMap<String, List<String>> {
try {
val params = HashMap<String, List<String>>()
val urlParts = url.split("\\?".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
if (urlParts.size > 1) {
val query = urlParts[1]
for (param in query.split("&".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()) {
val pair = param.split("=".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
val key = URLDecoder.decode(pair[0], "UTF-8")
var value = ""
if (pair.size > 1) {
value = URLDecoder.decode(pair[1], "UTF-8")
}
var values: MutableList<String>? = params[key]?.toMutableList()
if (values == null) {
values = ArrayList()
params[key] = values
}
values.add(value)
}
}
return params
} catch (ex: UnsupportedEncodingException) {
throw AssertionError(ex)
}
}
}
}

View File

@ -1,22 +0,0 @@
package me.gilo.woodroid.data.callbacks;
import com.google.gson.annotations.SerializedName;
import me.gilo.woodroid.models.Category;
import java.util.ArrayList;
public class CategoriesCallback {
@SerializedName("product_categories")
ArrayList<Category> categories;
public ArrayList<Category> getCategories() {
return categories;
}
public void setCategories(ArrayList<Category> categories) {
this.categories = categories;
}
}

View File

@ -0,0 +1,14 @@
package me.gilo.woodroid.data.callbacks
import com.google.gson.annotations.SerializedName
import me.gilo.woodroid.models.Category
import java.util.ArrayList
class CategoriesCallback {
@SerializedName("product_categories")
lateinit var categories: ArrayList<Category>
}

View File

@ -1,16 +0,0 @@
package me.gilo.woodroid.data.callbacks;
import me.gilo.woodroid.models.Customer;
public class CustomerData {
Customer customer;
public Customer getCustomer() {
return customer;
}
public void setCustomer(Customer customer) {
this.customer = customer;
}
}

View File

@ -0,0 +1,8 @@
package me.gilo.woodroid.data.callbacks
import me.gilo.woodroid.models.Customer
class CustomerData {
lateinit var customer: Customer
}

View File

@ -1,14 +0,0 @@
package me.gilo.woodroid.data.callbacks;
import me.gilo.woodroid.models.Order;
public class Data {
Order order;
public Order getOrder() {
return order;
}
public void setOrder(Order order) {
this.order = order;
}
}

View File

@ -0,0 +1,7 @@
package me.gilo.woodroid.data.callbacks
import me.gilo.woodroid.models.Order
class Data {
lateinit var order: Order
}

View File

@ -1,19 +0,0 @@
package me.gilo.woodroid.data.callbacks;
import me.gilo.woodroid.models.Order;
import java.util.ArrayList;
public class OrderCallback {
ArrayList<Order> orders = new ArrayList<>();
public ArrayList<Order> getOrders() {
return orders;
}
public void setOrders(ArrayList<Order> orders) {
this.orders = orders;
}
}

View File

@ -0,0 +1,11 @@
package me.gilo.woodroid.data.callbacks
import me.gilo.woodroid.models.Order
import java.util.ArrayList
class OrderCallback {
var orders = ArrayList<Order>()
}

View File

@ -1,28 +0,0 @@
package me.gilo.woodroid.data.callbacks;
import me.gilo.woodroid.models.Product;
import java.util.ArrayList;
public class ProductCallback {
ArrayList<Product> products = new ArrayList<>();
Product product;
public ArrayList<Product> getProducts() {
return products;
}
public void setProducts(ArrayList<Product> products) {
this.products = products;
}
public Product getProduct() {
return product;
}
public void setProduct(Product product) {
this.product = product;
}
}

View File

@ -0,0 +1,12 @@
package me.gilo.woodroid.data.callbacks
import me.gilo.woodroid.models.Product
import java.util.ArrayList
class ProductCallback {
var products = ArrayList<Product>()
lateinit var product: Product
}

View File

@ -1,16 +0,0 @@
package me.gilo.woodroid.data.callbacks;
import me.gilo.woodroid.models.Product;
public class ProductData {
private Product product;
public Product getProduct() {
return product;
}
public void setProduct(Product product) {
this.product = product;
}
}

View File

@ -0,0 +1,8 @@
package me.gilo.woodroid.data.callbacks
import me.gilo.woodroid.models.Product
class ProductData {
var product: Product? = null
}

Some files were not shown because too many files have changed in this diff Show More