Class: Locu::LocuObject
- Inherits:
-
Object
show all
- Defined in:
- lib/locu_wrapper/locu_object.rb
Instance Method Summary
collapse
Constructor Details
#initialize(host, path, api_key) ⇒ LocuObject
Returns a new instance of LocuObject.
4
5
6
7
|
# File 'lib/locu_wrapper/locu_object.rb', line 4
def initialize(host, path, api_key)
@api_key = api_key
@uri = URI(host+path)
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/locu_wrapper/locu_object.rb', line 15
def method_missing(method, *args, &block)
if method.to_s =~ /^search_by_(.+)$/
attrs = $1.split('_and_')
params = Hash[attrs.zip args]
search_by(params)
else
super
end
end
|
Instance Method Details
#respond_to?(meth) ⇒ Boolean
27
28
29
30
31
32
33
|
# File 'lib/locu_wrapper/locu_object.rb', line 27
def respond_to?(meth)
if meth.to_s =~ /^search_by_.*$/
true
else
super
end
end
|
#search_by(query_params) ⇒ Object
9
10
11
12
13
|
# File 'lib/locu_wrapper/locu_object.rb', line 9
def search_by(query_params)
@uri.query = formulate_query(query_params)
response = Net::HTTP.get_response @uri
parse_response response
end
|