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.
179 180 181 182 183 184 185 186 187 |
# File 'lib/smplkit/jobs/models.rb', line 179 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.
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 |
# File 'lib/smplkit/jobs/models.rb', line 175 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(url: "") 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”.
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 |
# File 'lib/smplkit/jobs/models.rb', line 175 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(url: "") 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.
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 |
# File 'lib/smplkit/jobs/models.rb', line 175 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(url: "") 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.
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 |
# File 'lib/smplkit/jobs/models.rb', line 175 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(url: "") 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”.
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 |
# File 'lib/smplkit/jobs/models.rb', line 175 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(url: "") 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.
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 |
# File 'lib/smplkit/jobs/models.rb', line 175 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(url: "") 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.
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 |
# File 'lib/smplkit/jobs/models.rb', line 175 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(url: "") 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.
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 |
# File 'lib/smplkit/jobs/models.rb', line 175 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(url: "") 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.
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 |
# File 'lib/smplkit/jobs/models.rb', line 222 def self.from_wire(src) return new(url: "") 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.
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
# File 'lib/smplkit/jobs/models.rb', line 194 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 |