Does Shopify Order API allows filtering by nested fields?

荒凉一梦 提交于 2019-12-12 10:46:35

问题


I'm using the shopify_api gem.

The API doc shows that you can skinny down a ShopifyAPI::Order response by telling it which fields to return. For example, the following will return only the id attribute, and the shipping_address attribute(s)

ShopifyAPI::Order.find(:all, params: {fields: "id,shipping_address"})

shipping_address happens to be a hash with multiple fields inside it. Is it possible to specify which fields nested within shipping_address to return? e.g.

ShopifyAPI::Order.find(:all, params: {fields: "id,shipping_address['country_code']"})

This might return something like

  #<ShopifyAPI::Order:0x0000010558b348 
    @attributes={
      "id"=>12345678, 
      "shipping_address"=>#<ShopifyAPI::ShippingAddress:0x0000010558aa88 
        @attributes={"country_code"=>"US"}, 
        @prefix_options={}, 
        @persisted=false>
      }, 
    @prefix_options={}, 
    @persisted=true>

I know I can pick that attributes out myself (order.shipping_address.country_code), but this is a more in the interests of 'skinnying down' the response.

Bonus Question 1: What are the perceivable advantages of using the fields parameter?

Bonus Question 2: When (if ever) might Shopify return a nil shipping address?


回答1:


It's usually better to post seperatly for each question, but here's the answers.

  1. No.
  2. If you limit the data being returned it will take less time to generate the response, less data to transfer across the wire and less data for you to parse. This means that it should be faster for you to do an operation. This depends on so many different factors that it's hard to say how much of a performance increase you will reciece. My feeling it is minimal unless you are doing a very large number of requests.
  3. Shipping address may be blank if the order (ie all line items) doesn't require shipping.


来源:https://stackoverflow.com/questions/11382519/does-shopify-order-api-allows-filtering-by-nested-fields

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!