From cf671d332e545b6c2d750366d709c45b29667452 Mon Sep 17 00:00:00 2001 From: Gilbert Kimutai Date: Sun, 7 Apr 2019 09:15:04 +0300 Subject: [PATCH] Added settings and webhooks api --- .../java/me/gilo/wc/adapter/ListAdapter.java | 34 ++++ app/src/main/res/layout/content_cart.xml | 2 +- build.gradle | 2 +- .../java/me/gilo/woodroid/data/api/API.java | 176 ------------------ .../gilo/woodroid/data/api/SettingsAPI.java | 11 ++ .../me/gilo/woodroid/data/api/WebhookAPI.java | 43 +++++ .../gilo/woodroid/models/SettingOption.java | 84 ++++++++- .../java/me/gilo/woodroid/models/Webhook.java | 123 ++++++++++++ .../gilo/woodroid/models/WebhookDelivery.java | 116 ++++++++++++ .../models/filters/WebhookFilter.java | 15 ++ 10 files changed, 426 insertions(+), 180 deletions(-) create mode 100644 app/src/main/java/me/gilo/wc/adapter/ListAdapter.java delete mode 100644 woodroid/src/main/java/me/gilo/woodroid/data/api/API.java create mode 100644 woodroid/src/main/java/me/gilo/woodroid/data/api/WebhookAPI.java create mode 100644 woodroid/src/main/java/me/gilo/woodroid/models/Webhook.java create mode 100644 woodroid/src/main/java/me/gilo/woodroid/models/WebhookDelivery.java create mode 100644 woodroid/src/main/java/me/gilo/woodroid/models/filters/WebhookFilter.java diff --git a/app/src/main/java/me/gilo/wc/adapter/ListAdapter.java b/app/src/main/java/me/gilo/wc/adapter/ListAdapter.java new file mode 100644 index 0000000..d2c72de --- /dev/null +++ b/app/src/main/java/me/gilo/wc/adapter/ListAdapter.java @@ -0,0 +1,34 @@ +package me.gilo.wc.adapter; + +import android.support.v7.widget.RecyclerView; +import android.view.LayoutInflater; +import android.view.ViewGroup; +import me.gilo.wc.R; +import me.gilo.wc.adapter.viewholder.ProductViewHolder; +import me.gilo.woodroid.models.Product; + +import java.util.List; + +public class ListAdapter extends RecyclerView.Adapter { + private List products; + + public ListAdapter(List products) { + this.products = products; + } + + @Override + public ProductViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { + return new ProductViewHolder(parent.getContext(), LayoutInflater.from(parent.getContext()).inflate(R.layout.single_product_item, parent, false)); + } + + @Override + public void onBindViewHolder(ProductViewHolder holder, int position) { + holder.renderView(products.get(position)); + } + + + @Override + public int getItemCount() { + return products.size() == 0 ? 0 : products.size(); + } +} diff --git a/app/src/main/res/layout/content_cart.xml b/app/src/main/res/layout/content_cart.xml index fc9957e..fb3d7da 100644 --- a/app/src/main/res/layout/content_cart.xml +++ b/app/src/main/res/layout/content_cart.xml @@ -244,6 +244,6 @@ - + \ No newline at end of file diff --git a/build.gradle b/build.gradle index f12ac1f..b2a4bfb 100644 --- a/build.gradle +++ b/build.gradle @@ -8,7 +8,7 @@ buildscript { } dependencies { - classpath 'com.android.tools.build:gradle:3.5.0-alpha08' + classpath 'com.android.tools.build:gradle:3.5.0-alpha10' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath 'com.google.gms:google-services:4.0.1' // NOTE: Do not place your application dependencies here; they belong diff --git a/woodroid/src/main/java/me/gilo/woodroid/data/api/API.java b/woodroid/src/main/java/me/gilo/woodroid/data/api/API.java deleted file mode 100644 index a74ed5a..0000000 --- a/woodroid/src/main/java/me/gilo/woodroid/data/api/API.java +++ /dev/null @@ -1,176 +0,0 @@ -package me.gilo.woodroid.data.api; - - -import me.gilo.woodroid.data.callbacks.*; -import me.gilo.woodroid.data.callbacks.Data; -import me.gilo.woodroid.models.*; -import retrofit2.Call; -import retrofit2.http.*; -import rx.Observable; - -import java.util.ArrayList; -import java.util.Map; - -public interface API { - - @GET - Observable store(@Url String url); - - //////////////////////////////////////////////////////////////////////// - //products - //////////////////////////////////////////////////////////////////////// - @GET("products/categories") - Call> getCategories(); - - @GET - Call getCategories2(@Url String url); - - @GET("products") - Call> getProducts(); - - @GET("products") - Call> getProducts(@Query("filter[category]") String category); - - @GET("products") - Call> search(@Query("search") String search); - - @GET - Call getProductReviews(@Url String url); - - @GET("products") - Call> filter(@QueryMap Map filter); - - @GET("products/{id}") - Call getRelatedProducts(@Path("id") int id); - - @GET("products/{id}") - Call getProduct(@Path("id") int id); - - //////////////////////////////////////////////////////////////////////// - //orders - //////////////////////////////////////////////////////////////////////// - @GET("orders") - Observable getOrders(); - - @Headers("Content-Type: application/json") - @POST("orders") - Call createOrder(@Body OrderData order); - - //////////////////////////////////////////////////////////////////////// - //customer - //////////////////////////////////////////////////////////////////////// - @GET - Observable viewMyOrders(@Url String url); - - @Headers("Content-Type: application/json") - @POST("customers") - Call registerUser(@Body CustomerData body); - - @Headers("Content-Type: application/json") - @POST("customers") - Call registerUser2(@Body Data body); - - @GET - Call loginUser(@Url String url); - - @GET("customers/email/{email}") - Call loginUser2(@Path("email") String email); - - //////////////////////////////////////////////////////////////////////// - /** Coupons - The coupons API allows you to - 1. create, - 2. view, - 3. update - 4. delete - individual, or a batch, of coupon codes. - - **/ - //////////////////////////////////////////////////////////////////////// - - @Headers("Content-Type: application/json") - @POST("coupons") - Call createCoupon(@Body Coupon body); - - @GET("coupons/{id}") - Call viewCoupon(@Path("id") int id); - - @GET("coupons/count") - Call viewCouponCount(); - - @GET("coupons") - Observable viewCouponList(@Path("id") int id); - - @PUT("coupons/{id}") - Call updateCoupon(@Path("id") int id); - - @DELETE("coupons/{id}") - Call deleteCoupon(@Path("id") int id); - - /////////////////////////////////////////////////////////////////////// - //Cart - //////////////////////////////////////////////////////////////////////// - - - - - - /* - - - /coupons - /coupons/count - /coupons/ - /coupons/code/ - /coupons/bulk - /customers - /customers/count - /customers/ - /customers/email/ - /customers//orders - /customers//downloads - /customers/bulk - /orders - /orders/count - /orders/statuses - /orders/ - /orders//notes - /orders//notes/ - /orders//refunds - /orders//refunds/ - /orders/bulk - /products - /products/count - /products/ - /products//reviews - /products//orders - /products/categories - /products/categories/ - /products/tags - /products/tags/ - /products/shipping_classes - /products/shipping_classes/ - /products/attributes - /products/attributes/ - /products/attributes//terms - /products/attributes//terms/ - /products/bulk - /reports - /reports/sales - /reports/sales/top_sellers - /taxes - /taxes/count - /taxes/ - /taxes/classes - /taxes/classes/count - /taxes/classes/ - /taxes/bulk - /webhooks - /webhooks/count - /webhooks/ - /webhooks//deliveries - /webhooks//deliveries/ - - */ - -} \ No newline at end of file diff --git a/woodroid/src/main/java/me/gilo/woodroid/data/api/SettingsAPI.java b/woodroid/src/main/java/me/gilo/woodroid/data/api/SettingsAPI.java index db225f2..f83f69b 100644 --- a/woodroid/src/main/java/me/gilo/woodroid/data/api/SettingsAPI.java +++ b/woodroid/src/main/java/me/gilo/woodroid/data/api/SettingsAPI.java @@ -2,7 +2,9 @@ package me.gilo.woodroid.data.api; import me.gilo.woodroid.models.SettingGroup; +import me.gilo.woodroid.models.SettingOption; import me.gilo.woodroid.models.TaxRate; +import me.gilo.woodroid.models.WebhookDelivery; import retrofit2.Call; import retrofit2.http.*; @@ -15,6 +17,15 @@ public interface SettingsAPI { @GET("settings") Call> settings(); + @GET("settings/{group_id}/{id}") + Call option(@Path("group_id") int group_id, @Path("id") int option_id); + + @GET("settings/{id}") + Call> options(@Path("id") int group_id); + + @Headers("Content-Type: application/json") + @GET("settings/{group_id}/{id}") + Call update(@Path("group_id") int group_id, @Path("id") int option_id); diff --git a/woodroid/src/main/java/me/gilo/woodroid/data/api/WebhookAPI.java b/woodroid/src/main/java/me/gilo/woodroid/data/api/WebhookAPI.java new file mode 100644 index 0000000..19530f5 --- /dev/null +++ b/woodroid/src/main/java/me/gilo/woodroid/data/api/WebhookAPI.java @@ -0,0 +1,43 @@ +package me.gilo.woodroid.data.api; + + +import me.gilo.woodroid.models.*; +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 create(@Body Webhook body); + + @GET("webhooks") + Call> list(); + + @GET("webhooks/{id}") + Call view(@Path("id") int id); + + @GET("webhooks/{id}/deliveries/{delivery_id}") + Call delivery(@Path("id") int webhook_id, @Path("delivery_id") int delivery_id); + + @GET("webhooks/{id}/deliveries") + Call> deliveries(@Path("id") int webhook_id); + + @Headers("Content-Type: application/json") + @PUT("webhooks/{id}") + Call update(@Path("id") int id, @Body Webhook body); + + @DELETE("webhooks/{id}") + Call delete(@Path("id") int id); + + @DELETE("webhooks/{id}") + Call delete(@Path("id") int id, @Query("force") boolean force); + + @GET("webhooks") + Call> filter(@QueryMap Map filter); + +} \ No newline at end of file diff --git a/woodroid/src/main/java/me/gilo/woodroid/models/SettingOption.java b/woodroid/src/main/java/me/gilo/woodroid/models/SettingOption.java index de4eb38..ea89ce4 100644 --- a/woodroid/src/main/java/me/gilo/woodroid/models/SettingOption.java +++ b/woodroid/src/main/java/me/gilo/woodroid/models/SettingOption.java @@ -2,10 +2,12 @@ package me.gilo.woodroid.models; import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.Map; + public class SettingOption { String id; - String option; + String label; String description; String value; @@ -14,8 +16,86 @@ public class SettingOption { String tip; String placeholder; String type; - String options; + Map options; String group_id; + public String getId() { + return id; + } + public void setId(String id) { + this.id = id; + } + + public String getLabel() { + return label; + } + + public void setLabel(String label) { + this.label = label; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + public String getDefault_value() { + return default_value; + } + + public void setDefault_value(String default_value) { + this.default_value = default_value; + } + + public String getTip() { + return tip; + } + + public void setTip(String tip) { + this.tip = tip; + } + + public String getPlaceholder() { + return placeholder; + } + + public void setPlaceholder(String placeholder) { + this.placeholder = placeholder; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public Map getOptions() { + return options; + } + + public void setOptions(Map options) { + this.options = options; + } + + public String getGroup_id() { + return group_id; + } + + public void setGroup_id(String group_id) { + this.group_id = group_id; + } } diff --git a/woodroid/src/main/java/me/gilo/woodroid/models/Webhook.java b/woodroid/src/main/java/me/gilo/woodroid/models/Webhook.java new file mode 100644 index 0000000..657e190 --- /dev/null +++ b/woodroid/src/main/java/me/gilo/woodroid/models/Webhook.java @@ -0,0 +1,123 @@ +package me.gilo.woodroid.models; + +import java.util.Date; + +public class Webhook { + int id; + String name; + String status; + String topic; + String resource; + String event; + String[] hooks; + String delivery_url; + String secret; + Date date_created; + Date date_created_gmt; + Date date_modified; + Date date_modified_gmt; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + + public String getTopic() { + return topic; + } + + public void setTopic(String topic) { + this.topic = topic; + } + + public String getResource() { + return resource; + } + + public void setResource(String resource) { + this.resource = resource; + } + + public String getEvent() { + return event; + } + + public void setEvent(String event) { + this.event = event; + } + + public String[] getHooks() { + return hooks; + } + + public void setHooks(String[] hooks) { + this.hooks = hooks; + } + + public String getDelivery_url() { + return delivery_url; + } + + public void setDelivery_url(String delivery_url) { + this.delivery_url = delivery_url; + } + + public String getSecret() { + return secret; + } + + public void setSecret(String secret) { + this.secret = secret; + } + + public Date getDate_created() { + return date_created; + } + + public void setDate_created(Date date_created) { + this.date_created = date_created; + } + + public Date getDate_created_gmt() { + return date_created_gmt; + } + + public void setDate_created_gmt(Date date_created_gmt) { + this.date_created_gmt = date_created_gmt; + } + + public Date getDate_modified() { + return date_modified; + } + + public void setDate_modified(Date date_modified) { + this.date_modified = date_modified; + } + + public Date getDate_modified_gmt() { + return date_modified_gmt; + } + + public void setDate_modified_gmt(Date date_modified_gmt) { + this.date_modified_gmt = date_modified_gmt; + } +} diff --git a/woodroid/src/main/java/me/gilo/woodroid/models/WebhookDelivery.java b/woodroid/src/main/java/me/gilo/woodroid/models/WebhookDelivery.java new file mode 100644 index 0000000..6d3cfbf --- /dev/null +++ b/woodroid/src/main/java/me/gilo/woodroid/models/WebhookDelivery.java @@ -0,0 +1,116 @@ +package me.gilo.woodroid.models; + +import java.util.Date; +import java.util.Map; + +public class WebhookDelivery { + + int id; + String duration; + String summary; + String request_url; + Map request_headers; + String request_body; + String response_code; + String response_message; + Map response_headers; + String response_body; + Date date_created; + Date date_created_gmt; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getDuration() { + return duration; + } + + public void setDuration(String duration) { + this.duration = duration; + } + + public String getSummary() { + return summary; + } + + public void setSummary(String summary) { + this.summary = summary; + } + + public String getRequest_url() { + return request_url; + } + + public void setRequest_url(String request_url) { + this.request_url = request_url; + } + + public Map getRequest_headers() { + return request_headers; + } + + public void setRequest_headers(Map request_headers) { + this.request_headers = request_headers; + } + + public String getRequest_body() { + return request_body; + } + + public void setRequest_body(String request_body) { + this.request_body = request_body; + } + + public String getResponse_code() { + return response_code; + } + + public void setResponse_code(String response_code) { + this.response_code = response_code; + } + + public String getResponse_message() { + return response_message; + } + + public void setResponse_message(String response_message) { + this.response_message = response_message; + } + + public Map getResponse_headers() { + return response_headers; + } + + public void setResponse_headers(Map response_headers) { + this.response_headers = response_headers; + } + + public String getResponse_body() { + return response_body; + } + + public void setResponse_body(String response_body) { + this.response_body = response_body; + } + + public Date getDate_created() { + return date_created; + } + + public void setDate_created(Date date_created) { + this.date_created = date_created; + } + + public Date getDate_created_gmt() { + return date_created_gmt; + } + + public void setDate_created_gmt(Date date_created_gmt) { + this.date_created_gmt = date_created_gmt; + } +} diff --git a/woodroid/src/main/java/me/gilo/woodroid/models/filters/WebhookFilter.java b/woodroid/src/main/java/me/gilo/woodroid/models/filters/WebhookFilter.java new file mode 100644 index 0000000..be1fba0 --- /dev/null +++ b/woodroid/src/main/java/me/gilo/woodroid/models/filters/WebhookFilter.java @@ -0,0 +1,15 @@ +package me.gilo.woodroid.models.filters; + +public class WebhookFilter extends ListFilter{ + + String status; + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + addFilter("status", status); + } +}