lib/wcc/media/message.rb in wcc-media-client-0.1.0 vs lib/wcc/media/message.rb in wcc-media-client-0.1.1

- old
+ new

@@ -1,60 +1,68 @@ +require_relative 'cacheable' + module WCC module Media - Message = - Struct.new(:raw) do - def id - raw['id']&.to_s - end + class Message + include WCC::Media::Cacheable - def legacy_id - raw['legacy_id']&.to_s - end + attr_reader :raw, :headers - %w[ - date - title - description - series_position - ].each do |att| - define_method att do - raw[att] - end - end + def initialize(raw, headers = {}) + @raw = raw + @headers = headers + end - def speakers - (raw['speakers'] || []).map { |val| Speaker.new(val) } - end + def id + raw['id']&.to_s + end - def tags - (raw['tags'] || []).map { |val| Tag.new(val) } - end + def legacy_id + raw['legacy_id']&.to_s + end - %w[ - scripture_references - downloads - ].each do |att| - define_method att do - (raw[att] || []).map { |val| OpenStruct.new(val) } - end + %w[ + date + title + description + series_position + ].each do |att| + define_method att do + raw[att] end + end - def series - Series.new(raw['series']) if raw['series'] - end + def speakers + (raw['speakers'] || []).map { |val| Speaker.new(val) } + end - %w[ - embeds - assets - images - external_urls - transcript - ].each do |att| - define_method att do - OpenStruct.new(raw[att]) if raw[att] - 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 - undef raw= + 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 \ No newline at end of file