Class: Smplkit::Audit::ForwarderHttp

Inherits:
Struct
  • Object
show all
Defined in:
lib/smplkit/audit/forwarders.rb

Overview

rubocop:disable Lint/StructNewOverride – “:method“ matches the API attribute and shadowing Struct#method is the expected ergonomics.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(method: "POST", url: "", headers: nil, body: nil, success_status: "2xx") ⇒ ForwarderHttp

Returns a new instance of ForwarderHttp.



146
147
148
# File 'lib/smplkit/audit/forwarders.rb', line 146

def initialize(method: "POST", url: "", headers: nil, body: nil, success_status: "2xx")
  super(method: method, url: url, headers: headers || [], body: body, success_status: success_status)
end

Instance Attribute Details

#bodyObject

Returns the value of attribute body

Returns:

  • (Object)

    the current value of body



145
146
147
# File 'lib/smplkit/audit/forwarders.rb', line 145

def body
  @body
end

#headersObject

Returns the value of attribute headers

Returns:

  • (Object)

    the current value of headers



145
146
147
# File 'lib/smplkit/audit/forwarders.rb', line 145

def headers
  @headers
end

#methodObject

Returns the value of attribute method

Returns:

  • (Object)

    the current value of method



145
146
147
# File 'lib/smplkit/audit/forwarders.rb', line 145

def method
  @method
end

#success_statusObject

Returns the value of attribute success_status

Returns:

  • (Object)

    the current value of success_status



145
146
147
# File 'lib/smplkit/audit/forwarders.rb', line 145

def success_status
  @success_status
end

#urlObject

Returns the value of attribute url

Returns:

  • (Object)

    the current value of url



145
146
147
# File 'lib/smplkit/audit/forwarders.rb', line 145

def url
  @url
end

Class Method Details

.from_wire(src) ⇒ Object



169
170
171
172
173
174
175
176
177
178
179
# File 'lib/smplkit/audit/forwarders.rb', line 169

def self.from_wire(src)
  return new if src.nil?

  new(
    method: src.method || "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 || "2xx"
  )
end

.to_wire(src) ⇒ Object



150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/smplkit/audit/forwarders.rb', line 150

def self.to_wire(src)
  h = src.is_a?(Hash) ? new(**src) : src
  SmplkitGeneratedClient::Audit::ForwarderHttp.new(
    method: 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::Audit::HttpHeader.new(name: name, value: value)
    end,
    body: h.body,
    success_status: h.success_status
  )
end