Skip to content

Commit 5cbab3a

Browse files
committed
feat: add region to serialize player profile
1 parent 59ea8ff commit 5cbab3a

3 files changed

Lines changed: 15 additions & 7 deletions

File tree

app/controllers/api/v1/players_controller.rb

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -202,12 +202,13 @@ def import
202202
begin
203203
# Fetch summoner data from Riot API
204204
summoner_data = fetch_summoner_by_name(summoner_name, region, riot_api_key)
205-
ranked_data = fetch_ranked_stats(summoner_data['id'], region, riot_api_key)
205+
ranked_data = fetch_ranked_stats(summoner_data['puuid'], region, riot_api_key)
206206

207207
# Prepare player data
208208
player_data = {
209209
summoner_name: summoner_name,
210210
role: role,
211+
region: region,
211212
status: 'active',
212213
riot_puuid: summoner_data['puuid'],
213214
riot_summoner_id: summoner_data['id'],
@@ -302,8 +303,8 @@ def sync_from_riot
302303
summoner_data = fetch_summoner_by_name(@player.summoner_name, region, riot_api_key)
303304
end
304305

305-
# Get ranked stats
306-
ranked_data = fetch_ranked_stats(summoner_data['id'], region, riot_api_key)
306+
# Get ranked stats using PUUID
307+
ranked_data = fetch_ranked_stats(summoner_data['puuid'], region, riot_api_key)
307308

308309
# Update player with fresh data
309310
update_data = {
@@ -411,7 +412,7 @@ def player_params
411412
# :role refers to in-game position (top/jungle/mid/adc/support), not user role
412413
# nosemgrep
413414
params.require(:player).permit(
414-
:summoner_name, :real_name, :role, :status, :jersey_number,
415+
:summoner_name, :real_name, :role, :region, :status, :jersey_number,
415416
:birth_date, :country, :nationality,
416417
:contract_start_date, :contract_end_date,
417418
:solo_queue_tier, :solo_queue_rank, :solo_queue_lp,
@@ -517,11 +518,12 @@ def fetch_summoner_by_puuid(puuid, region, api_key)
517518
JSON.parse(response.body)
518519
end
519520

520-
def fetch_ranked_stats(summoner_id, region, api_key)
521+
def fetch_ranked_stats(puuid, region, api_key)
521522
require 'net/http'
522523
require 'json'
523524

524-
url = "https://#{region}.api.riotgames.com/lol/league/v4/entries/by-summoner/#{summoner_id}"
525+
# Riot API v4 now uses PUUID instead of summoner ID
526+
url = "https://#{region}.api.riotgames.com/lol/league/v4/entries/by-puuid/#{puuid}"
525527
uri = URI(url)
526528
request = Net::HTTP::Get.new(uri)
527529
request['X-Riot-Token'] = api_key
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class AddRegionToPlayers < ActiveRecord::Migration[7.2]
2+
def change
3+
add_column :players, :region, :string
4+
end
5+
end

db/schema.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#
1111
# It's strongly recommended that you check this file into your version control system.
1212

13-
ActiveRecord::Schema[7.2].define(version: 2025_10_12_022035) do
13+
ActiveRecord::Schema[7.2].define(version: 2025_10_12_033201) do
1414
create_schema "auth"
1515
create_schema "extensions"
1616
create_schema "graphql"
@@ -225,6 +225,7 @@
225225
t.datetime "created_at", null: false
226226
t.datetime "updated_at", null: false
227227
t.string "sync_status"
228+
t.string "region"
228229
t.index ["organization_id", "role"], name: "index_players_on_org_and_role"
229230
t.index ["organization_id", "status"], name: "idx_players_org_status"
230231
t.index ["organization_id", "status"], name: "index_players_on_org_and_status"

0 commit comments

Comments
 (0)