ruby-lol 0.0.2 → 0.0.6

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 (44) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +19 -0
  3. data/lib/lol.rb +13 -1
  4. data/lib/lol/aggregated_statistic.rb +21 -0
  5. data/lib/lol/champion.rb +0 -4
  6. data/lib/lol/champion_statistic.rb +25 -0
  7. data/lib/lol/champion_statistics_summary.rb +27 -0
  8. data/lib/lol/client.rb +52 -4
  9. data/lib/lol/game.rb +4 -8
  10. data/lib/lol/league.rb +2 -5
  11. data/lib/lol/league_entry.rb +86 -0
  12. data/lib/lol/match_summary.rb +59 -0
  13. data/lib/lol/mini_series.rb +29 -0
  14. data/lib/lol/model.rb +5 -1
  15. data/lib/lol/player.rb +1 -5
  16. data/lib/lol/player_statistic.rb +43 -0
  17. data/lib/lol/ranked_statistics_summary.rb +35 -0
  18. data/lib/lol/{statistic.rb → raw_statistic.rb} +2 -6
  19. data/lib/lol/roster.rb +23 -0
  20. data/lib/lol/team.rb +122 -0
  21. data/lib/lol/team_member.rb +33 -0
  22. data/lib/lol/team_statistic.rb +45 -0
  23. data/lib/lol/version.rb +1 -1
  24. data/spec/fixtures/v1.1/get-ranked_stats.json +1 -0
  25. data/spec/fixtures/v1.1/get-stats.json +1 -0
  26. data/spec/fixtures/v2.1/get-team.json +962 -0
  27. data/spec/lol/aggregated_statistic_spec.rb +19 -0
  28. data/spec/lol/champion_statistic_spec.rb +19 -0
  29. data/spec/lol/champion_statistics_summary_spec.rb +26 -0
  30. data/spec/lol/client_spec.rb +117 -0
  31. data/spec/lol/game_spec.rb +2 -7
  32. data/spec/lol/league_entry_spec.rb +56 -0
  33. data/spec/lol/league_spec.rb +4 -1
  34. data/spec/lol/match_summary_spec.rb +25 -0
  35. data/spec/lol/mini_series_spec.rb +25 -0
  36. data/spec/lol/player_statistic_spec.rb +32 -0
  37. data/spec/lol/ranked_statistics_summary_spec.rb +32 -0
  38. data/spec/lol/{statistic_spec.rb → raw_statistic_spec.rb} +1 -1
  39. data/spec/lol/roster_spec.rb +24 -0
  40. data/spec/lol/team_member_spec.rb +27 -0
  41. data/spec/lol/team_spec.rb +66 -0
  42. data/spec/lol/team_statistic_spec.rb +31 -0
  43. data/spec/support/model_helpers.rb +25 -3
  44. metadata +47 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 40594303990be0131e05065ee27214203ddc6c34
4
- data.tar.gz: c145a0e4c8e88a5d078bd2899108646b48d63a31
3
+ metadata.gz: 4e4514fa6155984e91035d39c11f299138b3b104
4
+ data.tar.gz: 38fd725d0b900483523b5ffb7fb93c5131ce9eda
5
5
  SHA512:
6
- metadata.gz: 93d7b18857c428884b43d7eb71262c7211ca2c400f107f3ec3d3fbf66251374b433fed299bfceee92c04ce41e45d8f59ae5f87e659106aa1f2bea94ee1c3aa6f
7
- data.tar.gz: a47eeabc90db1141c5222ffdd4b16d1fd2491127ee1503e22427c44853f2dc9ac7412032b643ba38fc1e0c46d35967319d179b63874f90b6114e6d81c2f83307
6
+ metadata.gz: 2a9c947b9c8f803bf1cf13850bfd40f0d7aad75b1bd81878a508cef07f51353306154b859e26a7fab50f496913e3153275119f5d062786477a6d9105f7b08374
7
+ data.tar.gz: 26103c71d7782de216d3eeb7a81f0062e4bd33f101fa0bb4cc29d6e39de0a798221ce0516042060cbfaa275ff0cf4c51abce4752ff1222e0281a07f8c204383b
data/README.md CHANGED
@@ -39,6 +39,25 @@ Or install it yourself as:
39
39
  # let's play a bit, who is free to play?
40
40
  client.champion.select {|c| c.free_to_play }.map {|c| c.name}
41
41
  # => %w(Aatrox Cassiopeia Lux Malphite MissFortune MonkeyKing Nautilus Sivir Talon Taric)
42
+
43
+ # it's time to fetch some of my games, isn't it?
44
+ games = client.game my_summoner_id
45
+ # => Array of Lol::Game
46
+
47
+ # let's get one game and look into it
48
+ game = games.first
49
+
50
+ # who was I playing with?
51
+ game.fellow_players
52
+ # => Array of Lol::Player
53
+
54
+ # gimme some stats!
55
+ game.statistics
56
+ # => Array of Lol::RawStatistic
57
+
58
+ # let's get some info about my Leagues now
59
+ leagues = client.league my_summoner_id
60
+ # => Array of Lol::League
42
61
  ```
43
62
 
44
63
  ## Contributing
data/lib/lol.rb CHANGED
@@ -3,4 +3,16 @@ require __dir__ + "/lol/champion"
3
3
  require __dir__ + "/lol/game"
4
4
  require __dir__ + "/lol/league"
5
5
  require __dir__ + "/lol/player"
6
- require __dir__ + "/lol/statistic"
6
+ require __dir__ + "/lol/raw_statistic"
7
+ require __dir__ + "/lol/player_statistic"
8
+ require __dir__ + "/lol/aggregated_statistic"
9
+ require __dir__ + "/lol/ranked_statistics_summary"
10
+ require __dir__ + "/lol/champion_statistics_summary"
11
+ require __dir__ + "/lol/champion_statistic"
12
+ require __dir__ + "/lol/team"
13
+ require __dir__ + "/lol/roster"
14
+ require __dir__ + "/lol/team_member"
15
+ require __dir__ + "/lol/team_statistic"
16
+ require __dir__ + "/lol/match_summary"
17
+ require __dir__ + "/lol/league_entry"
18
+ require __dir__ + "/lol/mini_series"
@@ -0,0 +1,21 @@
1
+ require 'lol/model'
2
+
3
+ module Lol
4
+ class AggregatedStatistic < Lol::Model
5
+ # @!attribute [r] id
6
+ # @return [Fixnum] Statistic Type Id
7
+ attr_reader :id
8
+
9
+ # @!attribute [r] name
10
+ # @return [String] Statistic Type name
11
+ attr_reader :name
12
+
13
+ # @!attribute [r] count
14
+ # @return [Fixnum] Statistic value
15
+ attr_reader :count
16
+
17
+ private
18
+
19
+ attr_writer :id, :name, :count
20
+ end
21
+ end
data/lib/lol/champion.rb CHANGED
@@ -2,10 +2,6 @@ require 'lol/model'
2
2
 
3
3
  module Lol
4
4
  class Champion < Lol::Model
5
- # @!attribute [r] raw
6
- # @return [String] raw version of options Hash used to initialize Champion
7
- attr_reader :raw
8
-
9
5
  # @!attribute [r] id
10
6
  # @return [Fixnum] id of Champion
11
7
  attr_reader :id
@@ -0,0 +1,25 @@
1
+ require 'lol/model'
2
+
3
+ module Lol
4
+ class ChampionStatistic < Lol::Model
5
+ # @!attribute [r] c
6
+ # @return [Fixnum] Count of samples (games) that make up the aggregated value, where relevant.
7
+ attr_reader :c
8
+
9
+ # @!attribute [r] id
10
+ # @return [Fixnum] Aggregated stat type Id
11
+ attr_reader :id
12
+
13
+ # @!attribute [r] name
14
+ # @return [String] Aggregated stat type Name
15
+ attr_reader :name
16
+
17
+ # @!attribute [r] value
18
+ # @return [Fixnum] Aggregated stat type Value
19
+ attr_reader :value
20
+
21
+ private
22
+
23
+ attr_writer :id, :name, :c, :value
24
+ end
25
+ end
@@ -0,0 +1,27 @@
1
+ require 'lol/model'
2
+
3
+ module Lol
4
+ class ChampionStatisticsSummary < Lol::Model
5
+ # @!attribute [r] id
6
+ # @return [Fixnum] Champion Id
7
+ attr_reader :id
8
+
9
+ # @!attribute [r] name
10
+ # @return [String] Champion Name
11
+ attr_reader :name
12
+
13
+ # @!attribute [r] stats
14
+ # @return [Array] List of stats associated with this champion
15
+ attr_reader :stats
16
+
17
+ private
18
+
19
+ attr_writer :id, :name
20
+
21
+ def stats= collection
22
+ @stats = collection.map do |c|
23
+ c.respond_to?(:[]) && ChampionStatistic.new(c) || c
24
+ end
25
+ end
26
+ end
27
+ end
data/lib/lol/client.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'httparty'
2
+ require 'uri'
2
3
 
3
4
  module Lol
4
5
  class InvalidAPIResponse < StandardError; end
@@ -18,16 +19,17 @@ module Lol
18
19
  # @param version [String] API version to call
19
20
  # @param path [String] API path to call
20
21
  # @return [String] full fledged url
21
- def api_url version, path
22
+ def api_url version, path, params = {}
22
23
  lol = version == "v1.1" ? "lol" : ""
23
- File.join "http://prod.api.pvp.net/api/", lol, "/#{region}/#{version}/", "#{path}?api_key=#{api_key}"
24
+ query_string = URI.encode_www_form params.merge api_key: api_key
25
+ File.join "http://prod.api.pvp.net/api/", lol, "/#{region}/#{version}/", "#{path}?#{query_string}"
24
26
  end
25
27
 
26
28
  # Calls the API via HTTParty and handles errors
27
29
  #
28
30
  def get url
29
31
  response = self.class.get(url)
30
- if response["status"]
32
+ if response.is_a?(Hash) && response["status"]
31
33
  raise InvalidAPIResponse.new(response["status"]["message"])
32
34
  else
33
35
  response
@@ -69,9 +71,55 @@ module Lol
69
71
  # Retrieves leagues data for summoner, including leagues for all of summoner's teams, v2.1
70
72
  # @return [Array] an array of champions
71
73
  def league21 summoner_id
72
- get(api_url("v2.1", "league/by-summoner/#{summoner_id}"))[summoner_id].map {|l| League.new}
74
+ response = get(api_url("v2.1", "league/by-summoner/#{summoner_id}"))[summoner_id]
75
+ response.is_a?(Hash) ? [League.new(response)] : response.map {|l| League.new l}
73
76
  end
74
77
 
78
+ # Calls the latest API version of stats
79
+ def stats *args
80
+ stats11 *args
81
+ end
82
+
83
+ # Retrieves player statistics summaries for the given summoner
84
+ # @return [Array] an array of player statistics, one per queue type
85
+ def stats11 summoner_id, extra = {}
86
+ if extra.keys.select { |k| k.to_sym != :season }.any?
87
+ raise ArgumentError, 'Only :season is allowed as extra parameter'
88
+ end
89
+ stats_api_path = "stats/by-summoner/#{summoner_id}/summary"
90
+ get(api_url('v1.1', stats_api_path, extra))['playerStatSummaries'].map do |player_stat_data|
91
+ PlayerStatistic.new player_stat_data
92
+ end
93
+ end
94
+
95
+ # Calls the latest API version of ranked_stats
96
+ def ranked_stats *args
97
+ ranked_stats11 *args
98
+ end
99
+
100
+ # Retrieves ranked statistics summary for the given summoner
101
+ # @return [RankedStatisticsSummary] Ranked Stats.
102
+ # Includes stats for Twisted Treeline and Summoner's Rift
103
+ def ranked_stats11 summoner_id, extra = {}
104
+ if extra.keys.select { |k| k.to_sym != :season }.any?
105
+ raise ArgumentError, 'Only :season is allowed as extra parameter'
106
+ end
107
+ stats_api_path = "stats/by-summoner/#{summoner_id}/ranked"
108
+ RankedStatisticsSummary.new get api_url 'v1.1', stats_api_path, extra
109
+ end
110
+
111
+ # Calls the latest API version of team returning the list of teams for the given summoner
112
+ def team *args
113
+ team21 *args
114
+ end
115
+
116
+ # Retrieves the list of Teams for the given summoner
117
+ # @return [Array] List of Team
118
+ def team21 summoner_id
119
+ get(api_url 'v2.1', "team/by-summoner/#{summoner_id}").map do |team_data|
120
+ Team.new team_data
121
+ end
122
+ end
75
123
 
76
124
  # Initializes a Lol::Client
77
125
  # @param api_key [String]
data/lib/lol/game.rb CHANGED
@@ -2,10 +2,6 @@ require 'lol/model'
2
2
 
3
3
  module Lol
4
4
  class Game < Lol::Model
5
- # @!attribute [r] raw
6
- # @return [Hash] raw version of options Hash used to initialize Game
7
- attr_reader :raw
8
-
9
5
  # @!attribute [r] id
10
6
  # @return [Fixnum] Game Id
11
7
  attr_reader :game_id
@@ -15,7 +11,7 @@ module Lol
15
11
  attr_reader :champion_id
16
12
 
17
13
  # @!attribute [r] create_date
18
- # @return [DateTime] Date game was played
14
+ # @return [Time] Date game was played
19
15
  attr_reader :create_date
20
16
 
21
17
  # @!attribute [r] create_date_str
@@ -74,7 +70,7 @@ module Lol
74
70
  :create_date_str
75
71
 
76
72
  def create_date= value
77
- @create_date = value.is_a?(DateTime) && value || DateTime.strptime(value.to_s, '%s')
73
+ @create_date = value.is_a?(Numeric) && Time.at(value / 1000) || value
78
74
  end
79
75
 
80
76
  def fellow_players= collection
@@ -85,8 +81,8 @@ module Lol
85
81
 
86
82
  def statistics= collection
87
83
  @statistics = collection.map do |c|
88
- c.respond_to?(:[]) && Statistic.new(c) || c
84
+ c.respond_to?(:[]) && RawStatistic.new(c) || c
89
85
  end
90
86
  end
91
87
  end
92
- end
88
+ end
data/lib/lol/league.rb CHANGED
@@ -1,10 +1,6 @@
1
1
  module Lol
2
2
  # Holds the representation of a League
3
3
  class League < Model
4
- # @!attribute [r] raw
5
- # @return [String] raw version of options Hash used to initialize League
6
- attr_reader :raw
7
-
8
4
  # @!attribute [r] timestamp
9
5
  # @return [String] timestamp of league snapshot
10
6
  attr_reader :timestamp
@@ -30,7 +26,8 @@ module Lol
30
26
  attr_writer :timestamp, :name, :tier, :queue
31
27
 
32
28
  def entries= list
33
- "foo"
29
+ @entries = []
30
+ list.each {|entry| @entries << LeagueEntry.new(entry)}
34
31
  end
35
32
  end
36
33
  end
@@ -0,0 +1,86 @@
1
+ module Lol
2
+ # Holds the representation of a League
3
+ class LeagueEntry < Model
4
+ # @!attribute [r] player_or_team_id
5
+ # @return [String] id for the player or the team returned
6
+ attr_reader :player_or_team_id
7
+
8
+ # @!attribute [r] player_or_team_name
9
+ # @return [String] name for the player or the team returned
10
+ attr_reader :player_or_team_name
11
+
12
+ # @!attribute [r] league_name
13
+ # @return [String] name of league
14
+ attr_reader :league_name
15
+
16
+ # @!attribute [r] queue_type
17
+ # @return [String] type of queue
18
+ attr_reader :queue_type
19
+
20
+ # @!attribute [r] entry tier
21
+ # @return [String] tier of league
22
+ attr_reader :tier
23
+
24
+ # @!attribute [r] rank
25
+ # @return [String] entry rank
26
+ attr_reader :rank
27
+
28
+ # @!attribute [r] league_points
29
+ # @return [String] league points of entry
30
+ attr_reader :league_points
31
+
32
+ # @!attribute [r] wins
33
+ # @return [String] wins
34
+ attr_reader :wins
35
+
36
+ # @!attribute [r] losses
37
+ # @return [String] losses
38
+ attr_reader :losses
39
+
40
+ # @!attribute [r] is_hot_streak
41
+ # @return [Boolean] is currently on hot streak
42
+ attr_reader :is_hot_streak
43
+
44
+ # @!attribute [r] is_veteran
45
+ # @return [Boolean] is a veteran in this league
46
+ attr_reader :is_veteran
47
+
48
+ # @!attribute [r] is_fresh_blood
49
+ # @return [Boolean] is fresh blood in this league
50
+ attr_reader :is_fresh_blood
51
+
52
+ # @!attribute [r] is_inactive
53
+ # @return [Boolean] is marked as inactive
54
+ attr_reader :is_inactive
55
+
56
+ # @!attribute [r] last_played
57
+ # @return [DateTime] date of last played game
58
+ # at the time of writing this attributes is broken in the API
59
+ # it always returns 0.
60
+ attr_reader :last_played
61
+
62
+ # @!attribute [r] time_until_decay
63
+ # @return [Boolean] time until league decay
64
+ attr_reader :time_until_decay
65
+
66
+ # @!attribute [r] mini_series
67
+ # @return [MiniSeries] if player is in a mini_series, returns the MiniSeries object
68
+ # representing it
69
+ attr_reader :mini_series
70
+
71
+ private
72
+
73
+ attr_writer :player_or_team_id, :player_or_team_name, :league_name, :queue_type, :tier,
74
+ :league_points, :wins, :losses, :is_hot_streak, :is_veteran, :is_fresh_blood,
75
+ :is_inactive, :time_until_decay, :rank
76
+
77
+ def last_played= date
78
+ @last_played = date
79
+ end
80
+
81
+ def mini_series= raw
82
+ @mini_series = MiniSeries.new raw
83
+ end
84
+
85
+ end
86
+ end
@@ -0,0 +1,59 @@
1
+ require 'lol/model'
2
+
3
+ module Lol
4
+ class MatchSummary < Lol::Model
5
+ # @!attribute [r] assists
6
+ # @return [Fixnum] Number of assists
7
+ attr_reader :assists
8
+
9
+ # @!attribute [r] date
10
+ # @return [Time] Match date
11
+ attr_reader :date
12
+
13
+ # @!attribute [r] deaths
14
+ # @return [Fixnum] Number of deaths
15
+ attr_reader :deaths
16
+
17
+ # @!attribute [r] game_id
18
+ # @return [Fixnum] Game Id
19
+ attr_reader :game_id
20
+
21
+ # @!attribute [r] game_mode
22
+ # @return [String] Game Mode
23
+ attr_reader :game_mode
24
+
25
+ # @!attribute [r] invalid
26
+ # @return [true] If the match is invalid
27
+ # @return [false] If the match is valid
28
+ attr_reader :invalid
29
+
30
+ # @!attribute [r] kills
31
+ # @return [Fixnum] Number of kills
32
+ attr_reader :kills
33
+
34
+ # @!attribute [r] map_id
35
+ # @return [Fixnum] Map Id
36
+ attr_reader :map_id
37
+
38
+ # @!attribute [r] opposing_team_kills
39
+ # @return [Fixnum] Opposing Team Kills
40
+ attr_reader :opposing_team_kills
41
+
42
+ # @!attribute [r] opposing_team_name
43
+ # @return [String] Opposing Team Name
44
+ attr_reader :opposing_team_name
45
+
46
+ # @!attribute [r] win
47
+ # @return [true] If the team won this match
48
+ # @return [false] If the team lost this match
49
+ attr_reader :win
50
+
51
+ private
52
+
53
+ attr_writer :assists, :deaths, :game_id, :game_mode, :invalid, :kills, :map_id, :opposing_team_kills, :opposing_team_name, :win
54
+
55
+ def date= value
56
+ @date = value.is_a?(Numeric) && Time.at(value / 1000) || value
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,29 @@
1
+ module Lol
2
+ # Holds the representation of a MiniSeries
3
+ class MiniSeries < Model
4
+ # @!attribute [r] target
5
+ # @return [String] number of games required to advance
6
+ attr_reader :target
7
+
8
+ # @!attribute [r] wins
9
+ # @return [Fixnum] wins in the miniseries
10
+ attr_reader :wins
11
+
12
+ # @!attribute [r] losses
13
+ # @return [Fixnum] losses in the miniseries
14
+ attr_reader :losses
15
+
16
+ # @!attribute [r] time_left_to_play_millis
17
+ # @return [Fixnum] time left to play the miniseries, expressed in milliseconds
18
+ attr_reader :time_left_to_play_millis
19
+
20
+ # @!attribute [r] progress
21
+ # @return [String] string representation of the miniseries progress.
22
+ # i.e. "WLN" (Win / Loss / Not played)
23
+ attr_reader :progress
24
+
25
+ private
26
+
27
+ attr_writer :target, :wins, :losses, :time_left_to_play_millis, :progress
28
+ end
29
+ end