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.
210 211 212 213 214 215 216 217 218 |
# File 'lib/smplkit/jobs/models.rb', line 210 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.
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 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 |
# File 'lib/smplkit/jobs/models.rb', line 206 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”.
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 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 |
# File 'lib/smplkit/jobs/models.rb', line 206 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.
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 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 |
# File 'lib/smplkit/jobs/models.rb', line 206 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.
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 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 |
# File 'lib/smplkit/jobs/models.rb', line 206 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”.
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 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 |
# File 'lib/smplkit/jobs/models.rb', line 206 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.
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 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 |
# File 'lib/smplkit/jobs/models.rb', line 206 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.
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 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 |
# File 'lib/smplkit/jobs/models.rb', line 206 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.
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 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 |
# File 'lib/smplkit/jobs/models.rb', line 206 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.
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 |
# File 'lib/smplkit/jobs/models.rb', line 253 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.
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 225 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 |