# frozen_string_literal: true module WCC::Blogs class CollectionSummary extend WCC::Blogs::Utils attr_reader :raw def initialize(raw, client: WCC::Blogs.client) @raw = raw @client = client end define_camelcase_alias( 'key', 'title' ) do |camelcase| raw[camelcase] end def posts @posts ||= (raw['posts'] || []).map do |summary| PostReference.new(summary, client: @client) end end class PostReference extend WCC::Blogs::Utils attr_reader :raw def initialize(raw, client: WCC::Blogs.client) @raw = raw @client = client end def full_post Post.new(@client.get(_links.self).raw) end define_camelcase_alias( 'slug' ) do |camelcase| raw[camelcase] end def _links OpenStruct.new(raw['_links'] || {}) end end end end