Class: Chirpstream::User

Inherits:
TwitterObject show all
Defined in:
lib/chirpstream/user.rb

Constant Summary collapse

ATTRS =
[
  :profile_background_tile, :name, :profile_sidebar_border_color, :profile_sidebar_fill_color, :profile_image_url, :location, :created_at,
  :profile_link_color, :url, :contributors_enabled, :favourites_count, :utc_offset, :id, :followers_count, :protected, :lang,
  :profile_text_color, :geo_enabled, :profile_background_color, :time_zone, :notifications, :description, :verified, :profile_background_image_url,
  :statuses_count, :friends_count, :screen_name, :following
]

Constants inherited from TwitterObject

TwitterObject::SINGLE_TWEET_URL, TwitterObject::SINGLE_USER_URL

Instance Attribute Summary

Attributes inherited from TwitterObject

#base

Instance Method Summary collapse

Methods inherited from TwitterObject

attrs, #from_json, #get_tweet_data, #get_user_data, #initialize, #load_all, #load_tweet_data, #load_user_data, tweet_writer, user_writer

Constructor Details

This class inherits a constructor from TwitterObject

Instance Method Details

#loaded?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/chirpstream/user.rb', line 16

def loaded?
  name
end

#user_loadable_idObject



20
21
22
# File 'lib/chirpstream/user.rb', line 20

def user_loadable_id
  id
end

#with_profile_image(loading_user, cache_dir) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/chirpstream/user.rb', line 24

def with_profile_image(loading_user, cache_dir)
  raise unless loaded?
  
  cached_file = File.join(cache_dir, "#{Digest::MD5.hexdigest(profile_image_url)}#{File.extname(profile_image_url)}")
  
  if File.exist?(cached_file)
    yield cached_file
  else
    http = base.get_connection(loading_user, profile_image_url, :get)
    http.callback do
      if http.response_header.status == 200
        File.open(cached_file, 'w') {|f| f << http.response}
        yield cached_file
      else
        yield nil
      end
    end
  end
  
end