class ThreeTapsAPI::Search
Attributes
location[RW]
parameters[R]
postings[R]
Public Class Methods
new(args = {})
click to toggle source
# File lib/three_taps_api/search.rb, line 17 def initialize(args = {}) @parameters = args @location = Location.new(args.delete(:location) || {}) @postings = OpenStruct.new #args.delete :location args.each do |k, v| create_getter_and_setter k if ThreeTapsAPI.valid_parameter? k.to_s self.send "#{k.to_s}=", v end end
Public Instance Methods
create_getter_and_setter(name)
click to toggle source
# File lib/three_taps_api/search.rb, line 10 def create_getter_and_setter(name) get = Proc.new { instance_variable_get "@#{name}" } set = Proc.new { |val| instance_variable_set "@#{name}", val; @parameters[name.to_sym] = val } self.class.send :define_method, "#{name}", get self.class.send :define_method, "#{name}=", set end
method_missing(name, *args, &block)
click to toggle source
# File lib/three_taps_api/search.rb, line 38 def method_missing(name, *args, &block) # TODO: return if not a setter function name = name.to_s.chop if name.to_s.reverse[0] == '=' p "#{name} is not a valid parameter." and return if ThreeTapsAPI.invalid_parameter? name @parameters[name.to_sym] = args[0] create_getter_and_setter name self.send "#{name.to_s}=".to_sym, args[0] end
search()
click to toggle source
# File lib/three_taps_api/search.rb, line 30 def search opts = {} opts.merge!(auth_token_hash) .merge!(@parameters) @results = self.class.get self.class.base_uri, { query: opts } @postings = @results.parsed_response['postings'].map { |p| ThreeTapsAPI.rec_hash_to_openstruct p } end