shopify
shopify copied to clipboard
Getting resources that don't necessarily match Resources / NestedResource
I'm trying to call: https://help.shopify.com/en/api/reference/sales-channels/collectionlisting#product_ids and would love to use this lib to do this.
It doesn't seem like its supported, nor is it clear how to add support for this. the product_ids in the response data doesn't really match to a resource struct.
Hmm, how should we do this... You think just returning a list would be appropriate?
Shopify.CollectionListing.get_product_ids(session, collection_id)
# => %{product_ids: [123123, 987786, ...]}
@lewisf It's pretty easy to implement, question is should we add a generic section for things that do not really justify a resource struct.
EDIT: What I mean is, are there any other endpoints that return something like this outside of count
? If so, we should probably look into it.
returning a list is good but maybe also in the standard %Shopify.Response struct with code/data?
I just clicked through the api docs there's only one other instance of this: https://help.shopify.com/en/api/reference/sales-channels/productlisting#product_ids
and I also need it :P lucky me I guess?
@Ninigi if you agree then we can move forward with this. so far it doesn't look like there are any other endpoints that return a list of ids, so maybe it makes sense to build a general escape hatch?
here's my quick analysis of the changes that need to be made:
since it seems like this is only local to these resources, we can manually add functions to make the right calls here: https://github.com/nsweeting/shopify/blob/master/lib/shopify/resources/collection_listing.ex https://github.com/nsweeting/shopify/blob/master/lib/shopify/resources/product_listing.ex
we'd also need to overload Shopify.Request.new
to handle the case where resource
isn't specified. Would it be sufficient to pass in nil
as the resource
here? https://github.com/nsweeting/shopify/blob/master/lib/shopify/request.ex#L30-L40
and change Shopify.Response
to handle responses where something other than Shopify.resources are returned as data.
The one thing I think needs to be configured is the "singular" / "plural" of the returned data to handle parsing {product_ids: [...]}
into the proper %Shopify.Response{code: 200, data: [...]}
struct.
@lewisf If you have the time to look into it, it would be very much appreciated 👍
I think it might actually be not that different from a call to the count
resources or spam
in this resource
So it might actually not need many modifications, but if you want to come up with a fancy solution I'll be happy to do a review 👍