hearth 1.0.0.pre1 → 1.0.0.pre2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -4
- data/VERSION +1 -1
- data/lib/hearth/api_error.rb +15 -1
- data/lib/hearth/auth_option.rb +21 -0
- data/lib/hearth/auth_schemes/anonymous.rb +21 -0
- data/lib/hearth/auth_schemes/http_api_key.rb +16 -0
- data/lib/hearth/auth_schemes/http_basic.rb +16 -0
- data/lib/hearth/auth_schemes/http_bearer.rb +16 -0
- data/lib/hearth/auth_schemes/http_digest.rb +16 -0
- data/lib/hearth/auth_schemes.rb +32 -0
- data/lib/hearth/checksums.rb +31 -0
- data/lib/hearth/client_stubs.rb +130 -0
- data/lib/hearth/config/env_provider.rb +53 -0
- data/lib/hearth/config/resolver.rb +52 -0
- data/lib/hearth/configuration.rb +15 -0
- data/lib/hearth/connection_pool.rb +77 -0
- data/lib/hearth/context.rb +28 -4
- data/lib/hearth/dns/host_address.rb +23 -0
- data/lib/hearth/dns/host_resolver.rb +92 -0
- data/lib/hearth/dns.rb +48 -0
- data/lib/hearth/http/api_error.rb +4 -8
- data/lib/hearth/http/client.rb +208 -59
- data/lib/hearth/http/error_inspector.rb +85 -0
- data/lib/hearth/http/error_parser.rb +18 -20
- data/lib/hearth/http/field.rb +64 -0
- data/lib/hearth/http/fields.rb +117 -0
- data/lib/hearth/http/middleware/content_length.rb +5 -2
- data/lib/hearth/http/middleware/content_md5.rb +31 -0
- data/lib/hearth/http/middleware/request_compression.rb +157 -0
- data/lib/hearth/http/middleware.rb +12 -0
- data/lib/hearth/http/networking_error.rb +1 -14
- data/lib/hearth/http/request.rb +83 -56
- data/lib/hearth/http/response.rb +42 -13
- data/lib/hearth/http.rb +14 -5
- data/lib/hearth/identities/anonymous.rb +8 -0
- data/lib/hearth/identities/http_api_key.rb +16 -0
- data/lib/hearth/identities/http_bearer.rb +16 -0
- data/lib/hearth/identities/http_login.rb +20 -0
- data/lib/hearth/identities.rb +21 -0
- data/lib/hearth/identity_resolver.rb +17 -0
- data/lib/hearth/interceptor.rb +506 -0
- data/lib/hearth/interceptor_context.rb +36 -0
- data/lib/hearth/interceptor_list.rb +48 -0
- data/lib/hearth/interceptors.rb +75 -0
- data/lib/hearth/middleware/auth.rb +100 -0
- data/lib/hearth/middleware/build.rb +32 -0
- data/lib/hearth/middleware/host_prefix.rb +10 -6
- data/lib/hearth/middleware/initialize.rb +58 -0
- data/lib/hearth/middleware/parse.rb +45 -6
- data/lib/hearth/middleware/retry.rb +97 -23
- data/lib/hearth/middleware/send.rb +137 -25
- data/lib/hearth/middleware/sign.rb +65 -0
- data/lib/hearth/middleware/validate.rb +11 -1
- data/lib/hearth/middleware.rb +19 -8
- data/lib/hearth/middleware_stack.rb +1 -43
- data/lib/hearth/networking_error.rb +18 -0
- data/lib/hearth/number_helper.rb +2 -2
- data/lib/hearth/output.rb +8 -4
- data/lib/hearth/plugin_list.rb +53 -0
- data/lib/hearth/query/param.rb +52 -0
- data/lib/hearth/query/param_list.rb +54 -0
- data/lib/hearth/query/param_matcher.rb +32 -0
- data/lib/hearth/refreshing_identity_resolver.rb +63 -0
- data/lib/hearth/request.rb +22 -0
- data/lib/hearth/response.rb +33 -0
- data/lib/hearth/retry/adaptive.rb +60 -0
- data/lib/hearth/retry/capacity_not_available_error.rb +9 -0
- data/lib/hearth/retry/client_rate_limiter.rb +143 -0
- data/lib/hearth/retry/exponential_backoff.rb +15 -0
- data/lib/hearth/retry/retry_quota.rb +56 -0
- data/lib/hearth/retry/standard.rb +46 -0
- data/lib/hearth/retry/strategy.rb +20 -0
- data/lib/hearth/retry.rb +16 -0
- data/lib/hearth/signers/anonymous.rb +16 -0
- data/lib/hearth/signers/http_api_key.rb +29 -0
- data/lib/hearth/signers/http_basic.rb +23 -0
- data/lib/hearth/signers/http_bearer.rb +19 -0
- data/lib/hearth/signers/http_digest.rb +19 -0
- data/lib/hearth/signers.rb +23 -0
- data/lib/hearth/stubs.rb +30 -0
- data/lib/hearth/time_helper.rb +5 -3
- data/lib/hearth/validator.rb +44 -5
- data/lib/hearth/waiters/poller.rb +6 -7
- data/lib/hearth/waiters/waiter.rb +17 -4
- data/lib/hearth/xml/formatter.rb +11 -2
- data/lib/hearth/xml/node.rb +2 -2
- data/lib/hearth.rb +32 -5
- data/sig/lib/hearth/aliases.rbs +4 -0
- data/sig/lib/hearth/api_error.rbs +13 -0
- data/sig/lib/hearth/auth_option.rbs +11 -0
- data/sig/lib/hearth/auth_schemes/anonymous.rbs +7 -0
- data/sig/lib/hearth/auth_schemes/http_api_key.rbs +7 -0
- data/sig/lib/hearth/auth_schemes/http_basic.rbs +7 -0
- data/sig/lib/hearth/auth_schemes/http_bearer.rbs +7 -0
- data/sig/lib/hearth/auth_schemes/http_digest.rbs +7 -0
- data/sig/lib/hearth/auth_schemes.rbs +13 -0
- data/sig/lib/hearth/block_io.rbs +9 -0
- data/sig/lib/hearth/client_stubs.rbs +5 -0
- data/sig/lib/hearth/configuration.rbs +7 -0
- data/sig/lib/hearth/dns/host_address.rbs +13 -0
- data/sig/lib/hearth/dns/host_resolver.rbs +19 -0
- data/sig/lib/hearth/http/api_error.rbs +13 -0
- data/sig/lib/hearth/http/client.rbs +9 -0
- data/sig/lib/hearth/http/field.rbs +19 -0
- data/sig/lib/hearth/http/fields.rbs +43 -0
- data/sig/lib/hearth/http/request.rbs +25 -0
- data/sig/lib/hearth/http/response.rbs +21 -0
- data/sig/lib/hearth/identities/anonymous.rbs +6 -0
- data/sig/lib/hearth/identities/http_api_key.rbs +9 -0
- data/sig/lib/hearth/identities/http_bearer.rbs +9 -0
- data/sig/lib/hearth/identities/http_login.rbs +11 -0
- data/sig/lib/hearth/identities.rbs +9 -0
- data/sig/lib/hearth/identity_resolver.rbs +7 -0
- data/sig/lib/hearth/interceptor.rbs +9 -0
- data/sig/lib/hearth/interceptor_context.rbs +15 -0
- data/sig/lib/hearth/interceptor_list.rbs +16 -0
- data/sig/lib/hearth/interfaces.rbs +65 -0
- data/sig/lib/hearth/output.rbs +11 -0
- data/sig/lib/hearth/plugin_list.rbs +15 -0
- data/sig/lib/hearth/query/param.rbs +17 -0
- data/sig/lib/hearth/query/param_list.rbs +25 -0
- data/sig/lib/hearth/request.rbs +9 -0
- data/sig/lib/hearth/response.rbs +11 -0
- data/sig/lib/hearth/retry/adaptive.rbs +13 -0
- data/sig/lib/hearth/retry/exponential_backoff.rbs +7 -0
- data/sig/lib/hearth/retry/standard.rbs +13 -0
- data/sig/lib/hearth/retry/strategy.rbs +11 -0
- data/sig/lib/hearth/retry.rbs +9 -0
- data/sig/lib/hearth/signers/anonymous.rbs +9 -0
- data/sig/lib/hearth/signers/http_api_key.rbs +9 -0
- data/sig/lib/hearth/signers/http_basic.rbs +9 -0
- data/sig/lib/hearth/signers/http_bearer.rbs +9 -0
- data/sig/lib/hearth/signers/http_digest.rbs +9 -0
- data/sig/lib/hearth/signers.rbs +9 -0
- data/sig/lib/hearth/structure.rbs +7 -0
- data/sig/lib/hearth/union.rbs +5 -0
- data/sig/lib/hearth/waiters/waiter.rbs +17 -0
- metadata +132 -22
- data/lib/hearth/http/headers.rb +0 -70
- data/lib/hearth/middleware/around_handler.rb +0 -24
- data/lib/hearth/middleware/request_handler.rb +0 -24
- data/lib/hearth/middleware/response_handler.rb +0 -25
- data/lib/hearth/middleware_builder.rb +0 -246
- data/lib/hearth/stubbing/client_stubs.rb +0 -115
- data/lib/hearth/stubbing/stubs.rb +0 -32
- data/lib/hearth/waiters/errors.rb +0 -15
- data/sig/lib/seahorse/api_error.rbs +0 -10
- data/sig/lib/seahorse/document.rbs +0 -2
- data/sig/lib/seahorse/http/api_error.rbs +0 -21
- data/sig/lib/seahorse/http/headers.rbs +0 -47
- data/sig/lib/seahorse/http/response.rbs +0 -21
- data/sig/lib/seahorse/simple_delegator.rbs +0 -3
- data/sig/lib/seahorse/structure.rbs +0 -18
- data/sig/lib/seahorse/stubbing/client_stubs.rbs +0 -103
- data/sig/lib/seahorse/stubbing/stubs.rbs +0 -14
- data/sig/lib/seahorse/union.rbs +0 -6
data/lib/hearth/http/response.rb
CHANGED
@@ -1,29 +1,58 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'stringio'
|
4
|
-
|
5
3
|
module Hearth
|
6
4
|
module HTTP
|
7
5
|
# Represents an HTTP Response.
|
8
|
-
|
9
|
-
class Response
|
6
|
+
class Response < Hearth::Response
|
10
7
|
# @param [Integer] status
|
11
|
-
# @param [
|
12
|
-
# @param [
|
13
|
-
|
8
|
+
# @param [String, nil] reason
|
9
|
+
# @param [Fields] fields
|
10
|
+
# @param (see Hearth::Response#initialize)
|
11
|
+
def initialize(status: 0, reason: nil, fields: Fields.new, **kwargs)
|
12
|
+
super(**kwargs)
|
14
13
|
@status = status
|
15
|
-
@
|
16
|
-
@
|
14
|
+
@reason = reason
|
15
|
+
@fields = fields
|
16
|
+
@headers = Fields::Proxy.new(@fields, :header)
|
17
|
+
@trailers = Fields::Proxy.new(@fields, :trailer)
|
17
18
|
end
|
18
19
|
|
19
20
|
# @return [Integer]
|
20
21
|
attr_accessor :status
|
21
22
|
|
22
|
-
# @return [
|
23
|
-
attr_accessor :
|
23
|
+
# @return [String, nil]
|
24
|
+
attr_accessor :reason
|
25
|
+
|
26
|
+
# @return [Fields]
|
27
|
+
attr_reader :fields
|
28
|
+
|
29
|
+
# @return [Fields::Proxy]
|
30
|
+
attr_reader :headers
|
31
|
+
|
32
|
+
# @return [Fields::Proxy]
|
33
|
+
attr_reader :trailers
|
24
34
|
|
25
|
-
#
|
26
|
-
|
35
|
+
# Replace attributes from other response
|
36
|
+
# @param [Response] other
|
37
|
+
# @return [Response]
|
38
|
+
def replace(other)
|
39
|
+
@status = other.status
|
40
|
+
@reason = other.reason
|
41
|
+
@fields = other.fields
|
42
|
+
@headers = Fields::Proxy.new(@fields, :header)
|
43
|
+
@trailers = Fields::Proxy.new(@fields, :trailer)
|
44
|
+
|
45
|
+
super
|
46
|
+
end
|
47
|
+
|
48
|
+
# Resets the HTTP response.
|
49
|
+
# @return [Response]
|
50
|
+
def reset
|
51
|
+
@status = 0
|
52
|
+
@reason = nil
|
53
|
+
@fields.clear
|
54
|
+
super
|
55
|
+
end
|
27
56
|
end
|
28
57
|
end
|
29
58
|
end
|
data/lib/hearth/http.rb
CHANGED
@@ -3,9 +3,11 @@
|
|
3
3
|
require 'cgi'
|
4
4
|
require_relative 'http/api_error'
|
5
5
|
require_relative 'http/client'
|
6
|
+
require_relative 'http/error_inspector'
|
6
7
|
require_relative 'http/error_parser'
|
7
|
-
require_relative 'http/
|
8
|
-
require_relative 'http/
|
8
|
+
require_relative 'http/field'
|
9
|
+
require_relative 'http/fields'
|
10
|
+
require_relative 'http/middleware'
|
9
11
|
require_relative 'http/networking_error'
|
10
12
|
require_relative 'http/request'
|
11
13
|
require_relative 'http/response'
|
@@ -13,21 +15,28 @@ require_relative 'http/response'
|
|
13
15
|
module Hearth
|
14
16
|
# HTTP namespace for HTTP specific functionality. Also includes utility
|
15
17
|
# methods for URI escaping.
|
16
|
-
# @api private
|
17
18
|
module HTTP
|
18
|
-
# TODO: - do these belong here?
|
19
19
|
class << self
|
20
20
|
# URI escapes the given value.
|
21
21
|
#
|
22
|
-
# Hearth
|
22
|
+
# Hearth.uri_escape("a b/c")
|
23
23
|
# #=> "a%20b%2Fc"
|
24
24
|
#
|
25
25
|
# @param [String] value
|
26
26
|
# @return [String] URI encoded value except for '+' and '~'.
|
27
|
+
# @api private
|
27
28
|
def uri_escape(value)
|
28
29
|
CGI.escape(value.encode('UTF-8')).gsub('+', '%20').gsub('%7E', '~')
|
29
30
|
end
|
30
31
|
|
32
|
+
# URI escapes the given path.
|
33
|
+
#
|
34
|
+
# Hearth.uri_escape_path("a b/c")
|
35
|
+
# #=> "a%20b/c"
|
36
|
+
#
|
37
|
+
# @param [String] path
|
38
|
+
# @return [String] URI encoded path except for '+' and '~'.
|
39
|
+
# @api private
|
31
40
|
def uri_escape_path(path)
|
32
41
|
path.gsub(%r{[^/]+}) { |part| uri_escape(part) }
|
33
42
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Hearth
|
4
|
+
module Identities
|
5
|
+
# Identity class for API Key authentication.
|
6
|
+
class HTTPApiKey < Identities::Base
|
7
|
+
def initialize(key:, **kwargs)
|
8
|
+
super(**kwargs)
|
9
|
+
@key = key
|
10
|
+
end
|
11
|
+
|
12
|
+
# @return [String]
|
13
|
+
attr_reader :key
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Hearth
|
4
|
+
module Identities
|
5
|
+
# Identity class for bearer token authentication.
|
6
|
+
class HTTPBearer < Identities::Base
|
7
|
+
def initialize(token:, **kwargs)
|
8
|
+
super(**kwargs)
|
9
|
+
@token = token
|
10
|
+
end
|
11
|
+
|
12
|
+
# @return [String]
|
13
|
+
attr_reader :token
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Hearth
|
4
|
+
module Identities
|
5
|
+
# Identity class for login authentication.
|
6
|
+
class HTTPLogin < Identities::Base
|
7
|
+
def initialize(username:, password:, **kwargs)
|
8
|
+
super(**kwargs)
|
9
|
+
@username = username
|
10
|
+
@password = password
|
11
|
+
end
|
12
|
+
|
13
|
+
# @return [String]
|
14
|
+
attr_reader :username
|
15
|
+
|
16
|
+
# @return [String]
|
17
|
+
attr_reader :password
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Hearth
|
4
|
+
# Namespace for all Identity classes.
|
5
|
+
module Identities
|
6
|
+
# Base class for all Identity classes.
|
7
|
+
class Base
|
8
|
+
def initialize(expiration: nil)
|
9
|
+
@expiration = expiration
|
10
|
+
end
|
11
|
+
|
12
|
+
# @return [Time, nil]
|
13
|
+
attr_reader :expiration
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
require_relative 'identities/anonymous'
|
19
|
+
require_relative 'identities/http_api_key'
|
20
|
+
require_relative 'identities/http_bearer'
|
21
|
+
require_relative 'identities/http_login'
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Hearth
|
4
|
+
# Basic Identity resolver that uses a proc to resolve an Identity.
|
5
|
+
class IdentityResolver
|
6
|
+
# @param [Proc] proc A proc that takes identity properties (Hash)
|
7
|
+
# and returns a {Hearth::Identities::Base}.
|
8
|
+
def initialize(proc)
|
9
|
+
@proc = proc
|
10
|
+
end
|
11
|
+
|
12
|
+
# @param [Hash] properties
|
13
|
+
def identity(properties = {})
|
14
|
+
@proc.call(properties)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|