lolxin 0.12.1 → 0.13.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.
Files changed (57) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +1 -0
  3. data/LICENSE.txt +1 -1
  4. data/README.md +34 -3
  5. data/Rakefile +1 -1
  6. data/bin/bundle +105 -0
  7. data/bin/byebug +29 -0
  8. data/bin/cc-tddium-post-worker +12 -0
  9. data/bin/codeclimate-test-reporter +12 -0
  10. data/bin/coderay +12 -0
  11. data/bin/console +1 -1
  12. data/bin/dotenv +12 -0
  13. data/bin/htmldiff +12 -0
  14. data/bin/ldiff +12 -0
  15. data/bin/pry +12 -0
  16. data/bin/rake +12 -0
  17. data/bin/rspec +12 -0
  18. data/lib/lolxin.rb +29 -18
  19. data/lib/lolxin/api/champion.rb +24 -0
  20. data/lib/lolxin/api/champion_mastery.rb +38 -0
  21. data/lib/lolxin/api/league.rb +39 -0
  22. data/lib/lolxin/api/lol_static_data.rb +116 -0
  23. data/lib/lolxin/api/lol_status.rb +7 -0
  24. data/lib/lolxin/api/match.rb +41 -0
  25. data/lib/lolxin/api/spectator.rb +180 -0
  26. data/lib/lolxin/api/summoner.rb +25 -0
  27. data/lib/lolxin/api/third_party_code.rb +15 -0
  28. data/lib/lolxin/client.rb +26 -78
  29. data/lib/lolxin/dto/champion_dto.rb +29 -0
  30. data/lib/lolxin/dto/champion_mastery_dto.rb +33 -0
  31. data/lib/lolxin/dto/dto.rb +10 -0
  32. data/lib/lolxin/dto/game_info_dto.rb +31 -0
  33. data/lib/lolxin/dto/league_item_dto.rb +38 -0
  34. data/lib/lolxin/dto/league_list_dto.rb +27 -0
  35. data/lib/lolxin/dto/league_position_dto.rb +45 -0
  36. data/lib/lolxin/dto/mini_series_dto.rb +27 -0
  37. data/lib/lolxin/helpers/api.rb +20 -0
  38. data/lib/lolxin/helpers/api_version.rb +15 -0
  39. data/lib/lolxin/helpers/region.rb +21 -0
  40. data/lib/lolxin/helpers/version.rb +3 -0
  41. data/lolxin.gemspec +5 -2
  42. metadata +72 -22
  43. data/lib/lolxin/api_version.rb +0 -16
  44. data/lib/lolxin/champion.rb +0 -25
  45. data/lib/lolxin/champion_mastery.rb +0 -69
  46. data/lib/lolxin/current_game.rb +0 -44
  47. data/lib/lolxin/featured_games.rb +0 -23
  48. data/lib/lolxin/game.rb +0 -25
  49. data/lib/lolxin/league.rb +0 -58
  50. data/lib/lolxin/lol_static_data.rb +0 -41
  51. data/lib/lolxin/lol_status.rb +0 -21
  52. data/lib/lolxin/match.rb +0 -25
  53. data/lib/lolxin/match_list.rb +0 -40
  54. data/lib/lolxin/region.rb +0 -22
  55. data/lib/lolxin/stats.rb +0 -30
  56. data/lib/lolxin/summoner.rb +0 -55
  57. data/lib/lolxin/version.rb +0 -3
@@ -1,22 +1,33 @@
1
+ # dependency
1
2
  require 'faraday'
3
+ require 'json'
2
4
 
3
- require 'lolxin/version'
4
- require 'lolxin/api_version'
5
- require 'lolxin/client'
6
- require 'lolxin/region'
5
+ require 'lolxin/helpers/api'
6
+ require 'lolxin/helpers/api_version'
7
+ require 'lolxin/helpers/version'
8
+ require 'lolxin/helpers/region'
9
+
10
+ require 'lolxin/dto/dto'
11
+ require 'lolxin/dto/champion_dto'
12
+ require 'lolxin/dto/champion_mastery_dto'
13
+ require 'lolxin/dto/game_info_dto'
14
+ require 'lolxin/dto/league_item_dto'
15
+ require 'lolxin/dto/league_list_dto'
16
+ require 'lolxin/dto/league_position_dto'
17
+ require 'lolxin/dto/mini_series_dto'
7
18
 
8
- require 'lolxin/champion'
9
- require 'lolxin/champion_mastery'
10
- require 'lolxin/current_game'
11
- require 'lolxin/featured_games'
12
- require 'lolxin/game'
13
- require 'lolxin/league'
14
- require 'lolxin/lol_static_data'
15
- require 'lolxin/lol_status'
16
- require 'lolxin/match'
17
- require 'lolxin/match_list'
18
- require 'lolxin/stats'
19
- require 'lolxin/summoner'
19
+ require 'lolxin/api/champion_mastery'
20
+ require 'lolxin/api/champion'
21
+ require 'lolxin/api/league'
22
+ require 'lolxin/api/lol_static_data'
23
+ require 'lolxin/api/lol_status'
24
+ require 'lolxin/api/match'
25
+ require 'lolxin/api/spectator'
26
+ require 'lolxin/api/summoner'
27
+ require 'lolxin/api/third_party_code'
28
+ #require 'lolxin/api/tournament_stub'
29
+ #require 'lolxin/api/tournament'
30
+
31
+ require 'lolxin/client'
20
32
 
21
- module Lolxin
22
- end
33
+ module Lolxin; end
@@ -0,0 +1,24 @@
1
+ module Lolxin
2
+ class Champion < Api
3
+ def champions(id = nil)
4
+ endpoint = "platform/%{version}/champions" % {version: version}
5
+
6
+ res = if id.nil?
7
+ conn.get(endpoint)
8
+ else
9
+ conn.get("#{endpoint}/#{id}")
10
+ end
11
+
12
+ return res if res.status != 200
13
+
14
+ body = JSON.parse(res.body)
15
+
16
+ if champs = body['champions']
17
+ champs.map { |champ| ChampionDto.new(champ) }
18
+ else
19
+ champ = body
20
+ ChampionDto.new(champ)
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,38 @@
1
+ module Lolxin
2
+ class ChampionMastery < Api
3
+ attr_reader :endpoint
4
+
5
+ def initialize(options = {})
6
+ super
7
+ @endpoint = "champion-mastery/%{version}" % {version: @version}
8
+ end
9
+
10
+ def by_summoner(summoner_id)
11
+ url = "#{endpoint}/champion-masteries/by-summoner/#{summoner_id}"
12
+ res = conn.get(url)
13
+ return res if res.status != 200
14
+
15
+ champion_masteries = JSON.parse(res.body)
16
+ champion_masteries.map do |champion_mastery|
17
+ ChampionMasteryDto.new(champion_mastery)
18
+ end
19
+ end
20
+
21
+ def by_summoner_by_champion(summoner_id, champion_id)
22
+ url = "#{endpoint}/champion-masteries/by-summoner/#{summoner_id}/by-champion/#{champion_id}"
23
+ res = conn.get(url)
24
+ return res if res.status != 200
25
+
26
+ champion_mastery = JSON.parse(res.body)
27
+ ChampionMasteryDto.new(champion_mastery)
28
+ end
29
+ alias_method :by_champion, :by_summoner_by_champion
30
+
31
+ def scores(summoner_id)
32
+ res = conn.get("#{endpoint}/scores/by-summoner/#{summoner_id}")
33
+ return res if res.status != 200
34
+
35
+ res.body
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,39 @@
1
+ module Lolxin
2
+ class League < Api
3
+ attr_accessor :endpoint
4
+
5
+ def initialize(options = {})
6
+ super
7
+ @endpoint = "league/%{version}" % {version: @version}
8
+ end
9
+
10
+ %i(challenger master).each do |league|
11
+ define_method("#{league}_by_queue".to_sym) do |queue|
12
+ url = "#{endpoint}/#{league}leagues/by-queue/#{queue}"
13
+ res = conn.get(url)
14
+ return res if res.status != 200
15
+
16
+ league_list = JSON.parse(res.body)
17
+ LeagueListDto.new(league_list)
18
+ end
19
+ end
20
+
21
+ def leagues(league_id)
22
+ url = "#{endpoint}/leagues/#{league_id}"
23
+ res = conn.get(url)
24
+ return res if res.status != 200
25
+
26
+ league_lists = JSON.parse(res.body)
27
+ league_lists.map { |league_list| LeagueListDto.new(league_list) }
28
+ end
29
+
30
+ def positions_by_summoner(summoner_id)
31
+ url = "#{endpoint}/positions/by-summoner/#{summoner_id}"
32
+ res = conn.get(url)
33
+ return res if res.status != 200
34
+
35
+ league_positions = JSON.parse(res.body)
36
+ league_positions.map { |lp| LeaguePositionDto.new(lp) }
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,116 @@
1
+ module Lolxin
2
+ class LolStaticData < Api
3
+ attr_accessor :endpoint
4
+
5
+ def initialize(options = {})
6
+ super
7
+ @endpoint = "static-data/%{version}" % {version: @version}
8
+ end
9
+
10
+ # TODO: get Faraday block to work with optional params
11
+ def champions(champion_id = nil)
12
+ url = if champion_id
13
+ "#{endpoint}/champions/#{champion_id}"
14
+ else
15
+ "#{endpoint}/champions"
16
+ end
17
+
18
+ conn.get(url)
19
+ end
20
+
21
+ def items(item_id = nil)
22
+ url = if item_id
23
+ "#{endpoint}/items/#{item_id}"
24
+ else
25
+ "#{endpoint}/items"
26
+ end
27
+
28
+ conn.get(url)
29
+ end
30
+
31
+ def language_strings
32
+ url = "#{endpoint}/language-strings"
33
+ conn.get(url)
34
+ end
35
+
36
+ def languages
37
+ url = "#{endpoint}/languages"
38
+ conn.get(url)
39
+ end
40
+
41
+ def maps
42
+ url = "#{endpoint}/maps"
43
+ conn.get(url)
44
+ end
45
+
46
+ def masteries(mastery_id = nil)
47
+ url = if mastery_id
48
+ "#{endpoint}/masteries/#{mastery_id}"
49
+ else
50
+ "#{endpoint}/masteries"
51
+ end
52
+
53
+ conn.get(url)
54
+ end
55
+
56
+ def profile_icons
57
+ url = "#{endpoint}/profile-icons"
58
+ conn.get(url)
59
+ end
60
+
61
+ def realms
62
+ url = "#{endpoint}/realms"
63
+ conn.get(url)
64
+ end
65
+
66
+ def reforged_rune_paths(path_id = nil)
67
+ url = if path_id
68
+ "#{endpoint}/reforged-rune-paths/#{path_id}"
69
+ else
70
+ "#{endpoint}/reforged-rune-paths"
71
+ end
72
+
73
+ conn.get(url)
74
+ end
75
+
76
+ def reforged_runes(reforged_rune_id = nil)
77
+ url = if reforged_rune_id
78
+ "#{endpoint}/reforged-runes/#{reforged_rune_id}"
79
+ else
80
+ "#{endpoint}/reforged-runes"
81
+ end
82
+
83
+ conn.get(url)
84
+ end
85
+
86
+ def runes(rune_id = nil)
87
+ url = if rune_id
88
+ "#{endpoint}/runes/#{rune_id}"
89
+ else
90
+ "#{endpoint}/runes"
91
+ end
92
+
93
+ conn.get(url)
94
+ end
95
+
96
+ def summoner_spells(spell_id = nil)
97
+ url = if spell_id
98
+ "#{endpoint}/summoner-spells/#{spell_id}"
99
+ else
100
+ "#{endpoint}/summoner-spells"
101
+ end
102
+
103
+ conn.get(url)
104
+ end
105
+
106
+ def tarball_links
107
+ url = "#{endpoint}/tarball-links"
108
+ conn.get(url)
109
+ end
110
+
111
+ def versions
112
+ url = "#{endpoint}/versions"
113
+ conn.get(url)
114
+ end
115
+ end
116
+ end
@@ -0,0 +1,7 @@
1
+ module Lolxin
2
+ class LolStatus < Api
3
+ def shard_data
4
+ conn.get("status/#{version}/shard-data")
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,41 @@
1
+ module Lolxin
2
+ class Match
3
+ attr_accessor :endpoint
4
+
5
+ # TODO: many endpoints to change and many DTOs to add
6
+ def initialize(options = {})
7
+ super
8
+ @endpoint = "match/%{version}" % {version: @version}
9
+ end
10
+
11
+ def matches(match_id)
12
+ url = "#{endpoint}/matches/#{match_id}"
13
+ conn.get(url)
14
+ end
15
+
16
+ def by_account(account_id, recent = false)
17
+ url = if recent
18
+ "#{endpoint}/matchlists/by-account/#{account_id}/recent"
19
+ else
20
+ "#{endpoint}/matchlists/by-account/#{account_id}"
21
+ end
22
+
23
+ conn.get(url)
24
+ end
25
+
26
+ def by_match(match_id)
27
+ url = "#{endpoint}/timelines/by-match/#{match_id}"
28
+ conn.get(url)
29
+ end
30
+
31
+ def tournament_code(tournament_code, match_id)
32
+ url = if tournament_code && match_id
33
+ "matches/by-tournament-code/#{tournament_code}/ids"
34
+ else
35
+ "matches/#{match_id}/by-tournament-code/#{tournament_code}"
36
+ end
37
+
38
+ conn.get(url)
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,180 @@
1
+ module Lolxin
2
+ class Spectator < Api
3
+ CurrentGameInfo = FeaturedGameInfo = Struct.new(
4
+ :game_id,
5
+ :game_start_time,
6
+ :platform_id,
7
+ :game_mode,
8
+ :map_id,
9
+ :game_type,
10
+ :banned_champions,
11
+ :observers,
12
+ :participants,
13
+ :game_length,
14
+ :game_queue_config_id
15
+ )
16
+
17
+ CurrentGameParticipant = Struct.new(
18
+ :profile_icon_id,
19
+ :champion_id,
20
+ :summoner_name,
21
+ :runes,
22
+ :bot,
23
+ :team_id,
24
+ :spell2d,
25
+ :masteries,
26
+ :spell1d,
27
+ :summoner_id
28
+ )
29
+
30
+ Rune = Struct.new(
31
+ :count,
32
+ :rune_id
33
+ )
34
+
35
+ Mastery = Struct.new(
36
+ :mastery_id,
37
+ :rank
38
+ )
39
+
40
+ FeaturedGames = Struct.new(
41
+ :client_refresh_interval,
42
+ :game_list
43
+ )
44
+
45
+ BannedChampion = Struct.new(
46
+ :pick_turn,
47
+ :champion_id,
48
+ :team_id
49
+ )
50
+
51
+ Observer = Struct.new(
52
+ :encryption_key
53
+ )
54
+
55
+ Participant = Struct.new(
56
+ :profile_icon_id,
57
+ :champion_id,
58
+ :summoner_name,
59
+ :bot,
60
+ :spell2d,
61
+ :team_id,
62
+ :spell1id
63
+ )
64
+
65
+ attr_accessor :endpoint
66
+
67
+ def initialize(options = {})
68
+ super
69
+ @endpoint = "spectator/%{version}" % {version: @version}
70
+ end
71
+
72
+ def by_summoner(summoner_id)
73
+ url = "#{endpoint}/active-games/by-summoner/#{summoner_id}"
74
+ res = conn.get(url)
75
+ return res if res.status != 200
76
+
77
+ current_game = JSON.parse(res.body)
78
+ build_current_game_info(current_game)
79
+ end
80
+
81
+ def featured_games
82
+ url = "#{endpoint}/featured-games"
83
+ res = conn.get(url)
84
+ return res if res.status != 200
85
+
86
+ featured = JSON.parse(res.body)
87
+ build_featured_games(featured)
88
+ end
89
+
90
+ private
91
+
92
+ def build_current_game_info(current_game)
93
+ CurrentGameInfo.new(
94
+ current_game['gameId'],
95
+ current_game['gameStartTime'],
96
+ current_game['platformId'],
97
+ current_game['gameMode'],
98
+ current_game['mapId'],
99
+ current_game['gameType'],
100
+ build_banned_champions(current_game['bannedChampions']),
101
+ build_observer(current_game['observers']),
102
+ build_current_game_participants(current_game['participants']),
103
+ current_game['gameLength'],
104
+ current_game['gameQueueConfigId']
105
+ )
106
+ end
107
+
108
+ def build_featured_games(featured_games)
109
+ FeaturedGames.new(
110
+ featured_games['clientRefreshInterval'],
111
+ featured_games['gameList'].map { |f| build_featured_game_info(f) }
112
+ )
113
+ end
114
+
115
+ def build_featured_game_info(feature)
116
+ FeaturedGameInfo.new(
117
+ feature['gameId'],
118
+ feature['gameStartTime'],
119
+ feature['platformId'],
120
+ feature['gameMode'],
121
+ feature['mapId'],
122
+ feature['gameType'],
123
+ build_banned_champions(feature['bannedChampions']),
124
+ build_observer(feature['observer']),
125
+ build_participants(feature['participants']),
126
+ feature['gameLength'],
127
+ feature['gameQueueConfigId']
128
+ )
129
+ end
130
+
131
+ def build_banned_champions(banned_champions)
132
+ return [] if banned_champions.nil? or banned_champions.empty?
133
+
134
+ banned_champions.map do |banned_champion|
135
+ BannedChampion.new(
136
+ banned_champion['pickTurn'],
137
+ banned_champion['championId'],
138
+ banned_champion['teamId']
139
+ )
140
+ end
141
+ end
142
+
143
+ def build_observer(observer)
144
+ return nil if observer.nil?
145
+
146
+ Observer.new(observer['encryptionKey'])
147
+ end
148
+
149
+ def build_current_game_participants(participants)
150
+ participants.map do |participant|
151
+ CurrentGameParticipant.new(
152
+ participant['profileIconId'],
153
+ participant['championId'],
154
+ participant['summonerName'],
155
+ participant['runes'],
156
+ participant['bot'],
157
+ participant['teamId'],
158
+ participant['spell2d'],
159
+ participant['masteries'],
160
+ participant['spell1id'],
161
+ participant['summonerId']
162
+ )
163
+ end
164
+ end
165
+
166
+ def build_participants(participants)
167
+ participants.map do |participant|
168
+ Participant.new(
169
+ participant['profileIconId'],
170
+ participant['championId'],
171
+ participant['summonerName'],
172
+ participant['bot'],
173
+ participant['spell2d'],
174
+ participant['teamId'],
175
+ participant['spell1id']
176
+ )
177
+ end
178
+ end
179
+ end
180
+ end