diff --git a/lib/sightstone/league.rb b/lib/sightstone/league.rb index fcd60e0..0221c57 100644 --- a/lib/sightstone/league.rb +++ b/lib/sightstone/league.rb @@ -3,6 +3,7 @@ module Sightstone # @attr [String] name name of the league # @attr [String] queue queue Type (can be: RANKED_SOLO_5x5, RANKED_TEAM_3x3, RANKED_TEAM_5x5) # @attr [String] tier tier of the requestet summoner (can be: CHALLENGER, DIAMOND, PLATINUM, GOLD, SILVER, BRONZE) +# @attr [String] participantId id of the requested summoner or team # @attr [Array] entries class League attr_accessor :entries, :name, :queue, :tier, :participantId @@ -23,11 +24,11 @@ end # @attr [Boolean] isFreshBlood determines if summoner is new in the league # @attr [Boolean] isHotStreak hotStreak = 3 games won in a row # @attr [Boolean] isInactive true if summoner is inactive -# @attr [Boolean] isVetern true if veteran +# @attr [Boolean] isVeteran true if veteran # @attr [Fixnum] lastPlayed timestamp of last played game # @attr [String] leagueName name of the league # @attr [Fixnum] leaguePoints leaguePoints -# @attr [MiniSeries, nil] nil if player has no miniseries, a miniseries object if he is in one +# @attr [MiniSeries] miniSeries a miniseries object if he is in one # @attr [String] playerOrTeamId id of the player or team as a string # @attr [String] playerOrTeamName name of the player/team # @attr [String] queueType type of the queue @@ -60,7 +61,7 @@ end # @attr [Fixnum] wins number of won games of the series # @attr [Fixnum] target number of required wins to win the series # @attr [Fixnum] timeLeftToPlayMillis time left to complete the series -# @attr [String] win/loose history as a string. Each character shows a (W)in, (L)oss or (N)ot played +# @attr [String] progress win/loose history as a string. Each character shows a (W)in, (L)oss or (N)ot played class MiniSeries attr_accessor :losses, :wins, :target, :progress, :timeLeftToPlayMillis def initialize(data) diff --git a/spec/champion_spec.rb b/spec/champion_spec.rb index 46747f2..9ef23a3 100644 --- a/spec/champion_spec.rb +++ b/spec/champion_spec.rb @@ -5,10 +5,10 @@ module Sightstone describe Champion do before :all do - json = JSON.parse('{"botMmEnabled": false,"defenseRank": 4,"attackRank": 8,"id": 266, + response_mockup = JSON.parse('{"botMmEnabled": false,"defenseRank": 4,"attackRank": 8,"id": 266, "rankedPlayEnabled": true,"name": "Aatrox","botEnabled": false,"difficultyRank": 6, "active": true,"freeToPlay": false,"magicRank": 3}') - @c = Champion.new(json) + @c = Champion.new(response_mockup) end describe "#new" do diff --git a/spec/league_spec.rb b/spec/league_spec.rb new file mode 100644 index 0000000..e08803d --- /dev/null +++ b/spec/league_spec.rb @@ -0,0 +1,108 @@ +require 'spec_helper' +require 'json' + +module Sightstone +describe League do + + before :all do + json_mockup = JSON.parse('{"queue": "RANKED_SOLO_5x5","name": "Vladimirs Maulers","participantId": "5908","entries": + [{"isHotStreak": false,"isFreshBlood": false,"leagueName": "Vladimirs Maulers","isVeteran": true,"tier": "DIAMOND","lastPlayed": -1, + "playerOrTeamId": "27280077","leaguePoints": 0,"rank": "V","isInactive": false,"queueType": "RANKED_SOLO_5x5","playerOrTeamName": "TLP fierce1","wins": 210}, + {"isHotStreak": false,"isFreshBlood": false,"leagueName": "Vladimirs Maulers","isVeteran": true,"tier": "DIAMOND","lastPlayed": -1,"playerOrTeamId": "19571444","leaguePoints": 84, + "rank": "IV","isInactive": false,"queueType": "RANKED_SOLO_5x5","playerOrTeamName": "KINGSTON PLEASE","wins": 111},{"isHotStreak": false,"isFreshBlood": false, + "leagueName": "Vladimirs Maulers","isVeteran": false,"tier": "DIAMOND","lastPlayed": -1,"playerOrTeamId": "77988","leaguePoints": 42, + "rank": "V","isInactive": false,"queueType": "RANKED_SOLO_5x5","playerOrTeamName": "Pluripotential","wins": 69},{"isHotStreak": false, + "isFreshBlood": false,"leagueName": "Vladimirs Maulers","isVeteran": false,"tier": "DIAMOND","lastPlayed": -1,"playerOrTeamId": "24717856", + "leaguePoints": 22,"rank": "IV","isInactive": false,"queueType": "RANKED_SOLO_5x5","playerOrTeamName": "Red X Hero","wins": 66}, + {"isHotStreak": false,"isFreshBlood": false,"leagueName": "Vladimirs Maulers","isVeteran": true,"tier": "DIAMOND","lastPlayed": -1, + "playerOrTeamId": "477045","leaguePoints": 68,"rank": "III","isInactive": false,"queueType": "RANKED_SOLO_5x5", + "playerOrTeamName": "SmashGizmo","wins": 130},{"isHotStreak": true,"isFreshBlood": false,"leagueName": "Vladimirs Maulers", + "isVeteran": true,"tier": "DIAMOND","lastPlayed": -1,"playerOrTeamId": "21466580","leaguePoints": 69,"rank": "IV", + "isInactive": false,"queueType": "RANKED_SOLO_5x5","playerOrTeamName": "TLP TerminaTop","wins": 103}, + {"isHotStreak": false,"isFreshBlood": false,"leagueName": "Vladimirs Maulers","isVeteran": false, + "tier": "DIAMOND","lastPlayed": -1,"playerOrTeamId": "19033574","leaguePoints": 0,"rank": "V", + "isInactive": false,"queueType": "RANKED_SOLO_5x5","playerOrTeamName": "NeiLy","wins": 155}, + {"isHotStreak": false,"isFreshBlood": false,"leagueName": "Vladimirs Maulers", + "isVeteran": false,"tier": "DIAMOND","lastPlayed": -1,"playerOrTeamId": "30753436","leaguePoints": 26,"rank": "III","isInactive": false, + "queueType": "RANKED_SOLO_5x5","playerOrTeamName": "HellFire114N","wins": 39},{"isHotStreak": false,"isFreshBlood": false,"leagueName": "Vladimirs Maulers", + "isVeteran": true,"tier": "DIAMOND","lastPlayed": -1,"playerOrTeamId": "19322489","leaguePoints": 27,"rank": "I","isInactive": false, + "queueType": "RANKED_SOLO_5x5","playerOrTeamName": "EyeMtheStron9est","wins": 86},{"isHotStreak": false,"isFreshBlood": false, + "leagueName": "Vladimirs Maulers","isVeteran": true,"tier": "DIAMOND","lastPlayed": -1,"playerOrTeamId": "21020883", + "leaguePoints": 28,"rank": "I","isInactive": false,"queueType": "RANKED_SOLO_5x5","playerOrTeamName": "Bobo the Builder","wins": 75}], + "tier": "DIAMOND"}') + @league = League.new(json_mockup) + end + + describe "#new" do + it "should initialize a league object" do + @league.should be_an_instance_of League + end + + it "should initialize with correct params" do + @league.name.should be_a_kind_of String + @league.queue.should be_a_kind_of String + @league.tier.should be_a_kind_of String + @league.entries.should be_an_instance_of Array + end + end + + describe "#entries" do + it "should return a list of league entries" do + @league.entries.each {|e| e.should be_an_instance_of LeagueItem} + end + end + +end + + +describe LeagueItem do + before :all do + json_mockup = JSON.parse('{"isHotStreak": true,"isFreshBlood": false,"leagueName": "Vladimirs Maulers","miniSeries": {"progress": "WNN","target": 2,"losses": 0,"timeLeftToPlayMillis": -1,"wins": 1},"isVeteran": false,"tier": "DIAMOND","lastPlayed": -1,"playerOrTeamId": "19046003","leaguePoints": 100,"rank": "IV","isInactive": false,"queueType": "RANKED_SOLO_5x5","playerOrTeamName": "Taishi Masamune","wins": 55}') + @le = LeagueItem.new(json_mockup) + end + + describe "#new" do + it "should initialize a LeagueItem" do + @le.should be_an_instance_of LeagueItem + end + + it "should initiliaze with correct params" do + @le.isHotStreak.should satisfy {|s| [true, false].include? s} + @le.isFreshBlood.should satisfy {|s| [true, false].include? s} + @le.isVeteran.should satisfy {|s| [true, false].include? s} + @le.isInactive.should satisfy {|s| [true, false].include? s} + @le.leagueName.should be_a_kind_of String + @le.tier.should be_a_kind_of String + @le.lastPlayed.should be_a_kind_of Fixnum + @le.playerOrTeamId.should be_a_kind_of String + @le.leaguePoints.should be_a_kind_of Fixnum + @le.rank.should be_a_kind_of String + @le.queueType.should be_a_kind_of String + @le.playerOrTeamName.should be_a_kind_of String + @le.wins.should be_a_kind_of Fixnum + @le.miniSeries.should be_an_instance_of MiniSeries + end + end +end + +describe MiniSeries do + before :all do + json_mockup = JSON.parse('{"progress": "WNN","target": 2,"losses": 0,"timeLeftToPlayMillis": -1,"wins": 1}') + @ms = MiniSeries.new(json_mockup) + end + + describe "#new" do + it "should initilaize a miniSeries object" do + @ms.should be_an_instance_of MiniSeries + end + + it "should initialize with correct params" do + @ms.progress.should be_a_kind_of String + @ms.target.should be_a_kind_of Fixnum + @ms.losses.should be_a_kind_of Fixnum + @ms.wins.should be_a_kind_of Fixnum + @ms.timeLeftToPlayMillis.should be_a_kind_of Fixnum + end + end +end +end \ No newline at end of file diff --git a/spec/ranked_stats_spec.rb b/spec/ranked_stats_spec.rb index 54475a2..7667a83 100644 --- a/spec/ranked_stats_spec.rb +++ b/spec/ranked_stats_spec.rb @@ -1,38 +1,68 @@ require 'spec_helper' +require 'json' module Sightstone describe RankedStats do - before :each do - stats = [{"id" => 1, "stats"=> {"Stat1" => 1, "Stat2" => 2}}, {"id" => 2, "stats"=> {"Stat1" => 1, "Stat2" => 2}}] - @rs = RankedStats.new({"summonerId" => 1, "modifyDate" => 1, "champions" => stats }) - end - - it "should have a summoner id" do - @rs.summonerId.should eql 1 - end - - it "should have a modification date" do - @rs.modifyDate.should eql 1 - end - - it "should have an array of champion stats" do - @rs.champions.should be_an_instance_of Hash - @rs.champions.should have(2).items - @rs.champions.each do |key, hash| - key.should be_a_kind_of Fixnum - hash.should be_an_instance_of Hash - hash.each do |stat, value| - stat.should be_an_instance_of String - value.should be_a_kind_of Fixnum - end - end + before :all do + response_mockup = JSON.parse('{"modifyDate": 1395302832000,"champions": [{"id": 32,"stats": {"totalDeathsPerSession": 9,"totalSessionsPlayed": 2,"totalDamageTaken": 61928,"totalQuadraKills": 0, + "totalTripleKills": 0,"totalMinionKills": 123,"maxChampionsKilled": 5,"totalDoubleKills": 0,"totalPhysicalDamageDealt": 46675,"totalChampionKills": 6,"totalAssists": 14, + "mostChampionKillsPerSession": 5,"totalDamageDealt": 321647,"totalFirstBlood": 0,"totalSessionsLost": 2,"totalSessionsWon": 0,"totalMagicDamageDealt": 235049, + "totalGoldEarned": 20974,"totalPentaKills": 0,"totalTurretsKilled": 0,"mostSpellsCast": 0,"maxNumDeaths": 6,"totalUnrealKills": 0},"name": "Amumu"}, + {"id": 1,"stats": {"totalDeathsPerSession": 62,"totalSessionsPlayed": 10,"totalDamageTaken": 143058,"totalQuadraKills": 0,"totalTripleKills": 0, + "totalMinionKills": 482,"maxChampionsKilled": 6,"totalDoubleKills": 1,"totalPhysicalDamageDealt": 59834,"totalChampionKills": 23,"totalAssists": 88, + "mostChampionKillsPerSession": 6,"totalDamageDealt": 432245,"totalFirstBlood": 0,"totalSessionsLost": 7,"totalSessionsWon": 3,"totalMagicDamageDealt": 370212, + "totalGoldEarned": 84267,"totalPentaKills": 0,"totalTurretsKilled": 3,"mostSpellsCast": 0,"maxNumDeaths": 11,"totalUnrealKills": 0},"name": "Annie"}, + {"id": 0,"stats": {"totalDamageTaken": 3097057,"totalTripleKills": 8,"totalMinionKills": 10853,"maxChampionsKilled": 17, + "maxLargestCriticalStrike": 1121,"totalChampionKills": 690,"totalPhysicalDamageDealt": 6284046, + "rankedPremadeGamesPlayed": 0,"totalSessionsLost": 68,"totalNeutralMinionsKilled": 4342, + "totalSessionsWon": 63,"totalMagicDamageDealt": 6696776,"maxLargestKillingSpree": 8,"totalPentaKills": 0, + "maxTimeSpentLiving": 1731,"totalDeathsPerSession": 701,"totalQuadraKills": 1,"totalSessionsPlayed": 131, + "totalDoubleKills": 49,"totalAssists": 1157,"maxTimePlayed": 3158,"mostChampionKillsPerSession": 17, + "totalDamageDealt": 13820857,"botGamesPlayed": 0,"killingSpree": 320,"totalFirstBlood": 0,"rankedSoloGamesPlayed": 0, + "totalHeal": 800579,"totalGoldEarned": 1423092,"mostSpellsCast": 0,"totalTurretsKilled": 99,"maxNumDeaths": 11, + "totalUnrealKills": 0,"normalGamesPlayed": 0},"name": "Combined"}],"summonerId": 12345}') + @rs = RankedStats.new(response_mockup) end describe "#new" do it "should create a ranked stats obejct" do @rs.should be_an_instance_of RankedStats end + + it "should have a modification date" do + @rs.modifyDate.should be_a_kind_of Fixnum + end + + it "should have a summoner id" do + @rs.summonerId.should be_a_kind_of Fixnum + end + end + + describe "#champions" do + it "should have combined statsitics" do + @rs.champions[0].should be_an_instance_of Hash + end + + it "should have some champion dependent statistic" do + @rs.champions.should be_a_kind_of Hash + @rs.champions.should have_at_least(1).items + @rs.champions[32].should be_a_kind_of Hash + end + end + + describe "#get_statistics_by_name" do + it "should return combined stats for attr 'Combined'" do + @rs.get_statistics_by_name('Combined').should eql @rs.champions[0] + end + + it "should return champions statistics for champion name" do + @rs.get_statistics_by_name("Annie").should eql @rs.champions[1] + end + + it "should return nil if champion name is not in the stats" do + @rs.get_statistics_by_name("asdf").should be_nil + end end end diff --git a/spec/summoner_spec.rb b/spec/summoner_spec.rb new file mode 100644 index 0000000..d3ce3fe --- /dev/null +++ b/spec/summoner_spec.rb @@ -0,0 +1,30 @@ +require 'spec_helper' +require 'json' + + +module Sightstone + + describe Summoner do + + before :all do + response_mockup = JSON.parse('{"id": 5908,"name": "Dyrus","profileIconId": 627,"revisionDate": 1395525467000,"summonerLevel": 30}') + @sum = Summoner.new(response_mockup) + end + + describe "#new" do + it "should initialize a summoner object" do + @sum.should be_an_instance_of Summoner + end + + it "should initialize with correct params" do + @sum.id.should be_a_kind_of Fixnum + @sum.name.should be_a_kind_of String + @sum.profileIconId.should be_a_kind_of Fixnum + @sum.revisionDate.should be_a_kind_of Fixnum + @sum.level.should be_a_kind_of Fixnum + end + end + + end + +end \ No newline at end of file