Class: Socialoud::Services::Twitter

Inherits:
Base
  • Object
show all
Defined in:
lib/socialoud/services/twitter.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#aggregator, #data

Instance Method Summary collapse

Methods inherited from Base

#initialize, #set

Constructor Details

This class inherits a constructor from Socialoud::Services::Base

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object

Allow to retrieve each user attribute by aggr.twitter.attribute.

Examples:

aggr.twitter.is_translator
aggr.twitter.profile_background_image_url_https
aggr.twitter.profile_text_color
aggr.twitter.followers_count
aggr.twitter.protected
aggr.twitter.default_profile
aggr.twitter.follow_request_sent
aggr.twitter.profile_background_image_url
aggr.twitter.friends_count
aggr.twitter.name
aggr.twitter.id_str
aggr.twitter.profile_link_color
aggr.twitter.lang
aggr.twitter.utc_offset
aggr.twitter.created_at
aggr.twitter.profile_image_url_https
aggr.twitter.description
aggr.twitter.profile_background_color
aggr.twitter.listed_count
aggr.twitter.notifications
aggr.twitter.profile_background_tile
aggr.twitter.show_all_inline_media
aggr.twitter.contributors_enabled
aggr.twitter.favourites_count
aggr.twitter.profile_sidebar_fill_color
aggr.twitter.verified
aggr.twitter.profile_image_url
aggr.twitter.following
aggr.twitter.time_zone
aggr.twitter.profile_sidebar_border_color
aggr.twitter.location
aggr.twitter.screen_name
aggr.twitter.default_profile_image
aggr.twitter.id
aggr.twitter.statuses_count
aggr.twitter.geo_enabled
aggr.twitter.profile_use_background_image
aggr.twitter.url


74
75
76
77
# File 'lib/socialoud/services/twitter.rb', line 74

def method_missing(method, *args)
  fetch_user!
  @user[method.to_s]
end

Instance Attribute Details

#userObject (readonly)

Returns the value of attribute user.



6
7
8
# File 'lib/socialoud/services/twitter.rb', line 6

def user
  @user
end

Instance Method Details

#last_tweetObject



25
26
27
28
# File 'lib/socialoud/services/twitter.rb', line 25

def last_tweet
  last_tweets = @client.user_timeline(@username, {:count => 5})
  (last_tweets.select {|t| t['text'].index('@') != 0 }.first || last_tweets.first)['text']
end

#profile_urlObject



21
22
23
# File 'lib/socialoud/services/twitter.rb', line 21

def profile_url
  "http://twitter.com/#{@username}"
end

#setup!Object



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/socialoud/services/twitter.rb', line 8

def setup!
  @username = @data['user'] || @data

  ::Twitter.configure do |config|
    config.consumer_key = @data['consumer_key']
    config.consumer_secret = @data['consumer_secret']
    config.oauth_token = @data['oauth_token']
    config.oauth_token_secret = @data['oauth_token_secret']
  end

  @client = ::Twitter::Client.new
end