com.dft.api.shopify.ShopifyProductAPI Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of shopify-admin-rest Show documentation
Show all versions of shopify-admin-rest Show documentation
Shopify Admin REST API using JDK 11 and Reactive Programming
The newest version!
package com.dft.api.shopify;
import com.dft.api.shopify.model.Pagination;
import com.dft.api.shopify.model.ShopifyProduct;
import com.dft.api.shopify.model.auth.AccessCredential;
import com.dft.api.shopify.model.product.ShopifyProductWrapper;
import lombok.SneakyThrows;
import java.net.URI;
import java.net.http.HttpRequest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import static com.dft.api.shopify.constantcode.ConstantCodes.HTTPS;
import static com.dft.api.shopify.constantcode.ConstantCodes.PRODUCTS_END_POINT_WITH_JSON;
import static com.dft.api.shopify.constantcode.ConstantCodes.VERSION_2023_01;
import static com.dft.api.shopify.constantcode.ConstantCodes.DEFAULT_REQUEST_LIMIT;
import static com.dft.api.shopify.constantcode.ConstantCodes.LIMIT;
import static com.dft.api.shopify.constantcode.ConstantCodes.PAGE_INFO;
public class ShopifyProductAPI extends ShopifySdkNew {
public ShopifyProductAPI(AccessCredential accessCredential) {
super(accessCredential);
}
@SneakyThrows
public ShopifyProductWrapper getProducts(HashMap params) {
URI uri = addParameters(new URI(HTTPS + accessCredential.getStoreDomain() + VERSION_2023_01 + PRODUCTS_END_POINT_WITH_JSON), params);
HttpRequest request = get(uri);
return getRequestWrapped(request, ShopifyProductWrapper.class);
}
public List getAllProducts() {
HashMap params = new HashMap<>();
params.put(LIMIT, DEFAULT_REQUEST_LIMIT);
ShopifyProductWrapper shopifyProductWrapper = getProducts(params);
List shopifyProductList = new ArrayList<>(shopifyProductWrapper.getProducts());
Pagination pagination = shopifyProductWrapper.getPagination();
while (pagination.getNext() != null) {
params.put(PAGE_INFO, pagination.getNext());
shopifyProductWrapper = getProducts(params);
shopifyProductList.addAll(shopifyProductWrapper.getProducts());
pagination = shopifyProductWrapper.getPagination();
}
return shopifyProductList;
}
}