lib/loquor/api_calls/index.rb in loquor-1.2.1 vs lib/loquor/api_calls/index.rb in loquor-1.3.0
- old
+ new
@@ -1,18 +1,24 @@
module Loquor
class ApiCall::Index < ApiCall
- attr_reader :criteria
+ attr_reader :criteria, :clauses
def initialize(klass)
super(klass)
@criteria = {}
+ @clauses = []
end
- def where(value)
- value.each do |key, value|
- @criteria[key] = value
+ def where(data)
+ case data
+ when String
+ @clauses << data
+ else
+ data.each do |key, value|
+ @criteria[key] = value
+ end
end
self
end
def select(value)
@@ -52,10 +58,14 @@
def generate_url
query_string = []
@criteria.each do |key,value|
add_criteria(query_string, key, value)
end
+ @clauses.each do |clause|
+ add_clause(query_string, clause)
+ end
+
"#{klass.path}?#{query_string.join("&")}"
end
def add_criteria(query_string, key, value)
substitute_value = Loquor.config.substitute_values[value]
@@ -75,8 +85,12 @@
end
else
raise LoquorError.new("Filter values must be strings, arrays or single-depth hashes.")
end
end
+ end
+
+ def add_clause(query_string, clause)
+ query_string << "clauses[]=#{URI.encode(clause.to_s)}"
end
end
end