Skip to content

Commit 3f2e368

Browse files
committed
Merged in feature/WOOS-3-add-product-images-api-into-shopi (pull request #5)
Feature/WOOS-3 add product images api into shopi
2 parents 817cdc1 + 8ea2320 commit 3f2e368

8 files changed

+310
-9
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":"/Users/anthony/.pub-cache/hosted/pub.dev/device_info_plus-9.0.2/","native_build":true,"dependencies":[]},{"name":"shared_preferences_foundation","path":"/Users/anthony/.pub-cache/hosted/pub.dev/shared_preferences_foundation-2.2.2/","shared_darwin_source":true,"native_build":true,"dependencies":[]}],"android":[{"name":"device_info_plus","path":"/Users/anthony/.pub-cache/hosted/pub.dev/device_info_plus-9.0.2/","native_build":true,"dependencies":[]},{"name":"shared_preferences_android","path":"/Users/anthony/.pub-cache/hosted/pub.dev/shared_preferences_android-2.1.4/","native_build":true,"dependencies":[]}],"macos":[{"name":"device_info_plus","path":"/Users/anthony/.pub-cache/hosted/pub.dev/device_info_plus-9.0.2/","native_build":true,"dependencies":[]},{"name":"shared_preferences_foundation","path":"/Users/anthony/.pub-cache/hosted/pub.dev/shared_preferences_foundation-2.2.2/","shared_darwin_source":true,"native_build":true,"dependencies":[]}],"linux":[{"name":"device_info_plus","path":"/Users/anthony/.pub-cache/hosted/pub.dev/device_info_plus-9.0.2/","native_build":false,"dependencies":[]},{"name":"path_provider_linux","path":"/Users/anthony/.pub-cache/hosted/pub.dev/path_provider_linux-2.1.8/","native_build":false,"dependencies":[]},{"name":"shared_preferences_linux","path":"/Users/anthony/.pub-cache/hosted/pub.dev/shared_preferences_linux-2.2.0/","native_build":false,"dependencies":["path_provider_linux"]}],"windows":[{"name":"device_info_plus","path":"/Users/anthony/.pub-cache/hosted/pub.dev/device_info_plus-9.0.2/","native_build":false,"dependencies":[]},{"name":"path_provider_windows","path":"/Users/anthony/.pub-cache/hosted/pub.dev/path_provider_windows-2.1.6/","native_build":false,"dependencies":[]},{"name":"shared_preferences_windows","path":"/Users/anthony/.pub-cache/hosted/pub.dev/shared_preferences_windows-2.2.0/","native_build":false,"dependencies":["path_provider_windows"]}],"web":[{"name":"device_info_plus","path":"/Users/anthony/.pub-cache/hosted/pub.dev/device_info_plus-9.0.2/","dependencies":[]},{"name":"shared_preferences_web","path":"/Users/anthony/.pub-cache/hosted/pub.dev/shared_preferences_web-2.1.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-25 23:30:52.686698","version":"3.10.6"}
1+
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"device_info_plus","path":"/Users/anthony/.pub-cache/hosted/pub.dev/device_info_plus-9.0.2/","native_build":true,"dependencies":[]},{"name":"shared_preferences_foundation","path":"/Users/anthony/.pub-cache/hosted/pub.dev/shared_preferences_foundation-2.2.2/","shared_darwin_source":true,"native_build":true,"dependencies":[]}],"android":[{"name":"device_info_plus","path":"/Users/anthony/.pub-cache/hosted/pub.dev/device_info_plus-9.0.2/","native_build":true,"dependencies":[]},{"name":"shared_preferences_android","path":"/Users/anthony/.pub-cache/hosted/pub.dev/shared_preferences_android-2.1.4/","native_build":true,"dependencies":[]}],"macos":[{"name":"device_info_plus","path":"/Users/anthony/.pub-cache/hosted/pub.dev/device_info_plus-9.0.2/","native_build":true,"dependencies":[]},{"name":"shared_preferences_foundation","path":"/Users/anthony/.pub-cache/hosted/pub.dev/shared_preferences_foundation-2.2.2/","shared_darwin_source":true,"native_build":true,"dependencies":[]}],"linux":[{"name":"device_info_plus","path":"/Users/anthony/.pub-cache/hosted/pub.dev/device_info_plus-9.0.2/","native_build":false,"dependencies":[]},{"name":"path_provider_linux","path":"/Users/anthony/.pub-cache/hosted/pub.dev/path_provider_linux-2.1.8/","native_build":false,"dependencies":[]},{"name":"shared_preferences_linux","path":"/Users/anthony/.pub-cache/hosted/pub.dev/shared_preferences_linux-2.2.0/","native_build":false,"dependencies":["path_provider_linux"]}],"windows":[{"name":"device_info_plus","path":"/Users/anthony/.pub-cache/hosted/pub.dev/device_info_plus-9.0.2/","native_build":false,"dependencies":[]},{"name":"path_provider_windows","path":"/Users/anthony/.pub-cache/hosted/pub.dev/path_provider_windows-2.1.6/","native_build":false,"dependencies":[]},{"name":"shared_preferences_windows","path":"/Users/anthony/.pub-cache/hosted/pub.dev/shared_preferences_windows-2.2.0/","native_build":false,"dependencies":["path_provider_windows"]}],"web":[{"name":"device_info_plus","path":"/Users/anthony/.pub-cache/hosted/pub.dev/device_info_plus-9.0.2/","dependencies":[]},{"name":"shared_preferences_web","path":"/Users/anthony/.pub-cache/hosted/pub.dev/shared_preferences_web-2.1.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:03:01.639184","version":"3.10.6"}

dart_test.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
tags:
2+
get-product-images:
3+
products-single-product-image:
4+
products-count-of-product-images:
25
shopify-products:
36
products-list-of-products:
47
products-single-product:

lib/models/product_image.dart

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// Copyright (c) 2023, 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+
class ProductImage {
17+
int? id;
18+
int? productId;
19+
int? position;
20+
DateTime? createdAt;
21+
DateTime? updatedAt;
22+
String? alt;
23+
int? width;
24+
int? height;
25+
String? src;
26+
List<int>? variantIds;
27+
String? adminGraphqlApiId;
28+
29+
ProductImage(
30+
{this.id,
31+
this.productId,
32+
this.position,
33+
this.createdAt,
34+
this.updatedAt,
35+
this.alt,
36+
this.width,
37+
this.height,
38+
this.src,
39+
this.variantIds,
40+
this.adminGraphqlApiId});
41+
42+
ProductImage.fromJson(Map<String, dynamic> json) {
43+
id = json['id'];
44+
productId = json['product_id'];
45+
position = json['position'];
46+
createdAt = json['created_at'] != null ? DateTime.parse(json['created_at']) : null;
47+
updatedAt = json['updated_at'] != null ? DateTime.parse(json['updated_at']) : null;
48+
alt = json['alt'];
49+
width = json['width'];
50+
height = json['height'];
51+
src = json['src'];
52+
variantIds = json['variant_ids'].cast<int>();
53+
adminGraphqlApiId = json['admin_graphql_api_id'];
54+
}
55+
56+
Map<String, dynamic> toJson() {
57+
final Map<String, dynamic> data = {};
58+
data['id'] = id;
59+
data['product_id'] = productId;
60+
data['position'] = position;
61+
data['created_at'] = createdAt;
62+
data['updated_at'] = updatedAt;
63+
data['alt'] = alt;
64+
data['width'] = width;
65+
data['height'] = height;
66+
data['src'] = src;
67+
data['variant_ids'] = variantIds;
68+
data['admin_graphql_api_id'] = adminGraphqlApiId;
69+
return data;
70+
}
71+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright (c) 2023, 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+
class ProductImageCountResponse {
17+
int? count;
18+
19+
ProductImageCountResponse({this.count});
20+
21+
ProductImageCountResponse.fromJson(Map<String, dynamic> json) {
22+
count = json['count'];
23+
}
24+
25+
Map<String, dynamic> toJson() {
26+
final Map<String, dynamic> data = new Map<String, dynamic>();
27+
data['count'] = this.count;
28+
return data;
29+
}
30+
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
// Copyright (c) 2023, 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+
class ProductImageResponse {
17+
Image? image;
18+
19+
ProductImageResponse({this.image});
20+
21+
ProductImageResponse.fromJson(Map<String, dynamic> json) {
22+
image = json['image'] != null ? Image.fromJson(json['image']) : null;
23+
}
24+
25+
Map<String, dynamic> toJson() {
26+
final Map<String, dynamic> data = <String, dynamic>{};
27+
if (image != null) {
28+
data['image'] = image!.toJson();
29+
}
30+
return data;
31+
}
32+
}
33+
34+
class Image {
35+
int? id;
36+
int? productId;
37+
int? position;
38+
DateTime? createdAt;
39+
DateTime? updatedAt;
40+
String? alt;
41+
int? width;
42+
int? height;
43+
String? src;
44+
List<int>? variantIds;
45+
String? adminGraphqlApiId;
46+
47+
Image(
48+
{this.id,
49+
this.productId,
50+
this.position,
51+
this.createdAt,
52+
this.updatedAt,
53+
this.alt,
54+
this.width,
55+
this.height,
56+
this.src,
57+
this.variantIds,
58+
this.adminGraphqlApiId});
59+
60+
Image.fromJson(Map<String, dynamic> json) {
61+
id = json['id'];
62+
productId = json['product_id'];
63+
position = json['position'];
64+
createdAt = json['created_at'] != null ? DateTime.parse(json['created_at']) : null;
65+
updatedAt = json['updated_at'] != null ? DateTime.parse(json['updated_at']) : null;
66+
alt = json['alt'];
67+
width = json['width'];
68+
height = json['height'];
69+
src = json['src'];
70+
variantIds = json['variant_ids'].cast<int>();
71+
adminGraphqlApiId = json['admin_graphql_api_id'];
72+
}
73+
74+
Map<String, dynamic> toJson() {
75+
final Map<String, dynamic> data = <String, dynamic>{};
76+
data['id'] = id;
77+
data['product_id'] = productId;
78+
data['position'] = position;
79+
data['created_at'] = createdAt;
80+
data['updated_at'] = updatedAt;
81+
data['alt'] = alt;
82+
data['width'] = width;
83+
data['height'] = height;
84+
data['src'] = src;
85+
data['variant_ids'] = variantIds;
86+
data['admin_graphql_api_id'] = adminGraphqlApiId;
87+
return data;
88+
}
89+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright (c) 2023, 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_shopify/models/product_image.dart';
17+
18+
class ProductImagesResponse {
19+
List<ProductImage>? images;
20+
21+
ProductImagesResponse({this.images});
22+
23+
ProductImagesResponse.fromJson(Map<String, dynamic> json) {
24+
if (json['images'] != null) {
25+
images = <ProductImage>[];
26+
json['images'].forEach((v) {
27+
images!.add(ProductImage.fromJson(v));
28+
});
29+
}
30+
}
31+
32+
Map<String, dynamic> toJson() {
33+
final Map<String, dynamic> data = {};
34+
if (images != null) {
35+
data['images'] = images!.map((v) => v.toJson()).toList();
36+
}
37+
return data;
38+
}
39+
}

lib/woosignal_shopify.dart

Lines changed: 55 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ library woosignal_shopify;
1414
// IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
1515
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
1616

17-
17+
import 'package:woosignal_shopify/models/product_image.dart';
18+
import 'package:woosignal_shopify/models/response/product_image_count_response.dart';
19+
import 'package:woosignal_shopify/models/response/product_images_response.dart';
1820
import 'package:woosignal_shopify/models/product.dart';
1921
import 'package:woosignal_shopify/models/response/count_response.dart';
2022
import '/models/response/products_response.dart';
@@ -259,11 +261,11 @@ class WooSignal {
259261
if (vendor != null) payload["vendor"] = vendor;
260262

261263
return await _wooSignalRequest<ProductsResponse>(
262-
path: "products",
263-
method: "post",
264-
payload: payload,
265-
jsonResponse: (json) => ProductsResponse.fromJson(json)
266-
);
264+
path: "products",
265+
method: "post",
266+
payload: payload,
267+
jsonResponse: (json) => ProductsResponse.fromJson(json)
268+
);
267269
}
268270

269271
Future<Product?> getProduct(
@@ -312,4 +314,51 @@ class WooSignal {
312314
jsonResponse: (json) => CountResponse.fromJson(json)
313315
);
314316
}
317+
318+
Future<ProductImagesResponse?> getProductImages(
319+
{required int productId,
320+
String? fields,
321+
int? sinceId,
322+
}) async {
323+
Map<String, dynamic> payload = {};
324+
if (fields != null) payload["fields"] = fields;
325+
if (sinceId != null) payload["since_id"] = sinceId;
326+
return await _wooSignalRequest<ProductImagesResponse>(
327+
path: "products/$productId/images",
328+
method: "post",
329+
payload: payload,
330+
jsonResponse: (json) => ProductImagesResponse.fromJson(json)
331+
);
332+
}
333+
334+
Future<ProductImage?> getProductImage(
335+
{required int imageId,
336+
required int productId,
337+
String? fields,
338+
}) async {
339+
Map<String, dynamic> payload = {};
340+
if (fields != null) payload["fields"] = fields;
341+
342+
return await _wooSignalRequest<ProductImage>(
343+
path: "products/$productId/image/$imageId",
344+
method: "post",
345+
payload: payload,
346+
jsonResponse: (json) => ProductImage.fromJson(json['image'])
347+
);
348+
}
349+
350+
Future<ProductImageCountResponse?> getProductImageCount(
351+
{required int? productId,
352+
int? sinceId,
353+
}) async {
354+
Map<String, dynamic> payload = {};
355+
if (sinceId != null) payload["since_id"] = sinceId;
356+
357+
return await _wooSignalRequest<ProductImageCountResponse>(
358+
path: "products/$productId/images/count",
359+
method: "post",
360+
payload: payload,
361+
jsonResponse: (json) => ProductImageCountResponse.fromJson(json)
362+
);
363+
}
315364
}

test/woosignal_woocommerce_api_test.dart

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import 'package:flutter/material.dart';
22
import 'package:shared_preferences/shared_preferences.dart';
33
import 'package:test/test.dart';
4+
import 'package:woosignal_shopify/models/product_image.dart';
5+
import 'package:woosignal_shopify/models/response/product_image_count_response.dart';
6+
import 'package:woosignal_shopify/models/response/product_images_response.dart';
47
import 'package:woosignal_shopify/models/product.dart';
58
import 'package:woosignal_shopify/models/response/count_response.dart';
69
import 'package:woosignal_shopify/models/response/products_response.dart';
@@ -20,9 +23,9 @@ void main() {
2023
/// Test Shopify Products
2124
group('Testing Shopify Products', () {
2225

26+
/// PRODUCTS
2327
test('products - list of products', () async {
2428
ProductsResponse? productsResponse = await WooSignal.instance.getProducts();
25-
2629
expect(productsResponse is ProductsResponse, true);
2730
expect(productsResponse?.products!.isNotEmpty, true);
2831
}, tags: ['products-list-of-products']);
@@ -40,6 +43,23 @@ void main() {
4043
expect(countResponse is CountResponse, true);
4144
}, tags: ['products-count-of-products']);
4245

43-
}, tags: ['shopify-products']);
46+
/// IMAGES
47+
test('get product images', () async {
48+
ProductImagesResponse? productImagesResponse = await WooSignal.instance.getProductImages(productId: 8443055702328);
49+
expect(productImagesResponse is ProductImagesResponse, true);
50+
expect(productImagesResponse?.images!.isNotEmpty, true);
51+
}, tags: ['get-product-images']);
52+
53+
test('products single product image', () async {
54+
ProductImage? productImage = await WooSignal.instance.getProductImage(imageId: 42256696181048, productId: 8443055702328);
55+
expect(productImage is ProductImage, true);
56+
}, tags: ['products-single-product-image']);
4457

58+
test('products count of product images', () async {
59+
ProductImageCountResponse? productImageCountResponse = await WooSignal.instance.getProductImageCount(productId: 8443055702328);
60+
expect(productImageCountResponse is ProductImageCountResponse, true);
61+
}, tags: ['products-count-of-product-images']);
62+
63+
}, tags: ['shopify-products']);
4564
}
65+

0 commit comments

Comments
 (0)