lhc 7.1.0 → 7.2.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: ad563c7a18adf9ec842d204bed81599304dac1c4
4
- data.tar.gz: ef62b6ce7f4b80475ee0adbb4c502e6918706d8f
3
+ metadata.gz: 7dd0e9ffa97a410938b008214a1169dd92baad1a
4
+ data.tar.gz: 0c3e70e1aed73f71ab15cc8956f268c95ee4961e
5
5
  SHA512:
6
- metadata.gz: cc1a310cd83690e9aeea40affabae0c47eda9abaccac038efb52440d806cb675b410b4dd0252989e88cb9b529fb6b9d4525029cb63d3a2f2385e3d9ed3750db5
7
- data.tar.gz: 34307e36153349564b30d2e5aeb62aff588911cbcd0bd3646aab83ba0c05b484b39d00c5c6b1bb7774a97ef6e488d984c05b364c150a990939264d8266c10093
6
+ metadata.gz: b7ef93685b6321f92e3d211a15503b34f67acbaa6395ccf866f13b0ad1f03f14b42008a70e350950c124738ecd94e553f9aa0149026cac84b760287a18651be5
7
+ data.tar.gz: e348b6290e471eaec282c9cb883d129284029ea8644b4899fb5288f40c4c96ce24d03fb4c97ba30c1ded064df56945b2b77e96b212c2e24727b29ff606e395c4
data/README.md CHANGED
@@ -98,6 +98,39 @@ Also consider setting the http header for content-type.
98
98
  )
99
99
  ```
100
100
 
101
+ ## Parameter
102
+
103
+ When using LHC, try to pass params via `params` option. It's not recommended to build a url and attach the parameter yourself:
104
+
105
+ DO
106
+ ```ruby
107
+ LHC.get('http://local.ch', params: { q: 'Restaurant' })
108
+ ```
109
+
110
+ DON'T
111
+ ```ruby
112
+ LHC.get('http://local.ch?q=Restaurant')
113
+ ```
114
+
115
+ ## Encoding
116
+
117
+ LHC, by default, encodes urls:
118
+
119
+ ```ruby
120
+ LHC.get('http://local.ch?q=some space')
121
+ # http://local.ch?q=some%20space
122
+
123
+ LHC.get('http://local.ch', params: { q: 'some space' })
124
+ # http://local.ch?q=some%20space
125
+ ```
126
+
127
+ which can be disabled:
128
+
129
+ ```ruby
130
+ LHC.get('http://local.ch?q=some space', url_encoding: false)
131
+ # http://local.ch?q=some space
132
+ ```
133
+
101
134
  ## Configuration
102
135
 
103
136
  You can configure global endpoints, placeholders and interceptors.
data/lib/lhc/request.rb CHANGED
@@ -52,8 +52,13 @@ class LHC::Request
52
52
 
53
53
  attr_accessor :iprocessor
54
54
 
55
+ def optionally_encoded_url(options)
56
+ return options[:url] unless options.fetch(:url_encoding, true)
57
+ encode_url(options[:url])
58
+ end
59
+
55
60
  def create_request
56
- request = Typhoeus::Request.new(encode_url(options[:url]), typhoeusize(options))
61
+ request = Typhoeus::Request.new(optionally_encoded_url(options), typhoeusize(options))
57
62
  request.on_headers do
58
63
  iprocessor.intercept(:after_request, self)
59
64
  iprocessor.intercept(:before_response, self)
data/lib/lhc/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module LHC
2
- VERSION ||= '7.1.0'
2
+ VERSION ||= '7.2.0'
3
3
  end
@@ -18,4 +18,18 @@ describe LHC::Request do
18
18
  LHC.get(url, params: { name: 'My name is rabbit' })
19
19
  end
20
20
  end
21
+
22
+ context 'skip encoding' do
23
+ let(:url) { 'http://local.ch/api/search?names[]=seba&names[]=david' }
24
+
25
+ it 'does not encode if encoding is skipped' do
26
+ stub_request(:get, 'http://local.ch/api/search?names%5B%5D%3Dseba%26names%5B%5D%3Ddavid')
27
+ LHC.get('http://local.ch/api/search?names%5B%5D%3Dseba%26names%5B%5D%3Ddavid', url_encoding: false)
28
+ end
29
+
30
+ it 'does double encoding, if you really want to' do
31
+ stub_request(:get, 'http://local.ch/api/search?names%255B%255D%253Dseba%2526names%255B%255D%253Ddavid')
32
+ LHC.get('http://local.ch/api/search?names%5B%5D%3Dseba%26names%5B%5D%3Ddavid')
33
+ end
34
+ end
21
35
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lhc
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.1.0
4
+ version: 7.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - https://github.com/local-ch/lhc/contributors
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-02-07 00:00:00.000000000 Z
11
+ date: 2018-02-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: typhoeus