lib/keen/client.rb in keen-0.7.8 vs lib/keen/client.rb in keen-0.8.0
- old
+ new
@@ -1,15 +1,15 @@
require 'keen/http'
require 'keen/version'
require 'keen/client/publishing_methods'
require 'keen/client/querying_methods'
require 'keen/client/maintenance_methods'
-
require 'openssl'
require 'multi_json'
require 'base64'
require 'cgi'
+require 'addressable/uri'
module Keen
class Client
include Keen::Client::PublishingMethods
include Keen::Client::QueryingMethods
@@ -90,36 +90,48 @@
def ensure_read_key!
raise ConfigurationError, "Read Key must be set for queries" unless self.read_key
end
def api_event_collection_resource_path(event_collection)
- "/#{api_version}/projects/#{project_id}/events/#{CGI.escape(event_collection.to_s)}"
+ encoded_collection_name = Addressable::URI.escape(event_collection.to_s)
+ encoded_collection_name.gsub! '/', '%2F'
+ "/#{api_version}/projects/#{project_id}/events/#{encoded_collection_name}"
end
def preprocess_params(params)
- if params.key?(:filters)
- params[:filters] = MultiJson.encode(params[:filters])
- end
+ preprocess_encodables(params)
+ preprocess_timeframe(params)
+ preprocess_group_by(params)
- if params.key?(:steps)
- params[:steps] = MultiJson.encode(params[:steps])
- end
-
- if params.key?(:analyses)
- params[:analyses] = MultiJson.encode(params[:analyses])
- end
-
- if params.key?(:timeframe) && params[:timeframe].is_a?(Hash)
- params[:timeframe] = MultiJson.encode(params[:timeframe])
- end
-
query_params = ""
params.each do |param, value|
query_params << "#{param}=#{CGI.escape(value)}&"
end
query_params.chop!
query_params
+ end
+
+ def preprocess_encodables(params)
+ [:filters, :steps, :analyses].each do |key|
+ if params.key?(key)
+ params[key] = MultiJson.encode(params[key])
+ end
+ end
+ end
+
+ def preprocess_timeframe(params)
+ timeframe = params[:timeframe]
+ if timeframe.is_a?(Hash)
+ params[:timeframe] = MultiJson.encode(timeframe)
+ end
+ end
+
+ def preprocess_group_by(params)
+ group_by = params[:group_by]
+ if group_by.is_a?(Array)
+ params[:group_by] = MultiJson.encode(group_by)
+ end
end
def method_missing(_method, *args, &block)
if config = CONFIG[_method.to_sym]
if config.is_a?(Proc)