require 'fanforce/utils' module Fanforce::Api::Utils include Fanforce::Utils extend Fanforce::Api::Utils def self.included(base) base.extend(self) end def valid_fanforce_js_request?(params=@params) return false if !params.is_a?(Hash) return false if is_blank?(params[:fanforce_id]) or is_blank?(params[:api_key]) return true end def valid_fanforce_request?(params=@params) return false if !params.is_a?(Hash) return false if is_blank?(params[:fanforce_id]) return false if is_blank?(params[:app_id]) and is_blank?(params[:behavior_plugin_id]) and is_blank?(params[:plugin_id]) and is_blank?(params[:widget_id]) return true end def valid_install_request?(params=@params) return false if !params.is_a?(Hash) return false if is_blank?(params[:fanforce_id]) return false if is_blank?(params[:app_id]) and is_blank?(params[:behavior_plugin_id]) and is_blank?(params[:plugin_id]) and is_blank?(params[:widget_id]) return false if is_blank?(params[:api_key]) return true end def valid_uninstall_request?(params=@params) return false if !params.is_a?(Hash) return false if is_blank?(params[:fanforce_id]) return false if is_blank?(params[:app_id]) and is_blank?(params[:behavior_plugin_id]) and is_blank?(params[:plugin_id]) and is_blank?(params[:widget_id]) return false if is_blank?(params[:api_key]) return true end def remove_nil_values(hash) hash.clone.delete_if {|k,v| v.nil? } end def collect_known_params(params) params = params.symbolize_keys if is_present?(params[:app_id]) addon_type = :app addon_id = params[:app_id] elsif is_present?(params[:behavior_plugin_id]) addon_type = :plugin addon_id = params[:behavior_plugin_id] elsif is_present?(params[:plugin_id]) addon_type = :plugin addon_id = params[:plugin_id] elsif is_present?(params[:widget_id]) addon_type = :widget addon_id = params[:widget_id] end remove_nil_values(:"#{addon_type}_id" => params[:"#{addon_type}_id"], addon_type: addon_type, addon_id: addon_id, fanforce_id: params[:fanforce_id], fanforce_slug: params[:fanforce_slug], api_key: params[:api_key], session_id: params[:session_id]) end def remove_internal_params(params) params.clone.delete_if { |k,v| [:app_id, :behavior_plugin_id, :plugin_id, :widget_id, :addon_type, :addon_id, :fanforce_id, :fanforce_slug, :api_key].include? k } end def remove_sensitive_params(params) params.clone.delete_if { |k,v| [:api_key].include? k } end end