Class: Gnip::Activity

Inherits:
Message show all
Defined in:
lib/gnip_api/gnip/activity.rb

Constant Summary

Constants inherited from Message

Message::SYSTEM_MESSAGE_TYPES

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Message

#activity?, build, #error?, #generate_json, #info?, #system_message?, #warn?

Constructor Details

#initialize(params = {}) ⇒ Activity

Returns a new instance of Activity.

[View source]

7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/gnip_api/gnip/activity.rb', line 7

def initialize params = {}
  @id = params['id']
  @object_type = params['objectType']
  @actor = Gnip::Actor.new params['actor']
  @verb = params['verb']
  @posted_time = params['postedTime']
  @generator = params['generator']
  @provider = params['provider']
  @link = params['link']
  @body = params['body']
  @object = retweet? ? Gnip::Activity.new(params['object']) : params['object']
  @favorites_count = params['favoritesCount']
  @twitter_entities = params['twitter_entities']
  @twitter_filter_level = params['twitter_filter_level']
  @twitter_lang = params['twitter_lang']
  @retweet_count = params['retweetCount']
  @gnip = Gnip::GnipData.new(params['gnip']) if params['gnip']
end

Instance Attribute Details

#actorObject (readonly)

Returns the value of attribute actor.


3
4
5
# File 'lib/gnip_api/gnip/activity.rb', line 3

def actor
  @actor
end

#bodyObject (readonly)

Returns the value of attribute body.


3
4
5
# File 'lib/gnip_api/gnip/activity.rb', line 3

def body
  @body
end

#favorites_countObject (readonly)

Returns the value of attribute favorites_count.


3
4
5
# File 'lib/gnip_api/gnip/activity.rb', line 3

def favorites_count
  @favorites_count
end

#generatorObject (readonly)

Returns the value of attribute generator.


3
4
5
# File 'lib/gnip_api/gnip/activity.rb', line 3

def generator
  @generator
end

#gnipObject (readonly)

Returns the value of attribute gnip.


3
4
5
# File 'lib/gnip_api/gnip/activity.rb', line 3

def gnip
  @gnip
end

#idObject (readonly)

Returns the value of attribute id.


3
4
5
# File 'lib/gnip_api/gnip/activity.rb', line 3

def id
  @id
end

Returns the value of attribute link.


3
4
5
# File 'lib/gnip_api/gnip/activity.rb', line 3

def link
  @link
end

#objectObject (readonly)

Returns the value of attribute object.


3
4
5
# File 'lib/gnip_api/gnip/activity.rb', line 3

def object
  @object
end

#object_typeObject (readonly)

Returns the value of attribute object_type.


3
4
5
# File 'lib/gnip_api/gnip/activity.rb', line 3

def object_type
  @object_type
end

#posted_timeObject (readonly)

Returns the value of attribute posted_time.


3
4
5
# File 'lib/gnip_api/gnip/activity.rb', line 3

def posted_time
  @posted_time
end

#providerObject (readonly)

Returns the value of attribute provider.


3
4
5
# File 'lib/gnip_api/gnip/activity.rb', line 3

def provider
  @provider
end

#retweet_countObject (readonly)

Returns the value of attribute retweet_count.


3
4
5
# File 'lib/gnip_api/gnip/activity.rb', line 3

def retweet_count
  @retweet_count
end

#twitter_entitiesObject (readonly)

Returns the value of attribute twitter_entities.


3
4
5
# File 'lib/gnip_api/gnip/activity.rb', line 3

def twitter_entities
  @twitter_entities
end

#twitter_filter_levelObject (readonly)

Returns the value of attribute twitter_filter_level.


3
4
5
# File 'lib/gnip_api/gnip/activity.rb', line 3

def twitter_filter_level
  @twitter_filter_level
end

#twitter_langObject (readonly)

Returns the value of attribute twitter_lang.


3
4
5
# File 'lib/gnip_api/gnip/activity.rb', line 3

def twitter_lang
  @twitter_lang
end

#verbObject (readonly)

Returns the value of attribute verb.


3
4
5
# File 'lib/gnip_api/gnip/activity.rb', line 3

def verb
  @verb
end

Instance Method Details

#authorObject

[View source]

63
64
65
# File 'lib/gnip_api/gnip/activity.rb', line 63

def author
  actor.display_name
end

#original_attributesObject

[View source]

26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/gnip_api/gnip/activity.rb', line 26

def original_attributes
  {
    :id => @id,
    :objectType => @object_type,
    :actor => @actor.original_attributes,
    :verb => @verb,
    :postedTime => @posted_time,
    :generator => @generator,
    :provider => @provider,
    :link => @link,
    :body => @body,
    :object => @object.kind_of?(Gnip::Activity) ? @object.original_attributes : @object,
    :favoritesCount => @favorites_count,
    :twitter_entities => @twitter_entities,
    :twitter_filter_level => @twitter_filter_level,
    :twitter_lang => @twitter_lang,
    :retweetCount => @retweet_count,
    :gnip => @gnip ? @gnip.original_attributes : nil
  }
end

#retweet?Boolean

Returns:

  • (Boolean)
[View source]

67
68
69
# File 'lib/gnip_api/gnip/activity.rb', line 67

def retweet? 
  verb == 'share'
end

#to_jsonObject

[View source]

59
60
61
# File 'lib/gnip_api/gnip/activity.rb', line 59

def to_json
  generate_json(original_attributes)
end

#tweet_idObject

[View source]

55
56
57
# File 'lib/gnip_api/gnip/activity.rb', line 55

def tweet_id
  @id.split(':').last
end