Shopify / shopify-api-ruby

ShopifyAPI is a lightweight gem for accessing the Shopify admin REST and GraphQL web services.
MIT License
1.06k stars 469 forks source link

Create Hashes in Object instances with_indifferent_access #1296

Closed DaveEshopGuide closed 3 months ago

DaveEshopGuide commented 7 months ago

Overview

Enable indifferent access on all Hashes in Shopify Objects

The proposed change involves modifying the create_instances_from_response method in the ShopifyAPI::Rest::Base class to use with_indifferent_access on the body hash. This change allows for accessing the hash keys as either strings or symbols interchangeably. This feature would be beneficial for the following reasons:
Flexibility: It provides flexibility in accessing hash keys, which can be particularly useful when dealing with JSON responses where keys can be either strings or symbols.
Error Prevention: It can help prevent potential key access errors that might occur due to mismatched key types.
Consistency: It aligns with the Rails convention of indifferent access, providing a more consistent experience for developers

We ran into this upgrading beyond V10 where we had to restructure a lot of Code and Factories in Specs for the Shopify Objects were Producing Hashes with symbol access while the "real" objects come with string keys.

If there is no strong reason against it I would be happy to see indifferent_access on the Shopify objects or at least a config parameter to enable this analog to "response_as_struct"

sle-c commented 7 months ago

Hi @DaveEshopGuide , thank you for creating this issue. We'll look into this and prioritize it accordingly. Given that this is a minor issue, this may take us some time to get to it.

elizasorber commented 6 months ago

Hi, I'm looking into making my first contribution. Could I work on this issue?

sle-c commented 6 months ago

hi @elizasorber , please go ahead, we always welcome contributions from the community 🎉

lizkenyon commented 3 months ago

Closed with https://github.com/Shopify/shopify-api-ruby/pull/1308