Sha256: 2060b2ac2a2dc7e96ec25876ae691f489b6bdc9b2d327aaf389b1e0d3427fa75

Contents?: true

Size: 1.26 KB

Versions: 4

Compression:

Stored size: 1.26 KB

Contents

module Livefyre
  # Public: Proxy object for an item from a Conversation activity feed
  class Activity
    attr_accessor :id, :user, :conversation, :body, :state, :created_at
    def initialize(client, params = {})
      @client = Livefyre.client
      @params = params
      @id = params["activity_id"]
      @conversation = Conversation.new(@params["lf_conv_id"], @params["article_identifier"])
      @created_at = Time.at(@params["created"]) - Time.at(0).utc_offset
    end

    # Public: Cast this activity to a Comment
    #
    # Return [Comment]
    def comment
      Comment.new(@params["lf_comment_id"], conversation,
        :body => @params["body_text"],
        :user => user,
        :parent_id => @params["lf_parent_comment_id"],
        :author_ip => @params["author_ip"],
        :state => @params["state"]
      )
    end

    # Public: Fetch the user that created this record
    #
    # Returns [User]
    def user
      User.new((@params["lf_jid"] || "").split("@", 2).first, @client, @params["author"],
        :email => @params["author_email"],
        :url => @params["author_url"]
      )
    end

    # Internal: Test if this activity represented a comment
    #
    # Returns [Boolean]
    def comment?
      @params["activity_type"] == "comment-add"
    end
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
livefyre-mashable-0.2.0 lib/livefyre/activity.rb
livefyre-0.1.2 lib/livefyre/activity.rb
livefyre-0.1.1 lib/livefyre/activity.rb
livefyre-0.1.0 lib/livefyre/activity.rb