-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmulti-query-param.patch
44 lines (44 loc) · 1.05 KB
/
multi-query-param.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
diff --git a/lib/simplyrets/api_client.rb b/lib/simplyrets/api_client.rb
index 84b814b..678ec23 100644
--- a/lib/simplyrets/api_client.rb
+++ b/lib/simplyrets/api_client.rb
@@ -332,3 +332,39 @@ module SimplyRetsClient
end
end
end
+
+
+# PATCH: array parameter rendering
+#
+# Typheous defaults to rendering array query parameters with
+# an index:
+#
+# ?points[0]=23.232,-98.232&points[1]=23.232,-98.232
+#
+# The simplyrets api uses the form:
+#
+# ?points=23.232,-98.232&points=23.232,-98.232
+#
+# this monkey-patch removes the array index when the query
+# parameter is rendered.
+module Ethon
+ class Easy
+ module Queryable
+ private
+ def recursively_generate_pairs(h, prefix, pairs)
+ case h
+ when Hash
+ h.each_pair do |k,v|
+ key = prefix.nil? ? k : "#{prefix}"
+ pairs_for(v, key, pairs)
+ end
+ when Array
+ h.each_with_index do |v, i|
+ key = "#{prefix}"
+ pairs_for(v, key, pairs)
+ end
+ end
+ end
+ end
+ end
+end