Browse Source

include_root_in_json for all but ActiveResource 3.1

Neil Costford 11 years ago
parent
commit
581419c16f
2 changed files with 6 additions and 1 deletions
  1. 2 0
      lib/shopify_api/json_format.rb
  2. 4 1
      lib/shopify_api/resources/base.rb

+ 2 - 0
lib/shopify_api/json_format.rb

@@ -1,4 +1,6 @@
 module ActiveResource
+
+  # ActiveResource 3.1 removes root on decoding, so this patch is only needed in 3.0
   if ActiveResource::VERSION::MAJOR == 3 && ActiveResource::VERSION::MINOR == 0
     module Formats
       module JsonFormat

+ 4 - 1
lib/shopify_api/resources/base.rb

@@ -3,12 +3,15 @@ require 'shopify_api/version'
 module ShopifyAPI
   class Base < ActiveResource::Base
     extend Countable
-    self.include_root_in_json = false
+    self.include_root_in_json = true
     self.headers['User-Agent'] = ["ShopifyAPI/#{ShopifyAPI::VERSION}",
                                   "ActiveResource/#{ActiveResource::VERSION::STRING}",
                                   "Ruby/#{RUBY_VERSION}"].join(' ')
 
+    # this patch only needed until 3.1 because ActiveResouce 3.2 passes :root to as_json (and encode regardless of include_root_in_json)
     if ActiveResource::VERSION::MAJOR == 3 && ActiveResource::VERSION::MINOR <= 1
+      self.include_root_in_json = false
+
       def encode(options = {})
         same = dup
         same.attributes = {self.class.element_name => same.attributes} if self.class.format.extension == 'json'