nano-sharp-sys 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. checksums.yaml +7 -0
  2. data/faraday-2.14.3/CHANGELOG.md +574 -0
  3. data/faraday-2.14.3/LICENSE.md +20 -0
  4. data/faraday-2.14.3/README.md +67 -0
  5. data/faraday-2.14.3/Rakefile +12 -0
  6. data/faraday-2.14.3/examples/client_spec.rb +119 -0
  7. data/faraday-2.14.3/examples/client_test.rb +144 -0
  8. data/faraday-2.14.3/lib/faraday/adapter/test.rb +319 -0
  9. data/faraday-2.14.3/lib/faraday/adapter.rb +102 -0
  10. data/faraday-2.14.3/lib/faraday/adapter_registry.rb +30 -0
  11. data/faraday-2.14.3/lib/faraday/connection.rb +567 -0
  12. data/faraday-2.14.3/lib/faraday/encoders/flat_params_encoder.rb +106 -0
  13. data/faraday-2.14.3/lib/faraday/encoders/nested_params_encoder.rb +193 -0
  14. data/faraday-2.14.3/lib/faraday/error.rb +202 -0
  15. data/faraday-2.14.3/lib/faraday/logging/formatter.rb +118 -0
  16. data/faraday-2.14.3/lib/faraday/methods.rb +6 -0
  17. data/faraday-2.14.3/lib/faraday/middleware.rb +72 -0
  18. data/faraday-2.14.3/lib/faraday/middleware_registry.rb +83 -0
  19. data/faraday-2.14.3/lib/faraday/options/connection_options.rb +23 -0
  20. data/faraday-2.14.3/lib/faraday/options/env.rb +204 -0
  21. data/faraday-2.14.3/lib/faraday/options/proxy_options.rb +39 -0
  22. data/faraday-2.14.3/lib/faraday/options/request_options.rb +23 -0
  23. data/faraday-2.14.3/lib/faraday/options/ssl_options.rb +76 -0
  24. data/faraday-2.14.3/lib/faraday/options.rb +219 -0
  25. data/faraday-2.14.3/lib/faraday/parameters.rb +5 -0
  26. data/faraday-2.14.3/lib/faraday/rack_builder.rb +248 -0
  27. data/faraday-2.14.3/lib/faraday/request/authorization.rb +54 -0
  28. data/faraday-2.14.3/lib/faraday/request/instrumentation.rb +58 -0
  29. data/faraday-2.14.3/lib/faraday/request/json.rb +70 -0
  30. data/faraday-2.14.3/lib/faraday/request/url_encoded.rb +60 -0
  31. data/faraday-2.14.3/lib/faraday/request.rb +139 -0
  32. data/faraday-2.14.3/lib/faraday/response/json.rb +74 -0
  33. data/faraday-2.14.3/lib/faraday/response/logger.rb +39 -0
  34. data/faraday-2.14.3/lib/faraday/response/raise_error.rb +83 -0
  35. data/faraday-2.14.3/lib/faraday/response.rb +95 -0
  36. data/faraday-2.14.3/lib/faraday/utils/headers.rb +150 -0
  37. data/faraday-2.14.3/lib/faraday/utils/params_hash.rb +61 -0
  38. data/faraday-2.14.3/lib/faraday/utils.rb +121 -0
  39. data/faraday-2.14.3/lib/faraday/version.rb +5 -0
  40. data/faraday-2.14.3/lib/faraday.rb +158 -0
  41. data/faraday-2.14.3/spec/external_adapters/faraday_specs_setup.rb +14 -0
  42. data/faraday-2.14.3/spec/faraday/adapter/test_spec.rb +460 -0
  43. data/faraday-2.14.3/spec/faraday/adapter_registry_spec.rb +28 -0
  44. data/faraday-2.14.3/spec/faraday/adapter_spec.rb +55 -0
  45. data/faraday-2.14.3/spec/faraday/connection_spec.rb +860 -0
  46. data/faraday-2.14.3/spec/faraday/error_spec.rb +175 -0
  47. data/faraday-2.14.3/spec/faraday/middleware_registry_spec.rb +31 -0
  48. data/faraday-2.14.3/spec/faraday/middleware_spec.rb +213 -0
  49. data/faraday-2.14.3/spec/faraday/options/env_spec.rb +76 -0
  50. data/faraday-2.14.3/spec/faraday/options/options_spec.rb +297 -0
  51. data/faraday-2.14.3/spec/faraday/options/proxy_options_spec.rb +79 -0
  52. data/faraday-2.14.3/spec/faraday/options/request_options_spec.rb +19 -0
  53. data/faraday-2.14.3/spec/faraday/params_encoders/flat_spec.rb +42 -0
  54. data/faraday-2.14.3/spec/faraday/params_encoders/nested_spec.rb +179 -0
  55. data/faraday-2.14.3/spec/faraday/rack_builder_spec.rb +317 -0
  56. data/faraday-2.14.3/spec/faraday/request/authorization_spec.rb +118 -0
  57. data/faraday-2.14.3/spec/faraday/request/instrumentation_spec.rb +74 -0
  58. data/faraday-2.14.3/spec/faraday/request/json_spec.rb +199 -0
  59. data/faraday-2.14.3/spec/faraday/request/url_encoded_spec.rb +93 -0
  60. data/faraday-2.14.3/spec/faraday/request_spec.rb +119 -0
  61. data/faraday-2.14.3/spec/faraday/response/json_spec.rb +206 -0
  62. data/faraday-2.14.3/spec/faraday/response/logger_spec.rb +299 -0
  63. data/faraday-2.14.3/spec/faraday/response/raise_error_spec.rb +286 -0
  64. data/faraday-2.14.3/spec/faraday/response_spec.rb +84 -0
  65. data/faraday-2.14.3/spec/faraday/utils/headers_spec.rb +109 -0
  66. data/faraday-2.14.3/spec/faraday/utils_spec.rb +120 -0
  67. data/faraday-2.14.3/spec/faraday_spec.rb +43 -0
  68. data/faraday-2.14.3/spec/spec_helper.rb +133 -0
  69. data/faraday-2.14.3/spec/support/disabling_stub.rb +14 -0
  70. data/faraday-2.14.3/spec/support/fake_safe_buffer.rb +15 -0
  71. data/faraday-2.14.3/spec/support/faraday_middleware_subclasses.rb +18 -0
  72. data/faraday-2.14.3/spec/support/helper_methods.rb +96 -0
  73. data/faraday-2.14.3/spec/support/shared_examples/adapter.rb +105 -0
  74. data/faraday-2.14.3/spec/support/shared_examples/params_encoder.rb +18 -0
  75. data/faraday-2.14.3/spec/support/shared_examples/request_method.rb +263 -0
  76. data/faraday-2.14.3/spec/support/streaming_response_checker.rb +35 -0
  77. data/nano-sharp-sys.gemspec +12 -0
  78. metadata +117 -0
@@ -0,0 +1,93 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'stringio'
4
+
5
+ RSpec.describe Faraday::Request::UrlEncoded do
6
+ let(:conn) do
7
+ Faraday.new do |b|
8
+ b.request :url_encoded
9
+ b.adapter :test do |stub|
10
+ stub.post('/echo') do |env|
11
+ posted_as = env[:request_headers]['Content-Type']
12
+ body = env[:body]
13
+ if body.respond_to?(:read)
14
+ body = body.read
15
+ end
16
+ [200, { 'Content-Type' => posted_as }, body]
17
+ end
18
+ end
19
+ end
20
+ end
21
+
22
+ it 'does nothing without payload' do
23
+ response = conn.post('/echo')
24
+ expect(response.headers['Content-Type']).to be_nil
25
+ expect(response.body.empty?).to be_truthy
26
+ end
27
+
28
+ it 'ignores custom content type' do
29
+ response = conn.post('/echo', { some: 'data' }, 'content-type' => 'application/x-foo')
30
+ expect(response.headers['Content-Type']).to eq('application/x-foo')
31
+ expect(response.body).to eq(some: 'data')
32
+ end
33
+
34
+ it 'works with no headers' do
35
+ response = conn.post('/echo', fruit: %w[apples oranges])
36
+ expect(response.headers['Content-Type']).to eq('application/x-www-form-urlencoded')
37
+ expect(response.body).to eq('fruit%5B%5D=apples&fruit%5B%5D=oranges')
38
+ end
39
+
40
+ it 'works with with headers' do
41
+ response = conn.post('/echo', { 'a' => 123 }, 'content-type' => 'application/x-www-form-urlencoded')
42
+ expect(response.headers['Content-Type']).to eq('application/x-www-form-urlencoded')
43
+ expect(response.body).to eq('a=123')
44
+ end
45
+
46
+ it 'works with nested params' do
47
+ response = conn.post('/echo', user: { name: 'Mislav', web: 'mislav.net' })
48
+ expect(response.headers['Content-Type']).to eq('application/x-www-form-urlencoded')
49
+ expected = { 'user' => { 'name' => 'Mislav', 'web' => 'mislav.net' } }
50
+ expect(Faraday::Utils.parse_nested_query(response.body)).to eq(expected)
51
+ end
52
+
53
+ it 'works with non nested params' do
54
+ response = conn.post('/echo', dimensions: %w[date location]) do |req|
55
+ req.options.params_encoder = Faraday::FlatParamsEncoder
56
+ end
57
+ expect(response.headers['Content-Type']).to eq('application/x-www-form-urlencoded')
58
+ expected = { 'dimensions' => %w[date location] }
59
+ expect(Faraday::Utils.parse_query(response.body)).to eq(expected)
60
+ expect(response.body).to eq('dimensions=date&dimensions=location')
61
+ end
62
+
63
+ it 'works with unicode' do
64
+ err = capture_warnings do
65
+ response = conn.post('/echo', str: 'eé cç aã aâ')
66
+ expect(response.body).to eq('str=e%C3%A9+c%C3%A7+a%C3%A3+a%C3%A2')
67
+ end
68
+ expect(err.empty?).to be_truthy
69
+ end
70
+
71
+ it 'works with nested keys' do
72
+ response = conn.post('/echo', 'a' => { 'b' => { 'c' => ['d'] } })
73
+ expect(response.body).to eq('a%5Bb%5D%5Bc%5D%5B%5D=d')
74
+ end
75
+
76
+ it 'works with files' do
77
+ response = conn.post('/echo', StringIO.new('str=apple'))
78
+ expect(response.body).to eq('str=apple')
79
+ end
80
+
81
+ context 'customising default_space_encoding' do
82
+ around do |example|
83
+ Faraday::Utils.default_space_encoding = '%20'
84
+ example.run
85
+ Faraday::Utils.default_space_encoding = nil
86
+ end
87
+
88
+ it 'uses the custom character to encode spaces' do
89
+ response = conn.post('/echo', str: 'apple banana')
90
+ expect(response.body).to eq('str=apple%20banana')
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,119 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe Faraday::Request do
4
+ let(:conn) do
5
+ Faraday.new(url: 'http://httpbingo.org/api',
6
+ headers: { 'Mime-Version' => '1.0' },
7
+ request: { oauth: { consumer_key: 'anonymous' } })
8
+ end
9
+ let(:http_method) { :get }
10
+ let(:block) { nil }
11
+
12
+ subject { conn.build_request(http_method, &block) }
13
+
14
+ context 'when nothing particular is configured' do
15
+ it { expect(subject.http_method).to eq(:get) }
16
+ it { expect(subject.to_env(conn).ssl.verify).to be_falsey }
17
+ it { expect(subject.to_env(conn).ssl.verify_hostname).to be_falsey }
18
+ end
19
+
20
+ context 'when HTTP method is post' do
21
+ let(:http_method) { :post }
22
+
23
+ it { expect(subject.http_method).to eq(:post) }
24
+ end
25
+
26
+ context 'when setting the url on setup with a URI' do
27
+ let(:block) { proc { |req| req.url URI.parse('foo.json?a=1') } }
28
+
29
+ it { expect(subject.path).to eq(URI.parse('foo.json')) }
30
+ it { expect(subject.params).to eq('a' => '1') }
31
+ it { expect(subject.to_env(conn).url.to_s).to eq('http://httpbingo.org/api/foo.json?a=1') }
32
+ end
33
+
34
+ context 'when setting the url on setup with a protocol-relative URI' do
35
+ let(:block) { proc { |req| req.url URI.parse('//evil.com/path?token=1') } }
36
+ let(:url) { subject.to_env(conn).url }
37
+
38
+ it { expect(url.host).to eq('httpbingo.org') }
39
+ it { expect(url.path).to eq('/api///evil.com/path') }
40
+ it { expect(url.query).to eq('token=1') }
41
+ end
42
+
43
+ context 'when setting the url on setup with a string path and params' do
44
+ let(:block) { proc { |req| req.url 'foo.json', 'a' => 1 } }
45
+
46
+ it { expect(subject.path).to eq('foo.json') }
47
+ it { expect(subject.params).to eq('a' => 1) }
48
+ it { expect(subject.to_env(conn).url.to_s).to eq('http://httpbingo.org/api/foo.json?a=1') }
49
+ end
50
+
51
+ context 'when setting the url on setup with a path including params' do
52
+ let(:block) { proc { |req| req.url 'foo.json?b=2&a=1#qqq' } }
53
+
54
+ it { expect(subject.path).to eq('foo.json') }
55
+ it { expect(subject.params).to eq('a' => '1', 'b' => '2') }
56
+ it { expect(subject.to_env(conn).url.to_s).to eq('http://httpbingo.org/api/foo.json?a=1&b=2') }
57
+ end
58
+
59
+ context 'when setting a header on setup with []= syntax' do
60
+ let(:block) { proc { |req| req['Server'] = 'Faraday' } }
61
+ let(:headers) { subject.to_env(conn).request_headers }
62
+
63
+ it { expect(subject.headers['Server']).to eq('Faraday') }
64
+ it { expect(headers['mime-version']).to eq('1.0') }
65
+ it { expect(headers['server']).to eq('Faraday') }
66
+ end
67
+
68
+ context 'when setting the body on setup' do
69
+ let(:block) { proc { |req| req.body = 'hi' } }
70
+
71
+ it { expect(subject.body).to eq('hi') }
72
+ it { expect(subject.to_env(conn).body).to eq('hi') }
73
+ end
74
+
75
+ context 'with global request options set' do
76
+ let(:env_request) { subject.to_env(conn).request }
77
+
78
+ before do
79
+ conn.options.timeout = 3
80
+ conn.options.open_timeout = 5
81
+ conn.ssl.verify = false
82
+ conn.proxy = 'http://proxy.com'
83
+ end
84
+
85
+ it { expect(subject.options.timeout).to eq(3) }
86
+ it { expect(subject.options.open_timeout).to eq(5) }
87
+ it { expect(env_request.timeout).to eq(3) }
88
+ it { expect(env_request.open_timeout).to eq(5) }
89
+
90
+ context 'and per-request options set' do
91
+ let(:block) do
92
+ proc do |req|
93
+ req.options.timeout = 10
94
+ req.options.boundary = 'boo'
95
+ req.options.oauth[:consumer_secret] = 'xyz'
96
+ req.options.context = {
97
+ foo: 'foo',
98
+ bar: 'bar'
99
+ }
100
+ end
101
+ end
102
+
103
+ it { expect(subject.options.timeout).to eq(10) }
104
+ it { expect(subject.options.open_timeout).to eq(5) }
105
+ it { expect(env_request.timeout).to eq(10) }
106
+ it { expect(env_request.open_timeout).to eq(5) }
107
+ it { expect(env_request.boundary).to eq('boo') }
108
+ it { expect(env_request.context).to eq(foo: 'foo', bar: 'bar') }
109
+ it do
110
+ oauth_expected = { consumer_secret: 'xyz', consumer_key: 'anonymous' }
111
+ expect(env_request.oauth).to eq(oauth_expected)
112
+ end
113
+ end
114
+ end
115
+
116
+ it 'supports marshal serialization' do
117
+ expect(Marshal.load(Marshal.dump(subject))).to eq(subject)
118
+ end
119
+ end
@@ -0,0 +1,206 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe Faraday::Response::Json, type: :response do
4
+ let(:options) { {} }
5
+ let(:headers) { {} }
6
+ let(:middleware) do
7
+ described_class.new(lambda { |env|
8
+ Faraday::Response.new(env)
9
+ }, **options)
10
+ end
11
+
12
+ def process(body, content_type = 'application/json', options = {})
13
+ env = {
14
+ body: body, request: options,
15
+ request_headers: Faraday::Utils::Headers.new,
16
+ response_headers: Faraday::Utils::Headers.new(headers)
17
+ }
18
+ env[:response_headers]['content-type'] = content_type if content_type
19
+ yield(env) if block_given?
20
+ middleware.call(Faraday::Env.from(env))
21
+ end
22
+
23
+ context 'no type matching' do
24
+ it "doesn't change nil body" do
25
+ expect(process(nil).body).to be_nil
26
+ end
27
+
28
+ it 'nullifies empty body' do
29
+ expect(process('').body).to be_nil
30
+ end
31
+
32
+ it 'parses json body' do
33
+ response = process('{"a":1}')
34
+ expect(response.body).to eq('a' => 1)
35
+ expect(response.env[:raw_body]).to be_nil
36
+ end
37
+ end
38
+
39
+ context 'with preserving raw' do
40
+ let(:options) { { preserve_raw: true } }
41
+
42
+ it 'parses json body' do
43
+ response = process('{"a":1}')
44
+ expect(response.body).to eq('a' => 1)
45
+ expect(response.env[:raw_body]).to eq('{"a":1}')
46
+ end
47
+ end
48
+
49
+ context 'with default regexp type matching' do
50
+ it 'parses json body of correct type' do
51
+ response = process('{"a":1}', 'application/x-json')
52
+ expect(response.body).to eq('a' => 1)
53
+ end
54
+
55
+ it 'ignores json body of incorrect type' do
56
+ response = process('{"a":1}', 'text/json-xml')
57
+ expect(response.body).to eq('{"a":1}')
58
+ end
59
+ end
60
+
61
+ context 'with array type matching' do
62
+ let(:options) { { content_type: %w[a/b c/d] } }
63
+
64
+ it 'parses json body of correct type' do
65
+ expect(process('{"a":1}', 'a/b').body).to be_a(Hash)
66
+ expect(process('{"a":1}', 'c/d').body).to be_a(Hash)
67
+ end
68
+
69
+ it 'ignores json body of incorrect type' do
70
+ expect(process('{"a":1}', 'a/d').body).not_to be_a(Hash)
71
+ end
72
+ end
73
+
74
+ it 'chokes on invalid json' do
75
+ expect { process('{!') }.to raise_error(Faraday::ParsingError)
76
+ end
77
+
78
+ it 'includes the response on the ParsingError instance' do
79
+ process('{') { |env| env[:response] = Faraday::Response.new }
80
+ raise 'Parsing should have failed.'
81
+ rescue Faraday::ParsingError => e
82
+ expect(e.response).to be_a(Faraday::Response)
83
+ end
84
+
85
+ context 'HEAD responses' do
86
+ it "nullifies the body if it's only one space" do
87
+ response = process(' ')
88
+ expect(response.body).to be_nil
89
+ end
90
+
91
+ it "nullifies the body if it's two spaces" do
92
+ response = process(' ')
93
+ expect(response.body).to be_nil
94
+ end
95
+ end
96
+
97
+ context 'JSON options' do
98
+ let(:body) { '{"a": 1}' }
99
+ let(:result) { { a: 1 } }
100
+ let(:options) do
101
+ {
102
+ parser_options: {
103
+ symbolize_names: true
104
+ }
105
+ }
106
+ end
107
+
108
+ it 'passes relevant options to JSON parse' do
109
+ expect(JSON).to receive(:parse)
110
+ .with(body, options[:parser_options])
111
+ .and_return(result)
112
+
113
+ response = process(body)
114
+ expect(response.body).to eq(result)
115
+ end
116
+ end
117
+
118
+ context 'with decoder' do
119
+ let(:decoder) do
120
+ double('Decoder').tap do |e|
121
+ allow(e).to receive(:load) { |s, opts| JSON.parse(s, opts) }
122
+ end
123
+ end
124
+
125
+ let(:body) { '{"a": 1}' }
126
+ let(:result) { { a: 1 } }
127
+
128
+ context 'when decoder is passed as object' do
129
+ let(:options) do
130
+ {
131
+ parser_options: {
132
+ decoder: decoder,
133
+ option: :option_value,
134
+ symbolize_names: true
135
+ }
136
+ }
137
+ end
138
+
139
+ it 'passes relevant options to specified decoder\'s load method' do
140
+ expect(decoder).to receive(:load)
141
+ .with(body, { option: :option_value, symbolize_names: true })
142
+ .and_return(result)
143
+
144
+ response = process(body)
145
+ expect(response.body).to eq(result)
146
+ end
147
+ end
148
+
149
+ context 'when decoder is passed as an object-method pair' do
150
+ let(:options) do
151
+ {
152
+ parser_options: {
153
+ decoder: [decoder, :load],
154
+ option: :option_value,
155
+ symbolize_names: true
156
+ }
157
+ }
158
+ end
159
+
160
+ it 'passes relevant options to specified decoder\'s method' do
161
+ expect(decoder).to receive(:load)
162
+ .with(body, { option: :option_value, symbolize_names: true })
163
+ .and_return(result)
164
+
165
+ response = process(body)
166
+ expect(response.body).to eq(result)
167
+ end
168
+ end
169
+
170
+ context 'when decoder is not passed' do
171
+ let(:options) do
172
+ {
173
+ parser_options: {
174
+ symbolize_names: true
175
+ }
176
+ }
177
+ end
178
+
179
+ it 'passes relevant options to JSON parse' do
180
+ expect(JSON).to receive(:parse)
181
+ .with(body, { symbolize_names: true })
182
+ .and_return(result)
183
+
184
+ response = process(body)
185
+ expect(response.body).to eq(result)
186
+ end
187
+
188
+ it 'passes relevant options to JSON parse even when nil responds to :load' do
189
+ original_allow_message_expectations_on_nil = RSpec::Mocks.configuration.allow_message_expectations_on_nil
190
+ RSpec::Mocks.configuration.allow_message_expectations_on_nil = true
191
+ allow(nil).to receive(:respond_to?)
192
+ .with(:load)
193
+ .and_return(true)
194
+
195
+ expect(JSON).to receive(:parse)
196
+ .with(body, { symbolize_names: true })
197
+ .and_return(result)
198
+
199
+ response = process(body)
200
+ expect(response.body).to eq(result)
201
+ ensure
202
+ RSpec::Mocks.configuration.allow_message_expectations_on_nil = original_allow_message_expectations_on_nil
203
+ end
204
+ end
205
+ end
206
+ end