Class: LearnWeb::Client::User::Me

Inherits:
Object
  • Object
show all
Includes:
AttributePopulatable
Defined in:
lib/learn_web/client/user/me.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from AttributePopulatable

included

Constructor Details

#initialize(response, silent_output: false) ⇒ Me

Returns a new instance of Me.



11
12
13
14
15
16
# File 'lib/learn_web/client/user/me.rb', line 11

def initialize(response, silent_output: false)
  @response      = response
  @silent_output = silent_output

  parse!
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



5
6
7
# File 'lib/learn_web/client/user/me.rb', line 5

def data
  @data
end

#emailObject

Returns the value of attribute email.



5
6
7
# File 'lib/learn_web/client/user/me.rb', line 5

def email
  @email
end

#first_nameObject

Returns the value of attribute first_name.



5
6
7
# File 'lib/learn_web/client/user/me.rb', line 5

def first_name
  @first_name
end

#full_nameObject

Returns the value of attribute full_name.



5
6
7
# File 'lib/learn_web/client/user/me.rb', line 5

def full_name
  @full_name
end

#github_gravatarObject

Returns the value of attribute github_gravatar.



5
6
7
# File 'lib/learn_web/client/user/me.rb', line 5

def github_gravatar
  @github_gravatar
end

#github_uidObject

Returns the value of attribute github_uid.



5
6
7
# File 'lib/learn_web/client/user/me.rb', line 5

def github_uid
  @github_uid
end

#idObject

Returns the value of attribute id.



5
6
7
# File 'lib/learn_web/client/user/me.rb', line 5

def id
  @id
end

#last_nameObject

Returns the value of attribute last_name.



5
6
7
# File 'lib/learn_web/client/user/me.rb', line 5

def last_name
  @last_name
end

#responseObject

Returns the value of attribute response.



5
6
7
# File 'lib/learn_web/client/user/me.rb', line 5

def response
  @response
end

#silent_outputObject

Returns the value of attribute silent_output.



5
6
7
# File 'lib/learn_web/client/user/me.rb', line 5

def silent_output
  @silent_output
end

#usernameObject

Returns the value of attribute username.



5
6
7
# File 'lib/learn_web/client/user/me.rb', line 5

def username
  @username
end

Instance Method Details

#parse!Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/learn_web/client/user/me.rb', line 18

def parse!
  if response.status == 200
    self.data = Oj.load(response.body, symbol_keys: true)

    populate_attributes!
  elsif silent_output == false
    case response.status
    when 401
      puts "It seems your OAuth token is incorrect. Please re-run config with: learn reset"
      exit 1
    when 500
      puts "Something went wrong. Please try again."
      exit 1
    else
      puts "Something went wrong. Please try again."
      exit 1
    end
  end

  self
end