oso-cloud 1.8.0 → 1.9.1.pre.vendored.0
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.
- checksums.yaml +4 -4
- data/.gitignore +0 -1
- data/Gemfile +5 -0
- data/Gemfile.lock +31 -12
- data/README.md +1 -1
- data/lib/oso/api.rb +18 -2
- data/lib/oso/oso.rb +10 -7
- data/lib/oso/version.rb +1 -1
- data/vendor/gems/faraday-2.5.2/CHANGELOG.md +574 -0
- data/vendor/gems/faraday-2.5.2/LICENSE.md +20 -0
- data/vendor/gems/faraday-2.5.2/README.md +55 -0
- data/vendor/gems/faraday-2.5.2/Rakefile +7 -0
- data/vendor/gems/faraday-2.5.2/examples/client_spec.rb +119 -0
- data/vendor/gems/faraday-2.5.2/examples/client_test.rb +144 -0
- data/vendor/gems/faraday-2.5.2/lib/faraday/adapter/test.rb +298 -0
- data/vendor/gems/faraday-2.5.2/lib/faraday/adapter.rb +102 -0
- data/vendor/gems/faraday-2.5.2/lib/faraday/adapter_registry.rb +30 -0
- data/vendor/gems/faraday-2.5.2/lib/faraday/connection.rb +561 -0
- data/vendor/gems/faraday-2.5.2/lib/faraday/encoders/flat_params_encoder.rb +105 -0
- data/vendor/gems/faraday-2.5.2/lib/faraday/encoders/nested_params_encoder.rb +183 -0
- data/vendor/gems/faraday-2.5.2/lib/faraday/error.rb +147 -0
- data/vendor/gems/faraday-2.5.2/lib/faraday/logging/formatter.rb +106 -0
- data/vendor/gems/faraday-2.5.2/lib/faraday/methods.rb +6 -0
- data/vendor/gems/faraday-2.5.2/lib/faraday/middleware.rb +30 -0
- data/vendor/gems/faraday-2.5.2/lib/faraday/middleware_registry.rb +83 -0
- data/vendor/gems/faraday-2.5.2/lib/faraday/options/connection_options.rb +22 -0
- data/vendor/gems/faraday-2.5.2/lib/faraday/options/env.rb +199 -0
- data/vendor/gems/faraday-2.5.2/lib/faraday/options/proxy_options.rb +32 -0
- data/vendor/gems/faraday-2.5.2/lib/faraday/options/request_options.rb +22 -0
- data/vendor/gems/faraday-2.5.2/lib/faraday/options/ssl_options.rb +69 -0
- data/vendor/gems/faraday-2.5.2/lib/faraday/options.rb +218 -0
- data/vendor/gems/faraday-2.5.2/lib/faraday/parameters.rb +5 -0
- data/vendor/gems/faraday-2.5.2/lib/faraday/rack_builder.rb +252 -0
- data/vendor/gems/faraday-2.5.2/lib/faraday/request/authorization.rb +49 -0
- data/vendor/gems/faraday-2.5.2/lib/faraday/request/instrumentation.rb +56 -0
- data/vendor/gems/faraday-2.5.2/lib/faraday/request/json.rb +55 -0
- data/vendor/gems/faraday-2.5.2/lib/faraday/request/url_encoded.rb +60 -0
- data/vendor/gems/faraday-2.5.2/lib/faraday/request.rb +136 -0
- data/vendor/gems/faraday-2.5.2/lib/faraday/response/json.rb +54 -0
- data/vendor/gems/faraday-2.5.2/lib/faraday/response/logger.rb +33 -0
- data/vendor/gems/faraday-2.5.2/lib/faraday/response/raise_error.rb +64 -0
- data/vendor/gems/faraday-2.5.2/lib/faraday/response.rb +90 -0
- data/vendor/gems/faraday-2.5.2/lib/faraday/utils/headers.rb +139 -0
- data/vendor/gems/faraday-2.5.2/lib/faraday/utils/params_hash.rb +61 -0
- data/vendor/gems/faraday-2.5.2/lib/faraday/utils.rb +122 -0
- data/vendor/gems/faraday-2.5.2/lib/faraday/version.rb +5 -0
- data/vendor/gems/faraday-2.5.2/lib/faraday.rb +157 -0
- data/vendor/gems/faraday-2.5.2/spec/external_adapters/faraday_specs_setup.rb +14 -0
- data/vendor/gems/faraday-2.5.2/spec/faraday/adapter/test_spec.rb +413 -0
- data/vendor/gems/faraday-2.5.2/spec/faraday/adapter_registry_spec.rb +28 -0
- data/vendor/gems/faraday-2.5.2/spec/faraday/adapter_spec.rb +55 -0
- data/vendor/gems/faraday-2.5.2/spec/faraday/connection_spec.rb +793 -0
- data/vendor/gems/faraday-2.5.2/spec/faraday/error_spec.rb +60 -0
- data/vendor/gems/faraday-2.5.2/spec/faraday/middleware_registry_spec.rb +31 -0
- data/vendor/gems/faraday-2.5.2/spec/faraday/middleware_spec.rb +52 -0
- data/vendor/gems/faraday-2.5.2/spec/faraday/options/env_spec.rb +76 -0
- data/vendor/gems/faraday-2.5.2/spec/faraday/options/options_spec.rb +297 -0
- data/vendor/gems/faraday-2.5.2/spec/faraday/options/proxy_options_spec.rb +44 -0
- data/vendor/gems/faraday-2.5.2/spec/faraday/options/request_options_spec.rb +19 -0
- data/vendor/gems/faraday-2.5.2/spec/faraday/params_encoders/flat_spec.rb +42 -0
- data/vendor/gems/faraday-2.5.2/spec/faraday/params_encoders/nested_spec.rb +150 -0
- data/vendor/gems/faraday-2.5.2/spec/faraday/rack_builder_spec.rb +317 -0
- data/vendor/gems/faraday-2.5.2/spec/faraday/request/authorization_spec.rb +83 -0
- data/vendor/gems/faraday-2.5.2/spec/faraday/request/instrumentation_spec.rb +74 -0
- data/vendor/gems/faraday-2.5.2/spec/faraday/request/json_spec.rb +111 -0
- data/vendor/gems/faraday-2.5.2/spec/faraday/request/url_encoded_spec.rb +93 -0
- data/vendor/gems/faraday-2.5.2/spec/faraday/request_spec.rb +110 -0
- data/vendor/gems/faraday-2.5.2/spec/faraday/response/json_spec.rb +117 -0
- data/vendor/gems/faraday-2.5.2/spec/faraday/response/logger_spec.rb +220 -0
- data/vendor/gems/faraday-2.5.2/spec/faraday/response/raise_error_spec.rb +172 -0
- data/vendor/gems/faraday-2.5.2/spec/faraday/response_spec.rb +75 -0
- data/vendor/gems/faraday-2.5.2/spec/faraday/utils/headers_spec.rb +82 -0
- data/vendor/gems/faraday-2.5.2/spec/faraday/utils_spec.rb +118 -0
- data/vendor/gems/faraday-2.5.2/spec/faraday_spec.rb +37 -0
- data/vendor/gems/faraday-2.5.2/spec/spec_helper.rb +132 -0
- data/vendor/gems/faraday-2.5.2/spec/support/disabling_stub.rb +14 -0
- data/vendor/gems/faraday-2.5.2/spec/support/fake_safe_buffer.rb +15 -0
- data/vendor/gems/faraday-2.5.2/spec/support/helper_methods.rb +96 -0
- data/vendor/gems/faraday-2.5.2/spec/support/shared_examples/adapter.rb +105 -0
- data/vendor/gems/faraday-2.5.2/spec/support/shared_examples/params_encoder.rb +18 -0
- data/vendor/gems/faraday-2.5.2/spec/support/shared_examples/request_method.rb +263 -0
- data/vendor/gems/faraday-2.5.2/spec/support/streaming_response_checker.rb +35 -0
- data/vendor/gems/faraday-net_http-3.0.2/LICENSE.md +21 -0
- data/vendor/gems/faraday-net_http-3.0.2/README.md +57 -0
- data/vendor/gems/faraday-net_http-3.0.2/lib/faraday/adapter/net_http.rb +208 -0
- data/vendor/gems/faraday-net_http-3.0.2/lib/faraday/net_http/version.rb +7 -0
- data/vendor/gems/faraday-net_http-3.0.2/lib/faraday/net_http.rb +10 -0
- data/vendor/gems/faraday-net_http_persistent-2.3.0/LICENSE.md +21 -0
- data/vendor/gems/faraday-net_http_persistent-2.3.0/README.md +66 -0
- data/vendor/gems/faraday-net_http_persistent-2.3.0/lib/faraday/adapter/net_http_persistent.rb +234 -0
- data/vendor/gems/faraday-net_http_persistent-2.3.0/lib/faraday/net_http_persistent/version.rb +7 -0
- data/vendor/gems/faraday-net_http_persistent-2.3.0/lib/faraday/net_http_persistent.rb +18 -0
- data/vendor/gems/faraday-retry-2.0.0/CHANGELOG.md +24 -0
- data/vendor/gems/faraday-retry-2.0.0/LICENSE.md +21 -0
- data/vendor/gems/faraday-retry-2.0.0/README.md +169 -0
- data/vendor/gems/faraday-retry-2.0.0/lib/faraday/retriable_response.rb +8 -0
- data/vendor/gems/faraday-retry-2.0.0/lib/faraday/retry/middleware.rb +254 -0
- data/vendor/gems/faraday-retry-2.0.0/lib/faraday/retry/version.rb +7 -0
- data/vendor/gems/faraday-retry-2.0.0/lib/faraday/retry.rb +13 -0
- data/vendor/gems/net-http-persistent-4.0.5/.autotest +9 -0
- data/vendor/gems/net-http-persistent-4.0.5/.gemtest +0 -0
- data/vendor/gems/net-http-persistent-4.0.5/Gemfile +14 -0
- data/vendor/gems/net-http-persistent-4.0.5/History.txt +460 -0
- data/vendor/gems/net-http-persistent-4.0.5/Manifest.txt +13 -0
- data/vendor/gems/net-http-persistent-4.0.5/README.rdoc +82 -0
- data/vendor/gems/net-http-persistent-4.0.5/Rakefile +25 -0
- data/vendor/gems/net-http-persistent-4.0.5/lib/net/http/persistent/connection.rb +41 -0
- data/vendor/gems/net-http-persistent-4.0.5/lib/net/http/persistent/pool.rb +65 -0
- data/vendor/gems/net-http-persistent-4.0.5/lib/net/http/persistent/timed_stack_multi.rb +79 -0
- data/vendor/gems/net-http-persistent-4.0.5/lib/net/http/persistent.rb +1158 -0
- data/vendor/gems/net-http-persistent-4.0.5/test/test_net_http_persistent.rb +1512 -0
- data/vendor/gems/net-http-persistent-4.0.5/test/test_net_http_persistent_timed_stack_multi.rb +151 -0
- metadata +112 -8
@@ -0,0 +1,64 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Faraday
|
4
|
+
class Response
|
5
|
+
# RaiseError is a Faraday middleware that raises exceptions on common HTTP
|
6
|
+
# client or server error responses.
|
7
|
+
class RaiseError < Middleware
|
8
|
+
# rubocop:disable Naming/ConstantName
|
9
|
+
ClientErrorStatuses = (400...500).freeze
|
10
|
+
ServerErrorStatuses = (500...600).freeze
|
11
|
+
# rubocop:enable Naming/ConstantName
|
12
|
+
|
13
|
+
def on_complete(env)
|
14
|
+
case env[:status]
|
15
|
+
when 400
|
16
|
+
raise Faraday::BadRequestError, response_values(env)
|
17
|
+
when 401
|
18
|
+
raise Faraday::UnauthorizedError, response_values(env)
|
19
|
+
when 403
|
20
|
+
raise Faraday::ForbiddenError, response_values(env)
|
21
|
+
when 404
|
22
|
+
raise Faraday::ResourceNotFound, response_values(env)
|
23
|
+
when 407
|
24
|
+
# mimic the behavior that we get with proxy requests with HTTPS
|
25
|
+
msg = %(407 "Proxy Authentication Required")
|
26
|
+
raise Faraday::ProxyAuthError.new(msg, response_values(env))
|
27
|
+
when 409
|
28
|
+
raise Faraday::ConflictError, response_values(env)
|
29
|
+
when 422
|
30
|
+
raise Faraday::UnprocessableEntityError, response_values(env)
|
31
|
+
when ClientErrorStatuses
|
32
|
+
raise Faraday::ClientError, response_values(env)
|
33
|
+
when ServerErrorStatuses
|
34
|
+
raise Faraday::ServerError, response_values(env)
|
35
|
+
when nil
|
36
|
+
raise Faraday::NilStatusError, response_values(env)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def response_values(env)
|
41
|
+
{
|
42
|
+
status: env.status,
|
43
|
+
headers: env.response_headers,
|
44
|
+
body: env.body,
|
45
|
+
request: {
|
46
|
+
method: env.method,
|
47
|
+
url: env.url,
|
48
|
+
url_path: env.url.path,
|
49
|
+
params: query_params(env),
|
50
|
+
headers: env.request_headers,
|
51
|
+
body: env.request_body
|
52
|
+
}
|
53
|
+
}
|
54
|
+
end
|
55
|
+
|
56
|
+
def query_params(env)
|
57
|
+
env.request.params_encoder ||= Faraday::Utils.default_params_encoder
|
58
|
+
env.params_encoder.decode(env.url.query)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
Faraday::Response.register_middleware(raise_error: Faraday::Response::RaiseError)
|
@@ -0,0 +1,90 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'forwardable'
|
4
|
+
|
5
|
+
module Faraday
|
6
|
+
# Response represents an HTTP response from making an HTTP request.
|
7
|
+
class Response
|
8
|
+
extend Forwardable
|
9
|
+
extend MiddlewareRegistry
|
10
|
+
|
11
|
+
def initialize(env = nil)
|
12
|
+
@env = Env.from(env) if env
|
13
|
+
@on_complete_callbacks = []
|
14
|
+
end
|
15
|
+
|
16
|
+
attr_reader :env
|
17
|
+
|
18
|
+
def status
|
19
|
+
finished? ? env.status : nil
|
20
|
+
end
|
21
|
+
|
22
|
+
def reason_phrase
|
23
|
+
finished? ? env.reason_phrase : nil
|
24
|
+
end
|
25
|
+
|
26
|
+
def headers
|
27
|
+
finished? ? env.response_headers : {}
|
28
|
+
end
|
29
|
+
|
30
|
+
def_delegator :headers, :[]
|
31
|
+
|
32
|
+
def body
|
33
|
+
finished? ? env.body : nil
|
34
|
+
end
|
35
|
+
|
36
|
+
def finished?
|
37
|
+
!!env
|
38
|
+
end
|
39
|
+
|
40
|
+
def on_complete(&block)
|
41
|
+
if finished?
|
42
|
+
yield(env)
|
43
|
+
else
|
44
|
+
@on_complete_callbacks << block
|
45
|
+
end
|
46
|
+
self
|
47
|
+
end
|
48
|
+
|
49
|
+
def finish(env)
|
50
|
+
raise 'response already finished' if finished?
|
51
|
+
|
52
|
+
@env = env.is_a?(Env) ? env : Env.from(env)
|
53
|
+
@on_complete_callbacks.each { |callback| callback.call(@env) }
|
54
|
+
self
|
55
|
+
end
|
56
|
+
|
57
|
+
def success?
|
58
|
+
finished? && env.success?
|
59
|
+
end
|
60
|
+
|
61
|
+
def to_hash
|
62
|
+
{
|
63
|
+
status: env.status, body: env.body,
|
64
|
+
response_headers: env.response_headers
|
65
|
+
}
|
66
|
+
end
|
67
|
+
|
68
|
+
# because @on_complete_callbacks cannot be marshalled
|
69
|
+
def marshal_dump
|
70
|
+
finished? ? to_hash : nil
|
71
|
+
end
|
72
|
+
|
73
|
+
def marshal_load(env)
|
74
|
+
@env = Env.from(env)
|
75
|
+
end
|
76
|
+
|
77
|
+
# Expand the env with more properties, without overriding existing ones.
|
78
|
+
# Useful for applying request params after restoring a marshalled Response.
|
79
|
+
def apply_request(request_env)
|
80
|
+
raise "response didn't finish yet" unless finished?
|
81
|
+
|
82
|
+
@env = Env.from(request_env).update(@env)
|
83
|
+
self
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
require 'faraday/response/json'
|
89
|
+
require 'faraday/response/logger'
|
90
|
+
require 'faraday/response/raise_error'
|
@@ -0,0 +1,139 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Faraday
|
4
|
+
module Utils
|
5
|
+
# A case-insensitive Hash that preserves the original case of a header
|
6
|
+
# when set.
|
7
|
+
#
|
8
|
+
# Adapted from Rack::Utils::HeaderHash
|
9
|
+
class Headers < ::Hash
|
10
|
+
def self.from(value)
|
11
|
+
new(value)
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.allocate
|
15
|
+
new_self = super
|
16
|
+
new_self.initialize_names
|
17
|
+
new_self
|
18
|
+
end
|
19
|
+
|
20
|
+
def initialize(hash = nil)
|
21
|
+
super()
|
22
|
+
@names = {}
|
23
|
+
update(hash || {})
|
24
|
+
end
|
25
|
+
|
26
|
+
def initialize_names
|
27
|
+
@names = {}
|
28
|
+
end
|
29
|
+
|
30
|
+
# on dup/clone, we need to duplicate @names hash
|
31
|
+
def initialize_copy(other)
|
32
|
+
super
|
33
|
+
@names = other.names.dup
|
34
|
+
end
|
35
|
+
|
36
|
+
# need to synchronize concurrent writes to the shared KeyMap
|
37
|
+
keymap_mutex = Mutex.new
|
38
|
+
|
39
|
+
# symbol -> string mapper + cache
|
40
|
+
KeyMap = Hash.new do |map, key|
|
41
|
+
value = if key.respond_to?(:to_str)
|
42
|
+
key
|
43
|
+
else
|
44
|
+
key.to_s.split('_') # user_agent: %w(user agent)
|
45
|
+
.each(&:capitalize!) # => %w(User Agent)
|
46
|
+
.join('-') # => "User-Agent"
|
47
|
+
end
|
48
|
+
keymap_mutex.synchronize { map[key] = value }
|
49
|
+
end
|
50
|
+
KeyMap[:etag] = 'ETag'
|
51
|
+
|
52
|
+
def [](key)
|
53
|
+
key = KeyMap[key]
|
54
|
+
super(key) || super(@names[key.downcase])
|
55
|
+
end
|
56
|
+
|
57
|
+
def []=(key, val)
|
58
|
+
key = KeyMap[key]
|
59
|
+
key = (@names[key.downcase] ||= key)
|
60
|
+
# join multiple values with a comma
|
61
|
+
val = val.to_ary.join(', ') if val.respond_to?(:to_ary)
|
62
|
+
super(key, val)
|
63
|
+
end
|
64
|
+
|
65
|
+
def fetch(key, *args, &block)
|
66
|
+
key = KeyMap[key]
|
67
|
+
key = @names.fetch(key.downcase, key)
|
68
|
+
super(key, *args, &block)
|
69
|
+
end
|
70
|
+
|
71
|
+
def delete(key)
|
72
|
+
key = KeyMap[key]
|
73
|
+
key = @names[key.downcase]
|
74
|
+
return unless key
|
75
|
+
|
76
|
+
@names.delete key.downcase
|
77
|
+
super(key)
|
78
|
+
end
|
79
|
+
|
80
|
+
def include?(key)
|
81
|
+
@names.include? key.downcase
|
82
|
+
end
|
83
|
+
|
84
|
+
alias has_key? include?
|
85
|
+
alias member? include?
|
86
|
+
alias key? include?
|
87
|
+
|
88
|
+
def merge!(other)
|
89
|
+
other.each { |k, v| self[k] = v }
|
90
|
+
self
|
91
|
+
end
|
92
|
+
|
93
|
+
alias update merge!
|
94
|
+
|
95
|
+
def merge(other)
|
96
|
+
hash = dup
|
97
|
+
hash.merge! other
|
98
|
+
end
|
99
|
+
|
100
|
+
def replace(other)
|
101
|
+
clear
|
102
|
+
@names.clear
|
103
|
+
update other
|
104
|
+
self
|
105
|
+
end
|
106
|
+
|
107
|
+
def to_hash
|
108
|
+
{}.update(self)
|
109
|
+
end
|
110
|
+
|
111
|
+
def parse(header_string)
|
112
|
+
return unless header_string && !header_string.empty?
|
113
|
+
|
114
|
+
headers = header_string.split("\r\n")
|
115
|
+
|
116
|
+
# Find the last set of response headers.
|
117
|
+
start_index = headers.rindex { |x| x.start_with?('HTTP/') } || 0
|
118
|
+
last_response = headers.slice(start_index, headers.size)
|
119
|
+
|
120
|
+
last_response
|
121
|
+
.tap { |a| a.shift if a.first.start_with?('HTTP/') }
|
122
|
+
.map { |h| h.split(/:\s*/, 2) } # split key and value
|
123
|
+
.reject { |p| p[0].nil? } # ignore blank lines
|
124
|
+
.each { |key, value| add_parsed(key, value) }
|
125
|
+
end
|
126
|
+
|
127
|
+
protected
|
128
|
+
|
129
|
+
attr_reader :names
|
130
|
+
|
131
|
+
private
|
132
|
+
|
133
|
+
# Join multiple values with a comma.
|
134
|
+
def add_parsed(key, value)
|
135
|
+
self[key] ? self[key] << ', ' << value : self[key] = value
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Faraday
|
4
|
+
module Utils
|
5
|
+
# A hash with stringified keys.
|
6
|
+
class ParamsHash < Hash
|
7
|
+
def [](key)
|
8
|
+
super(convert_key(key))
|
9
|
+
end
|
10
|
+
|
11
|
+
def []=(key, value)
|
12
|
+
super(convert_key(key), value)
|
13
|
+
end
|
14
|
+
|
15
|
+
def delete(key)
|
16
|
+
super(convert_key(key))
|
17
|
+
end
|
18
|
+
|
19
|
+
def include?(key)
|
20
|
+
super(convert_key(key))
|
21
|
+
end
|
22
|
+
|
23
|
+
alias has_key? include?
|
24
|
+
alias member? include?
|
25
|
+
alias key? include?
|
26
|
+
|
27
|
+
def update(params)
|
28
|
+
params.each do |key, value|
|
29
|
+
self[key] = value
|
30
|
+
end
|
31
|
+
self
|
32
|
+
end
|
33
|
+
alias merge! update
|
34
|
+
|
35
|
+
def merge(params)
|
36
|
+
dup.update(params)
|
37
|
+
end
|
38
|
+
|
39
|
+
def replace(other)
|
40
|
+
clear
|
41
|
+
update(other)
|
42
|
+
end
|
43
|
+
|
44
|
+
def merge_query(query, encoder = nil)
|
45
|
+
return self unless query && !query.empty?
|
46
|
+
|
47
|
+
update((encoder || Utils.default_params_encoder).decode(query))
|
48
|
+
end
|
49
|
+
|
50
|
+
def to_query(encoder = nil)
|
51
|
+
(encoder || Utils.default_params_encoder).encode(self)
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
def convert_key(key)
|
57
|
+
key.to_s
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,122 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'base64'
|
4
|
+
require 'uri'
|
5
|
+
require 'faraday/utils/headers'
|
6
|
+
require 'faraday/utils/params_hash'
|
7
|
+
|
8
|
+
module Faraday
|
9
|
+
# Utils contains various static helper methods.
|
10
|
+
module Utils
|
11
|
+
module_function
|
12
|
+
|
13
|
+
def build_query(params)
|
14
|
+
FlatParamsEncoder.encode(params)
|
15
|
+
end
|
16
|
+
|
17
|
+
def build_nested_query(params)
|
18
|
+
NestedParamsEncoder.encode(params)
|
19
|
+
end
|
20
|
+
|
21
|
+
def default_space_encoding
|
22
|
+
@default_space_encoding ||= '+'
|
23
|
+
end
|
24
|
+
|
25
|
+
class << self
|
26
|
+
attr_writer :default_space_encoding
|
27
|
+
end
|
28
|
+
|
29
|
+
ESCAPE_RE = /[^a-zA-Z0-9 .~_-]/.freeze
|
30
|
+
|
31
|
+
def escape(str)
|
32
|
+
str.to_s.gsub(ESCAPE_RE) do |match|
|
33
|
+
"%#{match.unpack('H2' * match.bytesize).join('%').upcase}"
|
34
|
+
end.gsub(' ', default_space_encoding)
|
35
|
+
end
|
36
|
+
|
37
|
+
def unescape(str)
|
38
|
+
CGI.unescape str.to_s
|
39
|
+
end
|
40
|
+
|
41
|
+
DEFAULT_SEP = /[&;] */n.freeze
|
42
|
+
|
43
|
+
# Adapted from Rack
|
44
|
+
def parse_query(query)
|
45
|
+
FlatParamsEncoder.decode(query)
|
46
|
+
end
|
47
|
+
|
48
|
+
def parse_nested_query(query)
|
49
|
+
NestedParamsEncoder.decode(query)
|
50
|
+
end
|
51
|
+
|
52
|
+
def default_params_encoder
|
53
|
+
@default_params_encoder ||= NestedParamsEncoder
|
54
|
+
end
|
55
|
+
|
56
|
+
def basic_header_from(login, pass)
|
57
|
+
value = Base64.encode64("#{login}:#{pass}")
|
58
|
+
value.delete!("\n")
|
59
|
+
"Basic #{value}"
|
60
|
+
end
|
61
|
+
|
62
|
+
class << self
|
63
|
+
attr_writer :default_params_encoder
|
64
|
+
end
|
65
|
+
|
66
|
+
# Normalize URI() behavior across Ruby versions
|
67
|
+
#
|
68
|
+
# url - A String or URI.
|
69
|
+
#
|
70
|
+
# Returns a parsed URI.
|
71
|
+
def URI(url) # rubocop:disable Naming/MethodName
|
72
|
+
if url.respond_to?(:host)
|
73
|
+
url
|
74
|
+
elsif url.respond_to?(:to_str)
|
75
|
+
default_uri_parser.call(url)
|
76
|
+
else
|
77
|
+
raise ArgumentError, 'bad argument (expected URI object or URI string)'
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def default_uri_parser
|
82
|
+
@default_uri_parser ||= Kernel.method(:URI)
|
83
|
+
end
|
84
|
+
|
85
|
+
def default_uri_parser=(parser)
|
86
|
+
@default_uri_parser = if parser.respond_to?(:call) || parser.nil?
|
87
|
+
parser
|
88
|
+
else
|
89
|
+
parser.method(:parse)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
# Receives a String or URI and returns just
|
94
|
+
# the path with the query string sorted.
|
95
|
+
def normalize_path(url)
|
96
|
+
url = URI(url)
|
97
|
+
(url.path.start_with?('/') ? url.path : "/#{url.path}") +
|
98
|
+
(url.query ? "?#{sort_query_params(url.query)}" : '')
|
99
|
+
end
|
100
|
+
|
101
|
+
# Recursive hash update
|
102
|
+
def deep_merge!(target, hash)
|
103
|
+
hash.each do |key, value|
|
104
|
+
target[key] = if value.is_a?(Hash) && (target[key].is_a?(Hash) || target[key].is_a?(Options))
|
105
|
+
deep_merge(target[key], value)
|
106
|
+
else
|
107
|
+
value
|
108
|
+
end
|
109
|
+
end
|
110
|
+
target
|
111
|
+
end
|
112
|
+
|
113
|
+
# Recursive hash merge
|
114
|
+
def deep_merge(source, hash)
|
115
|
+
deep_merge!(source.dup, hash)
|
116
|
+
end
|
117
|
+
|
118
|
+
def sort_query_params(query)
|
119
|
+
query.split('&').sort.join('&')
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
@@ -0,0 +1,157 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'cgi'
|
4
|
+
require 'date'
|
5
|
+
require 'set'
|
6
|
+
require 'forwardable'
|
7
|
+
require 'faraday/version'
|
8
|
+
require 'faraday/methods'
|
9
|
+
require 'faraday/error'
|
10
|
+
require 'faraday/middleware_registry'
|
11
|
+
require 'faraday/utils'
|
12
|
+
require 'faraday/options'
|
13
|
+
require 'faraday/connection'
|
14
|
+
require 'faraday/rack_builder'
|
15
|
+
require 'faraday/parameters'
|
16
|
+
require 'faraday/middleware'
|
17
|
+
require 'faraday/adapter'
|
18
|
+
require 'faraday/request'
|
19
|
+
require 'faraday/response'
|
20
|
+
require 'faraday/net_http'
|
21
|
+
# This is the main namespace for Faraday.
|
22
|
+
#
|
23
|
+
# It provides methods to create {Connection} objects, and HTTP-related
|
24
|
+
# methods to use directly.
|
25
|
+
#
|
26
|
+
# @example Helpful class methods for easy usage
|
27
|
+
# Faraday.get "http://faraday.com"
|
28
|
+
#
|
29
|
+
# @example Helpful class method `.new` to create {Connection} objects.
|
30
|
+
# conn = Faraday.new "http://faraday.com"
|
31
|
+
# conn.get '/'
|
32
|
+
#
|
33
|
+
module Faraday
|
34
|
+
CONTENT_TYPE = 'Content-Type'
|
35
|
+
|
36
|
+
class << self
|
37
|
+
# The root path that Faraday is being loaded from.
|
38
|
+
#
|
39
|
+
# This is the root from where the libraries are auto-loaded.
|
40
|
+
#
|
41
|
+
# @return [String]
|
42
|
+
attr_accessor :root_path
|
43
|
+
|
44
|
+
# Gets or sets the path that the Faraday libs are loaded from.
|
45
|
+
# @return [String]
|
46
|
+
attr_accessor :lib_path
|
47
|
+
|
48
|
+
# @overload default_adapter
|
49
|
+
# Gets the Symbol key identifying a default Adapter to use
|
50
|
+
# for the default {Faraday::Connection}. Defaults to `:net_http`.
|
51
|
+
# @return [Symbol] the default adapter
|
52
|
+
# @overload default_adapter=(adapter)
|
53
|
+
# Updates default adapter while resetting {.default_connection}.
|
54
|
+
# @return [Symbol] the new default_adapter.
|
55
|
+
attr_reader :default_adapter
|
56
|
+
|
57
|
+
# Option for the default_adapter
|
58
|
+
# @return [Hash] default_adapter options
|
59
|
+
attr_accessor :default_adapter_options
|
60
|
+
|
61
|
+
# Documented below, see default_connection
|
62
|
+
attr_writer :default_connection
|
63
|
+
|
64
|
+
# Tells Faraday to ignore the environment proxy (http_proxy).
|
65
|
+
# Defaults to `false`.
|
66
|
+
# @return [Boolean]
|
67
|
+
attr_accessor :ignore_env_proxy
|
68
|
+
|
69
|
+
# Initializes a new {Connection}.
|
70
|
+
#
|
71
|
+
# @param url [String,Hash] The optional String base URL to use as a prefix
|
72
|
+
# for all requests. Can also be the options Hash. Any of these
|
73
|
+
# values will be set on every request made, unless overridden
|
74
|
+
# for a specific request.
|
75
|
+
# @param options [Hash]
|
76
|
+
# @option options [String] :url Base URL
|
77
|
+
# @option options [Hash] :params Hash of unencoded URI query params.
|
78
|
+
# @option options [Hash] :headers Hash of unencoded HTTP headers.
|
79
|
+
# @option options [Hash] :request Hash of request options.
|
80
|
+
# @option options [Hash] :ssl Hash of SSL options.
|
81
|
+
# @option options [Hash] :proxy Hash of Proxy options.
|
82
|
+
# @return [Faraday::Connection]
|
83
|
+
#
|
84
|
+
# @example With an URL argument
|
85
|
+
# Faraday.new 'http://faraday.com'
|
86
|
+
# # => Faraday::Connection to http://faraday.com
|
87
|
+
#
|
88
|
+
# @example With an URL argument and an options hash
|
89
|
+
# Faraday.new 'http://faraday.com', params: { page: 1 }
|
90
|
+
# # => Faraday::Connection to http://faraday.com?page=1
|
91
|
+
#
|
92
|
+
# @example With everything in an options hash
|
93
|
+
# Faraday.new url: 'http://faraday.com',
|
94
|
+
# params: { page: 1 }
|
95
|
+
# # => Faraday::Connection to http://faraday.com?page=1
|
96
|
+
def new(url = nil, options = {}, &block)
|
97
|
+
options = Utils.deep_merge(default_connection_options, options)
|
98
|
+
Faraday::Connection.new(url, options, &block)
|
99
|
+
end
|
100
|
+
|
101
|
+
# Documented elsewhere, see default_adapter reader
|
102
|
+
def default_adapter=(adapter)
|
103
|
+
@default_connection = nil
|
104
|
+
@default_adapter = adapter
|
105
|
+
end
|
106
|
+
|
107
|
+
def respond_to_missing?(symbol, include_private = false)
|
108
|
+
default_connection.respond_to?(symbol, include_private) || super
|
109
|
+
end
|
110
|
+
|
111
|
+
# @overload default_connection
|
112
|
+
# Gets the default connection used for simple scripts.
|
113
|
+
# @return [Faraday::Connection] a connection configured with
|
114
|
+
# the default_adapter.
|
115
|
+
# @overload default_connection=(connection)
|
116
|
+
# @param connection [Faraday::Connection]
|
117
|
+
# Sets the default {Faraday::Connection} for simple scripts that
|
118
|
+
# access the Faraday constant directly, such as
|
119
|
+
# <code>Faraday.get "https://faraday.com"</code>.
|
120
|
+
def default_connection
|
121
|
+
@default_connection ||= Connection.new(default_connection_options)
|
122
|
+
end
|
123
|
+
|
124
|
+
# Gets the default connection options used when calling {Faraday#new}.
|
125
|
+
#
|
126
|
+
# @return [Faraday::ConnectionOptions]
|
127
|
+
def default_connection_options
|
128
|
+
@default_connection_options ||= ConnectionOptions.new
|
129
|
+
end
|
130
|
+
|
131
|
+
# Sets the default options used when calling {Faraday#new}.
|
132
|
+
#
|
133
|
+
# @param options [Hash, Faraday::ConnectionOptions]
|
134
|
+
def default_connection_options=(options)
|
135
|
+
@default_connection = nil
|
136
|
+
@default_connection_options = ConnectionOptions.from(options)
|
137
|
+
end
|
138
|
+
|
139
|
+
private
|
140
|
+
|
141
|
+
# Internal: Proxies method calls on the Faraday constant to
|
142
|
+
# .default_connection.
|
143
|
+
def method_missing(name, *args, &block)
|
144
|
+
if default_connection.respond_to?(name)
|
145
|
+
default_connection.send(name, *args, &block)
|
146
|
+
else
|
147
|
+
super
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
self.ignore_env_proxy = false
|
153
|
+
self.root_path = File.expand_path __dir__
|
154
|
+
self.lib_path = File.expand_path 'faraday', __dir__
|
155
|
+
self.default_adapter = :net_http
|
156
|
+
self.default_adapter_options = {}
|
157
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'webmock/rspec'
|
4
|
+
WebMock.disable_net_connect!(allow_localhost: true)
|
5
|
+
|
6
|
+
require_relative '../support/helper_methods'
|
7
|
+
require_relative '../support/disabling_stub'
|
8
|
+
require_relative '../support/streaming_response_checker'
|
9
|
+
require_relative '../support/shared_examples/adapter'
|
10
|
+
require_relative '../support/shared_examples/request_method'
|
11
|
+
|
12
|
+
RSpec.configure do |config|
|
13
|
+
config.include Faraday::HelperMethods
|
14
|
+
end
|