<commit_before>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<commit_msg>Set state and share URL<commit_after>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, :share_url, :state
    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']
      
      # Some special properties that need to be manually set.
      @document = Document.new(data.delete('document'))
      @share_url = data.delete('share_url')
      @state = data.delete('state')

      load_properties(data)
    end
  end
end
{'fraction_non_alphanumeric': 0.10726351351351351, 'fraction_numerical': 0.0008445945945945946, 'mean_word_length': 3.0289115646258504, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4860195', 'n_tokens_mistral': 713, 'n_tokens_neox': 683, 'n_words': 180}