|
@@ -4,6 +4,7 @@ module ShopifyAPI
|
|
class Base < ActiveResource::Base
|
|
class Base < ActiveResource::Base
|
|
class InvalidSessionError < StandardError; end
|
|
class InvalidSessionError < StandardError; end
|
|
extend Countable
|
|
extend Countable
|
|
|
|
+
|
|
self.timeout = 90
|
|
self.timeout = 90
|
|
self.include_root_in_json = false
|
|
self.include_root_in_json = false
|
|
self.headers['User-Agent'] = ["ShopifyAPI/#{ShopifyAPI::VERSION}",
|
|
self.headers['User-Agent'] = ["ShopifyAPI/#{ShopifyAPI::VERSION}",
|
|
@@ -70,16 +71,45 @@ module ShopifyAPI
|
|
end
|
|
end
|
|
|
|
|
|
def prefix(options = {})
|
|
def prefix(options = {})
|
|
- self.prefix = api_prefix
|
|
|
|
- prefix(options)
|
|
|
|
|
|
+ "#{api_prefix}#{resource_prefix(options)}"
|
|
|
|
+ end
|
|
|
|
+
|
|
|
|
+ def prefix_source
|
|
|
|
+ ''
|
|
end
|
|
end
|
|
|
|
|
|
|
|
+ def resource_prefix(_options = {})
|
|
|
|
+ ''
|
|
|
|
+ end
|
|
|
|
+
|
|
|
|
+ # Sets the \prefix for a resource's nested URL (e.g., <tt>prefix/collectionname/1.json</tt>).
|
|
|
|
+ # Default value is <tt>site.path</tt>.
|
|
|
|
+ def resource_prefix=(value)
|
|
|
|
+ @prefix_parameters = nil
|
|
|
|
+
|
|
|
|
+ resource_prefix_call = value.gsub(/:\w+/) { |key| "\#{URI.parser.escape options[#{key}].to_s}" }
|
|
|
|
+
|
|
|
|
+ silence_warnings do
|
|
|
|
+ # Redefine the new methods.
|
|
|
|
+ instance_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
|
|
|
|
+ def prefix_source() "#{value}" end
|
|
|
|
+ def resource_prefix(options={}) "#{resource_prefix_call}" end
|
|
|
|
+ RUBY_EVAL
|
|
|
|
+ end
|
|
|
|
+ rescue => e
|
|
|
|
+ logger&.error("Couldn't set prefix: #{e}\n #{code}")
|
|
|
|
+ raise
|
|
|
|
+ end
|
|
|
|
+
|
|
|
|
+ alias_method :set_prefix, :resource_prefix=
|
|
|
|
+ alias_method :prefix=, :resource_prefix=
|
|
|
|
+
|
|
def init_prefix(resource)
|
|
def init_prefix(resource)
|
|
init_prefix_explicit(resource.to_s.pluralize, "#{resource}_id")
|
|
init_prefix_explicit(resource.to_s.pluralize, "#{resource}_id")
|
|
end
|
|
end
|
|
|
|
|
|
def init_prefix_explicit(resource_type, resource_id)
|
|
def init_prefix_explicit(resource_type, resource_id)
|
|
- self.prefix = "#{api_prefix}#{resource_type}/:#{resource_id}/"
|
|
|
|
|
|
+ self.prefix = "#{resource_type}/:#{resource_id}/"
|
|
|
|
|
|
define_method resource_id.to_sym do
|
|
define_method resource_id.to_sym do
|
|
@prefix_options[resource_id]
|
|
@prefix_options[resource_id]
|