Class: CodewarsApi::User

Inherits:
Object
  • Object
show all
Includes:
Common
Defined in:
lib/codewars_api/user.rb

Instance Method Summary collapse

Methods included from Common

#reason, #success, #to_h

Constructor Details

#initialize(id_or_username) ⇒ User



5
6
7
8
9
# File 'lib/codewars_api/user.rb', line 5

def initialize(id_or_username)
  fail 'Username or id is not set' unless id_or_username
  @response = RequestHelper.get("#{CodewarsApi::API_URL}/users/#{id_or_username}")
  ResponseChecker.check_errors(@response)
end

Instance Method Details

#clanObject



23
24
25
# File 'lib/codewars_api/user.rb', line 23

def clan
  @response.to_h['clan']
end

#honorObject



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

def honor
  @response.to_h['honor']
end

#katas_authoredObject



43
44
45
# File 'lib/codewars_api/user.rb', line 43

def katas_authored
  @response.to_h['codeChallenges'].andand['totalAuthored']
end

#katas_completedObject



47
48
49
# File 'lib/codewars_api/user.rb', line 47

def katas_completed
  @response.to_h['codeChallenges'].andand['totalCompleted']
end

#leaderboard_positionObject



27
28
29
# File 'lib/codewars_api/user.rb', line 27

def leaderboard_position
  @response.to_h['leaderboardPosition']
end

#nameObject



15
16
17
# File 'lib/codewars_api/user.rb', line 15

def name
  @response.to_h['name']
end

#rank_languagesObject



39
40
41
# File 'lib/codewars_api/user.rb', line 39

def rank_languages
  @response.to_h['ranks'].andand['languages']
end

#rank_overallObject



35
36
37
# File 'lib/codewars_api/user.rb', line 35

def rank_overall
  @response.to_h['ranks'].andand['overall']
end

#skillsObject



31
32
33
# File 'lib/codewars_api/user.rb', line 31

def skills
  @response.to_h['skills']
end

#usernameObject



11
12
13
# File 'lib/codewars_api/user.rb', line 11

def username
  @response.to_h['username']
end