require 'apple-news/article/attachments' require 'apple-news/article/persistence' module AppleNews class Article extend Forwardable include Attachments include Persistence include Resource include Properties optional_properties :is_sponsored, :is_preview, :accessory_text, :revision optional_property :links, {} attr_reader :id attr_accessor :document def_delegator :@document, :title def initialize(id = nil, data = {}) super(data) @resource_path = "/articles" @id = id document = (data[:document] || data['document']) @document = document.is_a?(AppleNews::Document) ? document : Document.new(document) @files = {} # These are read-only properties that are not submitted to the API @share_url = data['shareUrl'] @state = data['state'] hydrate! if !id.nil? && data.keys.size == 0 end private def hydrate! data = fetch_data['data'] @document = Document.new(data.delete('document')) load_properties(data) end end end