Skip to content

Commit cd52b43

Browse files
committed
provinces data is fetched
1 parent 9d7b091 commit cd52b43

File tree

5 files changed

+94
-2
lines changed

5 files changed

+94
-2
lines changed

.flutter-plugins-dependencies

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"device_info_plus","path":"/home/arif/.pub-cache/hosted/pub.dev/device_info_plus-9.0.2/","native_build":true,"dependencies":[]},{"name":"shared_preferences_foundation","path":"/home/arif/.pub-cache/hosted/pub.dev/shared_preferences_foundation-2.3.2/","shared_darwin_source":true,"native_build":true,"dependencies":[]}],"android":[{"name":"device_info_plus","path":"/home/arif/.pub-cache/hosted/pub.dev/device_info_plus-9.0.2/","native_build":true,"dependencies":[]},{"name":"shared_preferences_android","path":"/home/arif/.pub-cache/hosted/pub.dev/shared_preferences_android-2.2.0/","native_build":true,"dependencies":[]}],"macos":[{"name":"device_info_plus","path":"/home/arif/.pub-cache/hosted/pub.dev/device_info_plus-9.0.2/","native_build":true,"dependencies":[]},{"name":"shared_preferences_foundation","path":"/home/arif/.pub-cache/hosted/pub.dev/shared_preferences_foundation-2.3.2/","shared_darwin_source":true,"native_build":true,"dependencies":[]}],"linux":[{"name":"device_info_plus","path":"/home/arif/.pub-cache/hosted/pub.dev/device_info_plus-9.0.2/","native_build":false,"dependencies":[]},{"name":"path_provider_linux","path":"/home/arif/.pub-cache/hosted/pub.dev/path_provider_linux-2.1.11/","native_build":false,"dependencies":[]},{"name":"shared_preferences_linux","path":"/home/arif/.pub-cache/hosted/pub.dev/shared_preferences_linux-2.3.0/","native_build":false,"dependencies":["path_provider_linux"]}],"windows":[{"name":"device_info_plus","path":"/home/arif/.pub-cache/hosted/pub.dev/device_info_plus-9.0.2/","native_build":false,"dependencies":[]},{"name":"path_provider_windows","path":"/home/arif/.pub-cache/hosted/pub.dev/path_provider_windows-2.1.7/","native_build":false,"dependencies":[]},{"name":"shared_preferences_windows","path":"/home/arif/.pub-cache/hosted/pub.dev/shared_preferences_windows-2.3.0/","native_build":false,"dependencies":["path_provider_windows"]}],"web":[{"name":"device_info_plus","path":"/home/arif/.pub-cache/hosted/pub.dev/device_info_plus-9.0.2/","dependencies":[]},{"name":"shared_preferences_web","path":"/home/arif/.pub-cache/hosted/pub.dev/shared_preferences_web-2.2.0/","dependencies":[]}]},"dependencyGraph":[{"name":"device_info_plus","dependencies":[]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_windows","dependencies":[]},{"name":"shared_preferences","dependencies":["shared_preferences_android","shared_preferences_foundation","shared_preferences_linux","shared_preferences_web","shared_preferences_windows"]},{"name":"shared_preferences_android","dependencies":[]},{"name":"shared_preferences_foundation","dependencies":[]},{"name":"shared_preferences_linux","dependencies":["path_provider_linux"]},{"name":"shared_preferences_web","dependencies":[]},{"name":"shared_preferences_windows","dependencies":["path_provider_windows"]}],"date_created":"2023-07-26 00:55:16.472508","version":"3.10.5"}
1+
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"device_info_plus","path":"/home/arif/.pub-cache/hosted/pub.dev/device_info_plus-9.0.2/","native_build":true,"dependencies":[]},{"name":"shared_preferences_foundation","path":"/home/arif/.pub-cache/hosted/pub.dev/shared_preferences_foundation-2.3.2/","shared_darwin_source":true,"native_build":true,"dependencies":[]}],"android":[{"name":"device_info_plus","path":"/home/arif/.pub-cache/hosted/pub.dev/device_info_plus-9.0.2/","native_build":true,"dependencies":[]},{"name":"shared_preferences_android","path":"/home/arif/.pub-cache/hosted/pub.dev/shared_preferences_android-2.2.0/","native_build":true,"dependencies":[]}],"macos":[{"name":"device_info_plus","path":"/home/arif/.pub-cache/hosted/pub.dev/device_info_plus-9.0.2/","native_build":true,"dependencies":[]},{"name":"shared_preferences_foundation","path":"/home/arif/.pub-cache/hosted/pub.dev/shared_preferences_foundation-2.3.2/","shared_darwin_source":true,"native_build":true,"dependencies":[]}],"linux":[{"name":"device_info_plus","path":"/home/arif/.pub-cache/hosted/pub.dev/device_info_plus-9.0.2/","native_build":false,"dependencies":[]},{"name":"path_provider_linux","path":"/home/arif/.pub-cache/hosted/pub.dev/path_provider_linux-2.1.11/","native_build":false,"dependencies":[]},{"name":"shared_preferences_linux","path":"/home/arif/.pub-cache/hosted/pub.dev/shared_preferences_linux-2.3.0/","native_build":false,"dependencies":["path_provider_linux"]}],"windows":[{"name":"device_info_plus","path":"/home/arif/.pub-cache/hosted/pub.dev/device_info_plus-9.0.2/","native_build":false,"dependencies":[]},{"name":"path_provider_windows","path":"/home/arif/.pub-cache/hosted/pub.dev/path_provider_windows-2.1.7/","native_build":false,"dependencies":[]},{"name":"shared_preferences_windows","path":"/home/arif/.pub-cache/hosted/pub.dev/shared_preferences_windows-2.3.0/","native_build":false,"dependencies":["path_provider_windows"]}],"web":[{"name":"device_info_plus","path":"/home/arif/.pub-cache/hosted/pub.dev/device_info_plus-9.0.2/","dependencies":[]},{"name":"shared_preferences_web","path":"/home/arif/.pub-cache/hosted/pub.dev/shared_preferences_web-2.2.0/","dependencies":[]}]},"dependencyGraph":[{"name":"device_info_plus","dependencies":[]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_windows","dependencies":[]},{"name":"shared_preferences","dependencies":["shared_preferences_android","shared_preferences_foundation","shared_preferences_linux","shared_preferences_web","shared_preferences_windows"]},{"name":"shared_preferences_android","dependencies":[]},{"name":"shared_preferences_foundation","dependencies":[]},{"name":"shared_preferences_linux","dependencies":["path_provider_linux"]},{"name":"shared_preferences_web","dependencies":[]},{"name":"shared_preferences_windows","dependencies":["path_provider_windows"]}],"date_created":"2023-07-26 01:38:52.416907","version":"3.10.5"}

dart_test.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@ tags:
99
policies-properties:
1010
get-shipping-zones:
1111
shipping-zones-properties:
12+
shipping-provinces:
13+
get-provinces:
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
class ProvincesResponse {
2+
List<Province> provinces;
3+
4+
ProvincesResponse({
5+
required this.provinces,
6+
});
7+
8+
factory ProvincesResponse.fromJson(Map<String, dynamic> json) => ProvincesResponse(
9+
provinces: List<Province>.from(json["provinces"].map((x) => Province.fromJson(x))),
10+
);
11+
12+
Map<String, dynamic> toJson() => {
13+
"provinces": List<dynamic>.from(provinces.map((x) => x.toJson())),
14+
};
15+
}
16+
17+
class Province {
18+
int id;
19+
int countryId;
20+
String name;
21+
String code;
22+
String taxName;
23+
String? taxType;
24+
dynamic shippingZoneId;
25+
int tax;
26+
int taxPercentage;
27+
28+
Province({
29+
required this.id,
30+
required this.countryId,
31+
required this.name,
32+
required this.code,
33+
required this.taxName,
34+
this.taxType,
35+
this.shippingZoneId,
36+
required this.tax,
37+
required this.taxPercentage,
38+
});
39+
40+
factory Province.fromJson(Map<String, dynamic> json) => Province(
41+
id: json["id"],
42+
countryId: json["country_id"],
43+
name: json["name"],
44+
code: json["code"],
45+
taxName: json["tax_name"],
46+
taxType: json["tax_type"],
47+
shippingZoneId: json["shipping_zone_id"],
48+
tax: json["tax"],
49+
taxPercentage: json["tax_percentage"],
50+
);
51+
52+
Map<String, dynamic> toJson() => {
53+
"id": id,
54+
"country_id": countryId,
55+
"name": name,
56+
"code": code,
57+
"tax_name": taxName,
58+
"tax_type": taxType,
59+
"shipping_zone_id": shippingZoneId,
60+
"tax": tax,
61+
"tax_percentage": taxPercentage,
62+
};
63+
}

lib/woosignal_shopify.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ library woosignal_shopify;
1717

1818
import 'package:woosignal_shopify/models/response/countries_response.dart';
1919
import 'package:woosignal_shopify/models/response/policies_response.dart';
20+
import 'package:woosignal_shopify/models/response/provinces_response.dart';
2021
import 'package:woosignal_shopify/models/response/shop_response.dart';
2122

2223
import '/models/response/products_response.dart';
@@ -293,5 +294,19 @@ class WooSignal {
293294
jsonResponse: (json) => ShippingZonesResponse.fromJson(json)
294295
);
295296
}
297+
/// https://woosignal.com/docs/api/1.0/provinces/{countryId}
298+
Future<ProvincesResponse?> getProvinces({String? fields,
299+
required int id,
300+
}) async {
301+
Map<String, dynamic> payload = {};
302+
if (fields != null) payload["fields"] = fields;
303+
304+
return await _wooSignalRequest<ProvincesResponse>(
305+
path: "provinces/$id",
306+
method: "post",
307+
payload: payload,
308+
jsonResponse: (json) => ProvincesResponse.fromJson(json)
309+
);
310+
}
296311

297312
}

test/woosignal_woocommerce_api_test.dart

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import 'package:test/test.dart';
4343
import 'package:woosignal_shopify/models/response/countries_response.dart';
4444
import 'package:woosignal_shopify/models/response/policies_response.dart';
4545
import 'package:woosignal_shopify/models/response/products_response.dart';
46+
import 'package:woosignal_shopify/models/response/provinces_response.dart';
4647
import 'package:woosignal_shopify/models/response/shipping_zones_response.dart';
4748
import 'package:woosignal_shopify/models/response/shop_response.dart';
4849
import 'package:woosignal_shopify/woosignal_shopify.dart';
@@ -115,5 +116,16 @@ void main() {
115116
expect(shippingZonesResponse != null, true);
116117
}, tags: ['get-shipping-zones']);
117118
}, tags: ['shipping-zones-properties']);
118-
}
119119

120+
/// test for policies retrieval
121+
group('Testing Shopify provinces', () {
122+
test('get provinces', () async {
123+
ProvincesResponse? provincesResponse =
124+
await WooSignal.instance.getProvinces(id: 765701030200);
125+
126+
expect(provincesResponse is ProvincesResponse, true);
127+
128+
expect(provincesResponse != null, true);
129+
}, tags: ['get-provinces']);
130+
}, tags: ['shipping-provinces']);
131+
}

0 commit comments

Comments
 (0)