Class: Metwit::User
Overview
A user of Metwit
Instance Attribute Summary collapse
-
#activities ⇒ Array<Symbol>
Sport activities.
-
#avatar ⇒ URI
Guaranteed.
-
#badges ⇒ Array<Symbol>
The badges the user earned.
-
#email ⇒ String
Personal The user email.
-
#followers_count ⇒ Fixnum
readonly
Guaranteed.
-
#following_count ⇒ Fixnum
readonly
Guaranteed.
-
#id ⇒ String
readonly
Guaranteed.
-
#metags_count ⇒ Fixnum
readonly
Guaranteed.
-
#nickname ⇒ String
Guaranteed.
-
#today_metags_count ⇒ Fixnum
readonly
Guaranteed.
Class Method Summary collapse
-
.authenticated(opts) ⇒ Hash
Default HTTParty options.
-
.find(id) ⇒ User
Return the user associated with the id.
-
.from_json(response) ⇒ User
Create a user from an HTTParty::Response.
Instance Method Summary collapse
-
#authenticated(opts) ⇒ Hash
HTTParty options for authenticaded calls.
-
#facebook? ⇒ Boolean
Guaranteed.
-
#followed? ⇒ Boolean
Guaranteed.
-
#initialize(args = {}) ⇒ User
constructor
A new instance of User.
-
#twitter? ⇒ Boolean
Guaranteed.
Constructor Details
#initialize(args = {}) ⇒ User
Returns a new instance of User.
79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/metwit/user.rb', line 79 def initialize(args={}) @id = args[:id] @nickname = args[:nickname] @metags_count = args[:metags_count] @today_metags_count = args[:today_metags_count] @avatar = args[:avatar] @is_followed = args[:followed] @followers_count = args[:followers_count] @following_count = args[:following_count] @has_facebook = args[:has_facebook] @has_twitter = args[:has_twitter] end |
Instance Attribute Details
#activities ⇒ Array<Symbol>
Sport activities
55 56 57 |
# File 'lib/metwit/user.rb', line 55 def activities @activities end |
#avatar ⇒ URI
Guaranteed. Avatar url
34 35 36 |
# File 'lib/metwit/user.rb', line 34 def avatar @avatar end |
#badges ⇒ Array<Symbol>
The badges the user earned
59 60 61 |
# File 'lib/metwit/user.rb', line 59 def badges @badges end |
#email ⇒ String
Personal The user email
77 78 79 |
# File 'lib/metwit/user.rb', line 77 def email @email end |
#followers_count ⇒ Fixnum (readonly)
Guaranteed. Followers count
46 47 48 |
# File 'lib/metwit/user.rb', line 46 def followers_count @followers_count end |
#following_count ⇒ Fixnum (readonly)
Guaranteed. Following count
51 52 53 |
# File 'lib/metwit/user.rb', line 51 def following_count @following_count end |
#id ⇒ String (readonly)
Guaranteed. The user id
14 15 16 |
# File 'lib/metwit/user.rb', line 14 def id @id end |
#metags_count ⇒ Fixnum (readonly)
Guaranteed. Total number of metags sent by the user
24 25 26 |
# File 'lib/metwit/user.rb', line 24 def @metags_count end |
#nickname ⇒ String
Guaranteed. The user nickname
19 20 21 |
# File 'lib/metwit/user.rb', line 19 def nickname @nickname end |
#today_metags_count ⇒ Fixnum (readonly)
Guaranteed. Number of metags sent today by the user
29 30 31 |
# File 'lib/metwit/user.rb', line 29 def @today_metags_count end |
Class Method Details
.authenticated(opts) ⇒ Hash
Default HTTParty options
121 122 123 |
# File 'lib/metwit/user.rb', line 121 def authenticated(opts) # opts.deep_merge(:headers => {'Authorization' => "Bearer #{Metwit.bearer_token}"}) end |
.find(id) ⇒ User
Return the user associated with the id
95 96 97 98 99 |
# File 'lib/metwit/user.rb', line 95 def find(id) response = get("/#{id}/", authenticated({})) raise "http error" unless response.code == 200 self.from_json(response) end |
.from_json(response) ⇒ User
Create a user from an HTTParty::Response
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/metwit/user.rb', line 103 def from_json(response) args = { id: response['id'], nickname: response['nickname'], metags_count: response['reports_count'], today_metags_count: response['todays_reports_count'], avatar: URI.parse(response['avatar_url']), followed: response['is_followed'], followers_count: response['followers_count'], following_count: response['following_count'], has_facebook: response['has_facebook'], has_twitter: response['has_twitter'], } User.new(args) end |
Instance Method Details
#authenticated(opts) ⇒ Hash
HTTParty options for authenticaded calls
128 129 130 |
# File 'lib/metwit/user.rb', line 128 def authenticated(opts) self.class.authenticated(opts) end |
#facebook? ⇒ Boolean
Guaranteed. Tells if the user is connected with facebook
64 65 66 |
# File 'lib/metwit/user.rb', line 64 def facebook? @has_facebook end |
#followed? ⇒ Boolean
Guaranteed. Tells if you follow the user
39 40 41 |
# File 'lib/metwit/user.rb', line 39 def followed? @is_followed end |
#twitter? ⇒ Boolean
Guaranteed. Tells if the user is connected with twitter
70 71 72 |
# File 'lib/metwit/user.rb', line 70 def twitter? @has_twitter end |