Skip to content
Browse files

Merge pull request #69 from Shopify/bugfix/encode_decode_activeresour…

…ce_versions

Bugfix/encode decode activeresource versions
  • Loading branch information...
2 parents 5c36ccb + 4d35518 commit a291fc837fc668c45ee58c151b73355f02ef41cc @costford costford committed
Showing with 18 additions and 16 deletions.
  1. +3 −6 CHANGELOG
  2. +14 −9 lib/shopify_api/resources/base.rb
  3. +1 −1 lib/shopify_api/version.rb
View
9 CHANGELOG
@@ -1,14 +1,11 @@
-== Version 3.1.1
+== Version 3.1.2
* Includes port in domain URI (when other than http/80 or https/443)
* Adds access to CustomerSavedSearch
* Adds resources: Order::DefaultAddress, Client::ClientDetails, Announcement
* Allows access to Articles without a blog_id
-* Qualifies and scopes encode/decode changes in ActiveResource 3.0, 3.1, 3.2, 4.0
-
-== Version 3.1.0
-
-* Expose the `order` action in SmartCollection for general use
+* Moves encode and as_json overrides to ShopifyAPI::Base scope
+* Exposes the `order` action in SmartCollection for general use
== Version 3.0.3
View
23 lib/shopify_api/resources/base.rb
@@ -3,20 +3,25 @@
module ShopifyAPI
class Base < ActiveResource::Base
extend Countable
- self.include_root_in_json = true
+ self.include_root_in_json = false
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'
- def encode(options = {})
- same = dup
- same.attributes = {self.class.element_name => same.attributes} if self.class.format.extension == 'json'
-
- same.send("to_#{self.class.format.extension}", options)
+ same.send("to_#{self.class.format.extension}", options)
+ end
+
+ def as_json(options = nil)
+ root = options[:root] if options.try(:key?, :root)
+ if include_root_in_json
+ root = self.class.model_name.element if root == true
+ { root => serializable_hash(options) }
+ else
+ serializable_hash(options)
end
end
View
2 lib/shopify_api/version.rb
@@ -1,3 +1,3 @@
module ShopifyAPI
- VERSION = "3.1.1"
+ VERSION = "3.1.2"
end

0 comments on commit a291fc8

Please sign in to comment.
Something went wrong with that request. Please try again.