Created
July 11, 2017 17:18
-
-
Save joshubrown/d4901eba24e318ad40242462ff8d2cb2 to your computer and use it in GitHub Desktop.
Getting product images URLs and variant prices with the Android Buy SDK
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
GraphClient graphClient = GraphClient.builder(this) | |
.shopDomain(BuildConfig.SHOP_DOMAIN) | |
.accessToken(BuildConfig.API_KEY) | |
.build(); | |
ID id = new ID("Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0Lzk1OTAwMjcyNjY="); | |
Storefront.QueryRootQuery query = Storefront.query(rootQueryBuilder -> | |
rootQueryBuilder | |
.node(id, nodeQuery -> | |
nodeQuery | |
.onProduct(productQuery -> | |
productQuery | |
.images(100, imageConnectionQuery -> imageConnectionQuery | |
.edges(imageEdgeQuery -> imageEdgeQuery | |
.node(imageQuery -> imageQuery | |
.src() | |
) | |
) | |
) | |
.variants(100, variantConnectionQuery -> variantConnectionQuery | |
.edges(variantEdgeQuery -> variantEdgeQuery | |
.node(variantQuery -> variantQuery | |
.price() | |
) | |
) | |
) | |
) | |
) | |
); | |
QueryGraphCall call = graphClient.queryGraph(query); | |
call.enqueue(new GraphCall.Callback<Storefront.QueryRoot>() { | |
@Override | |
public void onResponse(@NonNull GraphResponse<Storefront.QueryRoot> response) { | |
for (Storefront.ImageEdge imageEdge : ((Storefront.Product) response.data().getNode()).getImages().getEdges()) { | |
String src = imageEdge.getNode().getSrc(); | |
Log.i(TAG, src); | |
} | |
for (Storefront.ProductVariantEdge productVariantEdge : ((Storefront.Product) response.data().getNode()).getVariants().getEdges()) { | |
BigDecimal price = productVariantEdge.getNode().getPrice(); | |
Log.i(TAG, (price.toString())); | |
} | |
} | |
@Override | |
public void onFailure(@NonNull GraphError error) { | |
Log.e(TAG, "Failed to execute query", error); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment