require_relative 'cacheable' module WCC module Media class Message include WCC::Media::Cacheable attr_reader :raw, :headers def initialize(raw, headers = {}) @raw = raw @headers = headers end def id raw['id']&.to_s end def legacy_id raw['legacy_id']&.to_s end %w[ date title description series_position ].each do |att| define_method att do raw[att] end end def speakers (raw['speakers'] || []).map { |val| Speaker.new(val) } end def tags (raw['tags'] || []).map { |val| Tag.new(val) } end %w[ scripture_references downloads ].each do |att| define_method att do (raw[att] || []).map { |val| OpenStruct.new(val) } end end def series Series.new(raw['series']) if raw['series'] end %w[ embeds assets images external_urls transcript ].each do |att| define_method att do OpenStruct.new(raw[att]) if raw[att] end end end end end