Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/encode decode activeresource versions #69

Merged
merged 2 commits into from Oct 29, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 3 additions & 6 deletions 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

Expand Down
23 changes: 14 additions & 9 deletions lib/shopify_api/resources/base.rb
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion lib/shopify_api/version.rb
@@ -1,3 +1,3 @@
module ShopifyAPI
VERSION = "3.1.1"
VERSION = "3.1.2"
end