Class: Ahub::User

Inherits:
Object
  • Object
show all
Extended by:
APIHelpers
Includes:
ClassHelpers
Defined in:
lib/ahub/user.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from APIHelpers

admin_headers, base_url, find, find_all, headers, object_id_from_response

Methods included from ClassHelpers

#destroy, included, #update

Constructor Details

#initialize(attrs) ⇒ User

Returns a new instance of User.



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/ahub/user.rb', line 28

def initialize(attrs)
  @username = attrs[:username]
  @realname = attrs[:realname]
  @avatar_url = attrs[:avatar]
  @post_count = attrs[:postCount]
  @follow_count = attrs[:followCount]
  @follower_count = attrs[:followerCount]
  @active = attrs[:active]
  @suspended = attrs[:suspended]
  @deactivated  =attrs[:deactivated]
  @complete = attrs[:complete]
end

Instance Attribute Details

#activeObject (readonly)

Returns the value of attribute active.



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

def active
  @active
end

#avatar_urlObject (readonly)

Returns the value of attribute avatar_url.



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

def avatar_url
  @avatar_url
end

#deactivatedObject (readonly)

Returns the value of attribute deactivated.



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

def deactivated
  @deactivated
end

#follow_countObject (readonly)

Returns the value of attribute follow_count.



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

def follow_count
  @follow_count
end

#follower_countObject (readonly)

Returns the value of attribute follower_count.



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

def follower_count
  @follower_count
end

#post_countObject (readonly)

Returns the value of attribute post_count.



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

def post_count
  @post_count
end

#realnameObject (readonly)

Returns the value of attribute realname.



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

def realname
  @realname
end

#suspendedObject (readonly)

Returns the value of attribute suspended.



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

def suspended
  @suspended
end

#usernameObject (readonly)

Returns the value of attribute username.



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

def username
  @username
end

Class Method Details

.create(username:, email:, password: nil) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/ahub/user.rb', line 6

def self.create(username:, email:, password:nil)
  url = "#{base_url}.json"

  payload = {
    email: email,
    username: username,
    password: password || Ahub::DEFAULT_PASSWORD,
  }

  response = RestClient.post(url, payload, admin_headers)
  find(object_id_from_response(response))
end

.find_by_username(username) ⇒ Object



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

def self.find_by_username(username)
  matches = find_all(params: {q: username})
  matches.find{|user| user.username.downcase.strip == username.downcase.strip}
end

Instance Method Details

#is_complete?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/ahub/user.rb', line 41

def is_complete?
  !!@complete
end