lol_data_fetcher 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +33 -7
- data/lib/lol_data_fetcher/cli.rb +26 -8
- data/lib/lol_data_fetcher/resources/champions.rb +42 -2
- data/lib/lol_data_fetcher/resources/items.rb +10 -2
- data/lib/lol_data_fetcher/resources/skins.rb +13 -5
- data/lib/lol_data_fetcher/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 84b940340e873c546e540b47349ceb1cae28e4503fbc0f4056226dd2d2cfe2d7
|
|
4
|
+
data.tar.gz: 5bd9d64f06def02eb3c70e168be0d2825cfcb61ec377a6296470a119abfcb15d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: fe02fd0be3d0413f3954143702624fc0e3c96e55cacb2c6376ebf2b72220bcc57c78fb10322060b2c6cd6438b5139d5a924ed8546a3c0c870b2729a44ac80934
|
|
7
|
+
data.tar.gz: 2bed146707485387697355cd10d51fecfb4f69c385f002062f306ceffeb5c1fea674f84b539b87a40188d77dbdf959706c09ef9961c7330557d2a555f2416933
|
data/README.md
CHANGED
|
@@ -7,6 +7,7 @@ A Ruby client for the League of Legends Data Dragon API. Fetch champions, items,
|
|
|
7
7
|
- Fetch all champions with detailed information including skills/spells
|
|
8
8
|
- Get all items and search by name
|
|
9
9
|
- Retrieve champion skins with image URLs
|
|
10
|
+
- **Case-insensitive search** for champions, items, and skins
|
|
10
11
|
- Support for multiple game versions and languages
|
|
11
12
|
- Command-line interface (CLI) for quick data access
|
|
12
13
|
- Comprehensive test coverage with RSpec
|
|
@@ -67,6 +68,19 @@ ahri_data = ahri["data"]["Ahri"]
|
|
|
67
68
|
puts ahri_data["name"] # => "Ahri"
|
|
68
69
|
puts ahri_data["title"] # => "the Nine-Tailed Fox"
|
|
69
70
|
|
|
71
|
+
# Case-insensitive search (works with any casing!)
|
|
72
|
+
client.champions.find("ahri") # => Works!
|
|
73
|
+
client.champions.find("AHRI") # => Works!
|
|
74
|
+
client.champions.find("DrAvEn") # => Works!
|
|
75
|
+
|
|
76
|
+
# Access champion's passive ability
|
|
77
|
+
passive = ahri_data["passive"]
|
|
78
|
+
puts "#{passive['name']}: #{passive['description']}"
|
|
79
|
+
|
|
80
|
+
# Or use the helper method (also case-insensitive)
|
|
81
|
+
passive = client.champions.passive("ahri")
|
|
82
|
+
puts "#{passive['name']}: #{passive['description']}"
|
|
83
|
+
|
|
70
84
|
# Access champion spells/skills
|
|
71
85
|
ahri_data["spells"].each do |spell|
|
|
72
86
|
puts "#{spell['name']}: #{spell['description']}"
|
|
@@ -93,8 +107,12 @@ end
|
|
|
93
107
|
boots = client.items.find("1001")
|
|
94
108
|
puts boots["name"] # => "Boots"
|
|
95
109
|
|
|
96
|
-
#
|
|
97
|
-
|
|
110
|
+
# Find item by name (case-insensitive exact match)
|
|
111
|
+
boots = client.items.find_by_name("boots") # Works with any casing
|
|
112
|
+
puts boots["name"] # => "Boots"
|
|
113
|
+
|
|
114
|
+
# Search items by name (case-insensitive partial match)
|
|
115
|
+
swords = client.items.search("SWORD") # Case doesn't matter
|
|
98
116
|
swords.each do |item|
|
|
99
117
|
puts item["name"]
|
|
100
118
|
end
|
|
@@ -106,8 +124,8 @@ ids = client.items.list_ids
|
|
|
106
124
|
#### Fetching Skins
|
|
107
125
|
|
|
108
126
|
```ruby
|
|
109
|
-
# Get all skins for a specific champion
|
|
110
|
-
skins = client.skins.for_champion("
|
|
127
|
+
# Get all skins for a specific champion (case-insensitive)
|
|
128
|
+
skins = client.skins.for_champion("ahri") # Works with any casing
|
|
111
129
|
skins.each do |skin|
|
|
112
130
|
puts skin["name"]
|
|
113
131
|
puts "Splash: #{skin['splash_url']}"
|
|
@@ -264,26 +282,34 @@ client = LolDataFetcher::Client.new(version: "15.23.1", language: "en_US")
|
|
|
264
282
|
|
|
265
283
|
### Champions Resource
|
|
266
284
|
|
|
285
|
+
All champion name searches are **case-insensitive**.
|
|
286
|
+
|
|
267
287
|
```ruby
|
|
268
288
|
client.champions.all # Get all champions (overview)
|
|
269
|
-
client.champions.find("
|
|
289
|
+
client.champions.find("ahri") # Get detailed champion data (case-insensitive)
|
|
290
|
+
client.champions.passive("AHRI") # Get champion's passive ability (case-insensitive)
|
|
270
291
|
client.champions.list_names # List all champion names
|
|
271
292
|
client.champions.find_by_id("103") # Find champion by ID
|
|
272
293
|
```
|
|
273
294
|
|
|
274
295
|
### Items Resource
|
|
275
296
|
|
|
297
|
+
Item searches are **case-insensitive**.
|
|
298
|
+
|
|
276
299
|
```ruby
|
|
277
300
|
client.items.all # Get all items
|
|
278
301
|
client.items.find("1001") # Find item by ID
|
|
302
|
+
client.items.find_by_name("boots") # Find item by name (case-insensitive)
|
|
279
303
|
client.items.list_ids # List all item IDs
|
|
280
|
-
client.items.search("
|
|
304
|
+
client.items.search("SWORD") # Search items by name (case-insensitive)
|
|
281
305
|
```
|
|
282
306
|
|
|
283
307
|
### Skins Resource
|
|
284
308
|
|
|
309
|
+
Champion name searches are **case-insensitive**.
|
|
310
|
+
|
|
285
311
|
```ruby
|
|
286
|
-
client.skins.for_champion("
|
|
312
|
+
client.skins.for_champion("ahri") # Get skins for a champion (case-insensitive)
|
|
287
313
|
```
|
|
288
314
|
|
|
289
315
|
### Versions Resource
|
data/lib/lol_data_fetcher/cli.rb
CHANGED
|
@@ -51,7 +51,10 @@ module LolDataFetcher
|
|
|
51
51
|
client = create_client
|
|
52
52
|
data = client.champions.find(name)
|
|
53
53
|
|
|
54
|
-
|
|
54
|
+
# Extract the normalized champion name from the response
|
|
55
|
+
normalized_name = data.dig("data")&.keys&.first
|
|
56
|
+
champion_data = data.dig("data", normalized_name)
|
|
57
|
+
|
|
55
58
|
unless champion_data
|
|
56
59
|
error("Champion '#{name}' not found")
|
|
57
60
|
return
|
|
@@ -62,12 +65,22 @@ module LolDataFetcher
|
|
|
62
65
|
puts "\nLore:"
|
|
63
66
|
puts word_wrap(champion_data["lore"])
|
|
64
67
|
|
|
65
|
-
if options[:skills]
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
puts "\
|
|
70
|
-
puts " #{word_wrap(strip_html(
|
|
68
|
+
if options[:skills]
|
|
69
|
+
# Display passive ability
|
|
70
|
+
if champion_data["passive"]
|
|
71
|
+
passive = champion_data["passive"]
|
|
72
|
+
puts "\nPassive: #{passive['name']}"
|
|
73
|
+
puts " #{word_wrap(strip_html(passive['description']), 3)}"
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
# Display active spells/abilities
|
|
77
|
+
if champion_data["spells"]
|
|
78
|
+
puts "\n#{champion_data['name']}'s Skills:"
|
|
79
|
+
puts "-" * 50
|
|
80
|
+
champion_data["spells"].each_with_index do |spell, idx|
|
|
81
|
+
puts "\n#{idx + 1}. #{spell['name']}"
|
|
82
|
+
puts " #{word_wrap(strip_html(spell['description']), 3)}"
|
|
83
|
+
end
|
|
71
84
|
end
|
|
72
85
|
end
|
|
73
86
|
|
|
@@ -120,7 +133,12 @@ module LolDataFetcher
|
|
|
120
133
|
client = create_client
|
|
121
134
|
skins = client.skins.for_champion(champion_name)
|
|
122
135
|
|
|
123
|
-
|
|
136
|
+
# Get the correctly-cased champion name from the first skin's URL if available
|
|
137
|
+
# Or fetch it directly from the champions resource
|
|
138
|
+
champion_data = client.champions.find(champion_name)
|
|
139
|
+
normalized_name = champion_data.dig("data")&.keys&.first || champion_name
|
|
140
|
+
|
|
141
|
+
puts "\n#{normalized_name}'s Skins:"
|
|
124
142
|
puts "=" * 50
|
|
125
143
|
|
|
126
144
|
skins.each do |skin|
|
|
@@ -11,10 +11,23 @@ module LolDataFetcher
|
|
|
11
11
|
end
|
|
12
12
|
|
|
13
13
|
# Fetch detailed data for a specific champion including skills
|
|
14
|
-
#
|
|
14
|
+
# Supports case-insensitive search (e.g., "ahri", "AHRI", "Ahri")
|
|
15
|
+
# @param name [String] Champion name (case-insensitive)
|
|
15
16
|
# @return [Hash] Detailed champion data including spells/skills
|
|
16
17
|
def find(name)
|
|
17
|
-
|
|
18
|
+
normalized_name = normalize_name(name)
|
|
19
|
+
data = get(cdn_path("champion/#{normalized_name}"))
|
|
20
|
+
# Return data with the normalized name key
|
|
21
|
+
data
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# Get passive ability for a specific champion
|
|
25
|
+
# Supports case-insensitive search
|
|
26
|
+
# @param name [String] Champion name (case-insensitive)
|
|
27
|
+
# @return [Hash, nil] Passive ability data or nil if not found
|
|
28
|
+
def passive(name)
|
|
29
|
+
normalized_name = normalize_name(name)
|
|
30
|
+
find(normalized_name).dig("data", normalized_name, "passive")
|
|
18
31
|
end
|
|
19
32
|
|
|
20
33
|
# List all champion names
|
|
@@ -29,6 +42,33 @@ module LolDataFetcher
|
|
|
29
42
|
def find_by_id(id)
|
|
30
43
|
all.dig("data")&.find { |_key, champ| champ["key"] == id.to_s }&.last
|
|
31
44
|
end
|
|
45
|
+
|
|
46
|
+
private
|
|
47
|
+
|
|
48
|
+
# Normalize champion name to match Data Dragon API casing
|
|
49
|
+
# Performs case-insensitive lookup to find the correct champion name
|
|
50
|
+
# @param name [String] Champion name in any casing
|
|
51
|
+
# @return [String] Properly-cased champion name for API
|
|
52
|
+
# @raise [NotFoundError] If champion is not found
|
|
53
|
+
def normalize_name(name)
|
|
54
|
+
return name if name.nil? || name.empty?
|
|
55
|
+
|
|
56
|
+
# Get all champion names from the API
|
|
57
|
+
champions_data = all.dig("data")
|
|
58
|
+
return name unless champions_data
|
|
59
|
+
|
|
60
|
+
# Find the champion with case-insensitive matching
|
|
61
|
+
normalized = champions_data.keys.find do |champion_name|
|
|
62
|
+
champion_name.downcase == name.downcase
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# If not found, raise an error
|
|
66
|
+
unless normalized
|
|
67
|
+
raise NotFoundError, "Champion '#{name}' not found. Check spelling and try again."
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
normalized
|
|
71
|
+
end
|
|
32
72
|
end
|
|
33
73
|
end
|
|
34
74
|
end
|
|
@@ -23,13 +23,21 @@ module LolDataFetcher
|
|
|
23
23
|
all.dig("data")&.keys || []
|
|
24
24
|
end
|
|
25
25
|
|
|
26
|
-
# Search items by name
|
|
27
|
-
# @param query [String] Search query
|
|
26
|
+
# Search items by name (case-insensitive)
|
|
27
|
+
# @param query [String] Search query (case-insensitive)
|
|
28
28
|
# @return [Array<Hash>] Array of matching items
|
|
29
29
|
def search(query)
|
|
30
30
|
items = all.dig("data") || {}
|
|
31
31
|
items.select { |_id, item| item["name"]&.downcase&.include?(query.downcase) }.values
|
|
32
32
|
end
|
|
33
|
+
|
|
34
|
+
# Find item by exact name match (case-insensitive)
|
|
35
|
+
# @param name [String] Item name (case-insensitive)
|
|
36
|
+
# @return [Hash, nil] Item data or nil if not found
|
|
37
|
+
def find_by_name(name)
|
|
38
|
+
items = all.dig("data") || {}
|
|
39
|
+
items.find { |_id, item| item["name"]&.downcase == name.downcase }&.last
|
|
40
|
+
end
|
|
33
41
|
end
|
|
34
42
|
end
|
|
35
43
|
end
|
|
@@ -5,19 +5,27 @@ module LolDataFetcher
|
|
|
5
5
|
# Resource for fetching champion skin data
|
|
6
6
|
class Skins < Base
|
|
7
7
|
# Fetch skins for a specific champion
|
|
8
|
-
#
|
|
8
|
+
# Supports case-insensitive search (e.g., "ahri", "AHRI", "Ahri")
|
|
9
|
+
# @param champion_name [String] Champion name (case-insensitive)
|
|
9
10
|
# @return [Array<Hash>] Array of skin data with image URLs
|
|
10
11
|
def for_champion(champion_name)
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
# Use the champions resource to get the data with normalized name
|
|
13
|
+
champion_data = client.champions.find(champion_name)
|
|
14
|
+
|
|
15
|
+
# The find method returns data with the normalized name as key
|
|
16
|
+
# We need to extract that key from the data
|
|
17
|
+
normalized_name = champion_data.dig("data")&.keys&.first
|
|
18
|
+
return [] unless normalized_name
|
|
19
|
+
|
|
20
|
+
skins = champion_data.dig("data", normalized_name, "skins") || []
|
|
13
21
|
|
|
14
22
|
skins.map do |skin|
|
|
15
23
|
{
|
|
16
24
|
"id" => skin["id"],
|
|
17
25
|
"num" => skin["num"],
|
|
18
26
|
"name" => skin["name"],
|
|
19
|
-
"splash_url" => splash_url(
|
|
20
|
-
"loading_url" => loading_url(
|
|
27
|
+
"splash_url" => splash_url(normalized_name, skin["num"]),
|
|
28
|
+
"loading_url" => loading_url(normalized_name, skin["num"]),
|
|
21
29
|
"chromas" => skin["chromas"] || false
|
|
22
30
|
}
|
|
23
31
|
end
|