From 80087d870484687b8fdba7c90227c925845ae500 Mon Sep 17 00:00:00 2001 From: "Nam.NguyenQuang" Date: Thu, 28 Sep 2023 15:09:50 +0700 Subject: [PATCH 01/17] add theme model --- .../java/com/shopify/model/ShopifyTheme.java | 26 +++++++++++++++++++ .../com/shopify/model/ShopifyThemeRoot.java | 14 ++++++++++ .../com/shopify/model/ShopifyThemesRoot.java | 16 ++++++++++++ 3 files changed, 56 insertions(+) create mode 100644 src/main/java/com/shopify/model/ShopifyTheme.java create mode 100644 src/main/java/com/shopify/model/ShopifyThemeRoot.java create mode 100644 src/main/java/com/shopify/model/ShopifyThemesRoot.java diff --git a/src/main/java/com/shopify/model/ShopifyTheme.java b/src/main/java/com/shopify/model/ShopifyTheme.java new file mode 100644 index 00000000..bb7fa99a --- /dev/null +++ b/src/main/java/com/shopify/model/ShopifyTheme.java @@ -0,0 +1,26 @@ +package com.shopify.model; + +import com.shopify.model.adapters.DateTimeAdapter; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; +import org.joda.time.DateTime; + +@XmlRootElement +public class ShopifyTheme { + @XmlElement(name = "created_at") + @XmlJavaTypeAdapter(DateTimeAdapter.class) + private DateTime createdAt; + public int id; + public String name; + public boolean previewable; + public boolean processing; + public String role; + public String src; + public int themeStoreId; + @XmlElement(name = "updated_at") + @XmlJavaTypeAdapter(DateTimeAdapter.class) + private DateTime updatedAt; + private String adminGraphqlApiId; + +} diff --git a/src/main/java/com/shopify/model/ShopifyThemeRoot.java b/src/main/java/com/shopify/model/ShopifyThemeRoot.java new file mode 100644 index 00000000..4410cf61 --- /dev/null +++ b/src/main/java/com/shopify/model/ShopifyThemeRoot.java @@ -0,0 +1,14 @@ +package com.shopify.model; + +public class ShopifyThemeRoot { + + private ShopifyTheme customer; + + public void setCustomer(ShopifyTheme customer) { + this.customer = customer; + } + + public ShopifyTheme getCustomer() { + return customer; + } +} diff --git a/src/main/java/com/shopify/model/ShopifyThemesRoot.java b/src/main/java/com/shopify/model/ShopifyThemesRoot.java new file mode 100644 index 00000000..f47b259b --- /dev/null +++ b/src/main/java/com/shopify/model/ShopifyThemesRoot.java @@ -0,0 +1,16 @@ +package com.shopify.model; + +import java.util.List; + +public class ShopifyThemesRoot { + + private List customer; + + public List getCustomer() { + return customer; + } + + public void setCustomer(List customer) { + this.customer = customer; + } +} From 4b9d501fc9f9f3640abb4756f20a6f1bb452482e Mon Sep 17 00:00:00 2001 From: "Nam.NguyenQuang" Date: Thu, 28 Sep 2023 17:16:09 +0700 Subject: [PATCH 02/17] add themes api --- src/main/java/com/shopify/Main.java | 20 ++++ src/main/java/com/shopify/ShopifySdk.java | 30 ++++++ .../java/com/shopify/model/ShopifyTheme.java | 95 +++++++++++++++++-- .../com/shopify/model/ShopifyThemesRoot.java | 10 +- 4 files changed, 143 insertions(+), 12 deletions(-) create mode 100644 src/main/java/com/shopify/Main.java diff --git a/src/main/java/com/shopify/Main.java b/src/main/java/com/shopify/Main.java new file mode 100644 index 00000000..70f28d47 --- /dev/null +++ b/src/main/java/com/shopify/Main.java @@ -0,0 +1,20 @@ +package com.shopify; + +import com.shopify.model.ShopifyProduct; +import com.shopify.model.ShopifyProducts; +import com.shopify.model.ShopifyShop; +import com.shopify.model.ShopifyTheme; +import java.util.List; + +public class Main { + public static void main(String[] args){ + + final ShopifySdk shopifySdk = ShopifySdk.newBuilder() + .withSubdomain("sukiyu09.myshopify.com") + .withAccessToken("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").build(); + System.out.println(shopifySdk.getShop().getShop().getName()); + +// final ShopifyProducts products = shopifySdk.getShop() +// System.out.println(products.size()); + } +} diff --git a/src/main/java/com/shopify/ShopifySdk.java b/src/main/java/com/shopify/ShopifySdk.java index dff77ff1..e06ef093 100644 --- a/src/main/java/com/shopify/ShopifySdk.java +++ b/src/main/java/com/shopify/ShopifySdk.java @@ -1,5 +1,7 @@ package com.shopify; +import com.shopify.model.ShopifyTheme; +import com.shopify.model.ShopifyThemesRoot; import java.net.URI; import java.util.Arrays; import java.util.LinkedList; @@ -133,6 +135,7 @@ public class ShopifySdk { static final String REVOKE = "revoke"; static final String ACCESS_TOKEN = "access_token"; static final String PRODUCTS = "products"; + static final String THEMES = "themes"; static final String VARIANTS = "variants"; static final String CUSTOM_COLLECTIONS = "custom_collections"; static final String RECURRING_APPLICATION_CHARGES = "recurring_application_charges"; @@ -481,6 +484,29 @@ public ShopifyProducts getProducts() { } return new ShopifyProducts(shopifyProducts); } + public List getThemes() { + final List shopifyThemes = new LinkedList<>(); + + ShopifyPage shopifyThemesPage = getThemes(DEFAULT_REQUEST_LIMIT); + LOGGER.info("Retrieved {} themes from first page", shopifyThemesPage.size()); + shopifyThemes.addAll(shopifyThemesPage); + while (shopifyThemesPage.getNextPageInfo() != null) { + shopifyThemesPage = getThemes(shopifyThemesPage.getNextPageInfo(), DEFAULT_REQUEST_LIMIT); + LOGGER.info("Retrieved {} themes from page {}", shopifyThemesPage.size(), + shopifyThemesPage.getNextPageInfo()); + shopifyThemes.addAll(shopifyThemesPage); + } + return shopifyThemes; + } + public ShopifyPage getThemes(final int pageSize) { + return this.getThemes(null, pageSize); + } + public ShopifyPage getThemes(final String pageInfo, final int pageSize) { + final Response response = get(getWebTarget().path(THEMES).queryParam(LIMIT_QUERY_PARAMETER, pageSize) + .queryParam(PAGE_INFO_QUERY_PARAMETER, pageInfo)); + final ShopifyThemesRoot shopifyThemesRoot = response.readEntity(ShopifyThemesRoot.class); + return mapPagedResponse(shopifyThemesRoot.getThemes(), response); + } public int getProductCount() { final Response response = get(getWebTarget().path(PRODUCTS).path(COUNT)); @@ -953,6 +979,10 @@ private ShopifyPage getCustomers(final Response response) { final ShopifyCustomersRoot shopifyCustomersRootResponse = response.readEntity(ShopifyCustomersRoot.class); return mapPagedResponse(shopifyCustomersRootResponse.getCustomers(), response); } + private ShopifyPage getThemes(final Response response) { + final ShopifyThemesRoot shopifyThemesRootResponse = response.readEntity(ShopifyThemesRoot.class); + return mapPagedResponse(shopifyThemesRootResponse.getThemes(), response); + } private ShopifyRefund calculateRefund(final ShopifyRefundCreationRequest shopifyRefundCreationRequest) { final ShopifyRefundRoot shopifyRefundRoot = new ShopifyRefundRoot(); diff --git a/src/main/java/com/shopify/model/ShopifyTheme.java b/src/main/java/com/shopify/model/ShopifyTheme.java index bb7fa99a..cb963738 100644 --- a/src/main/java/com/shopify/model/ShopifyTheme.java +++ b/src/main/java/com/shopify/model/ShopifyTheme.java @@ -11,16 +11,97 @@ public class ShopifyTheme { @XmlElement(name = "created_at") @XmlJavaTypeAdapter(DateTimeAdapter.class) private DateTime createdAt; - public int id; - public String name; - public boolean previewable; - public boolean processing; - public String role; - public String src; - public int themeStoreId; + private int id; + private String name; + private boolean previewable; + private boolean processing; + private String role; + private String src; + @XmlElement(name = "theme_store_id") + private int themeStoreId; @XmlElement(name = "updated_at") @XmlJavaTypeAdapter(DateTimeAdapter.class) private DateTime updatedAt; + @XmlElement(name = "admin_graphql_api_id") private String adminGraphqlApiId; + public DateTime getCreatedAt() { + return createdAt; + } + + public void setCreatedAt(DateTime createdAt) { + this.createdAt = createdAt; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public boolean isPreviewable() { + return previewable; + } + + public void setPreviewable(boolean previewable) { + this.previewable = previewable; + } + + public boolean isProcessing() { + return processing; + } + + public void setProcessing(boolean processing) { + this.processing = processing; + } + + public String getRole() { + return role; + } + + public void setRole(String role) { + this.role = role; + } + + public String getSrc() { + return src; + } + + public void setSrc(String src) { + this.src = src; + } + + public int getThemeStoreId() { + return themeStoreId; + } + + public void setThemeStoreId(int themeStoreId) { + this.themeStoreId = themeStoreId; + } + + public DateTime getUpdatedAt() { + return updatedAt; + } + + public void setUpdatedAt(DateTime updatedAt) { + this.updatedAt = updatedAt; + } + + public String getAdminGraphqlApiId() { + return adminGraphqlApiId; + } + + public void setAdminGraphqlApiId(String adminGraphqlApiId) { + this.adminGraphqlApiId = adminGraphqlApiId; + } } diff --git a/src/main/java/com/shopify/model/ShopifyThemesRoot.java b/src/main/java/com/shopify/model/ShopifyThemesRoot.java index f47b259b..5721c932 100644 --- a/src/main/java/com/shopify/model/ShopifyThemesRoot.java +++ b/src/main/java/com/shopify/model/ShopifyThemesRoot.java @@ -4,13 +4,13 @@ public class ShopifyThemesRoot { - private List customer; + private List themes; - public List getCustomer() { - return customer; + public List getThemes() { + return themes; } - public void setCustomer(List customer) { - this.customer = customer; + public void setThemes(List themes) { + this.themes = themes; } } From 4d27ed57a76eab7830ad9e8bf4b97076d122d532 Mon Sep 17 00:00:00 2001 From: "nam.nguyen" Date: Fri, 29 Sep 2023 00:09:16 +0700 Subject: [PATCH 03/17] test and fix access token --- src/main/java/com/shopify/Main.java | 24 +++++++++++++++---- .../java/com/shopify/model/ShopifyTheme.java | 12 +++++----- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/shopify/Main.java b/src/main/java/com/shopify/Main.java index 70f28d47..fdf43f21 100644 --- a/src/main/java/com/shopify/Main.java +++ b/src/main/java/com/shopify/Main.java @@ -4,15 +4,31 @@ import com.shopify.model.ShopifyProducts; import com.shopify.model.ShopifyShop; import com.shopify.model.ShopifyTheme; + +import javax.net.ssl.HttpsURLConnection; +import javax.net.ssl.SSLContext; +import javax.net.ssl.TrustManager; +import javax.net.ssl.X509TrustManager; +import java.security.KeyManagementException; +import java.security.NoSuchAlgorithmException; +import java.security.cert.CertificateException; +import java.security.cert.X509Certificate; import java.util.List; +import java.util.concurrent.TimeUnit; public class Main { + public static void main(String[] args){ + final ShopifySdk shopifySdk = ShopifySdk.newBuilder().withSubdomain("sukiyu09").withAccessToken("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") + .withMinimumRequestRetryRandomDelay(200, TimeUnit.MILLISECONDS) + .withMaximumRequestRetryTimeout(225, TimeUnit.MILLISECONDS) + .withConnectionTimeout(500, TimeUnit.MILLISECONDS).build(); +// final ShopifySdk shopifySdk = ShopifySdk.newBuilder().withSubdomain +// ("sukiyu09") +// .withAccessToken("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").build(); +//// - final ShopifySdk shopifySdk = ShopifySdk.newBuilder() - .withSubdomain("sukiyu09.myshopify.com") - .withAccessToken("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").build(); - System.out.println(shopifySdk.getShop().getShop().getName()); + System.out.println(shopifySdk.getThemes()); // final ShopifyProducts products = shopifySdk.getShop() // System.out.println(products.size()); diff --git a/src/main/java/com/shopify/model/ShopifyTheme.java b/src/main/java/com/shopify/model/ShopifyTheme.java index cb963738..a8b25c2d 100644 --- a/src/main/java/com/shopify/model/ShopifyTheme.java +++ b/src/main/java/com/shopify/model/ShopifyTheme.java @@ -11,14 +11,14 @@ public class ShopifyTheme { @XmlElement(name = "created_at") @XmlJavaTypeAdapter(DateTimeAdapter.class) private DateTime createdAt; - private int id; + private String id; private String name; private boolean previewable; private boolean processing; private String role; private String src; @XmlElement(name = "theme_store_id") - private int themeStoreId; + private String themeStoreId; @XmlElement(name = "updated_at") @XmlJavaTypeAdapter(DateTimeAdapter.class) private DateTime updatedAt; @@ -33,11 +33,11 @@ public void setCreatedAt(DateTime createdAt) { this.createdAt = createdAt; } - public int getId() { + public String getId() { return id; } - public void setId(int id) { + public void setId(String id) { this.id = id; } @@ -81,11 +81,11 @@ public void setSrc(String src) { this.src = src; } - public int getThemeStoreId() { + public String getThemeStoreId() { return themeStoreId; } - public void setThemeStoreId(int themeStoreId) { + public void setThemeStoreId(String themeStoreId) { this.themeStoreId = themeStoreId; } From c668ec5fb88a7485078966379930050e67d88369 Mon Sep 17 00:00:00 2001 From: "Nam.NguyenQuang" Date: Fri, 29 Sep 2023 14:57:27 +0700 Subject: [PATCH 04/17] add assets api --- src/main/java/com/shopify/Main.java | 28 +---- src/main/java/com/shopify/ShopifySdk.java | 43 +++++-- .../com/shopify/model/ShopifyAssertsRoot.java | 20 ++++ .../java/com/shopify/model/ShopifyAsset.java | 105 ++++++++++++++++++ .../com/shopify/model/ShopifyAssetRoot.java | 14 +++ .../com/shopify/model/ShopifyThemeRoot.java | 14 --- 6 files changed, 180 insertions(+), 44 deletions(-) create mode 100644 src/main/java/com/shopify/model/ShopifyAssertsRoot.java create mode 100644 src/main/java/com/shopify/model/ShopifyAsset.java create mode 100644 src/main/java/com/shopify/model/ShopifyAssetRoot.java delete mode 100644 src/main/java/com/shopify/model/ShopifyThemeRoot.java diff --git a/src/main/java/com/shopify/Main.java b/src/main/java/com/shopify/Main.java index fdf43f21..7154f650 100644 --- a/src/main/java/com/shopify/Main.java +++ b/src/main/java/com/shopify/Main.java @@ -1,18 +1,6 @@ package com.shopify; -import com.shopify.model.ShopifyProduct; -import com.shopify.model.ShopifyProducts; -import com.shopify.model.ShopifyShop; -import com.shopify.model.ShopifyTheme; - -import javax.net.ssl.HttpsURLConnection; -import javax.net.ssl.SSLContext; -import javax.net.ssl.TrustManager; -import javax.net.ssl.X509TrustManager; -import java.security.KeyManagementException; -import java.security.NoSuchAlgorithmException; -import java.security.cert.CertificateException; -import java.security.cert.X509Certificate; +import java.util.stream.Collectors; import java.util.List; import java.util.concurrent.TimeUnit; @@ -23,14 +11,10 @@ public static void main(String[] args){ .withMinimumRequestRetryRandomDelay(200, TimeUnit.MILLISECONDS) .withMaximumRequestRetryTimeout(225, TimeUnit.MILLISECONDS) .withConnectionTimeout(500, TimeUnit.MILLISECONDS).build(); -// final ShopifySdk shopifySdk = ShopifySdk.newBuilder().withSubdomain -// ("sukiyu09") -// .withAccessToken("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").build(); -//// - - System.out.println(shopifySdk.getThemes()); - -// final ShopifyProducts products = shopifySdk.getShop() -// System.out.println(products.size()); + List ids = shopifySdk.getThemes().stream().map(x -> x.getId()).collect(Collectors.toList()); + System.out.println(shopifySdk.getThemes().stream().map(x -> x.getId()).collect(Collectors.toList())); + String key = shopifySdk.getAssets(ids.get(0)).get(100).getKey(); + System.out.println(key); + System.out.println(shopifySdk.getAsset("97060814984",key ).getValue()); } } diff --git a/src/main/java/com/shopify/ShopifySdk.java b/src/main/java/com/shopify/ShopifySdk.java index e06ef093..e76d0041 100644 --- a/src/main/java/com/shopify/ShopifySdk.java +++ b/src/main/java/com/shopify/ShopifySdk.java @@ -1,5 +1,8 @@ package com.shopify; +import com.shopify.model.ShopifyAssertsRoot; +import com.shopify.model.ShopifyAsset; +import com.shopify.model.ShopifyAssetRoot; import com.shopify.model.ShopifyTheme; import com.shopify.model.ShopifyThemesRoot; import java.net.URI; @@ -136,6 +139,7 @@ public class ShopifySdk { static final String ACCESS_TOKEN = "access_token"; static final String PRODUCTS = "products"; static final String THEMES = "themes"; + static final String ASSETS = "assets"; static final String VARIANTS = "variants"; static final String CUSTOM_COLLECTIONS = "custom_collections"; static final String RECURRING_APPLICATION_CHARGES = "recurring_application_charges"; @@ -156,6 +160,7 @@ public class ShopifySdk { static final String INVENTORY_LEVELS = "inventory_levels"; static final String JSON = ".json"; static final String LIMIT_QUERY_PARAMETER = "limit"; + static final String ASSET_KEY_PARAMETER="asset[key]"; static final String PAGE_INFO_QUERY_PARAMETER = "page_info"; static final String STATUS_QUERY_PARAMETER = "status"; static final String ANY_STATUSES = "any"; @@ -178,6 +183,7 @@ public class ShopifySdk { private static final String AUTHORIZATION_CODE = "code"; private static final int DEFAULT_REQUEST_LIMIT = 50; + private static final int MAX_REQUEST_LIMIT = 250; private static final int TOO_MANY_REQUESTS_STATUS_CODE = 429; private static final int UNPROCESSABLE_ENTITY_STATUS_CODE = 422; private static final int LOCKED_STATUS_CODE = 423; @@ -486,12 +492,11 @@ public ShopifyProducts getProducts() { } public List getThemes() { final List shopifyThemes = new LinkedList<>(); - - ShopifyPage shopifyThemesPage = getThemes(DEFAULT_REQUEST_LIMIT); + ShopifyPage shopifyThemesPage = getThemes(MAX_REQUEST_LIMIT); LOGGER.info("Retrieved {} themes from first page", shopifyThemesPage.size()); shopifyThemes.addAll(shopifyThemesPage); while (shopifyThemesPage.getNextPageInfo() != null) { - shopifyThemesPage = getThemes(shopifyThemesPage.getNextPageInfo(), DEFAULT_REQUEST_LIMIT); + shopifyThemesPage = getThemes(shopifyThemesPage.getNextPageInfo(), MAX_REQUEST_LIMIT); LOGGER.info("Retrieved {} themes from page {}", shopifyThemesPage.size(), shopifyThemesPage.getNextPageInfo()); shopifyThemes.addAll(shopifyThemesPage); @@ -507,7 +512,33 @@ public ShopifyPage getThemes(final String pageInfo, final int page final ShopifyThemesRoot shopifyThemesRoot = response.readEntity(ShopifyThemesRoot.class); return mapPagedResponse(shopifyThemesRoot.getThemes(), response); } - + public ShopifyAsset getAsset(String themeId, String assetKey) { + final Response response = get(getWebTarget().path(THEMES).path(themeId).path(ASSETS).queryParam(ASSET_KEY_PARAMETER,assetKey)); + final ShopifyAssetRoot shopifyAssetRootResponse = response.readEntity(ShopifyAssetRoot.class); + return shopifyAssetRootResponse.getAsset(); + } + public List getAssets(String themeId) { + final List shopifyAssets = new LinkedList<>(); + ShopifyPage shopifyAssetsPage = getAssets(MAX_REQUEST_LIMIT, themeId); + LOGGER.info("Retrieved {} assets from first page", shopifyAssetsPage.size()); + shopifyAssets.addAll(shopifyAssetsPage); + while (shopifyAssetsPage.getNextPageInfo() != null) { + shopifyAssetsPage = getAssets(shopifyAssetsPage.getNextPageInfo(), MAX_REQUEST_LIMIT, themeId); + LOGGER.info("Retrieved {} assets from page {}", shopifyAssetsPage.size(), + shopifyAssetsPage.getNextPageInfo()); + shopifyAssets.addAll(shopifyAssetsPage); + } + return shopifyAssets; + } + public ShopifyPage getAssets(final String pageInfo, final int pageSize, String themeId) { + final Response response = get(getWebTarget().path(THEMES).path(themeId).path(ASSETS).queryParam(LIMIT_QUERY_PARAMETER, pageSize) + .queryParam(PAGE_INFO_QUERY_PARAMETER, pageInfo)); + final ShopifyAssertsRoot shopifyAsseRoot = response.readEntity(ShopifyAssertsRoot.class); + return mapPagedResponse(shopifyAsseRoot.getAssets(), response); + } + public ShopifyPage getAssets(final int pageSize, String themeId) { + return this.getAssets(null, pageSize, themeId); + } public int getProductCount() { final Response response = get(getWebTarget().path(PRODUCTS).path(COUNT)); final Count count = response.readEntity(Count.class); @@ -979,10 +1010,6 @@ private ShopifyPage getCustomers(final Response response) { final ShopifyCustomersRoot shopifyCustomersRootResponse = response.readEntity(ShopifyCustomersRoot.class); return mapPagedResponse(shopifyCustomersRootResponse.getCustomers(), response); } - private ShopifyPage getThemes(final Response response) { - final ShopifyThemesRoot shopifyThemesRootResponse = response.readEntity(ShopifyThemesRoot.class); - return mapPagedResponse(shopifyThemesRootResponse.getThemes(), response); - } private ShopifyRefund calculateRefund(final ShopifyRefundCreationRequest shopifyRefundCreationRequest) { final ShopifyRefundRoot shopifyRefundRoot = new ShopifyRefundRoot(); diff --git a/src/main/java/com/shopify/model/ShopifyAssertsRoot.java b/src/main/java/com/shopify/model/ShopifyAssertsRoot.java new file mode 100644 index 00000000..ed9c67f3 --- /dev/null +++ b/src/main/java/com/shopify/model/ShopifyAssertsRoot.java @@ -0,0 +1,20 @@ +package com.shopify.model; + +import java.util.LinkedList; +import java.util.List; + +import javax.xml.bind.annotation.XmlRootElement; + +@XmlRootElement +public class ShopifyAssertsRoot { + + private List assets = new LinkedList<>(); + + public List getAssets() { + return assets; + } + + public void setAssets(List assets) { + this.assets = assets; + } +} diff --git a/src/main/java/com/shopify/model/ShopifyAsset.java b/src/main/java/com/shopify/model/ShopifyAsset.java new file mode 100644 index 00000000..a9db5c03 --- /dev/null +++ b/src/main/java/com/shopify/model/ShopifyAsset.java @@ -0,0 +1,105 @@ +package com.shopify.model; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +@XmlRootElement +@XmlAccessorType(XmlAccessType.FIELD) +public class ShopifyAsset { + private String attachment; + private String checksum; + @XmlElement(name = "content_type") + private String contentType; + private String created_at; + private String key; + @XmlElement(name = "public_url") + private String publicUrl; + private Long size; + @XmlElement(name = "theme_id") + private Long themeId; + @XmlElement(name = "update_at") + private String updatedAt; + private String value; + + public String getAttachment() { + return attachment; + } + + public void setAttachment(String attachment) { + this.attachment = attachment; + } + + public String getChecksum() { + return checksum; + } + + public void setChecksum(String checksum) { + this.checksum = checksum; + } + + public String getContentType() { + return contentType; + } + + public void setContentType(String contentType) { + this.contentType = contentType; + } + + public String getCreated_at() { + return created_at; + } + + public void setCreated_at(String created_at) { + this.created_at = created_at; + } + + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } + + public String getPublicUrl() { + return publicUrl; + } + + public void setPublicUrl(String publicUrl) { + this.publicUrl = publicUrl; + } + + public Long getSize() { + return size; + } + + public void setSize(Long size) { + this.size = size; + } + + public Long getThemeId() { + return themeId; + } + + public void setThemeId(Long themeId) { + this.themeId = themeId; + } + + public String getUpdatedAt() { + return updatedAt; + } + + public void setUpdatedAt(String updatedAt) { + this.updatedAt = updatedAt; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } +} diff --git a/src/main/java/com/shopify/model/ShopifyAssetRoot.java b/src/main/java/com/shopify/model/ShopifyAssetRoot.java new file mode 100644 index 00000000..6f6cbb85 --- /dev/null +++ b/src/main/java/com/shopify/model/ShopifyAssetRoot.java @@ -0,0 +1,14 @@ +package com.shopify.model; + +public class ShopifyAssetRoot { + + private ShopifyAsset asset; + + public ShopifyAsset getAsset() { + return asset; + } + + public void setAsset(ShopifyAsset asset) { + this.asset = asset; + } +} diff --git a/src/main/java/com/shopify/model/ShopifyThemeRoot.java b/src/main/java/com/shopify/model/ShopifyThemeRoot.java deleted file mode 100644 index 4410cf61..00000000 --- a/src/main/java/com/shopify/model/ShopifyThemeRoot.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.shopify.model; - -public class ShopifyThemeRoot { - - private ShopifyTheme customer; - - public void setCustomer(ShopifyTheme customer) { - this.customer = customer; - } - - public ShopifyTheme getCustomer() { - return customer; - } -} From 385caddfe267ef509e71d1241ad796fddd66ee4e Mon Sep 17 00:00:00 2001 From: "Nam.NguyenQuang" Date: Fri, 29 Sep 2023 17:13:17 +0700 Subject: [PATCH 05/17] add webhook api --- src/main/java/com/shopify/ShopifySdk.java | 35 ++++++ .../com/shopify/model/ShopifyWebhook.java | 116 ++++++++++++++++++ .../com/shopify/model/ShopifyWebhookRoot.java | 17 +++ .../shopify/model/ShopifyWebhooksRoot.java | 18 +++ 4 files changed, 186 insertions(+) create mode 100644 src/main/java/com/shopify/model/ShopifyWebhook.java create mode 100644 src/main/java/com/shopify/model/ShopifyWebhookRoot.java create mode 100644 src/main/java/com/shopify/model/ShopifyWebhooksRoot.java diff --git a/src/main/java/com/shopify/ShopifySdk.java b/src/main/java/com/shopify/ShopifySdk.java index e76d0041..f03b3701 100644 --- a/src/main/java/com/shopify/ShopifySdk.java +++ b/src/main/java/com/shopify/ShopifySdk.java @@ -5,6 +5,8 @@ import com.shopify.model.ShopifyAssetRoot; import com.shopify.model.ShopifyTheme; import com.shopify.model.ShopifyThemesRoot; +import com.shopify.model.ShopifyWebhook; +import com.shopify.model.ShopifyWebhookRoot; import java.net.URI; import java.util.Arrays; import java.util.LinkedList; @@ -140,6 +142,7 @@ public class ShopifySdk { static final String PRODUCTS = "products"; static final String THEMES = "themes"; static final String ASSETS = "assets"; + static final String WEBHOOKS = "webhooks"; static final String VARIANTS = "variants"; static final String CUSTOM_COLLECTIONS = "custom_collections"; static final String RECURRING_APPLICATION_CHARGES = "recurring_application_charges"; @@ -539,6 +542,38 @@ public ShopifyPage getAssets(final String pageInfo, final int page public ShopifyPage getAssets(final int pageSize, String themeId) { return this.getAssets(null, pageSize, themeId); } + public ShopifyWebhookRoot createWebhook(ShopifyWebhookRoot request) { + final Response response = post(getWebTarget().path(WEBHOOKS), request); + final ShopifyWebhookRoot result = response.readEntity(ShopifyWebhookRoot.class); + return result; + } + public ShopifyWebhookRoot getWebooks() { + final Response response = get(getWebTarget().path(WEBHOOKS).path()); + final ShopifyWebhookRoot result = response.readEntity(ShopifyWebhookRoot.class); + return result; + } + public List getWebhooks() { + final List shopifyWebhooks = new LinkedList<>(); + ShopifyPage shopifyWebhooksPage = getWebhooks(MAX_REQUEST_LIMIT); + LOGGER.info("Retrieved {} Webhooks from first page", shopifyWebhooksPage.size()); + shopifyWebhooks.addAll(shopifyWebhooksPage); + while (shopifyWebhooksPage.getNextPageInfo() != null) { + shopifyWebhooksPage = getWebhooks(shopifyWebhooksPage.getNextPageInfo(), MAX_REQUEST_LIMIT); + LOGGER.info("Retrieved {} Webhooks from page {}", shopifyWebhooksPage.size(), + shopifyWebhooksPage.getNextPageInfo()); + shopifyWebhooks.addAll(shopifyWebhooksPage); + } + return shopifyWebhooks; + } + public ShopifyPage getAssets(final String pageInfo, final int pageSize, String themeId) { + final Response response = get(getWebTarget().path(THEMES).path(themeId).path(ASSETS).queryParam(LIMIT_QUERY_PARAMETER, pageSize) + .queryParam(PAGE_INFO_QUERY_PARAMETER, pageInfo)); + final ShopifyAssertsRoot shopifyAsseRoot = response.readEntity(ShopifyAssertsRoot.class); + return mapPagedResponse(shopifyAsseRoot.getAssets(), response); + } + public ShopifyPage getAssets(final int pageSize, String themeId) { + return this.getAssets(null, pageSize, themeId); + } public int getProductCount() { final Response response = get(getWebTarget().path(PRODUCTS).path(COUNT)); final Count count = response.readEntity(Count.class); diff --git a/src/main/java/com/shopify/model/ShopifyWebhook.java b/src/main/java/com/shopify/model/ShopifyWebhook.java new file mode 100644 index 00000000..f56f1a10 --- /dev/null +++ b/src/main/java/com/shopify/model/ShopifyWebhook.java @@ -0,0 +1,116 @@ +package com.shopify.model; + +import com.shopify.model.adapters.DateTimeAdapter; +import java.math.BigDecimal; + +import java.util.List; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlTransient; +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; + +import com.shopify.model.adapters.EscapedStringAdapter; +import com.shopify.model.adapters.InventoryPolicyAdapter; +import org.joda.time.DateTime; + +@XmlRootElement +@XmlAccessorType(XmlAccessType.FIELD) +public class ShopifyWebhook { + + private String id; + private String address; + private String topic; + private String api_version; + private String created_at; + private String fields; + private String format; + @XmlElement(name = "metafield_namespaces") + private List metafieldNamespaces; + @XmlElement(name = "private_metafield_namespaces") + private List privateMetafieldNamespaces; + @XmlElement(name = "updated_at") + @XmlJavaTypeAdapter(DateTimeAdapter.class) + private DateTime updatedAt; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + + public String getTopic() { + return topic; + } + + public void setTopic(String topic) { + this.topic = topic; + } + + public String getApi_version() { + return api_version; + } + + public void setApi_version(String api_version) { + this.api_version = api_version; + } + + public String getCreated_at() { + return created_at; + } + + public void setCreated_at(String created_at) { + this.created_at = created_at; + } + + public String getFields() { + return fields; + } + + public void setFields(String fields) { + this.fields = fields; + } + + public String getFormat() { + return format; + } + + public void setFormat(String format) { + this.format = format; + } + + public List getMetafieldNamespaces() { + return metafieldNamespaces; + } + + public void setMetafieldNamespaces(List metafieldNamespaces) { + this.metafieldNamespaces = metafieldNamespaces; + } + + public List getPrivateMetafieldNamespaces() { + return privateMetafieldNamespaces; + } + + public void setPrivateMetafieldNamespaces(List privateMetafieldNamespaces) { + this.privateMetafieldNamespaces = privateMetafieldNamespaces; + } + + public DateTime getUpdatedAt() { + return updatedAt; + } + + public void setUpdatedAt(DateTime updatedAt) { + this.updatedAt = updatedAt; + } +} diff --git a/src/main/java/com/shopify/model/ShopifyWebhookRoot.java b/src/main/java/com/shopify/model/ShopifyWebhookRoot.java new file mode 100644 index 00000000..d549c418 --- /dev/null +++ b/src/main/java/com/shopify/model/ShopifyWebhookRoot.java @@ -0,0 +1,17 @@ +package com.shopify.model; + +import javax.xml.bind.annotation.XmlRootElement; + +@XmlRootElement +public class ShopifyWebhookRoot { + + private ShopifyWebhook webhook; + + public ShopifyWebhook getWebhook() { + return webhook; + } + + public void setWebhook(ShopifyWebhook webhook) { + this.webhook = webhook; + } +} diff --git a/src/main/java/com/shopify/model/ShopifyWebhooksRoot.java b/src/main/java/com/shopify/model/ShopifyWebhooksRoot.java new file mode 100644 index 00000000..1e2345bc --- /dev/null +++ b/src/main/java/com/shopify/model/ShopifyWebhooksRoot.java @@ -0,0 +1,18 @@ +package com.shopify.model; + +import java.util.List; +import javax.xml.bind.annotation.XmlRootElement; + +@XmlRootElement +public class ShopifyWebhooksRoot { + + private List webhooks; + + public List getWebhooks() { + return webhooks; + } + + public void setWebhooks(List webhooks) { + this.webhooks = webhooks; + } +} From 561d8b474e2474c8dd584d237007c25408e68bd9 Mon Sep 17 00:00:00 2001 From: "Nam.NguyenQuang" Date: Mon, 2 Oct 2023 14:54:11 +0700 Subject: [PATCH 06/17] add webhook api --- src/main/java/com/shopify/ShopifySdk.java | 32 ++++++++++++++--------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/shopify/ShopifySdk.java b/src/main/java/com/shopify/ShopifySdk.java index f03b3701..4b3df3cf 100644 --- a/src/main/java/com/shopify/ShopifySdk.java +++ b/src/main/java/com/shopify/ShopifySdk.java @@ -7,6 +7,7 @@ import com.shopify.model.ShopifyThemesRoot; import com.shopify.model.ShopifyWebhook; import com.shopify.model.ShopifyWebhookRoot; +import com.shopify.model.ShopifyWebhooksRoot; import java.net.URI; import java.util.Arrays; import java.util.LinkedList; @@ -542,15 +543,22 @@ public ShopifyPage getAssets(final String pageInfo, final int page public ShopifyPage getAssets(final int pageSize, String themeId) { return this.getAssets(null, pageSize, themeId); } - public ShopifyWebhookRoot createWebhook(ShopifyWebhookRoot request) { - final Response response = post(getWebTarget().path(WEBHOOKS), request); + public ShopifyWebhook createWebhook(ShopifyWebhook request) { + final ShopifyWebhookRoot webhookRoot = new ShopifyWebhookRoot(); + webhookRoot.setWebhook(request); + final Response response = post(getWebTarget().path(WEBHOOKS), webhookRoot); final ShopifyWebhookRoot result = response.readEntity(ShopifyWebhookRoot.class); - return result; + return result.getWebhook(); } - public ShopifyWebhookRoot getWebooks() { - final Response response = get(getWebTarget().path(WEBHOOKS).path()); + public ShopifyWebhook getWeebhook(String webhookId) { + final Response response = get(getWebTarget().path(WEBHOOKS).path(webhookId)); final ShopifyWebhookRoot result = response.readEntity(ShopifyWebhookRoot.class); - return result; + return result.getWebhook(); + } + + public boolean deleteWebhook(final String webhookId) { + final Response response = delete(getWebTarget().path(WEBHOOKS).path(webhookId)); + return Status.OK.getStatusCode() == response.getStatus(); } public List getWebhooks() { final List shopifyWebhooks = new LinkedList<>(); @@ -565,14 +573,14 @@ public List getWebhooks() { } return shopifyWebhooks; } - public ShopifyPage getAssets(final String pageInfo, final int pageSize, String themeId) { - final Response response = get(getWebTarget().path(THEMES).path(themeId).path(ASSETS).queryParam(LIMIT_QUERY_PARAMETER, pageSize) + public ShopifyPage getWebhooks(final String pageInfo, final int pageSize) { + final Response response = get(getWebTarget().path(WEBHOOKS).queryParam(LIMIT_QUERY_PARAMETER, pageSize) .queryParam(PAGE_INFO_QUERY_PARAMETER, pageInfo)); - final ShopifyAssertsRoot shopifyAsseRoot = response.readEntity(ShopifyAssertsRoot.class); - return mapPagedResponse(shopifyAsseRoot.getAssets(), response); + final ShopifyWebhooksRoot shopifyWebhooksRoot = response.readEntity(ShopifyWebhooksRoot.class); + return mapPagedResponse(shopifyWebhooksRoot.getWebhooks(), response); } - public ShopifyPage getAssets(final int pageSize, String themeId) { - return this.getAssets(null, pageSize, themeId); + public ShopifyPage getWebhooks(final int pageSize) { + return this.getWebhooks(null, pageSize); } public int getProductCount() { final Response response = get(getWebTarget().path(PRODUCTS).path(COUNT)); From b13df414c43dc7d0788f0c20d4dd64edfc6481f8 Mon Sep 17 00:00:00 2001 From: "Nam.NguyenQuang" Date: Mon, 2 Oct 2023 15:10:28 +0700 Subject: [PATCH 07/17] add webhook api --- src/main/java/com/shopify/Main.java | 16 +++++++++++----- .../java/com/shopify/model/ShopifyWebhook.java | 6 +++--- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/shopify/Main.java b/src/main/java/com/shopify/Main.java index 7154f650..04cfe44a 100644 --- a/src/main/java/com/shopify/Main.java +++ b/src/main/java/com/shopify/Main.java @@ -1,5 +1,6 @@ package com.shopify; +import com.shopify.model.ShopifyWebhook; import java.util.stream.Collectors; import java.util.List; import java.util.concurrent.TimeUnit; @@ -11,10 +12,15 @@ public static void main(String[] args){ .withMinimumRequestRetryRandomDelay(200, TimeUnit.MILLISECONDS) .withMaximumRequestRetryTimeout(225, TimeUnit.MILLISECONDS) .withConnectionTimeout(500, TimeUnit.MILLISECONDS).build(); - List ids = shopifySdk.getThemes().stream().map(x -> x.getId()).collect(Collectors.toList()); - System.out.println(shopifySdk.getThemes().stream().map(x -> x.getId()).collect(Collectors.toList())); - String key = shopifySdk.getAssets(ids.get(0)).get(100).getKey(); - System.out.println(key); - System.out.println(shopifySdk.getAsset("97060814984",key ).getValue()); + ShopifyWebhook request = new ShopifyWebhook(); + request.setAddress("https://google.com.vn"); + request.setFormat("json"); + request.setTopic("app/uninstalled"); + shopifySdk.createWebhook(request); + List ids = shopifySdk.getWebhooks().stream().map(x -> x.getId()).collect(Collectors.toList()); + System.out.println(ids); + shopifySdk.deleteWebhook(ids.get(0)); + List ids1 = shopifySdk.getWebhooks().stream().map(x -> x.getId()).collect(Collectors.toList()); + System.out.println(ids1); } } diff --git a/src/main/java/com/shopify/model/ShopifyWebhook.java b/src/main/java/com/shopify/model/ShopifyWebhook.java index f56f1a10..77453698 100644 --- a/src/main/java/com/shopify/model/ShopifyWebhook.java +++ b/src/main/java/com/shopify/model/ShopifyWebhook.java @@ -24,7 +24,7 @@ public class ShopifyWebhook { private String topic; private String api_version; private String created_at; - private String fields; + private List fields; private String format; @XmlElement(name = "metafield_namespaces") private List metafieldNamespaces; @@ -74,11 +74,11 @@ public void setCreated_at(String created_at) { this.created_at = created_at; } - public String getFields() { + public List getFields() { return fields; } - public void setFields(String fields) { + public void setFields(List fields) { this.fields = fields; } From cdd857f212ccf23aaef0fd7d6ea3ca4923f01405 Mon Sep 17 00:00:00 2001 From: "Nam.NguyenQuang" Date: Mon, 2 Oct 2023 15:25:52 +0700 Subject: [PATCH 08/17] delete test class --- src/main/java/com/shopify/Main.java | 26 -------------------------- 1 file changed, 26 deletions(-) delete mode 100644 src/main/java/com/shopify/Main.java diff --git a/src/main/java/com/shopify/Main.java b/src/main/java/com/shopify/Main.java deleted file mode 100644 index 04cfe44a..00000000 --- a/src/main/java/com/shopify/Main.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.shopify; - -import com.shopify.model.ShopifyWebhook; -import java.util.stream.Collectors; -import java.util.List; -import java.util.concurrent.TimeUnit; - -public class Main { - - public static void main(String[] args){ - final ShopifySdk shopifySdk = ShopifySdk.newBuilder().withSubdomain("sukiyu09").withAccessToken("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") - .withMinimumRequestRetryRandomDelay(200, TimeUnit.MILLISECONDS) - .withMaximumRequestRetryTimeout(225, TimeUnit.MILLISECONDS) - .withConnectionTimeout(500, TimeUnit.MILLISECONDS).build(); - ShopifyWebhook request = new ShopifyWebhook(); - request.setAddress("https://google.com.vn"); - request.setFormat("json"); - request.setTopic("app/uninstalled"); - shopifySdk.createWebhook(request); - List ids = shopifySdk.getWebhooks().stream().map(x -> x.getId()).collect(Collectors.toList()); - System.out.println(ids); - shopifySdk.deleteWebhook(ids.get(0)); - List ids1 = shopifySdk.getWebhooks().stream().map(x -> x.getId()).collect(Collectors.toList()); - System.out.println(ids1); - } -} From 3fa1078e11813d2ed831cb44d94d57f3f26db3ec Mon Sep 17 00:00:00 2001 From: Son Chu Thai Date: Mon, 2 Oct 2023 18:31:05 +0700 Subject: [PATCH 09/17] Fix Object Mapper Bug --- pom.xml | 9 +++++++-- src/main/java/com/shopify/ShopifySdk.java | 7 ++----- .../shopify/mappers/ObjectMapperProvider.java | 19 +++++++++++++++++++ 3 files changed, 28 insertions(+), 7 deletions(-) create mode 100644 src/main/java/com/shopify/mappers/ObjectMapperProvider.java diff --git a/pom.xml b/pom.xml index 4363d975..d8ebcf9c 100644 --- a/pom.xml +++ b/pom.xml @@ -58,7 +58,7 @@ 1.8 4.13.1 1.7.22 - 2.25.1 + 2.33 1.4.3 0.8.2 @@ -74,10 +74,15 @@ jersey-client ${jersey.version} + + org.glassfish.jersey.inject + jersey-hk2 + ${jersey.version} + com.fasterxml.jackson.jaxrs jackson-jaxrs-json-provider - 2.4.0 + 2.12.1 org.glassfish.jersey.media diff --git a/src/main/java/com/shopify/ShopifySdk.java b/src/main/java/com/shopify/ShopifySdk.java index 4b3df3cf..ad72395d 100644 --- a/src/main/java/com/shopify/ShopifySdk.java +++ b/src/main/java/com/shopify/ShopifySdk.java @@ -1,5 +1,6 @@ package com.shopify; +import com.shopify.mappers.ObjectMapperProvider; import com.shopify.model.ShopifyAssertsRoot; import com.shopify.model.ShopifyAsset; import com.shopify.model.ShopifyAssetRoot; @@ -1241,11 +1242,7 @@ private WebTarget getWebTarget() { } private static Client buildClient() { - final ObjectMapper mapper = ShopifySdkObjectMapper.buildMapper(); - final JacksonJaxbJsonProvider provider = new JacksonJaxbJsonProvider(); - provider.setMapper(mapper); - - return ClientBuilder.newClient().register(JacksonFeature.class).register(provider); + return ClientBuilder.newClient().register(JacksonFeature.class).register(ObjectMapperProvider.class); } public class ShopifySdkRetryListener implements RetryListener { diff --git a/src/main/java/com/shopify/mappers/ObjectMapperProvider.java b/src/main/java/com/shopify/mappers/ObjectMapperProvider.java new file mode 100644 index 00000000..aa4e5b3e --- /dev/null +++ b/src/main/java/com/shopify/mappers/ObjectMapperProvider.java @@ -0,0 +1,19 @@ +package com.shopify.mappers; + +import com.fasterxml.jackson.databind.ObjectMapper; +import javax.ws.rs.ext.ContextResolver; +import javax.ws.rs.ext.Provider; + +@Provider +public class ObjectMapperProvider implements ContextResolver { + private final ObjectMapper objectMapper; + + public ObjectMapperProvider() { + objectMapper = ShopifySdkObjectMapper.buildMapper(); + } + + @Override + public ObjectMapper getContext(Class aClass) { + return objectMapper; + } +} From 21223d623fd27f7db379710839a7a993ec898958 Mon Sep 17 00:00:00 2001 From: "Nam.NguyenQuang" Date: Thu, 5 Oct 2023 15:51:56 +0700 Subject: [PATCH 10/17] fix data type for datetime --- src/main/java/com/shopify/Main.java | 26 ++++++++++++ .../java/com/shopify/model/ShopifyAsset.java | 41 +++++++++++-------- 2 files changed, 50 insertions(+), 17 deletions(-) create mode 100644 src/main/java/com/shopify/Main.java diff --git a/src/main/java/com/shopify/Main.java b/src/main/java/com/shopify/Main.java new file mode 100644 index 00000000..e18e9b61 --- /dev/null +++ b/src/main/java/com/shopify/Main.java @@ -0,0 +1,26 @@ +package com.shopify; + +import com.shopify.model.ShopifyWebhook; +import java.util.List; +import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; + +public class Main { + + public static void main(String[] args){ + final ShopifySdk shopifySdk = ShopifySdk.newBuilder().withSubdomain("sukiyu09").withAccessToken("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") + .withMinimumRequestRetryRandomDelay(200, TimeUnit.MILLISECONDS) + .withMaximumRequestRetryTimeout(225, TimeUnit.MILLISECONDS) + .withConnectionTimeout(500, TimeUnit.MILLISECONDS).build(); + ShopifyWebhook request = new ShopifyWebhook(); + request.setAddress("https://google.com.vn"); + request.setFormat("json"); + request.setTopic("app/uninstalled"); + shopifySdk.createWebhook(request); + List ids = shopifySdk.getWebhooks().stream().map(x -> x.getId()).collect(Collectors.toList()); + System.out.println(ids); + shopifySdk.deleteWebhook(ids.get(0)); + List ids1 = shopifySdk.getWebhooks().stream().map(x -> x.getId()).collect(Collectors.toList()); + System.out.println(ids1); + } +} diff --git a/src/main/java/com/shopify/model/ShopifyAsset.java b/src/main/java/com/shopify/model/ShopifyAsset.java index a9db5c03..492f7520 100644 --- a/src/main/java/com/shopify/model/ShopifyAsset.java +++ b/src/main/java/com/shopify/model/ShopifyAsset.java @@ -1,9 +1,12 @@ package com.shopify.model; +import com.shopify.model.adapters.DateTimeAdapter; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; +import org.joda.time.DateTime; @XmlRootElement @XmlAccessorType(XmlAccessType.FIELD) @@ -12,7 +15,9 @@ public class ShopifyAsset { private String checksum; @XmlElement(name = "content_type") private String contentType; - private String created_at; + @XmlElement(name = "create_at") + @XmlJavaTypeAdapter(DateTimeAdapter.class) + private DateTime createdAt; private String key; @XmlElement(name = "public_url") private String publicUrl; @@ -20,7 +25,8 @@ public class ShopifyAsset { @XmlElement(name = "theme_id") private Long themeId; @XmlElement(name = "update_at") - private String updatedAt; + @XmlJavaTypeAdapter(DateTimeAdapter.class) + private DateTime updatedAt; private String value; public String getAttachment() { @@ -47,13 +53,6 @@ public void setContentType(String contentType) { this.contentType = contentType; } - public String getCreated_at() { - return created_at; - } - - public void setCreated_at(String created_at) { - this.created_at = created_at; - } public String getKey() { return key; @@ -87,14 +86,6 @@ public void setThemeId(Long themeId) { this.themeId = themeId; } - public String getUpdatedAt() { - return updatedAt; - } - - public void setUpdatedAt(String updatedAt) { - this.updatedAt = updatedAt; - } - public String getValue() { return value; } @@ -102,4 +93,20 @@ public String getValue() { public void setValue(String value) { this.value = value; } + + public DateTime getCreatedAt() { + return createdAt; + } + + public void setCreatedAt(DateTime createdAt) { + this.createdAt = createdAt; + } + + public DateTime getUpdatedAt() { + return updatedAt; + } + + public void setUpdatedAt(DateTime updatedAt) { + this.updatedAt = updatedAt; + } } From f5edade7e799114e0eec0a7e20b188d722e1fac1 Mon Sep 17 00:00:00 2001 From: "Nam.NguyenQuang" Date: Thu, 5 Oct 2023 15:52:24 +0700 Subject: [PATCH 11/17] fix data type for datetime --- src/main/java/com/shopify/Main.java | 26 -------------------------- 1 file changed, 26 deletions(-) delete mode 100644 src/main/java/com/shopify/Main.java diff --git a/src/main/java/com/shopify/Main.java b/src/main/java/com/shopify/Main.java deleted file mode 100644 index e18e9b61..00000000 --- a/src/main/java/com/shopify/Main.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.shopify; - -import com.shopify.model.ShopifyWebhook; -import java.util.List; -import java.util.concurrent.TimeUnit; -import java.util.stream.Collectors; - -public class Main { - - public static void main(String[] args){ - final ShopifySdk shopifySdk = ShopifySdk.newBuilder().withSubdomain("sukiyu09").withAccessToken("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") - .withMinimumRequestRetryRandomDelay(200, TimeUnit.MILLISECONDS) - .withMaximumRequestRetryTimeout(225, TimeUnit.MILLISECONDS) - .withConnectionTimeout(500, TimeUnit.MILLISECONDS).build(); - ShopifyWebhook request = new ShopifyWebhook(); - request.setAddress("https://google.com.vn"); - request.setFormat("json"); - request.setTopic("app/uninstalled"); - shopifySdk.createWebhook(request); - List ids = shopifySdk.getWebhooks().stream().map(x -> x.getId()).collect(Collectors.toList()); - System.out.println(ids); - shopifySdk.deleteWebhook(ids.get(0)); - List ids1 = shopifySdk.getWebhooks().stream().map(x -> x.getId()).collect(Collectors.toList()); - System.out.println(ids1); - } -} From fa78d72bbfc3de4428a4e91643c054fa6536ee85 Mon Sep 17 00:00:00 2001 From: "Nam.NguyenQuang" Date: Thu, 5 Oct 2023 15:56:07 +0700 Subject: [PATCH 12/17] fix data type for datetime --- src/main/java/com/shopify/model/ShopifyAsset.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/shopify/model/ShopifyAsset.java b/src/main/java/com/shopify/model/ShopifyAsset.java index 492f7520..aafaffb6 100644 --- a/src/main/java/com/shopify/model/ShopifyAsset.java +++ b/src/main/java/com/shopify/model/ShopifyAsset.java @@ -15,7 +15,7 @@ public class ShopifyAsset { private String checksum; @XmlElement(name = "content_type") private String contentType; - @XmlElement(name = "create_at") + @XmlElement(name = "created_at") @XmlJavaTypeAdapter(DateTimeAdapter.class) private DateTime createdAt; private String key; @@ -24,7 +24,7 @@ public class ShopifyAsset { private Long size; @XmlElement(name = "theme_id") private Long themeId; - @XmlElement(name = "update_at") + @XmlElement(name = "updated_at") @XmlJavaTypeAdapter(DateTimeAdapter.class) private DateTime updatedAt; private String value; From 4771e1cdb7ff54bfcc060810638301e4faddda33 Mon Sep 17 00:00:00 2001 From: Son Chu Thai Date: Thu, 5 Oct 2023 18:28:00 +0700 Subject: [PATCH 13/17] Typo Error --- src/main/java/com/shopify/ShopifySdk.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/shopify/ShopifySdk.java b/src/main/java/com/shopify/ShopifySdk.java index ad72395d..08cbd8a3 100644 --- a/src/main/java/com/shopify/ShopifySdk.java +++ b/src/main/java/com/shopify/ShopifySdk.java @@ -551,7 +551,7 @@ public ShopifyWebhook createWebhook(ShopifyWebhook request) { final ShopifyWebhookRoot result = response.readEntity(ShopifyWebhookRoot.class); return result.getWebhook(); } - public ShopifyWebhook getWeebhook(String webhookId) { + public ShopifyWebhook getWebhook(String webhookId) { final Response response = get(getWebTarget().path(WEBHOOKS).path(webhookId)); final ShopifyWebhookRoot result = response.readEntity(ShopifyWebhookRoot.class); return result.getWebhook(); From 61777569fb4bd7a219b6b44a29478258ce9fb6df Mon Sep 17 00:00:00 2001 From: "nam.nguyen" Date: Mon, 18 Mar 2024 23:04:32 +0700 Subject: [PATCH 14/17] add api delete charge --- src/main/java/com/shopify/ShopifySdk.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/com/shopify/ShopifySdk.java b/src/main/java/com/shopify/ShopifySdk.java index 08cbd8a3..59da7c9f 100644 --- a/src/main/java/com/shopify/ShopifySdk.java +++ b/src/main/java/com/shopify/ShopifySdk.java @@ -707,6 +707,11 @@ public ShopifyRecurringApplicationCharge createRecurringApplicationCharge( return shopifyRecurringApplicationChargeRootResponse.getRecurringApplicationCharge(); } + public boolean deleteCharge(final String chargeId) { + final Response response = delete(getWebTarget().path(RECURRING_APPLICATION_CHARGES).path(chargeId)); + return Status.OK.getStatusCode() == response.getStatus(); + } + public ShopifyRecurringApplicationCharge getRecurringApplicationCharge(final String chargeId) { final Response response = get(getWebTarget().path(RECURRING_APPLICATION_CHARGES).path(chargeId)); final ShopifyRecurringApplicationChargeRoot shopifyRecurringApplicationChargeRootResponse = response From 3105c257de260a67ff79f093ad93c0f2102cc11c Mon Sep 17 00:00:00 2001 From: "nam.nguyen" Date: Thu, 28 Mar 2024 22:41:10 +0700 Subject: [PATCH 15/17] add create theme api --- src/main/java/com/shopify/ShopifySdk.java | 84 ++----------------- .../com/shopify/model/ShopifyThemeRoot.java | 14 ++++ 2 files changed, 23 insertions(+), 75 deletions(-) create mode 100644 src/main/java/com/shopify/model/ShopifyThemeRoot.java diff --git a/src/main/java/com/shopify/ShopifySdk.java b/src/main/java/com/shopify/ShopifySdk.java index 59da7c9f..b259c088 100644 --- a/src/main/java/com/shopify/ShopifySdk.java +++ b/src/main/java/com/shopify/ShopifySdk.java @@ -1,14 +1,8 @@ package com.shopify; import com.shopify.mappers.ObjectMapperProvider; -import com.shopify.model.ShopifyAssertsRoot; -import com.shopify.model.ShopifyAsset; -import com.shopify.model.ShopifyAssetRoot; -import com.shopify.model.ShopifyTheme; -import com.shopify.model.ShopifyThemesRoot; -import com.shopify.model.ShopifyWebhook; -import com.shopify.model.ShopifyWebhookRoot; -import com.shopify.model.ShopifyWebhooksRoot; +import com.shopify.model.*; + import java.net.URI; import java.util.Arrays; import java.util.LinkedList; @@ -51,73 +45,6 @@ import com.shopify.mappers.LegacyToFulfillmentOrderMapping; import com.shopify.mappers.ResponseEntityToStringMapper; import com.shopify.mappers.ShopifySdkObjectMapper; -import com.shopify.model.Count; -import com.shopify.model.Image; -import com.shopify.model.ImageAltTextCreationRequest; -import com.shopify.model.Metafield; -import com.shopify.model.MetafieldRoot; -import com.shopify.model.MetafieldsRoot; -import com.shopify.model.Shop; -import com.shopify.model.ShopifyAccessTokenRoot; -import com.shopify.model.ShopifyCancelOrderRequest; -import com.shopify.model.ShopifyCustomCollection; -import com.shopify.model.ShopifyCustomCollectionCreationRequest; -import com.shopify.model.ShopifyCustomCollectionRoot; -import com.shopify.model.ShopifyCustomCollectionsRoot; -import com.shopify.model.ShopifyCustomer; -import com.shopify.model.ShopifyCustomerRoot; -import com.shopify.model.ShopifyCustomerUpdateRequest; -import com.shopify.model.ShopifyCustomerUpdateRoot; -import com.shopify.model.ShopifyCustomersRoot; -import com.shopify.model.ShopifyFulfillment; -import com.shopify.model.ShopifyFulfillmentCreationRequest; -import com.shopify.model.ShopifyFulfillmentOrder; -import com.shopify.model.ShopifyFulfillmentOrderMoveRequestRoot; -import com.shopify.model.ShopifyFulfillmentOrderMoveResponseRoot; -import com.shopify.model.ShopifyFulfillmentOrdersRoot; -import com.shopify.model.ShopifyFulfillmentPayloadRoot; -import com.shopify.model.ShopifyFulfillmentRoot; -import com.shopify.model.ShopifyFulfillmentUpdateRequest; -import com.shopify.model.ShopifyGetCustomersRequest; -import com.shopify.model.ShopifyGiftCard; -import com.shopify.model.ShopifyGiftCardCreationRequest; -import com.shopify.model.ShopifyGiftCardRoot; -import com.shopify.model.ShopifyImageRoot; -import com.shopify.model.ShopifyInventoryLevel; -import com.shopify.model.ShopifyInventoryLevelRoot; -import com.shopify.model.ShopifyLocation; -import com.shopify.model.ShopifyLocationsRoot; -import com.shopify.model.ShopifyOrder; -import com.shopify.model.ShopifyOrderCreationRequest; -import com.shopify.model.ShopifyOrderRisk; -import com.shopify.model.ShopifyOrderRisksRoot; -import com.shopify.model.ShopifyOrderRoot; -import com.shopify.model.ShopifyOrderShippingAddressUpdateRequest; -import com.shopify.model.ShopifyOrderUpdateRoot; -import com.shopify.model.ShopifyOrdersRoot; -import com.shopify.model.ShopifyPage; -import com.shopify.model.ShopifyProduct; -import com.shopify.model.ShopifyProductCreationRequest; -import com.shopify.model.ShopifyProductMetafieldCreationRequest; -import com.shopify.model.ShopifyProductRequest; -import com.shopify.model.ShopifyProductRoot; -import com.shopify.model.ShopifyProductUpdateRequest; -import com.shopify.model.ShopifyProducts; -import com.shopify.model.ShopifyProductsRoot; -import com.shopify.model.ShopifyRecurringApplicationCharge; -import com.shopify.model.ShopifyRecurringApplicationChargeCreationRequest; -import com.shopify.model.ShopifyRecurringApplicationChargeRoot; -import com.shopify.model.ShopifyRefund; -import com.shopify.model.ShopifyRefundCreationRequest; -import com.shopify.model.ShopifyRefundRoot; -import com.shopify.model.ShopifyShop; -import com.shopify.model.ShopifyTransaction; -import com.shopify.model.ShopifyTransactionsRoot; -import com.shopify.model.ShopifyUpdateFulfillmentPayloadRoot; -import com.shopify.model.ShopifyVariant; -import com.shopify.model.ShopifyVariantMetafieldCreationRequest; -import com.shopify.model.ShopifyVariantRoot; -import com.shopify.model.ShopifyVariantUpdateRequest; public class ShopifySdk { @@ -544,6 +471,13 @@ public ShopifyPage getAssets(final String pageInfo, final int page public ShopifyPage getAssets(final int pageSize, String themeId) { return this.getAssets(null, pageSize, themeId); } + public ShopifyTheme createTheme(ShopifyTheme request) { + final ShopifyThemeRoot themeRoot = new ShopifyThemeRoot(); + themeRoot.setTheme(request); + final Response response = post(getWebTarget().path(THEMES), themeRoot); + final ShopifyThemeRoot result = response.readEntity(ShopifyThemeRoot.class); + return result.getTheme(); + } public ShopifyWebhook createWebhook(ShopifyWebhook request) { final ShopifyWebhookRoot webhookRoot = new ShopifyWebhookRoot(); webhookRoot.setWebhook(request); diff --git a/src/main/java/com/shopify/model/ShopifyThemeRoot.java b/src/main/java/com/shopify/model/ShopifyThemeRoot.java new file mode 100644 index 00000000..d1ecfd94 --- /dev/null +++ b/src/main/java/com/shopify/model/ShopifyThemeRoot.java @@ -0,0 +1,14 @@ +package com.shopify.model; + +public class ShopifyThemeRoot { + + private ShopifyTheme theme; + + public ShopifyTheme getTheme() { + return theme; + } + + public void setTheme(ShopifyTheme theme) { + this.theme = theme; + } +} From 3ad8c72e480931a129aa8405596a10db55ab2264 Mon Sep 17 00:00:00 2001 From: "nam.nguyen" Date: Thu, 28 Mar 2024 23:04:39 +0700 Subject: [PATCH 16/17] add delete theme api --- src/main/java/com/shopify/ShopifySdk.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/com/shopify/ShopifySdk.java b/src/main/java/com/shopify/ShopifySdk.java index b259c088..856f9fd1 100644 --- a/src/main/java/com/shopify/ShopifySdk.java +++ b/src/main/java/com/shopify/ShopifySdk.java @@ -478,6 +478,10 @@ public ShopifyTheme createTheme(ShopifyTheme request) { final ShopifyThemeRoot result = response.readEntity(ShopifyThemeRoot.class); return result.getTheme(); } + public boolean deleteTheme(final String themeId) { + final Response response = delete(getWebTarget().path(THEMES).path(themeId)); + return Status.OK.getStatusCode() == response.getStatus(); + } public ShopifyWebhook createWebhook(ShopifyWebhook request) { final ShopifyWebhookRoot webhookRoot = new ShopifyWebhookRoot(); webhookRoot.setWebhook(request); From c396374449f5b51ef36c7658f37e768a0c36aa74 Mon Sep 17 00:00:00 2001 From: "nam.nguyenquang" Date: Wed, 19 Mar 2025 21:20:59 +0700 Subject: [PATCH 17/17] ignore test --- pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pom.xml b/pom.xml index d1e3f857..9a690182 100644 --- a/pom.xml +++ b/pom.xml @@ -61,6 +61,7 @@ 2.33 1.4.3 0.8.2 + true