Class: EML::Payload

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/eml/payload.rb

Direct Known Subclasses

UK::Payload, UK::Payload::Location

Constant Summary collapse

ENDPOINT_CLASS_TYPE =
"Payload"

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(payload) ⇒ Payload

Returns a new instance of Payload.



10
11
12
13
# File 'lib/eml/payload.rb', line 10

def initialize(payload)
  assign_params(payload)
  validate_required_payload_presence
end

Class Method Details

.convert(resource_class, endpoint, payload) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/eml/payload.rb', line 27

def convert(resource_class, endpoint, payload)
  endpoint_class = EML::EndpointClass.(
    class_type: ENDPOINT_CLASS_TYPE,
    resource_class: resource_class,
    endpoint: endpoint
  )

  convert_with_endpoint_class(
    endpoint: endpoint, endpoint_class: endpoint_class,
    payload: payload, resource_class: resource_class
  )
end

Instance Method Details

#to_hObject



63
64
65
66
67
68
69
# File 'lib/eml/payload.rb', line 63

def to_h
  instance_variables.each_with_object({}) do |variable_name, params|
    key = T.must(variable_name.to_s[1..-1]).to_sym
    params[key] = instance_variable_get(variable_name)
    params[key] = params[key].to_h if params[key].respond_to?(:to_h)
  end
end