Class: Smplkit::Jobs::HttpConfig
- Inherits:
-
Struct
- Object
- Struct
- Smplkit::Jobs::HttpConfig
- Defined in:
- lib/smplkit/jobs/models.rb
Overview
The HTTP request a job performs when it fires (the http configuration).
Extends the shared forwarder shape with the two fields a scheduled job needs beyond a forwarder: a request body and a per-run timeout.
rubocop:disable Lint/StructNewOverride – “:method“ matches the API attribute and shadowing Struct#method is the expected ergonomics.
Instance Attribute Summary collapse
-
#body ⇒ String?
Request body sent on each run.
-
#ca_cert ⇒ String?
Optional PEM-encoded certificate (or bundle) trusted in addition to the system CA store.
-
#headers ⇒ Array<HttpHeader>
Headers attached to every request.
-
#method ⇒ String
HTTP verb used when the job fires.
-
#success_status ⇒ String
Status the destination must return for the run to count as success — an exact code (+“200”+, “204”) or a class (+“2xx”+, “4xx”).
-
#timeout ⇒ Integer
Per-run timeout in seconds.
-
#tls_verify ⇒ Boolean
Whether to verify the destination’s TLS certificate chain.
-
#url ⇒ String
Destination URL the job requests on each run.
Class Method Summary collapse
-
.from_wire(src) ⇒ HttpConfig
The wrapper-side configuration.
-
.to_wire(src) ⇒ SmplkitGeneratedClient::Jobs::JobHttpConfiguration
The wire model.
Instance Method Summary collapse
-
#initialize(url: "", method: HttpMethod::POST, headers: nil, body: nil, success_status: "2xx", timeout: 30, tls_verify: true, ca_cert: nil) ⇒ HttpConfig
constructor
A new instance of HttpConfig.
Constructor Details
#initialize(url: "", method: HttpMethod::POST, headers: nil, body: nil, success_status: "2xx", timeout: 30, tls_verify: true, ca_cert: nil) ⇒ HttpConfig
Returns a new instance of HttpConfig.
111 112 113 114 115 116 117 118 119 |
# File 'lib/smplkit/jobs/models.rb', line 111 def initialize( url: "", method: HttpMethod::POST, headers: nil, body: nil, success_status: "2xx", timeout: 30, tls_verify: true, ca_cert: nil ) super( method: HttpMethod.coerce(method), url: url, headers: headers || [], body: body, success_status: success_status, timeout: timeout, tls_verify: tls_verify, ca_cert: ca_cert ) end |
Instance Attribute Details
#body ⇒ String?
Returns Request body sent on each run. nil (the default) sends an empty body, suitable for a connectivity ping. Sent verbatim —pair with a matching Content-Type header.
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/smplkit/jobs/models.rb', line 107 HttpConfig = Struct.new( :method, :url, :headers, :body, :success_status, :timeout, :tls_verify, :ca_cert, keyword_init: true ) do def initialize( url: "", method: HttpMethod::POST, headers: nil, body: nil, success_status: "2xx", timeout: 30, tls_verify: true, ca_cert: nil ) super( method: HttpMethod.coerce(method), url: url, headers: headers || [], body: body, success_status: success_status, timeout: timeout, tls_verify: tls_verify, ca_cert: ca_cert ) end # @api private — Convert an {HttpConfig} (or a Hash with the same keys) # into the generated wire model the jobs service expects. # # @param src [HttpConfig, Hash] The HTTP configuration to serialize. # @return [SmplkitGeneratedClient::Jobs::JobHttpConfiguration] The wire model. def self.to_wire(src) h = src.is_a?(Hash) ? new(**src) : src SmplkitGeneratedClient::Jobs::JobHttpConfiguration.new( method: HttpMethod.coerce(h.method), url: h.url, headers: (h.headers || []).map do |hdr| name, value = if hdr.is_a?(Hash) [hdr[:name] || hdr["name"], hdr[:value] || hdr["value"]] else [hdr.name, hdr.value] end SmplkitGeneratedClient::Jobs::HttpHeader.new(name: name, value: value) end, body: h.body, success_status: h.success_status, timeout: h.timeout, tls_verify: h.tls_verify, ca_cert: h.ca_cert ) end # @api private — Build an {HttpConfig} from the generated wire model # returned by the jobs service. Header values arrive in plaintext, so a # round-trip back through {to_wire} preserves them. # # @param src [SmplkitGeneratedClient::Jobs::JobHttpConfiguration, nil] The # wire model, or +nil+ for an empty configuration. # @return [HttpConfig] The wrapper-side configuration. def self.from_wire(src) return new if src.nil? # +url+, +success_status+, and +timeout+ are required non-nil on the # generated jobs config, so they pass straight through. +method+, # +tls_verify+, +headers+, +body+, and +ca_cert+ are nullable and get # wrapper-side defaults when the wire omits them. new( method: src.method || HttpMethod::POST, url: src.url, headers: (src.headers || []).map { |h| HttpHeader.new(name: h.name, value: h.value) }, body: src.body, success_status: src.success_status, timeout: src.timeout, # rubocop:disable Style/RedundantCondition -- nil and false are # distinct: nil means "field absent on the wire" (default to true); # explicit false means "verification disabled". tls_verify: src.tls_verify.nil? ? true : src.tls_verify, # rubocop:enable Style/RedundantCondition ca_cert: src.ca_cert ) end end |
#ca_cert ⇒ String?
Returns Optional PEM-encoded certificate (or bundle) trusted in addition to the system CA store. Ignored when tls_verify is false. nil (the default) means “use system CAs only”.
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/smplkit/jobs/models.rb', line 107 HttpConfig = Struct.new( :method, :url, :headers, :body, :success_status, :timeout, :tls_verify, :ca_cert, keyword_init: true ) do def initialize( url: "", method: HttpMethod::POST, headers: nil, body: nil, success_status: "2xx", timeout: 30, tls_verify: true, ca_cert: nil ) super( method: HttpMethod.coerce(method), url: url, headers: headers || [], body: body, success_status: success_status, timeout: timeout, tls_verify: tls_verify, ca_cert: ca_cert ) end # @api private — Convert an {HttpConfig} (or a Hash with the same keys) # into the generated wire model the jobs service expects. # # @param src [HttpConfig, Hash] The HTTP configuration to serialize. # @return [SmplkitGeneratedClient::Jobs::JobHttpConfiguration] The wire model. def self.to_wire(src) h = src.is_a?(Hash) ? new(**src) : src SmplkitGeneratedClient::Jobs::JobHttpConfiguration.new( method: HttpMethod.coerce(h.method), url: h.url, headers: (h.headers || []).map do |hdr| name, value = if hdr.is_a?(Hash) [hdr[:name] || hdr["name"], hdr[:value] || hdr["value"]] else [hdr.name, hdr.value] end SmplkitGeneratedClient::Jobs::HttpHeader.new(name: name, value: value) end, body: h.body, success_status: h.success_status, timeout: h.timeout, tls_verify: h.tls_verify, ca_cert: h.ca_cert ) end # @api private — Build an {HttpConfig} from the generated wire model # returned by the jobs service. Header values arrive in plaintext, so a # round-trip back through {to_wire} preserves them. # # @param src [SmplkitGeneratedClient::Jobs::JobHttpConfiguration, nil] The # wire model, or +nil+ for an empty configuration. # @return [HttpConfig] The wrapper-side configuration. def self.from_wire(src) return new if src.nil? # +url+, +success_status+, and +timeout+ are required non-nil on the # generated jobs config, so they pass straight through. +method+, # +tls_verify+, +headers+, +body+, and +ca_cert+ are nullable and get # wrapper-side defaults when the wire omits them. new( method: src.method || HttpMethod::POST, url: src.url, headers: (src.headers || []).map { |h| HttpHeader.new(name: h.name, value: h.value) }, body: src.body, success_status: src.success_status, timeout: src.timeout, # rubocop:disable Style/RedundantCondition -- nil and false are # distinct: nil means "field absent on the wire" (default to true); # explicit false means "verification disabled". tls_verify: src.tls_verify.nil? ? true : src.tls_verify, # rubocop:enable Style/RedundantCondition ca_cert: src.ca_cert ) end end |
#headers ⇒ Array<HttpHeader>
Returns Headers attached to every request. Values often carry credentials and are returned in plaintext on reads, so a get-mutate-put round-trip preserves them without re-entering secrets.
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/smplkit/jobs/models.rb', line 107 HttpConfig = Struct.new( :method, :url, :headers, :body, :success_status, :timeout, :tls_verify, :ca_cert, keyword_init: true ) do def initialize( url: "", method: HttpMethod::POST, headers: nil, body: nil, success_status: "2xx", timeout: 30, tls_verify: true, ca_cert: nil ) super( method: HttpMethod.coerce(method), url: url, headers: headers || [], body: body, success_status: success_status, timeout: timeout, tls_verify: tls_verify, ca_cert: ca_cert ) end # @api private — Convert an {HttpConfig} (or a Hash with the same keys) # into the generated wire model the jobs service expects. # # @param src [HttpConfig, Hash] The HTTP configuration to serialize. # @return [SmplkitGeneratedClient::Jobs::JobHttpConfiguration] The wire model. def self.to_wire(src) h = src.is_a?(Hash) ? new(**src) : src SmplkitGeneratedClient::Jobs::JobHttpConfiguration.new( method: HttpMethod.coerce(h.method), url: h.url, headers: (h.headers || []).map do |hdr| name, value = if hdr.is_a?(Hash) [hdr[:name] || hdr["name"], hdr[:value] || hdr["value"]] else [hdr.name, hdr.value] end SmplkitGeneratedClient::Jobs::HttpHeader.new(name: name, value: value) end, body: h.body, success_status: h.success_status, timeout: h.timeout, tls_verify: h.tls_verify, ca_cert: h.ca_cert ) end # @api private — Build an {HttpConfig} from the generated wire model # returned by the jobs service. Header values arrive in plaintext, so a # round-trip back through {to_wire} preserves them. # # @param src [SmplkitGeneratedClient::Jobs::JobHttpConfiguration, nil] The # wire model, or +nil+ for an empty configuration. # @return [HttpConfig] The wrapper-side configuration. def self.from_wire(src) return new if src.nil? # +url+, +success_status+, and +timeout+ are required non-nil on the # generated jobs config, so they pass straight through. +method+, # +tls_verify+, +headers+, +body+, and +ca_cert+ are nullable and get # wrapper-side defaults when the wire omits them. new( method: src.method || HttpMethod::POST, url: src.url, headers: (src.headers || []).map { |h| HttpHeader.new(name: h.name, value: h.value) }, body: src.body, success_status: src.success_status, timeout: src.timeout, # rubocop:disable Style/RedundantCondition -- nil and false are # distinct: nil means "field absent on the wire" (default to true); # explicit false means "verification disabled". tls_verify: src.tls_verify.nil? ? true : src.tls_verify, # rubocop:enable Style/RedundantCondition ca_cert: src.ca_cert ) end end |
#method ⇒ String
Returns HTTP verb used when the job fires. Defaults to Smplkit::Jobs::HttpMethod::POST.
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/smplkit/jobs/models.rb', line 107 HttpConfig = Struct.new( :method, :url, :headers, :body, :success_status, :timeout, :tls_verify, :ca_cert, keyword_init: true ) do def initialize( url: "", method: HttpMethod::POST, headers: nil, body: nil, success_status: "2xx", timeout: 30, tls_verify: true, ca_cert: nil ) super( method: HttpMethod.coerce(method), url: url, headers: headers || [], body: body, success_status: success_status, timeout: timeout, tls_verify: tls_verify, ca_cert: ca_cert ) end # @api private — Convert an {HttpConfig} (or a Hash with the same keys) # into the generated wire model the jobs service expects. # # @param src [HttpConfig, Hash] The HTTP configuration to serialize. # @return [SmplkitGeneratedClient::Jobs::JobHttpConfiguration] The wire model. def self.to_wire(src) h = src.is_a?(Hash) ? new(**src) : src SmplkitGeneratedClient::Jobs::JobHttpConfiguration.new( method: HttpMethod.coerce(h.method), url: h.url, headers: (h.headers || []).map do |hdr| name, value = if hdr.is_a?(Hash) [hdr[:name] || hdr["name"], hdr[:value] || hdr["value"]] else [hdr.name, hdr.value] end SmplkitGeneratedClient::Jobs::HttpHeader.new(name: name, value: value) end, body: h.body, success_status: h.success_status, timeout: h.timeout, tls_verify: h.tls_verify, ca_cert: h.ca_cert ) end # @api private — Build an {HttpConfig} from the generated wire model # returned by the jobs service. Header values arrive in plaintext, so a # round-trip back through {to_wire} preserves them. # # @param src [SmplkitGeneratedClient::Jobs::JobHttpConfiguration, nil] The # wire model, or +nil+ for an empty configuration. # @return [HttpConfig] The wrapper-side configuration. def self.from_wire(src) return new if src.nil? # +url+, +success_status+, and +timeout+ are required non-nil on the # generated jobs config, so they pass straight through. +method+, # +tls_verify+, +headers+, +body+, and +ca_cert+ are nullable and get # wrapper-side defaults when the wire omits them. new( method: src.method || HttpMethod::POST, url: src.url, headers: (src.headers || []).map { |h| HttpHeader.new(name: h.name, value: h.value) }, body: src.body, success_status: src.success_status, timeout: src.timeout, # rubocop:disable Style/RedundantCondition -- nil and false are # distinct: nil means "field absent on the wire" (default to true); # explicit false means "verification disabled". tls_verify: src.tls_verify.nil? ? true : src.tls_verify, # rubocop:enable Style/RedundantCondition ca_cert: src.ca_cert ) end end |
#success_status ⇒ String
Returns Status the destination must return for the run to count as success — an exact code (+“200”+, “204”) or a class (+“2xx”+, “4xx”). Defaults to “2xx”.
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/smplkit/jobs/models.rb', line 107 HttpConfig = Struct.new( :method, :url, :headers, :body, :success_status, :timeout, :tls_verify, :ca_cert, keyword_init: true ) do def initialize( url: "", method: HttpMethod::POST, headers: nil, body: nil, success_status: "2xx", timeout: 30, tls_verify: true, ca_cert: nil ) super( method: HttpMethod.coerce(method), url: url, headers: headers || [], body: body, success_status: success_status, timeout: timeout, tls_verify: tls_verify, ca_cert: ca_cert ) end # @api private — Convert an {HttpConfig} (or a Hash with the same keys) # into the generated wire model the jobs service expects. # # @param src [HttpConfig, Hash] The HTTP configuration to serialize. # @return [SmplkitGeneratedClient::Jobs::JobHttpConfiguration] The wire model. def self.to_wire(src) h = src.is_a?(Hash) ? new(**src) : src SmplkitGeneratedClient::Jobs::JobHttpConfiguration.new( method: HttpMethod.coerce(h.method), url: h.url, headers: (h.headers || []).map do |hdr| name, value = if hdr.is_a?(Hash) [hdr[:name] || hdr["name"], hdr[:value] || hdr["value"]] else [hdr.name, hdr.value] end SmplkitGeneratedClient::Jobs::HttpHeader.new(name: name, value: value) end, body: h.body, success_status: h.success_status, timeout: h.timeout, tls_verify: h.tls_verify, ca_cert: h.ca_cert ) end # @api private — Build an {HttpConfig} from the generated wire model # returned by the jobs service. Header values arrive in plaintext, so a # round-trip back through {to_wire} preserves them. # # @param src [SmplkitGeneratedClient::Jobs::JobHttpConfiguration, nil] The # wire model, or +nil+ for an empty configuration. # @return [HttpConfig] The wrapper-side configuration. def self.from_wire(src) return new if src.nil? # +url+, +success_status+, and +timeout+ are required non-nil on the # generated jobs config, so they pass straight through. +method+, # +tls_verify+, +headers+, +body+, and +ca_cert+ are nullable and get # wrapper-side defaults when the wire omits them. new( method: src.method || HttpMethod::POST, url: src.url, headers: (src.headers || []).map { |h| HttpHeader.new(name: h.name, value: h.value) }, body: src.body, success_status: src.success_status, timeout: src.timeout, # rubocop:disable Style/RedundantCondition -- nil and false are # distinct: nil means "field absent on the wire" (default to true); # explicit false means "verification disabled". tls_verify: src.tls_verify.nil? ? true : src.tls_verify, # rubocop:enable Style/RedundantCondition ca_cert: src.ca_cert ) end end |
#timeout ⇒ Integer
Returns Per-run timeout in seconds. A run that does not complete within this many seconds fails with reason TIMEOUT. Defaults to 30; bounded by your plan’s maximum timeout.
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/smplkit/jobs/models.rb', line 107 HttpConfig = Struct.new( :method, :url, :headers, :body, :success_status, :timeout, :tls_verify, :ca_cert, keyword_init: true ) do def initialize( url: "", method: HttpMethod::POST, headers: nil, body: nil, success_status: "2xx", timeout: 30, tls_verify: true, ca_cert: nil ) super( method: HttpMethod.coerce(method), url: url, headers: headers || [], body: body, success_status: success_status, timeout: timeout, tls_verify: tls_verify, ca_cert: ca_cert ) end # @api private — Convert an {HttpConfig} (or a Hash with the same keys) # into the generated wire model the jobs service expects. # # @param src [HttpConfig, Hash] The HTTP configuration to serialize. # @return [SmplkitGeneratedClient::Jobs::JobHttpConfiguration] The wire model. def self.to_wire(src) h = src.is_a?(Hash) ? new(**src) : src SmplkitGeneratedClient::Jobs::JobHttpConfiguration.new( method: HttpMethod.coerce(h.method), url: h.url, headers: (h.headers || []).map do |hdr| name, value = if hdr.is_a?(Hash) [hdr[:name] || hdr["name"], hdr[:value] || hdr["value"]] else [hdr.name, hdr.value] end SmplkitGeneratedClient::Jobs::HttpHeader.new(name: name, value: value) end, body: h.body, success_status: h.success_status, timeout: h.timeout, tls_verify: h.tls_verify, ca_cert: h.ca_cert ) end # @api private — Build an {HttpConfig} from the generated wire model # returned by the jobs service. Header values arrive in plaintext, so a # round-trip back through {to_wire} preserves them. # # @param src [SmplkitGeneratedClient::Jobs::JobHttpConfiguration, nil] The # wire model, or +nil+ for an empty configuration. # @return [HttpConfig] The wrapper-side configuration. def self.from_wire(src) return new if src.nil? # +url+, +success_status+, and +timeout+ are required non-nil on the # generated jobs config, so they pass straight through. +method+, # +tls_verify+, +headers+, +body+, and +ca_cert+ are nullable and get # wrapper-side defaults when the wire omits them. new( method: src.method || HttpMethod::POST, url: src.url, headers: (src.headers || []).map { |h| HttpHeader.new(name: h.name, value: h.value) }, body: src.body, success_status: src.success_status, timeout: src.timeout, # rubocop:disable Style/RedundantCondition -- nil and false are # distinct: nil means "field absent on the wire" (default to true); # explicit false means "verification disabled". tls_verify: src.tls_verify.nil? ? true : src.tls_verify, # rubocop:enable Style/RedundantCondition ca_cert: src.ca_cert ) end end |
#tls_verify ⇒ Boolean
Returns Whether to verify the destination’s TLS certificate chain. Defaults to true; flip to false only for short-lived testing against an untrusted certificate. Prefer pinning the CA via ca_cert.
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/smplkit/jobs/models.rb', line 107 HttpConfig = Struct.new( :method, :url, :headers, :body, :success_status, :timeout, :tls_verify, :ca_cert, keyword_init: true ) do def initialize( url: "", method: HttpMethod::POST, headers: nil, body: nil, success_status: "2xx", timeout: 30, tls_verify: true, ca_cert: nil ) super( method: HttpMethod.coerce(method), url: url, headers: headers || [], body: body, success_status: success_status, timeout: timeout, tls_verify: tls_verify, ca_cert: ca_cert ) end # @api private — Convert an {HttpConfig} (or a Hash with the same keys) # into the generated wire model the jobs service expects. # # @param src [HttpConfig, Hash] The HTTP configuration to serialize. # @return [SmplkitGeneratedClient::Jobs::JobHttpConfiguration] The wire model. def self.to_wire(src) h = src.is_a?(Hash) ? new(**src) : src SmplkitGeneratedClient::Jobs::JobHttpConfiguration.new( method: HttpMethod.coerce(h.method), url: h.url, headers: (h.headers || []).map do |hdr| name, value = if hdr.is_a?(Hash) [hdr[:name] || hdr["name"], hdr[:value] || hdr["value"]] else [hdr.name, hdr.value] end SmplkitGeneratedClient::Jobs::HttpHeader.new(name: name, value: value) end, body: h.body, success_status: h.success_status, timeout: h.timeout, tls_verify: h.tls_verify, ca_cert: h.ca_cert ) end # @api private — Build an {HttpConfig} from the generated wire model # returned by the jobs service. Header values arrive in plaintext, so a # round-trip back through {to_wire} preserves them. # # @param src [SmplkitGeneratedClient::Jobs::JobHttpConfiguration, nil] The # wire model, or +nil+ for an empty configuration. # @return [HttpConfig] The wrapper-side configuration. def self.from_wire(src) return new if src.nil? # +url+, +success_status+, and +timeout+ are required non-nil on the # generated jobs config, so they pass straight through. +method+, # +tls_verify+, +headers+, +body+, and +ca_cert+ are nullable and get # wrapper-side defaults when the wire omits them. new( method: src.method || HttpMethod::POST, url: src.url, headers: (src.headers || []).map { |h| HttpHeader.new(name: h.name, value: h.value) }, body: src.body, success_status: src.success_status, timeout: src.timeout, # rubocop:disable Style/RedundantCondition -- nil and false are # distinct: nil means "field absent on the wire" (default to true); # explicit false means "verification disabled". tls_verify: src.tls_verify.nil? ? true : src.tls_verify, # rubocop:enable Style/RedundantCondition ca_cert: src.ca_cert ) end end |
#url ⇒ String
Returns Destination URL the job requests on each run.
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/smplkit/jobs/models.rb', line 107 HttpConfig = Struct.new( :method, :url, :headers, :body, :success_status, :timeout, :tls_verify, :ca_cert, keyword_init: true ) do def initialize( url: "", method: HttpMethod::POST, headers: nil, body: nil, success_status: "2xx", timeout: 30, tls_verify: true, ca_cert: nil ) super( method: HttpMethod.coerce(method), url: url, headers: headers || [], body: body, success_status: success_status, timeout: timeout, tls_verify: tls_verify, ca_cert: ca_cert ) end # @api private — Convert an {HttpConfig} (or a Hash with the same keys) # into the generated wire model the jobs service expects. # # @param src [HttpConfig, Hash] The HTTP configuration to serialize. # @return [SmplkitGeneratedClient::Jobs::JobHttpConfiguration] The wire model. def self.to_wire(src) h = src.is_a?(Hash) ? new(**src) : src SmplkitGeneratedClient::Jobs::JobHttpConfiguration.new( method: HttpMethod.coerce(h.method), url: h.url, headers: (h.headers || []).map do |hdr| name, value = if hdr.is_a?(Hash) [hdr[:name] || hdr["name"], hdr[:value] || hdr["value"]] else [hdr.name, hdr.value] end SmplkitGeneratedClient::Jobs::HttpHeader.new(name: name, value: value) end, body: h.body, success_status: h.success_status, timeout: h.timeout, tls_verify: h.tls_verify, ca_cert: h.ca_cert ) end # @api private — Build an {HttpConfig} from the generated wire model # returned by the jobs service. Header values arrive in plaintext, so a # round-trip back through {to_wire} preserves them. # # @param src [SmplkitGeneratedClient::Jobs::JobHttpConfiguration, nil] The # wire model, or +nil+ for an empty configuration. # @return [HttpConfig] The wrapper-side configuration. def self.from_wire(src) return new if src.nil? # +url+, +success_status+, and +timeout+ are required non-nil on the # generated jobs config, so they pass straight through. +method+, # +tls_verify+, +headers+, +body+, and +ca_cert+ are nullable and get # wrapper-side defaults when the wire omits them. new( method: src.method || HttpMethod::POST, url: src.url, headers: (src.headers || []).map { |h| HttpHeader.new(name: h.name, value: h.value) }, body: src.body, success_status: src.success_status, timeout: src.timeout, # rubocop:disable Style/RedundantCondition -- nil and false are # distinct: nil means "field absent on the wire" (default to true); # explicit false means "verification disabled". tls_verify: src.tls_verify.nil? ? true : src.tls_verify, # rubocop:enable Style/RedundantCondition ca_cert: src.ca_cert ) end end |
Class Method Details
.from_wire(src) ⇒ HttpConfig
Returns The wrapper-side configuration.
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/smplkit/jobs/models.rb', line 154 def self.from_wire(src) return new if src.nil? # +url+, +success_status+, and +timeout+ are required non-nil on the # generated jobs config, so they pass straight through. +method+, # +tls_verify+, +headers+, +body+, and +ca_cert+ are nullable and get # wrapper-side defaults when the wire omits them. new( method: src.method || HttpMethod::POST, url: src.url, headers: (src.headers || []).map { |h| HttpHeader.new(name: h.name, value: h.value) }, body: src.body, success_status: src.success_status, timeout: src.timeout, # rubocop:disable Style/RedundantCondition -- nil and false are # distinct: nil means "field absent on the wire" (default to true); # explicit false means "verification disabled". tls_verify: src.tls_verify.nil? ? true : src.tls_verify, # rubocop:enable Style/RedundantCondition ca_cert: src.ca_cert ) end |
.to_wire(src) ⇒ SmplkitGeneratedClient::Jobs::JobHttpConfiguration
Returns The wire model.
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/smplkit/jobs/models.rb', line 126 def self.to_wire(src) h = src.is_a?(Hash) ? new(**src) : src SmplkitGeneratedClient::Jobs::JobHttpConfiguration.new( method: HttpMethod.coerce(h.method), url: h.url, headers: (h.headers || []).map do |hdr| name, value = if hdr.is_a?(Hash) [hdr[:name] || hdr["name"], hdr[:value] || hdr["value"]] else [hdr.name, hdr.value] end SmplkitGeneratedClient::Jobs::HttpHeader.new(name: name, value: value) end, body: h.body, success_status: h.success_status, timeout: h.timeout, tls_verify: h.tls_verify, ca_cert: h.ca_cert ) end |