Skip to content

Commit 6bf3303

Browse files
committed
Merged main into feature/WOOS-2-add-products-api-into-shopify-sdk
2 parents 5b30e31 + d9b5ae5 commit 6bf3303

File tree

2 files changed

+16
-66
lines changed

2 files changed

+16
-66
lines changed

lib/networking/api_provider.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class ApiProvider {
7777

7878
/// Init Dio class
7979
_initDio() {
80-
BaseOptions options = BaseOptions(baseUrl: "https://api.woosignal.com/v3");
80+
BaseOptions options = BaseOptions(baseUrl: "https://api.woosignal.com/shopify/v1/");
8181
_dio = Dio(options);
8282
}
8383

lib/woosignal_shopify.dart

Lines changed: 15 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -73,20 +73,21 @@ class WooSignal {
7373
}
7474
}
7575

76-
Map<String, dynamic> _standardPayload(String type, json, String path) =>
77-
{"type": type, "payload": json, "path": path};
78-
7976
/// WooSignal Request
8077
Future<T?> _wooSignalRequest<T>(
8178
{dynamic payload = const {},
8279
required String method,
8380
required String path,
84-
required T Function(dynamic json) jsonResponse,
85-
String postUrl = "/request"}) async {
81+
required T Function(dynamic json) jsonResponse}) async {
8682
_printLog("Parameters: $payload");
87-
payload = _standardPayload(method, payload, path);
8883

89-
dynamic json = await _apiProvider.post(postUrl, payload);
84+
dynamic json;
85+
if (method == 'get') {
86+
json = await _apiProvider.get(path, data: payload);
87+
}
88+
if (method == 'post') {
89+
json = await _apiProvider.post(path, {"data": payload});
90+
}
9091
if (json is Map<String, dynamic> && json.containsKey('error')) {
9192
_printLog(json['error']);
9293
return null;
@@ -199,7 +200,6 @@ class WooSignal {
199200
method: "get",
200201
path: "ws/cart_check",
201202
payload: cartLines,
202-
postUrl: "/ws/cart_check",
203203
jsonResponse: (json) => json,
204204
);
205205
}
@@ -209,7 +209,6 @@ class WooSignal {
209209
return await _wooSignalRequest<bool>(
210210
method: "get",
211211
path: "ws/app-status",
212-
postUrl: "/ws/app-status",
213212
jsonResponse: (json) =>
214213
(json['status'] == "200" && json['result']['value'] == 1)
215214
? true
@@ -220,66 +219,17 @@ class WooSignal {
220219

221220
/// https://woosignal.com/docs/api/1.0/products
222221
Future<List<Product>> getProducts(
223-
{int? page,
224-
int? perPage,
225-
String? search,
226-
String? after,
227-
String? before,
228-
String? order,
229-
String? orderBy,
230-
String? slug,
231-
String? status,
232-
String? type,
233-
String? sku,
234-
String? category,
235-
String? tag,
236-
String? shippingClass,
237-
String? attribute,
238-
String? attributeTerm,
239-
String? taxClass,
240-
String? minPrice,
241-
String? maxPrice,
242-
String? stockStatus,
243-
List<int>? exclude,
244-
List<int>? parentExclude,
245-
List<int>? include,
246-
List<int>? parent,
247-
int? offset,
248-
bool? featured,
249-
bool? onSale}) async {
222+
{int? limit,
223+
String? productType
224+
}) async {
250225
Map<String, dynamic> payload = {};
251-
if (page != null) payload["page"] = page;
252-
if (perPage != null) payload["per_page"] = perPage;
253-
if (search != null) payload["search"] = search;
254-
if (after != null) payload["after"] = after;
255-
if (before != null) payload["before"] = before;
256-
if (order != null) payload["order"] = order;
257-
if (orderBy != null) payload["orderby"] = orderBy;
258-
if (slug != null) payload["slug"] = slug;
259-
if (status != null) payload["status"] = status;
260-
if (type != null) payload["type"] = type;
261-
if (sku != null) payload["sku"] = sku;
262-
if (category != null) payload["category"] = category;
263-
if (tag != null) payload["tag"] = tag;
264-
if (shippingClass != null) payload["shipping_class"] = shippingClass;
265-
if (attribute != null) payload["attribute"] = attribute;
266-
if (attributeTerm != null) payload["attribute_term"] = attributeTerm;
267-
if (taxClass != null) payload["tax_class"] = taxClass;
268-
if (minPrice != null) payload["min_price"] = minPrice;
269-
if (maxPrice != null) payload["max_price"] = maxPrice;
270-
if (stockStatus != null) payload["stock_status"] = stockStatus;
271-
if (exclude != null) payload["exclude"] = exclude;
272-
if (parentExclude != null) payload["parent_exclude"] = parentExclude;
273-
if (include != null) payload["include"] = include;
274-
if (parent != null) payload["parent"] = parent;
275-
if (offset != null) payload["offset"] = offset;
276-
if (featured != null) payload["featured"] = featured;
277-
if (onSale != null) payload["on_sale"] = onSale;
226+
if (limit != null) payload["limit"] = limit;
227+
if (productType != null) payload["product_type"] = productType;
278228

279229
return await _wooSignalRequest<List<Product>>(
280-
method: "get",
281-
payload: payload,
282230
path: "products",
231+
method: "post",
232+
payload: payload,
283233
jsonResponse: (json) =>
284234
(json as List).map((i) => Product.fromJson(i)).toList(),
285235
) ??

0 commit comments

Comments
 (0)