Skip to content

Commit 73edea2

Browse files
authored
Merge pull request #8 from woosignal/master
v3.1.0 updates
2 parents 55015a2 + 67df46d commit 73edea2

File tree

6 files changed

+165
-16
lines changed

6 files changed

+165
-16
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
## [3.1.0] - 2022-05-19
2+
3+
* New API for product tags
4+
* Flutter format
5+
* Dependency updates
6+
* Dart version 2.17
7+
18
## [3.0.5] - 2022-01-29
29

310
* Version added to woosignal.dart

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ In your flutter project add the dependency:
1515
``` dart
1616
dependencies:
1717
...
18-
woosignal: ^3.0.5
18+
woosignal: ^3.1.0
1919
```
2020

2121
### Usage example #
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Copyright (c) 2022, WooSignal Ltd.
2+
// All rights reserved.
3+
//
4+
// Redistribution and use in source and binary forms are permitted
5+
// provided that the above copyright notice and this paragraph are
6+
// duplicated in all such forms and that any documentation,
7+
// advertising materials, and other materials related to such
8+
// distribution and use acknowledge that the software was developed
9+
// by the WooSignal. The name of the
10+
// WooSignal may not be used to endorse or promote products derived
11+
// from this software without specific prior written permission.
12+
// THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
13+
// IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
14+
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
15+
16+
import 'package:woosignal/models/links.dart';
17+
18+
class ProductTag {
19+
int? id;
20+
String? name;
21+
String? slug;
22+
String? description;
23+
int? count;
24+
Links? links;
25+
26+
ProductTag(
27+
{this.id,
28+
this.name,
29+
this.slug,
30+
this.description,
31+
this.count,
32+
this.links});
33+
34+
ProductTag.fromJson(Map<String, dynamic> json) {
35+
id = json['id'];
36+
name = json['name'];
37+
slug = json['slug'];
38+
description = json['description'];
39+
count = json['count'];
40+
links = json['_links'] != null ? new Links.fromJson(json['_links']) : null;
41+
}
42+
43+
Map<String, dynamic> toJson() {
44+
final Map<String, dynamic> data = new Map<String, dynamic>();
45+
data['id'] = this.id;
46+
data['name'] = this.name;
47+
data['slug'] = this.slug;
48+
data['description'] = this.description;
49+
data['count'] = this.count;
50+
if (this.links != null) {
51+
data['_links'] = this.links!.toJson();
52+
}
53+
return data;
54+
}
55+
}

lib/networking/api_provider.dart

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
1515

1616
import 'dart:convert';
17+
import 'package:device_info_plus/device_info_plus.dart';
1718
import 'package:dio/dio.dart';
1819
import 'package:woosignal/helpers/shared_pref.dart';
19-
import 'package:device_info/device_info.dart';
2020
import 'dart:io' show Platform;
2121

2222
class ApiProvider {
@@ -36,8 +36,8 @@ class ApiProvider {
3636
AndroidDeviceInfo androidDeviceInfo = await deviceInfo.androidInfo;
3737
_deviceMeta = {
3838
"model": androidDeviceInfo.device,
39-
"brand":
40-
androidDeviceInfo.brand.replaceAll(RegExp('[^\u0001-\u007F]'), '_'),
39+
"brand": androidDeviceInfo.brand
40+
?.replaceAll(RegExp('[^\u0001-\u007F]'), '_'),
4141
"manufacturer": androidDeviceInfo.manufacturer,
4242
"version": androidDeviceInfo.version.sdkInt.toString(),
4343
"uuid": uuid,
@@ -48,7 +48,8 @@ class ApiProvider {
4848
IosDeviceInfo iosDeviceInfo = await deviceInfo.iosInfo;
4949
_deviceMeta = {
5050
"model": iosDeviceInfo.model,
51-
"brand": iosDeviceInfo.name.replaceAll(RegExp('[^\u0001-\u007F]'), '_'),
51+
"brand":
52+
iosDeviceInfo.name?.replaceAll(RegExp('[^\u0001-\u007F]'), '_'),
5253
"manufacturer": "Apple",
5354
"version": iosDeviceInfo.systemVersion,
5455
"uuid": uuid,
@@ -82,7 +83,7 @@ class ApiProvider {
8283
/// Set the http headers for Dio
8384
_setDioHeaders() {
8485
_dio.options.headers = {
85-
"Authorization": "Bearer " + _apiKey,
86+
"Authorization": "Bearer $_apiKey",
8687
"Content-Type": "application/json",
8788
"X-DMETA": json.encode(_deviceMeta).toString()
8889
};

lib/woosignal.dart

Lines changed: 89 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import 'package:woosignal/models/response/continent.dart';
2020
import 'package:woosignal/models/response/currencies.dart';
2121
import 'package:woosignal/models/response/customer_download.dart';
2222
import 'package:woosignal/models/response/order_batch.dart' as ob;
23+
import 'package:woosignal/models/response/product_tag.dart';
2324
import 'package:woosignal/models/response/refund.dart';
2425
import 'package:woosignal/models/response/order_notes.dart';
2526
import 'package:woosignal/models/response/coupon.dart';
@@ -52,7 +53,7 @@ import 'package:woosignal/models/response/setting_option_batch.dart';
5253
import 'package:woosignal/models/response/product_batch.dart';
5354

5455
/// WooSignal Package version
55-
const String wooSignalVersion = "3.0.5";
56+
const String wooSignalVersion = "3.1.0";
5657

5758
class WooSignal {
5859
WooSignal._privateConstructor();
@@ -85,7 +86,7 @@ class WooSignal {
8586
/// Print to the console a [message]
8687
void _printLog(String message) {
8788
if (_debugMode == true) {
88-
print("WOOSIGNAL LOG: " + message);
89+
print("WooSignal LOG: $message");
8990
}
9091
}
9192

@@ -99,7 +100,7 @@ class WooSignal {
99100
required String path,
100101
required T Function(dynamic json) jsonResponse,
101102
String postUrl = "/request"}) async {
102-
_printLog("Parameters: " + payload.toString());
103+
_printLog("Parameters: $payload");
103104
payload = _standardPayload(method, payload, path);
104105

105106
dynamic json = await _apiProvider.post(postUrl, payload);
@@ -1380,4 +1381,89 @@ class WooSignal {
13801381
jsonResponse: (json) => ProductBatch.fromJson(json),
13811382
);
13821383
}
1384+
1385+
/// https://woosignal.com/docs/api/1.0/products#create-product-tags
1386+
Future<ProductTag?> createProductTag(
1387+
{required String name, String? slug, String? description}) async {
1388+
Map<String, dynamic> payload = {'name': name};
1389+
if (slug != null) payload['slug'] = slug;
1390+
if (description != null) payload['description'] = description;
1391+
1392+
return await _wooSignalRequest<ProductTag?>(
1393+
method: "post",
1394+
path: "products/tags",
1395+
payload: payload,
1396+
jsonResponse: (json) => ProductTag.fromJson(json),
1397+
);
1398+
}
1399+
1400+
/// https://woosignal.com/docs/api/1.0/products#create-product-tag
1401+
Future<ProductTag?> retrieveProductTag(int id) async {
1402+
return await _wooSignalRequest<ProductTag?>(
1403+
method: "get",
1404+
path: "products/tags/" + id.toString(),
1405+
jsonResponse: (json) => ProductTag.fromJson(json),
1406+
);
1407+
}
1408+
1409+
/// https://woosignal.com/docs/api/1.0/products#create-product-tags
1410+
Future<List<ProductTag>?> getProductTags(
1411+
{String? context,
1412+
int? page,
1413+
int? perPage,
1414+
String? search,
1415+
List<int>? exclude,
1416+
List<int>? include,
1417+
int? offset,
1418+
String? order,
1419+
String? orderBy,
1420+
bool? hideEmpty,
1421+
int? product,
1422+
String? slug}) async {
1423+
Map<String, dynamic> payload = {};
1424+
1425+
if (context != null) payload["context"] = context;
1426+
if (page != null) payload["page"] = page;
1427+
if (perPage != null) payload["per_page"] = perPage;
1428+
if (search != null) payload["search"] = search;
1429+
if (exclude != null) payload["exclude"] = exclude;
1430+
if (include != null) payload["include"] = include;
1431+
if (offset != null) payload["offset"] = offset;
1432+
if (order != null) payload["order"] = order;
1433+
if (orderBy != null) payload["orderby"] = orderBy;
1434+
if (hideEmpty != null) payload["hide_empty"] = hideEmpty;
1435+
if (product != null) payload["product"] = product;
1436+
if (slug != null) payload["slug"] = slug;
1437+
1438+
return await _wooSignalRequest<List<ProductTag>?>(
1439+
method: "get",
1440+
path: "products/tags",
1441+
payload: payload,
1442+
jsonResponse: (json) =>
1443+
(json as List).map((i) => ProductTag.fromJson(i)).toList(),
1444+
);
1445+
}
1446+
1447+
/// https://woosignal.com/docs/api/1.0/products#create-product-tags
1448+
Future<ProductTag?> updateProductTag(int productTagId,
1449+
{Map<String, dynamic>? data}) async {
1450+
return await _wooSignalRequest<ProductTag?>(
1451+
method: "put",
1452+
path: "products/tags/" + productTagId.toString(),
1453+
payload: data ?? {},
1454+
jsonResponse: (json) => ProductTag.fromJson(json),
1455+
);
1456+
}
1457+
1458+
/// https://woosignal.com/docs/api/1.0/products#delete-product-tags
1459+
Future<ProductTag?> deleteProductTag(int productTagId,
1460+
{bool force = false}) async {
1461+
Map<String, dynamic> payload = {"force": force};
1462+
return await _wooSignalRequest<ProductTag?>(
1463+
method: "delete",
1464+
path: "products/tags/" + productTagId.toString(),
1465+
payload: payload,
1466+
jsonResponse: (json) => ProductTag.fromJson(json),
1467+
);
1468+
}
13831469
}

pubspec.yaml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
name: woosignal
22
description: WooCommerce REST API for dart, connect a WooCommerce store and start developing with our interface for their API endpoints.
3-
version: 3.0.5
3+
version: 3.1.0
44
homepage: https://woosignal.com
55
repository: https://github.com/woosignal/flutter-woocommerce-api
66
issue_tracker: https://github.com/woosignal/flutter-woocommerce-api/issues
77
documentation: https://woosignal.com/docs/api/1.0/overview
88

99
environment:
10-
sdk: '>=2.15.0 <3.0.0'
10+
sdk: '>=2.17.0 <3.0.0'
1111

1212
dependencies:
13-
dio: ^4.0.4
14-
device_info: ^2.0.3
15-
shared_preferences: ^2.0.12
16-
uuid: ^3.0.5
13+
dio: ^4.0.6
14+
device_info_plus: ^3.2.3
15+
shared_preferences: ^2.0.15
16+
uuid: ^3.0.6
1717

1818
flutter:
1919
sdk: flutter
2020

2121
dev_dependencies:
22-
lints: ^1.0.0
22+
lints: ^2.0.0
2323
test: ^1.16.0

0 commit comments

Comments
 (0)