rest-client 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +8 -0
  3. data/.rspec +2 -0
  4. data/.rubocop-disables.yml +384 -0
  5. data/.rubocop.yml +3 -0
  6. data/.travis.yml +48 -0
  7. data/AUTHORS +98 -0
  8. data/Gemfile +11 -0
  9. data/LICENSE +21 -0
  10. data/README.md +784 -0
  11. data/Rakefile +132 -0
  12. data/bin/restclient +92 -0
  13. data/history.md +324 -0
  14. data/lib/rest-client.rb +2 -0
  15. data/lib/rest_client.rb +2 -0
  16. data/lib/restclient.rb +184 -0
  17. data/lib/restclient/abstract_response.rb +226 -0
  18. data/lib/restclient/exceptions.rb +244 -0
  19. data/lib/restclient/params_array.rb +72 -0
  20. data/lib/restclient/payload.rb +209 -0
  21. data/lib/restclient/platform.rb +49 -0
  22. data/lib/restclient/raw_response.rb +38 -0
  23. data/lib/restclient/request.rb +853 -0
  24. data/lib/restclient/resource.rb +168 -0
  25. data/lib/restclient/response.rb +80 -0
  26. data/lib/restclient/utils.rb +235 -0
  27. data/lib/restclient/version.rb +8 -0
  28. data/lib/restclient/windows.rb +8 -0
  29. data/lib/restclient/windows/root_certs.rb +105 -0
  30. data/rest-client.gemspec +31 -0
  31. data/rest-client.windows.gemspec +19 -0
  32. data/spec/helpers.rb +22 -0
  33. data/spec/integration/_lib.rb +1 -0
  34. data/spec/integration/capath_digicert/244b5494.0 +19 -0
  35. data/spec/integration/capath_digicert/81b9768f.0 +19 -0
  36. data/spec/integration/capath_digicert/README +8 -0
  37. data/spec/integration/capath_digicert/digicert.crt +19 -0
  38. data/spec/integration/capath_verisign/415660c1.0 +14 -0
  39. data/spec/integration/capath_verisign/7651b327.0 +14 -0
  40. data/spec/integration/capath_verisign/README +8 -0
  41. data/spec/integration/capath_verisign/verisign.crt +14 -0
  42. data/spec/integration/certs/digicert.crt +19 -0
  43. data/spec/integration/certs/verisign.crt +14 -0
  44. data/spec/integration/httpbin_spec.rb +87 -0
  45. data/spec/integration/integration_spec.rb +125 -0
  46. data/spec/integration/request_spec.rb +127 -0
  47. data/spec/spec_helper.rb +29 -0
  48. data/spec/unit/_lib.rb +1 -0
  49. data/spec/unit/abstract_response_spec.rb +145 -0
  50. data/spec/unit/exceptions_spec.rb +108 -0
  51. data/spec/unit/master_shake.jpg +0 -0
  52. data/spec/unit/params_array_spec.rb +36 -0
  53. data/spec/unit/payload_spec.rb +263 -0
  54. data/spec/unit/raw_response_spec.rb +18 -0
  55. data/spec/unit/request2_spec.rb +54 -0
  56. data/spec/unit/request_spec.rb +1250 -0
  57. data/spec/unit/resource_spec.rb +134 -0
  58. data/spec/unit/response_spec.rb +241 -0
  59. data/spec/unit/restclient_spec.rb +79 -0
  60. data/spec/unit/utils_spec.rb +147 -0
  61. data/spec/unit/windows/root_certs_spec.rb +22 -0
  62. metadata +282 -0
@@ -0,0 +1,147 @@
1
+ require_relative '_lib'
2
+
3
+ describe RestClient::Utils do
4
+ describe '.get_encoding_from_headers' do
5
+ it 'assumes no encoding by default for text' do
6
+ headers = {:content_type => 'text/plain'}
7
+ expect(RestClient::Utils.get_encoding_from_headers(headers)).
8
+ to eq nil
9
+ end
10
+
11
+ it 'returns nil on failures' do
12
+ expect(RestClient::Utils.get_encoding_from_headers(
13
+ {:content_type => 'blah'})).to eq nil
14
+ expect(RestClient::Utils.get_encoding_from_headers(
15
+ {})).to eq nil
16
+ expect(RestClient::Utils.get_encoding_from_headers(
17
+ {:content_type => 'foo; bar=baz'})).to eq nil
18
+ end
19
+
20
+ it 'handles various charsets' do
21
+ expect(RestClient::Utils.get_encoding_from_headers(
22
+ {:content_type => 'text/plain; charset=UTF-8'})).to eq 'UTF-8'
23
+ expect(RestClient::Utils.get_encoding_from_headers(
24
+ {:content_type => 'application/json; charset=ISO-8859-1'})).
25
+ to eq 'ISO-8859-1'
26
+ expect(RestClient::Utils.get_encoding_from_headers(
27
+ {:content_type => 'text/html; charset=windows-1251'})).
28
+ to eq 'windows-1251'
29
+
30
+ expect(RestClient::Utils.get_encoding_from_headers(
31
+ {:content_type => 'text/html; charset="UTF-16"'})).
32
+ to eq 'UTF-16'
33
+ end
34
+ end
35
+
36
+ describe '.cgi_parse_header' do
37
+ it 'parses headers' do
38
+ expect(RestClient::Utils.cgi_parse_header('text/plain')).
39
+ to eq ['text/plain', {}]
40
+
41
+ expect(RestClient::Utils.cgi_parse_header('text/vnd.just.made.this.up ; ')).
42
+ to eq ['text/vnd.just.made.this.up', {}]
43
+
44
+ expect(RestClient::Utils.cgi_parse_header('text/plain;charset=us-ascii')).
45
+ to eq ['text/plain', {'charset' => 'us-ascii'}]
46
+
47
+ expect(RestClient::Utils.cgi_parse_header('text/plain ; charset="us-ascii"')).
48
+ to eq ['text/plain', {'charset' => 'us-ascii'}]
49
+
50
+ expect(RestClient::Utils.cgi_parse_header(
51
+ 'text/plain ; charset="us-ascii"; another=opt')).
52
+ to eq ['text/plain', {'charset' => 'us-ascii', 'another' => 'opt'}]
53
+
54
+ expect(RestClient::Utils.cgi_parse_header(
55
+ 'attachment; filename="silly.txt"')).
56
+ to eq ['attachment', {'filename' => 'silly.txt'}]
57
+
58
+ expect(RestClient::Utils.cgi_parse_header(
59
+ 'attachment; filename="strange;name"')).
60
+ to eq ['attachment', {'filename' => 'strange;name'}]
61
+
62
+ expect(RestClient::Utils.cgi_parse_header(
63
+ 'attachment; filename="strange;name";size=123;')).to eq \
64
+ ['attachment', {'filename' => 'strange;name', 'size' => '123'}]
65
+
66
+ expect(RestClient::Utils.cgi_parse_header(
67
+ 'form-data; name="files"; filename="fo\\"o;bar"')).to eq \
68
+ ['form-data', {'name' => 'files', 'filename' => 'fo"o;bar'}]
69
+ end
70
+ end
71
+
72
+ describe '.encode_query_string' do
73
+ it 'handles simple hashes' do
74
+ {
75
+ {foo: 123, bar: 456} => 'foo=123&bar=456',
76
+ {'foo' => 123, 'bar' => 456} => 'foo=123&bar=456',
77
+ {foo: 'abc', bar: 'one two'} => 'foo=abc&bar=one+two',
78
+ {escaped: '1+2=3'} => 'escaped=1%2B2%3D3',
79
+ {'escaped + key' => 'foo'} => 'escaped+%2B+key=foo',
80
+ }.each_pair do |input, expected|
81
+ expect(RestClient::Utils.encode_query_string(input)).to eq expected
82
+ end
83
+ end
84
+
85
+ it 'handles simple arrays' do
86
+ {
87
+ {foo: [1, 2, 3]} => 'foo[]=1&foo[]=2&foo[]=3',
88
+ {foo: %w{a b c}, bar: [1, 2, 3]} => 'foo[]=a&foo[]=b&foo[]=c&bar[]=1&bar[]=2&bar[]=3',
89
+ {foo: ['one two', 3]} => 'foo[]=one+two&foo[]=3',
90
+ {'a+b' => [1,2,3]} => 'a%2Bb[]=1&a%2Bb[]=2&a%2Bb[]=3',
91
+ }.each_pair do |input, expected|
92
+ expect(RestClient::Utils.encode_query_string(input)).to eq expected
93
+ end
94
+ end
95
+
96
+ it 'handles nested hashes' do
97
+ {
98
+ {outer: {foo: 123, bar: 456}} => 'outer[foo]=123&outer[bar]=456',
99
+ {outer: {foo: [1, 2, 3], bar: 'baz'}} => 'outer[foo][]=1&outer[foo][]=2&outer[foo][]=3&outer[bar]=baz',
100
+ }.each_pair do |input, expected|
101
+ expect(RestClient::Utils.encode_query_string(input)).to eq expected
102
+ end
103
+ end
104
+
105
+ it 'handles null and empty values' do
106
+ {
107
+ {string: '', empty: nil, list: [], hash: {}, falsey: false } =>
108
+ 'string=&empty&list&hash&falsey=false',
109
+ }.each_pair do |input, expected|
110
+ expect(RestClient::Utils.encode_query_string(input)).to eq expected
111
+ end
112
+ end
113
+
114
+ it 'handles nested nulls' do
115
+ {
116
+ {foo: {string: '', empty: nil}} => 'foo[string]=&foo[empty]',
117
+ }.each_pair do |input, expected|
118
+ expect(RestClient::Utils.encode_query_string(input)).to eq expected
119
+ end
120
+ end
121
+
122
+ it 'handles deep nesting' do
123
+ {
124
+ {coords: [{x: 1, y: 0}, {x: 2}, {x: 3}]} => 'coords[][x]=1&coords[][y]=0&coords[][x]=2&coords[][x]=3',
125
+ }.each_pair do |input, expected|
126
+ expect(RestClient::Utils.encode_query_string(input)).to eq expected
127
+ end
128
+ end
129
+
130
+ it 'handles multiple fields with the same name using ParamsArray' do
131
+ {
132
+ RestClient::ParamsArray.new([[:foo, 1], [:foo, 2], [:foo, 3]]) => 'foo=1&foo=2&foo=3',
133
+ }.each_pair do |input, expected|
134
+ expect(RestClient::Utils.encode_query_string(input)).to eq expected
135
+ end
136
+ end
137
+
138
+ it 'handles nested ParamsArrays' do
139
+ {
140
+ {foo: RestClient::ParamsArray.new([[:a, 1], [:a, 2]])} => 'foo[a]=1&foo[a]=2',
141
+ RestClient::ParamsArray.new([[:foo, {a: 1}], [:foo, {a: 2}]]) => 'foo[a]=1&foo[a]=2',
142
+ }.each_pair do |input, expected|
143
+ expect(RestClient::Utils.encode_query_string(input)).to eq expected
144
+ end
145
+ end
146
+ end
147
+ end
@@ -0,0 +1,22 @@
1
+ require_relative '../_lib'
2
+
3
+ describe 'RestClient::Windows::RootCerts',
4
+ :if => RestClient::Platform.windows? do
5
+ let(:x509_store) { RestClient::Windows::RootCerts.instance.to_a }
6
+
7
+ it 'should return at least one X509 certificate' do
8
+ expect(x509_store.to_a.size).to be >= 1
9
+ end
10
+
11
+ it 'should return an X509 certificate with a subject' do
12
+ x509 = x509_store.first
13
+
14
+ expect(x509.subject.to_s).to match(/CN=.*/)
15
+ end
16
+
17
+ it 'should return X509 certificate objects' do
18
+ x509_store.each do |cert|
19
+ expect(cert).to be_a(OpenSSL::X509::Certificate)
20
+ end
21
+ end
22
+ end
metadata ADDED
@@ -0,0 +1,282 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rest-client
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.0.2
5
+ platform: ruby
6
+ authors:
7
+ - REST Client Team
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-04-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: webmock
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry-doc
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rdoc
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 2.4.2
76
+ - - "<"
77
+ - !ruby/object:Gem::Version
78
+ version: '6.0'
79
+ type: :development
80
+ prerelease: false
81
+ version_requirements: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: 2.4.2
86
+ - - "<"
87
+ - !ruby/object:Gem::Version
88
+ version: '6.0'
89
+ - !ruby/object:Gem::Dependency
90
+ name: rubocop
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ - !ruby/object:Gem::Dependency
104
+ name: http-cookie
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: 1.0.2
110
+ - - "<"
111
+ - !ruby/object:Gem::Version
112
+ version: '2.0'
113
+ type: :runtime
114
+ prerelease: false
115
+ version_requirements: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: 1.0.2
120
+ - - "<"
121
+ - !ruby/object:Gem::Version
122
+ version: '2.0'
123
+ - !ruby/object:Gem::Dependency
124
+ name: mime-types
125
+ requirement: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: '1.16'
130
+ - - "<"
131
+ - !ruby/object:Gem::Version
132
+ version: '4.0'
133
+ type: :runtime
134
+ prerelease: false
135
+ version_requirements: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: '1.16'
140
+ - - "<"
141
+ - !ruby/object:Gem::Version
142
+ version: '4.0'
143
+ - !ruby/object:Gem::Dependency
144
+ name: netrc
145
+ requirement: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - "~>"
148
+ - !ruby/object:Gem::Version
149
+ version: '0.8'
150
+ type: :runtime
151
+ prerelease: false
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ requirements:
154
+ - - "~>"
155
+ - !ruby/object:Gem::Version
156
+ version: '0.8'
157
+ description: 'A simple HTTP and REST client for Ruby, inspired by the Sinatra microframework
158
+ style of specifying actions: get, put, post, delete.'
159
+ email: rest.client@librelist.com
160
+ executables:
161
+ - restclient
162
+ extensions: []
163
+ extra_rdoc_files:
164
+ - README.md
165
+ - history.md
166
+ files:
167
+ - ".gitignore"
168
+ - ".rspec"
169
+ - ".rubocop-disables.yml"
170
+ - ".rubocop.yml"
171
+ - ".travis.yml"
172
+ - AUTHORS
173
+ - Gemfile
174
+ - LICENSE
175
+ - README.md
176
+ - Rakefile
177
+ - bin/restclient
178
+ - history.md
179
+ - lib/rest-client.rb
180
+ - lib/rest_client.rb
181
+ - lib/restclient.rb
182
+ - lib/restclient/abstract_response.rb
183
+ - lib/restclient/exceptions.rb
184
+ - lib/restclient/params_array.rb
185
+ - lib/restclient/payload.rb
186
+ - lib/restclient/platform.rb
187
+ - lib/restclient/raw_response.rb
188
+ - lib/restclient/request.rb
189
+ - lib/restclient/resource.rb
190
+ - lib/restclient/response.rb
191
+ - lib/restclient/utils.rb
192
+ - lib/restclient/version.rb
193
+ - lib/restclient/windows.rb
194
+ - lib/restclient/windows/root_certs.rb
195
+ - rest-client.gemspec
196
+ - rest-client.windows.gemspec
197
+ - spec/helpers.rb
198
+ - spec/integration/_lib.rb
199
+ - spec/integration/capath_digicert/244b5494.0
200
+ - spec/integration/capath_digicert/81b9768f.0
201
+ - spec/integration/capath_digicert/README
202
+ - spec/integration/capath_digicert/digicert.crt
203
+ - spec/integration/capath_verisign/415660c1.0
204
+ - spec/integration/capath_verisign/7651b327.0
205
+ - spec/integration/capath_verisign/README
206
+ - spec/integration/capath_verisign/verisign.crt
207
+ - spec/integration/certs/digicert.crt
208
+ - spec/integration/certs/verisign.crt
209
+ - spec/integration/httpbin_spec.rb
210
+ - spec/integration/integration_spec.rb
211
+ - spec/integration/request_spec.rb
212
+ - spec/spec_helper.rb
213
+ - spec/unit/_lib.rb
214
+ - spec/unit/abstract_response_spec.rb
215
+ - spec/unit/exceptions_spec.rb
216
+ - spec/unit/master_shake.jpg
217
+ - spec/unit/params_array_spec.rb
218
+ - spec/unit/payload_spec.rb
219
+ - spec/unit/raw_response_spec.rb
220
+ - spec/unit/request2_spec.rb
221
+ - spec/unit/request_spec.rb
222
+ - spec/unit/resource_spec.rb
223
+ - spec/unit/response_spec.rb
224
+ - spec/unit/restclient_spec.rb
225
+ - spec/unit/utils_spec.rb
226
+ - spec/unit/windows/root_certs_spec.rb
227
+ homepage: https://github.com/rest-client/rest-client
228
+ licenses:
229
+ - MIT
230
+ metadata: {}
231
+ post_install_message:
232
+ rdoc_options: []
233
+ require_paths:
234
+ - lib
235
+ required_ruby_version: !ruby/object:Gem::Requirement
236
+ requirements:
237
+ - - ">="
238
+ - !ruby/object:Gem::Version
239
+ version: 2.0.0
240
+ required_rubygems_version: !ruby/object:Gem::Requirement
241
+ requirements:
242
+ - - ">="
243
+ - !ruby/object:Gem::Version
244
+ version: '0'
245
+ requirements: []
246
+ rubyforge_project:
247
+ rubygems_version: 2.6.11
248
+ signing_key:
249
+ specification_version: 4
250
+ summary: Simple HTTP and REST client for Ruby, inspired by microframework syntax for
251
+ specifying actions.
252
+ test_files:
253
+ - spec/helpers.rb
254
+ - spec/integration/_lib.rb
255
+ - spec/integration/capath_digicert/244b5494.0
256
+ - spec/integration/capath_digicert/81b9768f.0
257
+ - spec/integration/capath_digicert/README
258
+ - spec/integration/capath_digicert/digicert.crt
259
+ - spec/integration/capath_verisign/415660c1.0
260
+ - spec/integration/capath_verisign/7651b327.0
261
+ - spec/integration/capath_verisign/README
262
+ - spec/integration/capath_verisign/verisign.crt
263
+ - spec/integration/certs/digicert.crt
264
+ - spec/integration/certs/verisign.crt
265
+ - spec/integration/httpbin_spec.rb
266
+ - spec/integration/integration_spec.rb
267
+ - spec/integration/request_spec.rb
268
+ - spec/spec_helper.rb
269
+ - spec/unit/_lib.rb
270
+ - spec/unit/abstract_response_spec.rb
271
+ - spec/unit/exceptions_spec.rb
272
+ - spec/unit/master_shake.jpg
273
+ - spec/unit/params_array_spec.rb
274
+ - spec/unit/payload_spec.rb
275
+ - spec/unit/raw_response_spec.rb
276
+ - spec/unit/request2_spec.rb
277
+ - spec/unit/request_spec.rb
278
+ - spec/unit/resource_spec.rb
279
+ - spec/unit/response_spec.rb
280
+ - spec/unit/restclient_spec.rb
281
+ - spec/unit/utils_spec.rb
282
+ - spec/unit/windows/root_certs_spec.rb