Class: Metwit::User

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/metwit/user.rb

Overview

A user of Metwit

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#activitiesArray<Symbol>

Sport activities

Returns:

  • (Array<Symbol>)

    Sport activities array



55
56
57
# File 'lib/metwit/user.rb', line 55

def activities
  @activities
end

#avatarURI

Guaranteed. Avatar url

Returns:

  • (URI)

    avatar url



34
35
36
# File 'lib/metwit/user.rb', line 34

def avatar
  @avatar
end

#badgesArray<Symbol>

The badges the user earned

Returns:

  • (Array<Symbol>)

    Bagdges



59
60
61
# File 'lib/metwit/user.rb', line 59

def badges
  @badges
end

#emailString

Personal The user email

Returns:

  • (String)


77
78
79
# File 'lib/metwit/user.rb', line 77

def email
  @email
end

#followers_countFixnum (readonly)

Guaranteed. Followers count

Returns:

  • (Fixnum)

    The number of followers



46
47
48
# File 'lib/metwit/user.rb', line 46

def followers_count
  @followers_count
end

#following_countFixnum (readonly)

Guaranteed. Following count

Returns:

  • (Fixnum)

    The number of following users



51
52
53
# File 'lib/metwit/user.rb', line 51

def following_count
  @following_count
end

#idString (readonly)

Guaranteed. The user id

Returns:

  • (String)

    unique identifier of the user



14
15
16
# File 'lib/metwit/user.rb', line 14

def id
  @id
end

#metags_countFixnum (readonly)

Guaranteed. Total number of metags sent by the user

Returns:

  • (Fixnum)

    total number of metags



24
25
26
# File 'lib/metwit/user.rb', line 24

def metags_count
  @metags_count
end

#nicknameString

Guaranteed. The user nickname

Returns:

  • (String)

    nickname



19
20
21
# File 'lib/metwit/user.rb', line 19

def nickname
  @nickname
end

#today_metags_countFixnum (readonly)

Guaranteed. Number of metags sent today by the user

Returns:

  • (Fixnum)

    today metags number



29
30
31
# File 'lib/metwit/user.rb', line 29

def today_metags_count
  @today_metags_count
end

Class Method Details

.authenticated(opts) ⇒ Hash

Default HTTParty options

Returns:

  • (Hash)


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

Returns:



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

Returns:



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

Returns:

  • (Hash)


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

Returns:

  • (Boolean)


64
65
66
# File 'lib/metwit/user.rb', line 64

def facebook?
  @has_facebook
end

#followed?Boolean

Guaranteed. Tells if you follow the user

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)


70
71
72
# File 'lib/metwit/user.rb', line 70

def twitter?
  @has_twitter
end