module Rsbe::Client::Search
Public Class Methods
search(hsh = {})
click to toggle source
# File lib/rsbe/client/search.rb, line 4 def self.search(hsh = {}) raise ArgumentError.new("These args must be present: #{hsh_valid_keys}") if hsh.empty? @hsh = hsh # check if search params are valid is_valid? @args = hsh[:params] @required_keys = hsh[:required_params] @scope = hsh[:scope] # check search args sent chk_search_args # build query url @search_url = query_search_url query end
Private Class Methods
chk_search_args()
click to toggle source
# File lib/rsbe/client/search.rb, line 43 def self.chk_search_args string_keys? incoming_keys = @args.keys.sort compare_keys(incoming_keys,@required_keys) end
compare_keys(incoming_keys, required_keys)
click to toggle source
# File lib/rsbe/client/search.rb, line 56 def self.compare_keys(incoming_keys, required_keys) unless required_keys.empty? compare_keys = incoming_keys - required_keys raise ArgumentError.new("Required params: #{required_keys}") unless compare_keys.empty? end end
hsh_valid_keys()
click to toggle source
# File lib/rsbe/client/search.rb, line 73 def self.hsh_valid_keys [:params, :required_params, :scope].sort end
is_valid?()
click to toggle source
# File lib/rsbe/client/search.rb, line 63 def self.is_valid? case @hsh.class.to_s when "Hash" incoming_keys = @hsh.keys.sort compare_keys(incoming_keys,hsh_valid_keys) else raise ArgumentError.new("Expecting hash as a arguments with the following arguments: #{hsh_valid_keys}") end end
parameterize_params()
click to toggle source
# File lib/rsbe/client/search.rb, line 34 def self.parameterize_params query_hsh = @args.merge({scope: @scope}) arr = [] query_hsh.each_pair { |q,v| arr << "#{q}=#{v}" } arr.join("&") end
query()
click to toggle source
# File lib/rsbe/client/search.rb, line 25 def self.query conn = Rsbe::Client::Connection.new @response = conn.get @search_url end
query_search_url()
click to toggle source
# File lib/rsbe/client/search.rb, line 19 def self.query_search_url base_url = Rsbe::Client::Base.base_path query_hsh = parameterize_params search_url = "#{base_url}/#{search_url_fragment}?#{query_hsh}" end
search_url_fragment()
click to toggle source
# File lib/rsbe/client/search.rb, line 30 def self.search_url_fragment "search" end
string_keys?()
click to toggle source
# File lib/rsbe/client/search.rb, line 49 def self.string_keys? string_keys = [] @args.keys.each { |k| string_keys << k unless k.is_a?(Symbol) } raise ArgumentError.new("Param key: #{string_keys} should be of type Symbol") if string_keys.size > 0 end