resource_accessor 1.2.2 → 1.2.3

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: 6d2d15b6055967cca8b862fd69813d5c8154699e
4
- data.tar.gz: afc9134f365de6600f67232fbc034779b6bb8848
3
+ metadata.gz: 6169d6db0bcfd5e5cf81ae4c8e6e505fc0750753
4
+ data.tar.gz: b34e9360c0a8f64f56d4893069157341ea1444ff
5
5
  SHA512:
6
- metadata.gz: 1e00590a84cfb5c3db0ed097220efd85bb6dd5d2f377582d6fe17623feea583456952e3457af82b1ee28c21487631b11d96bbc056f71e92cd803760cc1af8746
7
- data.tar.gz: cd15639dc413a520b7cbb26c6a9be6a9cc53534dbe12e48650837a0e1acdeefad316250d209323cc0b046b04bfab23b454a268b0afd620adb91700f0eba8e767
6
+ metadata.gz: a33e7e4f12caaeff42aad4933991468617b8ed0d7e883fdab557c8ac3e5920d80934fb12b1b7694c338a8d954324f5e94f1a8de732ea1b6df56502ae9a7f9238
7
+ data.tar.gz: dfdb921a481be36821c21e54103d8e116caf6b0ad2093c3db80eada4fb6a105176aa1ecf6095b2de4837e13e2c8378cfbbc9a937715bd74106380625ece17ce7
data/CHANGES CHANGED
@@ -26,4 +26,8 @@
26
26
 
27
27
  == Version 1.2.2
28
28
 
29
- * Bug fix for 'put' http method.
29
+ * Bug fix for 'put' http method.
30
+
31
+ == Version 1.2.3
32
+
33
+ * Adding escape flag in order to control whether we want to escape parameter or not.
@@ -13,7 +13,7 @@ class ResourceAccessor
13
13
  end
14
14
 
15
15
  def get_response params, headers = {}
16
- locate_response(params[:url], params[:query], params[:method], headers, params[:body], params[:cookie])
16
+ locate_response(params[:url], params[:query], params[:method], headers, params[:body], params[:escape], params[:cookie])
17
17
  end
18
18
 
19
19
  def get_soap_response params, headers = {}
@@ -21,19 +21,19 @@ class ResourceAccessor
21
21
  headers["SOAPAction"] = "" unless headers["SOAPAction"]
22
22
  headers["Content-Type"] = "text/xml;charset=UTF-8" unless headers["Content-Type"]
23
23
 
24
- locate_response(params[:url], params[:query], params[:method], headers, params[:body], params[:cookie])
24
+ locate_response(params[:url], params[:query], params[:method], headers, params[:body], params[:escape], params[:cookie])
25
25
  end
26
26
 
27
27
  def get_ajax_response params, headers = {}
28
28
  headers['X-Requested-With'] = 'XMLHttpRequest'
29
29
 
30
- locate_response(params[:url], params[:query], params[:method], headers, params[:body], params[:cookie])
30
+ locate_response(params[:url], params[:query], params[:method], headers, params[:body], params[:escape], params[:cookie])
31
31
  end
32
32
 
33
33
  def get_json_response params, headers = {}
34
34
  headers["Content-Type"] = "application/json;charset=UTF-8"
35
35
 
36
- locate_response(params[:url], params[:query], params[:method], headers, params[:body], params[:cookie])
36
+ locate_response(params[:url], params[:query], params[:method], headers, params[:body], params[:escape], params[:cookie])
37
37
  end
38
38
 
39
39
  def get_cookie url, user_name, password
@@ -46,25 +46,29 @@ class ResourceAccessor
46
46
  response.response['set-cookie']
47
47
  end
48
48
 
49
- def self.query_from_hash(params)
49
+ def self.query_from_hash(params, escape=true)
50
50
  return nil if params.nil? or params.empty?
51
51
 
52
- params.sort.map {|key, value| "#{key}=#{value.nil? ? '' : CGI.escape(value)}"}.join("&")
52
+ params.sort.map do |key, value|
53
+ new_value = value.nil? ? '' : (escape ? CGI.escape(value) : value)
54
+
55
+ "#{key}=#{new_value}"
56
+ end.join("&")
53
57
  end
54
58
 
55
59
  private
56
60
 
57
- def locate_response url, query, method, headers, body, cookie=nil
58
- response = execute_request url, query, method, headers, body, cookie
61
+ def locate_response url, query, method, headers, body, escape=true, cookie=nil
62
+ response = execute_request url, query, method, headers, body, escape, cookie
59
63
 
60
64
  if response.class == Net::HTTPMovedPermanently
61
- response = execute_request response['location'], method, headers, body, cookie
65
+ response = execute_request response['location'], method, headers, body, escape, cookie
62
66
  end
63
67
 
64
68
  response
65
69
  end
66
70
 
67
- def execute_request url, query, method, headers, body, cookie=nil
71
+ def execute_request url, query, method, headers, body, escape, cookie=nil
68
72
  headers["User-Agent"] = "Ruby/#{RUBY_VERSION}" unless headers["User-Agent"]
69
73
  headers["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8" unless headers["Content-Type"]
70
74
 
@@ -72,8 +76,9 @@ class ResourceAccessor
72
76
  headers['Cookie'] = cookie
73
77
  end
74
78
 
75
- query_string = ResourceAccessor.query_from_hash(query)
79
+ query_string = ResourceAccessor.query_from_hash(query, escape)
76
80
  new_url = query_string.nil? ? url : "#{url}?#{query_string}"
81
+ # new_url = escape ? URI.escape(new_url) : new_url
77
82
 
78
83
  uri = URI.parse(URI.escape(new_url))
79
84
 
@@ -1,3 +1,3 @@
1
1
  class ResourceAccessor
2
- VERSION = "1.2.2"
2
+ VERSION = "1.2.3"
3
3
  end
@@ -28,6 +28,10 @@ describe ResourceAccessor do
28
28
  it "maps properly nil values " do
29
29
  subject.class.query_from_hash({:param1 => nil, :param2 => "A&B", :param3 => "C & D"}).should eql "param1=&param2=A%26B&param3=C+%26+D"
30
30
  end
31
+
32
+ it "does not escapes ampersands if escape is turned off" do
33
+ subject.class.query_from_hash({:name1 => "name 1", :name2 => "name 2"}, false).should eql "name1=name 1&name2=name 2"
34
+ end
31
35
  end
32
36
 
33
37
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: resource_accessor
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.2
4
+ version: 1.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Shvets
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-18 00:00:00.000000000 Z
11
+ date: 2014-03-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gemspec_deps_gen