Class: Hypem::User
- Inherits:
-
Object
- Object
- Hypem::User
- Defined in:
- lib/hypem/user.rb
Instance Attribute Summary collapse
-
#followed_items_count ⇒ Object
readonly
Returns the value of attribute followed_items_count.
-
#followed_queries_count ⇒ Object
readonly
Returns the value of attribute followed_queries_count.
-
#followed_sites_count ⇒ Object
readonly
Returns the value of attribute followed_sites_count.
-
#followed_users_count ⇒ Object
readonly
Returns the value of attribute followed_users_count.
-
#friends ⇒ Object
readonly
Returns the value of attribute friends.
-
#full_name ⇒ Object
readonly
Returns the value of attribute full_name.
-
#image_url ⇒ Object
readonly
Returns the value of attribute image_url.
-
#joined_at ⇒ Object
readonly
Returns the value of attribute joined_at.
-
#location ⇒ Object
readonly
Returns the value of attribute location.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#twitter_username ⇒ Object
readonly
Returns the value of attribute twitter_username.
Instance Method Summary collapse
- #api_request(path) ⇒ Object
- #favorite_blogs ⇒ Object
- #feed_playlist(page = 1) ⇒ Object
- #friends_favorites_playlist(page = 1) ⇒ Object
- #friends_history_playlist(page = 1) ⇒ Object
- #get_favorite_blogs ⇒ Object
- #get_friends ⇒ Object
- #get_profile ⇒ Object
-
#initialize(name) ⇒ User
constructor
A new instance of User.
-
#loved_playlist(page = 1) ⇒ Object
playlist requests.
- #obsessed_playlist(page = 1) ⇒ Object
- #update_from_response(response) ⇒ Object
Constructor Details
#initialize(name) ⇒ User
Returns a new instance of User.
7 8 9 10 |
# File 'lib/hypem/user.rb', line 7 def initialize(name) raise ArgumentError unless name.is_a? String @name = name end |
Instance Attribute Details
#followed_items_count ⇒ Object (readonly)
Returns the value of attribute followed_items_count.
3 4 5 |
# File 'lib/hypem/user.rb', line 3 def followed_items_count @followed_items_count end |
#followed_queries_count ⇒ Object (readonly)
Returns the value of attribute followed_queries_count.
3 4 5 |
# File 'lib/hypem/user.rb', line 3 def followed_queries_count @followed_queries_count end |
#followed_sites_count ⇒ Object (readonly)
Returns the value of attribute followed_sites_count.
3 4 5 |
# File 'lib/hypem/user.rb', line 3 def followed_sites_count @followed_sites_count end |
#followed_users_count ⇒ Object (readonly)
Returns the value of attribute followed_users_count.
3 4 5 |
# File 'lib/hypem/user.rb', line 3 def followed_users_count @followed_users_count end |
#friends ⇒ Object (readonly)
Returns the value of attribute friends.
3 4 5 |
# File 'lib/hypem/user.rb', line 3 def friends @friends end |
#full_name ⇒ Object (readonly)
Returns the value of attribute full_name.
3 4 5 |
# File 'lib/hypem/user.rb', line 3 def full_name @full_name end |
#image_url ⇒ Object (readonly)
Returns the value of attribute image_url.
3 4 5 |
# File 'lib/hypem/user.rb', line 3 def image_url @image_url end |
#joined_at ⇒ Object (readonly)
Returns the value of attribute joined_at.
3 4 5 |
# File 'lib/hypem/user.rb', line 3 def joined_at @joined_at end |
#location ⇒ Object (readonly)
Returns the value of attribute location.
3 4 5 |
# File 'lib/hypem/user.rb', line 3 def location @location end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/hypem/user.rb', line 3 def name @name end |
#twitter_username ⇒ Object (readonly)
Returns the value of attribute twitter_username.
3 4 5 |
# File 'lib/hypem/user.rb', line 3 def twitter_username @twitter_username end |
Instance Method Details
#api_request(path) ⇒ Object
12 13 14 15 16 |
# File 'lib/hypem/user.rb', line 12 def api_request(path) request = Request.new("/api/#{path}?username=#{@name}") request.get request.response.body end |
#favorite_blogs ⇒ Object
37 38 39 |
# File 'lib/hypem/user.rb', line 37 def favorite_blogs @favorite_blogs ||= get_favorite_blogs end |
#feed_playlist(page = 1) ⇒ Object
79 80 81 |
# File 'lib/hypem/user.rb', line 79 def feed_playlist(page=1) @f_p ||= Playlist.feed(@name,page) end |
#friends_favorites_playlist(page = 1) ⇒ Object
83 84 85 |
# File 'lib/hypem/user.rb', line 83 def friends_favorites_playlist(page=1) @f_f_p ||= Playlist.friends_favorites(@name,page) end |
#friends_history_playlist(page = 1) ⇒ Object
87 88 89 |
# File 'lib/hypem/user.rb', line 87 def friends_history_playlist(page=1) @f_h_p ||= Playlist.friends_history(@name,page) end |
#get_favorite_blogs ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/hypem/user.rb', line 27 def get_favorite_blogs response = api_request('get_favorite_blogs') response.map do |r| blog = Hypem::Blog.new(r['siteid']) blog.update_from_response(r) blog end end |
#get_friends ⇒ Object
41 42 43 44 45 46 47 48 49 |
# File 'lib/hypem/user.rb', line 41 def get_friends response = api_request('get_friends') response.map do |r| user = User.new(r['username']) user.update_from_response(r) user end end |
#get_profile ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/hypem/user.rb', line 18 def get_profile unless @has_profile response = api_request('get_profile') update_from_response(response) @has_profile = true end return self end |
#loved_playlist(page = 1) ⇒ Object
playlist requests
71 72 73 |
# File 'lib/hypem/user.rb', line 71 def loved_playlist(page=1) @l_p ||= Playlist.loved(@name,page) end |
#obsessed_playlist(page = 1) ⇒ Object
75 76 77 |
# File 'lib/hypem/user.rb', line 75 def obsessed_playlist(page=1) @o_p ||= Playlist.obsessed(@name,page) end |
#update_from_response(response) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/hypem/user.rb', line 55 def update_from_response(response) @full_name ||= response['fullname'] @location ||= response['location'] @image_url ||= response['userpic'] @followed_users_count ||= response['favorites_count']['user'] @followed_items_count ||= response['favorites_count']['item'] @followed_sites_count ||= response['favorites_count']['site'] @followed_queries_count ||= response['favorites_count']['query'] # only returned on get_profile @joined_at ||= Time.at(response['joined_ts']) unless response['joined_ts'].nil? @twitter_username ||= response['twitter_username'] end |