Class: Lotus::Activity

Inherits:
Object
  • Object
show all
Defined in:
lib/lotus/activity.rb

Overview

This class represents an Activity object for an Lotus::Entry.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Activity

Create a new entry with the given content.

options:

:object      => The object of this activity.
:type        => The type of object for this activity.
:target      => The target of this activity.
:verb        => The action of the activity.

:title        => The title of the entry. Defaults: "Untitled"
:actor        => An Lotus::Author responsible for generating this entry.
:content      => The content of the entry. Defaults: ""
:content_type => The MIME type of the content.
:source       => An Lotus::Feed where this Entry originated. This
                 should be used when an Entry is copied into this feed
                 from another.
:published    => The DateTime depicting when the entry was originally
                 published.
:updated      => The DateTime depicting when the entry was modified.
:url          => The canonical url of the entry.
:id           => The unique id that identifies this entry.
:activity     => The activity this entry represents. Either a single string
                 denoting what type of object this entry represents, or an
                 entire Lotus::Activity when a more detailed description is
                 appropriate.
:in_reply_to  => An Lotus::Entry for which this entry is a response.
                 Or an array of Lotus::Entry's that this entry is a
                 response to. Use this when this Entry is a reply
                 to an existing Entry.


84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/lotus/activity.rb', line 84

def initialize(options = {})
  @object      = options[:object]
  @type        = options[:type]
  @target      = options[:target]
  @verb        = options[:verb]

  @title        = options[:title] || "Untitled"
  @actor        = options[:actor]
  @content      = options[:content] || ""
  @content_type = options[:content_type]
  @source       = options[:source]
  @published    = options[:published]
  @updated      = options[:updated]
  @url          = options[:url]
  @id           = options[:id]

  unless options[:in_reply_to].nil? or options[:in_reply_to].is_a?(Array)
    options[:in_reply_to] = [options[:in_reply_to]]
  end
  @in_reply_to  = options[:in_reply_to] || []
end

Instance Attribute Details

#actorObject (readonly)

Holds an Lotus::Author.



29
30
31
# File 'lib/lotus/activity.rb', line 29

def actor
  @actor
end

#contentObject (readonly)

Holds the content.



32
33
34
# File 'lib/lotus/activity.rb', line 32

def content
  @content
end

#content_typeObject (readonly)

Holds the MIME type of the content.



35
36
37
# File 'lib/lotus/activity.rb', line 35

def content_type
  @content_type
end

#idObject (readonly)

Holds the id that uniquely identifies this entry.



38
39
40
# File 'lib/lotus/activity.rb', line 38

def id
  @id
end

#in_reply_toObject (readonly)

Holds an array of related Lotus::Entry’s that this entry is a response to.



54
55
56
# File 'lib/lotus/activity.rb', line 54

def in_reply_to
  @in_reply_to
end

#objectObject (readonly)

The object of this activity.



5
6
7
# File 'lib/lotus/activity.rb', line 5

def object
  @object
end

#publishedObject (readonly)

Holds the DateTime of when the entry was published originally.



47
48
49
# File 'lib/lotus/activity.rb', line 47

def published
  @published
end

#sourceObject (readonly)

Holds the source of this entry as an Lotus::Feed.



44
45
46
# File 'lib/lotus/activity.rb', line 44

def source
  @source
end

#targetObject (readonly)

The target of the action.



23
24
25
# File 'lib/lotus/activity.rb', line 23

def target
  @target
end

#titleObject (readonly)

Holds a String containing the title of the entry.



26
27
28
# File 'lib/lotus/activity.rb', line 26

def title
  @title
end

#typeObject (readonly)

The type of object for this activity.

The field can be a String for uncommon types. Several are standard:

:article, :audio, :bookmark, :comment, :file, :folder, :group,
:list, :note, :person, :photo, :"photo-album", :place, :playlist,
:product, :review, :service, :status, :video


13
14
15
# File 'lib/lotus/activity.rb', line 13

def type
  @type
end

#updatedObject (readonly)

Holds the DateTime of when the entry was last modified.



50
51
52
# File 'lib/lotus/activity.rb', line 50

def updated
  @updated
end

#urlObject (readonly)

Holds the url that represents the entry.



41
42
43
# File 'lib/lotus/activity.rb', line 41

def url
  @url
end

#verbObject (readonly)

The action being invoked in this activity.

The field can be a String for uncommon verbs. Several are standard:

:favorite, :follow, :like, :"make-friend", :join, :play,
:post, :save, :share, :tag, :update


20
21
22
# File 'lib/lotus/activity.rb', line 20

def verb
  @verb
end

Instance Method Details

#to_atomObject

Returns a string containing the Atom representation of this Activity.



128
129
130
131
132
# File 'lib/lotus/activity.rb', line 128

def to_atom
  require 'lotus/atom/entry'

  Lotus::Atom::Entry.from_canonical(self).to_xml
end

#to_hashObject

Returns a hash of all relevant fields.



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/lotus/activity.rb', line 107

def to_hash
  {
    :source => self.source,
    :title => self.title,
    :content => self.content,
    :content_type => self.content_type,
    :published => self.published,
    :updated => self.updated,
    :url => self.url,
    :id => self.id,
    :in_reply_to => self.in_reply_to.dup,

    :object => self.object,
    :target => self.target,
    :actor => self.actor,
    :verb => self.verb,
    :type => self.type
  }
end