motion-prime/api_client.rb in motion-prime-1.0.3 vs motion-prime/api_client.rb in motion-prime-1.0.4
- old
+ new
@@ -41,17 +41,16 @@
end
true
end
def page_url(path)
- "#{config.base}#{path}"
+ path_with_base(path, config.base)
end
def resource_url(path)
- # return if path.blank?
base = config.resource_base? ? config.resource_base : config.base
- "#{base}#{path}"
+ path_with_base(path, base)
end
def request(method, path, params = {}, options = {}, &block)
files = params.delete(:_files)
data = request_params(params.merge(access_token: access_token))
@@ -71,11 +70,11 @@
end
end
def request!(method, path, data, files = nil, options = {}, &block)
use_callback = block_given?
- path = "#{config.api_namespace}#{path}" unless path.starts_with?('http')
+ path = path_with_base(path, config.api_namespace)
client_method = files.present? ? :"multipart_#{method}" : method
AFMotion::Client.shared.send client_method, path, data do |response, form_data, progress|
if form_data && files.present?
append_files_to_data(files, form_data)
elsif progress
@@ -129,11 +128,10 @@
user_defaults['api_client_queue'] = queue_list
end
# TODO: temporary solution, add real caching system here
def read_cache(key)
- puts "read cache #{key}"
@cache ||= {}
@cache[key]
end
# TODO: temporary solution, add real caching system here
@@ -141,9 +139,13 @@
@cache ||= {}
@cache[key] = data
end
protected
+ def path_with_base(path, base)
+ path.to_s.starts_with?('http') ? path : "#{base}#{path}"
+ end
+
def allow_queue?(method, path, options)
options[:allow_queue] && config.allow_queue?
end
def allow_cache?(method, path, options)
\ No newline at end of file