Updated readme

This commit is contained in:
Gilbert Kimutai 2019-02-21 18:32:14 +03:00
parent 0f244cbb15
commit db41825cc3
3 changed files with 144 additions and 44 deletions

182
README.md
View File

@ -2,8 +2,6 @@
This is an android sdk for woocommerce This is an android sdk for woocommerce
# Under construction, is not ready for use yet. :(
![alt text](https://github.com/gilokimu/woocommerce-android-sdk/raw/master/screens/screenshot-1549248597583.jpg "Woocommerce Android app") ![alt text](https://github.com/gilokimu/woocommerce-android-sdk/raw/master/screens/screenshot-1549248597583.jpg "Woocommerce Android app")
Built-based on the documentation: http://woocommerce.github.io/woocommerce-rest-api-docs/#introduction Built-based on the documentation: http://woocommerce.github.io/woocommerce-rest-api-docs/#introduction
@ -76,55 +74,153 @@ Getting products example
```kotlin ```kotlin
woocommerce.ProductRepository().products().enqueue(object : Callback<List<Product>> { woocommerce.ProductRepository().products().enqueue(object : Callback<List<Product>> {
override fun onResponse(call: Call<List<Product>>, response: Response<List<Product>>) { override fun onResponse(call: Call<List<Product>>, response: Response<List<Product>>) {
val productsResponse = response.body() val productsResponse = response.body()
for (product in productsResponse!!) { for (product in productsResponse!!) {
products.add(product) products.add(product)
}
adapter.notifyDataSetChanged()
} }
override fun onFailure(call: Call<List<Product>>, t: Throwable) { adapter.notifyDataSetChanged()
}
} override fun onFailure(call: Call<List<Product>>, t: Throwable) {
})
}
})
``` ```
## API Support Checklist ## Supported resources
The sdk currently supports :
1. Order Notes
2. Refunds
3. Attributes
4. Attribute Terms
5. Product Category
6. Shipping Class
7. Product Tags
8. Variations
9. Coupons
10. Customers
11. Orders
12. Products
13. Reports
Method | Create | Delete | Retrieve | Update | Batch ### Coming soon
--------------------- | ------------- | ------------- | ------------- | ------------- | ------------- 14. Settings
Coupons | N | N | N | N | N 15. Payment gateway
Customers | N | N | N | N | N
Orders | N | N | N | N | N ## API Methods
Order notes | N | N | N | N | N The general resource method calls are
Refunds | N | N | N | N | N 1. Create - Pass the object to create
Products | N | N | N | N | N 2. List - a list of all items
Product variations | N | N | N | N | N 3. View single method - retries a single item
Product attributes | N | N | N | N | N 4. Delete - deletes the resource
Product attribute terms | N | N | N | N | N 5. Filter - provides a list that meets a criteria
Product categories | N | N | N | N | N
Product shipping classes | N | N | N | N | N ### Create Method
Product tags | N | N | N | N | N Create an instance of the resource then pass onto a .create() function on the resource repository
Product reviews | N | N | N | N | N
Reports | N | N | N | N | N ```kotlin
Tax rates | N | N | N | N | N val coupon = Coupon()
Tax classes | N | N | N | N | N coupon.code = code
Webhooks | N | N | N | N | N coupon.description = description
Settings | N | N | N | N | N
Setting options | N | N | N | N | N woocommerce.CouponRepository().create(coupon).enqueue(object : Callback<Coupon> {
Payment gateways | N | N | N | N | N override fun onResponse(call: Call<Coupon>, response: Response<Coupon>) {
Shipping zones | N | N | N | N | N val couponResponse = response.body()
Shipping zone locations | N | N | N | N | N finish()
Shipping zone methods | N | N | N | N | N }
Shipping methods | N | N | N | N | N
override fun onFailure(call: Call<Coupon>, t: Throwable) {
}
})
```
### List Method
```kotlin
woocommerce.CouponRepository().coupons().enqueue(object : Callback<List<Coupon>> {
override fun onResponse(call: Call<List<Coupon>>, response: Response<List<Coupon>>) {
val couponResponse = response.body()
for (coupon in couponResponse!!) {
coupons.add(coupon)
}
adapter.notifyDataSetChanged()
}
override fun onFailure(call: Call<List<Coupon>>, t: Throwable) {
}
})
```
### View single item
```kotlin
val couponId = intent.getIntExtra("couponId", 0)
woocommerce.CouponRepository().coupon(couponId).enqueue(object : Callback<Coupon> {
override fun onResponse(call: Call<Coupon>, response: Response<Coupon>) {
val coupon = response.body()!!
etCode.setText(coupon.code.toUpperCase())
etDescription.setText(coupon.description)
}
override fun onFailure(call: Call<Coupon>, t: Throwable) {
}
})
```
### Delete item
```kotlin
woocommerce.CouponRepository().delete(couponId).enqueue(object : Callback<Coupon> {
override fun onResponse(call: Call<Coupon>, response: Response<Coupon>) {
if (response.isSuccessful) {
val coupon = response.body()!!
finish()
}else{
Toast.makeText(this@CouponActivity, "" + response.code() + " : " + response.message(), Toast.LENGTH_SHORT).show()
}
}
override fun onFailure(call: Call<Coupon>, t: Throwable) {
stopShowingLoading()
}
})
```
### Filter item
```kotlin
val filter = CouponFilter()
filter.search = "FEB"
woocommerce.CouponRepository().coupons(filter).enqueue(object : Callback<List<Coupon>> {
override fun onResponse(call: Call<List<Coupon>>, response: Response<List<Coupon>>) {
val couponResponse = response.body()
for (coupon in couponResponse!!) {
coupons.add(coupon)
}
adapter.notifyDataSetChanged()
}
override fun onFailure(call: Call<List<Coupon>>, t: Throwable) {
}
})
```
### Sample app
The sample app implements an MVVM approach which would look slightly different from the above. The methods are the same though
## TODO ## Contribution
See the trello board for items and progress https://trello.com/b/Muw8vcBb/woocommerce-android-sdk
##Contribution
Contributions are highly welcomed, just create a PR Contributions are highly welcomed, just create a PR

View File

@ -9,6 +9,7 @@ import me.gilo.wc.R
import me.gilo.wc.adapter.CouponAdapter import me.gilo.wc.adapter.CouponAdapter
import me.gilo.wc.ui.BaseActivity import me.gilo.wc.ui.BaseActivity
import me.gilo.woodroid.models.Coupon import me.gilo.woodroid.models.Coupon
import me.gilo.woodroid.models.filters.CouponFilter
import retrofit2.Call import retrofit2.Call
import retrofit2.Callback import retrofit2.Callback
import retrofit2.Response import retrofit2.Response
@ -46,7 +47,10 @@ 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() {
woocommerce.CouponRepository().coupons().enqueue(object : Callback<List<Coupon>> { val filter = CouponFilter()
filter.search = "FEB"
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>>) {
val couponResponse = response.body() val couponResponse = response.body()
for (coupon in couponResponse!!) { for (coupon in couponResponse!!) {

0
docs/introduction.md Normal file
View File