hearth 1.0.0.pre1 → 1.0.0.pre2

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 (157) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +4 -4
  3. data/VERSION +1 -1
  4. data/lib/hearth/api_error.rb +15 -1
  5. data/lib/hearth/auth_option.rb +21 -0
  6. data/lib/hearth/auth_schemes/anonymous.rb +21 -0
  7. data/lib/hearth/auth_schemes/http_api_key.rb +16 -0
  8. data/lib/hearth/auth_schemes/http_basic.rb +16 -0
  9. data/lib/hearth/auth_schemes/http_bearer.rb +16 -0
  10. data/lib/hearth/auth_schemes/http_digest.rb +16 -0
  11. data/lib/hearth/auth_schemes.rb +32 -0
  12. data/lib/hearth/checksums.rb +31 -0
  13. data/lib/hearth/client_stubs.rb +130 -0
  14. data/lib/hearth/config/env_provider.rb +53 -0
  15. data/lib/hearth/config/resolver.rb +52 -0
  16. data/lib/hearth/configuration.rb +15 -0
  17. data/lib/hearth/connection_pool.rb +77 -0
  18. data/lib/hearth/context.rb +28 -4
  19. data/lib/hearth/dns/host_address.rb +23 -0
  20. data/lib/hearth/dns/host_resolver.rb +92 -0
  21. data/lib/hearth/dns.rb +48 -0
  22. data/lib/hearth/http/api_error.rb +4 -8
  23. data/lib/hearth/http/client.rb +208 -59
  24. data/lib/hearth/http/error_inspector.rb +85 -0
  25. data/lib/hearth/http/error_parser.rb +18 -20
  26. data/lib/hearth/http/field.rb +64 -0
  27. data/lib/hearth/http/fields.rb +117 -0
  28. data/lib/hearth/http/middleware/content_length.rb +5 -2
  29. data/lib/hearth/http/middleware/content_md5.rb +31 -0
  30. data/lib/hearth/http/middleware/request_compression.rb +157 -0
  31. data/lib/hearth/http/middleware.rb +12 -0
  32. data/lib/hearth/http/networking_error.rb +1 -14
  33. data/lib/hearth/http/request.rb +83 -56
  34. data/lib/hearth/http/response.rb +42 -13
  35. data/lib/hearth/http.rb +14 -5
  36. data/lib/hearth/identities/anonymous.rb +8 -0
  37. data/lib/hearth/identities/http_api_key.rb +16 -0
  38. data/lib/hearth/identities/http_bearer.rb +16 -0
  39. data/lib/hearth/identities/http_login.rb +20 -0
  40. data/lib/hearth/identities.rb +21 -0
  41. data/lib/hearth/identity_resolver.rb +17 -0
  42. data/lib/hearth/interceptor.rb +506 -0
  43. data/lib/hearth/interceptor_context.rb +36 -0
  44. data/lib/hearth/interceptor_list.rb +48 -0
  45. data/lib/hearth/interceptors.rb +75 -0
  46. data/lib/hearth/middleware/auth.rb +100 -0
  47. data/lib/hearth/middleware/build.rb +32 -0
  48. data/lib/hearth/middleware/host_prefix.rb +10 -6
  49. data/lib/hearth/middleware/initialize.rb +58 -0
  50. data/lib/hearth/middleware/parse.rb +45 -6
  51. data/lib/hearth/middleware/retry.rb +97 -23
  52. data/lib/hearth/middleware/send.rb +137 -25
  53. data/lib/hearth/middleware/sign.rb +65 -0
  54. data/lib/hearth/middleware/validate.rb +11 -1
  55. data/lib/hearth/middleware.rb +19 -8
  56. data/lib/hearth/middleware_stack.rb +1 -43
  57. data/lib/hearth/networking_error.rb +18 -0
  58. data/lib/hearth/number_helper.rb +2 -2
  59. data/lib/hearth/output.rb +8 -4
  60. data/lib/hearth/plugin_list.rb +53 -0
  61. data/lib/hearth/query/param.rb +52 -0
  62. data/lib/hearth/query/param_list.rb +54 -0
  63. data/lib/hearth/query/param_matcher.rb +32 -0
  64. data/lib/hearth/refreshing_identity_resolver.rb +63 -0
  65. data/lib/hearth/request.rb +22 -0
  66. data/lib/hearth/response.rb +33 -0
  67. data/lib/hearth/retry/adaptive.rb +60 -0
  68. data/lib/hearth/retry/capacity_not_available_error.rb +9 -0
  69. data/lib/hearth/retry/client_rate_limiter.rb +143 -0
  70. data/lib/hearth/retry/exponential_backoff.rb +15 -0
  71. data/lib/hearth/retry/retry_quota.rb +56 -0
  72. data/lib/hearth/retry/standard.rb +46 -0
  73. data/lib/hearth/retry/strategy.rb +20 -0
  74. data/lib/hearth/retry.rb +16 -0
  75. data/lib/hearth/signers/anonymous.rb +16 -0
  76. data/lib/hearth/signers/http_api_key.rb +29 -0
  77. data/lib/hearth/signers/http_basic.rb +23 -0
  78. data/lib/hearth/signers/http_bearer.rb +19 -0
  79. data/lib/hearth/signers/http_digest.rb +19 -0
  80. data/lib/hearth/signers.rb +23 -0
  81. data/lib/hearth/stubs.rb +30 -0
  82. data/lib/hearth/time_helper.rb +5 -3
  83. data/lib/hearth/validator.rb +44 -5
  84. data/lib/hearth/waiters/poller.rb +6 -7
  85. data/lib/hearth/waiters/waiter.rb +17 -4
  86. data/lib/hearth/xml/formatter.rb +11 -2
  87. data/lib/hearth/xml/node.rb +2 -2
  88. data/lib/hearth.rb +32 -5
  89. data/sig/lib/hearth/aliases.rbs +4 -0
  90. data/sig/lib/hearth/api_error.rbs +13 -0
  91. data/sig/lib/hearth/auth_option.rbs +11 -0
  92. data/sig/lib/hearth/auth_schemes/anonymous.rbs +7 -0
  93. data/sig/lib/hearth/auth_schemes/http_api_key.rbs +7 -0
  94. data/sig/lib/hearth/auth_schemes/http_basic.rbs +7 -0
  95. data/sig/lib/hearth/auth_schemes/http_bearer.rbs +7 -0
  96. data/sig/lib/hearth/auth_schemes/http_digest.rbs +7 -0
  97. data/sig/lib/hearth/auth_schemes.rbs +13 -0
  98. data/sig/lib/hearth/block_io.rbs +9 -0
  99. data/sig/lib/hearth/client_stubs.rbs +5 -0
  100. data/sig/lib/hearth/configuration.rbs +7 -0
  101. data/sig/lib/hearth/dns/host_address.rbs +13 -0
  102. data/sig/lib/hearth/dns/host_resolver.rbs +19 -0
  103. data/sig/lib/hearth/http/api_error.rbs +13 -0
  104. data/sig/lib/hearth/http/client.rbs +9 -0
  105. data/sig/lib/hearth/http/field.rbs +19 -0
  106. data/sig/lib/hearth/http/fields.rbs +43 -0
  107. data/sig/lib/hearth/http/request.rbs +25 -0
  108. data/sig/lib/hearth/http/response.rbs +21 -0
  109. data/sig/lib/hearth/identities/anonymous.rbs +6 -0
  110. data/sig/lib/hearth/identities/http_api_key.rbs +9 -0
  111. data/sig/lib/hearth/identities/http_bearer.rbs +9 -0
  112. data/sig/lib/hearth/identities/http_login.rbs +11 -0
  113. data/sig/lib/hearth/identities.rbs +9 -0
  114. data/sig/lib/hearth/identity_resolver.rbs +7 -0
  115. data/sig/lib/hearth/interceptor.rbs +9 -0
  116. data/sig/lib/hearth/interceptor_context.rbs +15 -0
  117. data/sig/lib/hearth/interceptor_list.rbs +16 -0
  118. data/sig/lib/hearth/interfaces.rbs +65 -0
  119. data/sig/lib/hearth/output.rbs +11 -0
  120. data/sig/lib/hearth/plugin_list.rbs +15 -0
  121. data/sig/lib/hearth/query/param.rbs +17 -0
  122. data/sig/lib/hearth/query/param_list.rbs +25 -0
  123. data/sig/lib/hearth/request.rbs +9 -0
  124. data/sig/lib/hearth/response.rbs +11 -0
  125. data/sig/lib/hearth/retry/adaptive.rbs +13 -0
  126. data/sig/lib/hearth/retry/exponential_backoff.rbs +7 -0
  127. data/sig/lib/hearth/retry/standard.rbs +13 -0
  128. data/sig/lib/hearth/retry/strategy.rbs +11 -0
  129. data/sig/lib/hearth/retry.rbs +9 -0
  130. data/sig/lib/hearth/signers/anonymous.rbs +9 -0
  131. data/sig/lib/hearth/signers/http_api_key.rbs +9 -0
  132. data/sig/lib/hearth/signers/http_basic.rbs +9 -0
  133. data/sig/lib/hearth/signers/http_bearer.rbs +9 -0
  134. data/sig/lib/hearth/signers/http_digest.rbs +9 -0
  135. data/sig/lib/hearth/signers.rbs +9 -0
  136. data/sig/lib/hearth/structure.rbs +7 -0
  137. data/sig/lib/hearth/union.rbs +5 -0
  138. data/sig/lib/hearth/waiters/waiter.rbs +17 -0
  139. metadata +132 -22
  140. data/lib/hearth/http/headers.rb +0 -70
  141. data/lib/hearth/middleware/around_handler.rb +0 -24
  142. data/lib/hearth/middleware/request_handler.rb +0 -24
  143. data/lib/hearth/middleware/response_handler.rb +0 -25
  144. data/lib/hearth/middleware_builder.rb +0 -246
  145. data/lib/hearth/stubbing/client_stubs.rb +0 -115
  146. data/lib/hearth/stubbing/stubs.rb +0 -32
  147. data/lib/hearth/waiters/errors.rb +0 -15
  148. data/sig/lib/seahorse/api_error.rbs +0 -10
  149. data/sig/lib/seahorse/document.rbs +0 -2
  150. data/sig/lib/seahorse/http/api_error.rbs +0 -21
  151. data/sig/lib/seahorse/http/headers.rbs +0 -47
  152. data/sig/lib/seahorse/http/response.rbs +0 -21
  153. data/sig/lib/seahorse/simple_delegator.rbs +0 -3
  154. data/sig/lib/seahorse/structure.rbs +0 -18
  155. data/sig/lib/seahorse/stubbing/client_stubs.rbs +0 -103
  156. data/sig/lib/seahorse/stubbing/stubs.rbs +0 -14
  157. data/sig/lib/seahorse/union.rbs +0 -6
@@ -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
- # @api private
9
- class Response
6
+ class Response < Hearth::Response
10
7
  # @param [Integer] status
11
- # @param [Headers] headers
12
- # @param [IO] body
13
- def initialize(status: 200, headers: Headers.new, body: StringIO.new)
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
- @headers = headers
16
- @body = body
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 [Headers]
23
- attr_accessor :headers
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
- # @return [IO]
26
- attr_accessor :body
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/headers'
8
- require_relative 'http/middleware/content_length'
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::_escape("a b/c")
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,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Hearth
4
+ module Identities
5
+ # Anonymous identity.
6
+ class Anonymous < Identities::Base; end
7
+ end
8
+ 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