Class: Lyrebird::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/lyrebird/response.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(issuer: DEFAULTS.issuer, destination: DEFAULTS.recipient, in_response_to: DEFAULTS.in_response_to, sign_with: nil, encrypt_with: nil, **assertion_options) ⇒ Response

Returns a new instance of Response.



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/lyrebird/response.rb', line 20

def initialize(
  issuer: DEFAULTS.issuer,
  destination: DEFAULTS.recipient,
  in_response_to: DEFAULTS.in_response_to,
  sign_with: nil,
  encrypt_with: nil,
  **assertion_options
)
  @issuer = issuer
  @destination = destination
  @in_response_to = in_response_to
  @sign_with = sign_with
  @encrypt_with = encrypt_with

  @assertion = Assertion.new(
    issuer: issuer,
    in_response_to: in_response_to,
    **assertion_options
  )
end

Class Method Details

.build(**kwargs) {|config| ... } ⇒ Object

Yields:

  • (config)


5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/lyrebird/response.rb', line 5

def self.build(**kwargs)
  config = OpenStruct.new(kwargs)

  config.define_singleton_method(:attributes) do |&block|
    current = self[:attributes] || {}
    return current unless block

    fresh = OpenStruct.new.tap(&block).to_h
    self[:attributes] = current.transform_keys(&:to_sym).merge(fresh)
  end

  yield config if block_given?
  new(**config.to_h)
end

Instance Method Details

#documentObject



49
50
51
52
53
54
55
# File 'lib/lyrebird/response.rb', line 49

def document
  @document ||= Nokogiri::XML::Document.new.tap do |doc|
    doc.root = build_response(doc)
    sign_assertion(doc) if @sign_with && !@encrypt_with
    sign_response(doc) if @sign_with
  end
end

#mimicObject



41
42
43
# File 'lib/lyrebird/response.rb', line 41

def mimic
  Base64.strict_encode64(to_xml)
end

#to_xmlObject



45
46
47
# File 'lib/lyrebird/response.rb', line 45

def to_xml
  document.to_xml(save_with: 0)
end