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

Returns a new instance of User.



5
6
7
8
# 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}")
end

Instance Method Details

#clanObject



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

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

#honorObject



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

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

#katas_authoredObject



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

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

#katas_completedObject



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

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

#leaderboard_positionObject



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

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

#nameObject



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

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

#rank_languagesObject



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

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

#rank_overallObject



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

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

#skillsObject



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

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

#usernameObject



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

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