Sha256: 687fa522da36eb7abc83634ff9350e862d861cf65a58f9952991c23782918a91

Contents?: true

Size: 740 Bytes

Versions: 3

Compression:

Stored size: 740 Bytes

Contents

require 'livefyre/exceptions/livefyre_exception'

module Livefyre
  class CollectionData
    attr_accessor :id, :type, :title, :article_id, :url, :tags, :topics, :extensions

    def initialize(type, title, article_id, url)
      @type = type
      @title = title
      @article_id = article_id
      @url = url
    end

    def as_hash
      hash = {}
      self.instance_variables.each {|var| hash[var.to_s.delete('@')] = self.instance_variable_get(var) }
      hash['articleId'] = @article_id
      hash.delete('article_id')
      hash.delete('id')
      hash
    end

    def id
      if (defined?(@id)).nil?
        raise LivefyreException, 'Call create_or_update on the collection to set the id.'
      end
      @id
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
livefyre-2.0.2 lib/livefyre/model/collection_data.rb
livefyre-2.0.1 lib/livefyre/model/collection_data.rb
livefyre-2.0.0 lib/livefyre/model/collection_data.rb