Skip to content

Commit b98c15b

Browse files
agwoosignalagordn52
authored andcommitted
Merged in feature/WFA-2-api-customers (pull request #4)
Feature/WFA-2 api customers Approved-by: Anthony Gordon <ants52@aol.com>
2 parents 67fed6b + 7fa7d31 commit b98c15b

File tree

3 files changed

+330
-2
lines changed

3 files changed

+330
-2
lines changed

.flutter-plugins

Lines changed: 0 additions & 2 deletions
This file was deleted.
Lines changed: 206 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
1+
// To parse this JSON data, do
2+
//
3+
// final customerBatch = customerBatchFromJson(jsonString);
4+
5+
import 'dart:convert';
6+
7+
CustomerBatch customerBatchFromJson(String str) =>
8+
CustomerBatch.fromJson(json.decode(str));
9+
10+
String customerBatchToJson(CustomerBatch data) => json.encode(data.toJson());
11+
12+
class CustomerBatch {
13+
CustomerBatch({
14+
this.create,
15+
this.update,
16+
this.delete,
17+
});
18+
List<Customers> create;
19+
List<Customers> update;
20+
List<Customers> delete;
21+
22+
factory CustomerBatch.fromJson(Map<String, dynamic> json) => CustomerBatch(
23+
create: List<Customers>.from(
24+
json["create"].map((x) => Customers.fromJson(x))),
25+
update: List<Customers>.from(
26+
json["update"].map((x) => Customers.fromJson(x))),
27+
delete: List<Customers>.from(
28+
json["delete"].map((x) => Customers.fromJson(x))),
29+
);
30+
31+
Map<String, dynamic> toJson() => {
32+
"create": List<dynamic>.from(create.map((x) => x.toJson())),
33+
"update": List<dynamic>.from(update.map((x) => x.toJson())),
34+
"delete": List<dynamic>.from(delete.map((x) => x.toJson())),
35+
};
36+
}
37+
38+
class Customers {
39+
Customers({
40+
this.id,
41+
this.dateCreated,
42+
this.dateCreatedGmt,
43+
this.dateModified,
44+
this.dateModifiedGmt,
45+
this.email,
46+
this.firstName,
47+
this.lastName,
48+
this.role,
49+
this.username,
50+
this.billing,
51+
this.shipping,
52+
this.isPayingCustomer,
53+
this.avatarUrl,
54+
this.metaData,
55+
this.links,
56+
});
57+
58+
int id;
59+
DateTime dateCreated;
60+
DateTime dateCreatedGmt;
61+
DateTime dateModified;
62+
DateTime dateModifiedGmt;
63+
String email;
64+
String firstName;
65+
String lastName;
66+
String role;
67+
String username;
68+
Ing billing;
69+
Ing shipping;
70+
bool isPayingCustomer;
71+
String avatarUrl;
72+
List<dynamic> metaData;
73+
Links links;
74+
75+
factory Customers.fromJson(Map<String, dynamic> json) => Customers(
76+
id: json["id"],
77+
dateCreated: DateTime.parse(json["date_created"]),
78+
dateCreatedGmt: DateTime.parse(json["date_created_gmt"]),
79+
dateModified: DateTime.parse(json["date_modified"]),
80+
dateModifiedGmt: DateTime.parse(json["date_modified_gmt"]),
81+
email: json["email"],
82+
firstName: json["first_name"],
83+
lastName: json["last_name"],
84+
role: json["role"],
85+
username: json["username"],
86+
billing: Ing.fromJson(json["billing"]),
87+
shipping: Ing.fromJson(json["shipping"]),
88+
isPayingCustomer: json["is_paying_customer"],
89+
avatarUrl: json["avatar_url"],
90+
metaData: List<dynamic>.from(json["meta_data"].map((x) => x)),
91+
links: Links.fromJson(json["_links"]),
92+
);
93+
94+
Map<String, dynamic> toJson() => {
95+
"id": id,
96+
"date_created": dateCreated.toIso8601String(),
97+
"date_created_gmt": dateCreatedGmt.toIso8601String(),
98+
"date_modified": dateModified.toIso8601String(),
99+
"date_modified_gmt": dateModifiedGmt.toIso8601String(),
100+
"email": email,
101+
"first_name": firstName,
102+
"last_name": lastName,
103+
"role": role,
104+
"username": username,
105+
"billing": billing.toJson(),
106+
"shipping": shipping.toJson(),
107+
"is_paying_customer": isPayingCustomer,
108+
"avatar_url": avatarUrl,
109+
"meta_data": List<dynamic>.from(metaData.map((x) => x)),
110+
"_links": links.toJson(),
111+
};
112+
}
113+
114+
class Ing {
115+
Ing({
116+
this.firstName,
117+
this.lastName,
118+
this.company,
119+
this.address1,
120+
this.address2,
121+
this.city,
122+
this.state,
123+
this.postcode,
124+
this.country,
125+
this.email,
126+
this.phone,
127+
});
128+
129+
String firstName;
130+
String lastName;
131+
String company;
132+
String address1;
133+
String address2;
134+
String city;
135+
String state;
136+
String postcode;
137+
String country;
138+
String email;
139+
String phone;
140+
141+
factory Ing.fromJson(Map<String, dynamic> json) => Ing(
142+
firstName: json["first_name"],
143+
lastName: json["last_name"],
144+
company: json["company"],
145+
address1: json["address_1"],
146+
address2: json["address_2"],
147+
city: json["city"],
148+
state: json["state"],
149+
postcode: json["postcode"],
150+
country: json["country"],
151+
email: json["email"] == null ? null : json["email"],
152+
phone: json["phone"] == null ? null : json["phone"],
153+
);
154+
155+
Map<String, dynamic> toJson() => {
156+
"first_name": firstName,
157+
"last_name": lastName,
158+
"company": company,
159+
"address_1": address1,
160+
"address_2": address2,
161+
"city": city,
162+
"state": state,
163+
"postcode": postcode,
164+
"country": country,
165+
"email": email == null ? null : email,
166+
"phone": phone == null ? null : phone,
167+
};
168+
}
169+
170+
class Links {
171+
Links({
172+
this.self,
173+
this.collection,
174+
});
175+
176+
List<Collection> self;
177+
List<Collection> collection;
178+
179+
factory Links.fromJson(Map<String, dynamic> json) => Links(
180+
self: List<Collection>.from(
181+
json["self"].map((x) => Collection.fromJson(x))),
182+
collection: List<Collection>.from(
183+
json["collection"].map((x) => Collection.fromJson(x))),
184+
);
185+
186+
Map<String, dynamic> toJson() => {
187+
"self": List<dynamic>.from(self.map((x) => x.toJson())),
188+
"collection": List<dynamic>.from(collection.map((x) => x.toJson())),
189+
};
190+
}
191+
192+
class Collection {
193+
Collection({
194+
this.href,
195+
});
196+
197+
String href;
198+
199+
factory Collection.fromJson(Map<String, dynamic> json) => Collection(
200+
href: json["href"],
201+
);
202+
203+
Map<String, dynamic> toJson() => {
204+
"href": href,
205+
};
206+
}

lib/woosignal.dart

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ library woosignal;
1515
// IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
1616
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
1717

18+
import 'package:flutter/cupertino.dart';
19+
import 'package:woosignal/models/response/customer_batch.dart';
1820
import 'package:woosignal/models/response/reports.dart';
1921
import 'package:woosignal/networking/api_provider.dart';
2022
import 'package:woosignal/helpers/shared_pref.dart';
@@ -713,6 +715,128 @@ class WooSignal {
713715
return payloadRsp;
714716
}
715717

718+
// Retrieve a customer
719+
// This API lets you retrieve and view a specific customer by ID.
720+
Future<Customers> retrieveCustomer({int id}) async {
721+
Map<String, dynamic> payload = {};
722+
_printLog("Parameters: " + payload.toString());
723+
payload = _standardPayload("get", payload, "customers/${id.toString()}");
724+
725+
Customers customers;
726+
await _apiProvider.post("/request", payload).then((json) {
727+
customers = Customers.fromJson(json);
728+
});
729+
_printLog(customers.toString());
730+
return customers;
731+
}
732+
733+
// Retrieve customer downloads
734+
// This API lets you retrieve customer downloads permissions.
735+
Future<Customers> retrieveCustomerDownloads(
736+
{@required int customerid,
737+
String downloadId,
738+
String downloadUrl,
739+
int productId,
740+
String productName,
741+
String downloadName,
742+
int orderId,
743+
String orderKey,
744+
String downloadsRemaining,
745+
String accessExpires,
746+
String accessExpiresGmt,
747+
Map<String, String> file}) async {
748+
Map<String, dynamic> payload = {};
749+
_printLog("Parameters: " + payload.toString());
750+
payload = _standardPayload(
751+
"get", payload, "customers/${customerid.toString()}/downloads");
752+
753+
Customers customers;
754+
await _apiProvider.post("/request", payload).then((json) {
755+
customers = Customers.fromJson(json);
756+
});
757+
_printLog(customers.toString());
758+
return customers;
759+
}
760+
761+
// Create a customer
762+
// This API helps you to create a new customer.
763+
Future<Customers> createCustomer({
764+
String email,
765+
String firstName,
766+
String lastName,
767+
String userName,
768+
Map<String, dynamic> billing,
769+
Map<String, dynamic> shipping,
770+
}) async {
771+
Map<String, dynamic> payload = {};
772+
if (email != null) payload['email'] = email;
773+
if (firstName != null) payload['first_name'] = firstName;
774+
if (lastName != null) payload['last_name'] = lastName;
775+
if (userName != null) payload['username'] = userName;
776+
if (billing != null) payload['billing'] = billing;
777+
if (shipping != null) payload['shipping'] = shipping;
778+
_printLog(payload.toString());
779+
payload = _standardPayload("post", payload, "customers/");
780+
Customers customers;
781+
await _apiProvider.post("/request", payload).then((json) {
782+
customers = Customers.fromJson(json);
783+
});
784+
_printLog(customers.toString());
785+
return customers;
786+
}
787+
788+
// Update a customer
789+
// This API lets you make changes to a customer.
790+
Future<Customers> updateCustomer(int id, {Map<String, dynamic> data}) async {
791+
Map<String, dynamic> payload = data;
792+
793+
_printLog(payload.toString());
794+
payload = _standardPayload("put", payload, "customers/" + id.toString());
795+
796+
Customers customers;
797+
await _apiProvider.post("/request", payload).then((json) {
798+
customers = Customers.fromJson(json);
799+
});
800+
_printLog(customers.toString());
801+
return customers;
802+
}
803+
804+
// Delete a customer
805+
// This API helps you delete a customer.
806+
Future<Customers> deleteCustomer(
807+
int id,
808+
) async {
809+
Map<String, dynamic> data;
810+
data = {'force': true};
811+
Map<String, dynamic> payload = data;
812+
813+
_printLog(payload.toString());
814+
payload = _standardPayload("delete", payload, "customers/" + id.toString());
815+
816+
Customers customers;
817+
await _apiProvider.post("/request", payload).then((json) {
818+
customers = Customers.fromJson(json);
819+
});
820+
_printLog(customers.toString());
821+
return customers;
822+
}
823+
824+
// This API helps you to batch create, update and delete multiple Customers.
825+
// This API helps you to batch create, update and delete multiple customers.
826+
// Note: By default it's limited to up to 100 objects to be created, updated or deleted.
827+
Future<CustomerBatch> batchCustomers({Map<String, dynamic> data}) async {
828+
Map<String, dynamic> payload = data;
829+
830+
_printLog(payload.toString());
831+
payload = _standardPayload("post", payload, "customers/batch");
832+
833+
CustomerBatch customerBatch;
834+
await _apiProvider.post("/request", payload).then((json) {
835+
customerBatch = CustomerBatch.fromJson(json);
836+
});
837+
_printLog(customerBatch.toString());
838+
return customerBatch;
839+
}
716840

717841
// List all reports
718842
// This API helps you to list all the coupons that have been created.

0 commit comments

Comments
 (0)