fanforce-base 1.2.3 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0c7c06328df60900994a9fbd1ccca3943ebc6cdc
4
- data.tar.gz: b33eb607565c95f517c0f46b7bbb633c2132ee9f
3
+ metadata.gz: 35cb24522fef11bc78e979e89f12426ee56a5d21
4
+ data.tar.gz: 41ee6031a00df9eea1a228a691e5c399fc38b38d
5
5
  SHA512:
6
- metadata.gz: 25eb80e3f29ae1f07b84e4af731138351b42f6a006ae2d77e2270ad7984bd8869cb3c7063b8318304fe27fd24556639d6d0064e3f1f10a81debcdf1847e72760
7
- data.tar.gz: 09d51992b3356d02037b2afec4ae336a3add9f3f7de0eff6da3d48e9a83b3e5bd9a5cd710c726b19eb8620f10c5e639262d07370d4a1b4cbae97fe5c67892c8c
6
+ metadata.gz: 4d48e6a7d74d0a2ca6232b59997c907a698693e9ad26623ce3a52d01b5d28d635da5050c445ea15855405b9b333addd306c943970b0a2e87a41d2ce573cfe4f2
7
+ data.tar.gz: ea901ee15248766f9028c2b4d7d353e6592f346e95b7dd8535bb3d6a5d69d0e1f7252938870455016418fd7546bb1eb4ddc34b8224b4bfcd3053645438f14b05
@@ -19,15 +19,15 @@ module Fanforce::Base::InternalUtils
19
19
 
20
20
  def self.to_param(obj, namespace=nil)
21
21
  if obj.is_a?(Array)
22
- collect { |e| to_param(e) }.join '/'
22
+ obj.collect { |e| to_param(e) }.join '/'
23
23
  elsif obj.is_a?(Hash)
24
24
  to_query_string(obj, namespace)
25
25
  elsif obj.is_a?(NilClass)
26
- obj
26
+ obj.to_s
27
27
  elsif obj.is_a?(TrueClass)
28
- obj
28
+ obj.to_s
29
29
  elsif obj.is_a?(FalseClass)
30
- obj
30
+ obj.to_s
31
31
  elsif obj.is_a?(Object)
32
32
  obj.to_s
33
33
  end
@@ -78,18 +78,30 @@ module Fanforce::Base::Utils
78
78
  end
79
79
  end
80
80
 
81
- def to_query_string(obj, namespace=nil)
82
- return '' if is_blank?(obj)
83
- if obj.is_a?(Array)
84
- obj.collect { |value| to_query_string(value, "#{namespace}[]") }.join '&'
85
- elsif obj.is_a?(Hash)
86
- obj.collect { |key, value| to_query_string(value, namespace ? "#{namespace}[#{key}]" : key) }.sort * '&'
87
- elsif obj.is_a?(Object)
88
- "#{CGI.escape(Fanforce::Base::InternalUtils.to_param(namespace))}=#{CGI.escape(Fanforce::Base::InternalUtils.to_param(obj).to_s)}"
89
- else
90
- raise "Argument must be an object, hash, or array; instead it was a #{obj.class}"
81
+ # Lifted from Rack::Utils.build_nested_query
82
+ #
83
+ def build_nested_query(value, prefix = nil)
84
+ case value
85
+ when Array
86
+ value.map { |v|
87
+ build_nested_query(v, "#{prefix}[]")
88
+ }.join("&")
89
+ when Hash
90
+ value.map { |k, v|
91
+ build_nested_query(v, prefix ? "#{prefix}[#{escape(k)}]" : escape(k))
92
+ }.reject(&:empty?).join('&')
93
+ when nil
94
+ prefix
95
+ else
96
+ raise ArgumentError, "value must be a Hash" if prefix.nil?
97
+ "#{prefix}=#{escape(value)}"
91
98
  end
92
99
  end
100
+ alias_method :to_query_string, :build_nested_query
101
+
102
+ def escape(s)
103
+ CGI.escape(Fanforce::Base::InternalUtils.to_param(s))
104
+ end
93
105
 
94
106
  def curl_command(method, url, req_params)
95
107
  case method.to_s.downcase.to_sym
@@ -1,5 +1,5 @@
1
1
  class Fanforce
2
2
  class Base
3
- VERSION = '1.2.3'
3
+ VERSION = '1.3.0'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fanforce-base
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.3
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Caleb Clark
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-30 00:00:00.000000000 Z
11
+ date: 2015-01-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack