From 51bf780cdbd1cf7e5cab787311b83edbc48a1bb6 Mon Sep 17 00:00:00 2001 From: Eliza Date: Fri, 5 Apr 2024 18:08:08 -0400 Subject: [PATCH 1/3] Tackling issue #1296 Added indifferent access to create_instances_from_response in the ShopifyAPI::Rest::Base class. --- lib/shopify_api/rest/base.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/shopify_api/rest/base.rb b/lib/shopify_api/rest/base.rb index 15035d78..b5b82aeb 100644 --- a/lib/shopify_api/rest/base.rb +++ b/lib/shopify_api/rest/base.rb @@ -2,6 +2,7 @@ # frozen_string_literal: true require "active_support/inflector" +require 'active_support/all' module ShopifyAPI module Rest @@ -248,7 +249,7 @@ def request(http_method:, operation:, session:, ids: {}, params: {}, body: nil, def create_instances_from_response(response:, session:) objects = [] - body = T.cast(response.body, T::Hash[String, T.untyped]) + body = T.cast(response.body, T::Hash[String, T.untyped]).with_indifferent_access response_names = json_response_body_names From 359d9ba32f06baf0124601549c3d471e2f902ccb Mon Sep 17 00:00:00 2001 From: Si Le Date: Mon, 15 Jul 2024 12:07:32 -0400 Subject: [PATCH 2/3] Require specific active support lib --- CHANGELOG.md | 1 + lib/shopify_api/rest/base.rb | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 10c8a398..4fabd444 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ Note: For changes to the API, see https://shopify.dev/changelog?filter=api ## Unreleased - [#1327](https://github.com/Shopify/shopify-api-ruby/pull/1327) Support `?debug=true` parameter in GraphQL client requests +- [#1308](https://github.com/Shopify/shopify-api-ruby/pull/1308) Support hash_with_indifferent_access when creating REST objects from Shopify responses. Closes #1296 ## 14.4.0 diff --git a/lib/shopify_api/rest/base.rb b/lib/shopify_api/rest/base.rb index b5b82aeb..b2bcc52f 100644 --- a/lib/shopify_api/rest/base.rb +++ b/lib/shopify_api/rest/base.rb @@ -2,7 +2,7 @@ # frozen_string_literal: true require "active_support/inflector" -require 'active_support/all' +require "active_support/core_ext/hash/indifferent_access" module ShopifyAPI module Rest From afa7fd64789939d9eb5851409c8d7af2766084a0 Mon Sep 17 00:00:00 2001 From: Si Le Date: Mon, 15 Jul 2024 14:37:40 -0400 Subject: [PATCH 3/3] Adds sorbet shim for Hash --- sorbet/rbi/shims/hash.rb | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 sorbet/rbi/shims/hash.rb diff --git a/sorbet/rbi/shims/hash.rb b/sorbet/rbi/shims/hash.rb new file mode 100644 index 00000000..7da0175c --- /dev/null +++ b/sorbet/rbi/shims/hash.rb @@ -0,0 +1,3 @@ +class Hash + def with_indifferent_access; end +end