3 Commits

Author SHA1 Message Date
danijoo
69af727471 added summoner module rspec 2014-03-26 10:54:53 +01:00
danijoo
844751077f summoner module now uses https 2014-03-26 10:38:34 +01:00
danijoo
6bb801ec3a game module rspec 2014-03-26 10:03:55 +01:00
12 changed files with 326 additions and 5 deletions

View File

@@ -75,7 +75,7 @@ class SummonerModule < SightstoneBaseModule
def names(ids, optional={}) def names(ids, optional={})
region = optional[:region] || @sightstone.region region = optional[:region] || @sightstone.region
ids = ids.join(',') ids = ids.join(',')
uri = "http://prod.api.pvp.net/api/lol/#{region}/v1.3/summoner/#{ids}/name" uri = "https://prod.api.pvp.net/api/lol/#{region}/v1.3/summoner/#{ids}/name"
response = _get_api_response(uri) response = _get_api_response(uri)
_parse_response(response) { |resp| _parse_response(response) { |resp|
data = JSON.parse(resp) data = JSON.parse(resp)
@@ -103,7 +103,7 @@ class SummonerModule < SightstoneBaseModule
else else
summoner summoner
end end
uri = "http://prod.api.pvp.net/api/lol/#{region}/v1.3/summoner/#{id}/runes" uri = "https://prod.api.pvp.net/api/lol/#{region}/v1.3/summoner/#{id}/runes"
response = _get_api_response(uri) response = _get_api_response(uri)
_parse_response(response) { |resp| _parse_response(response) { |resp|
data = JSON.parse(resp) data = JSON.parse(resp)
@@ -131,7 +131,7 @@ class SummonerModule < SightstoneBaseModule
summoner summoner
end end
} }
uri = "http://prod.api.pvp.net/api/lol/#{region}/v1.3/summoner/#{ids.join(',')}/runes" uri = "https://prod.api.pvp.net/api/lol/#{region}/v1.3/summoner/#{ids.join(',')}/runes"
response = _get_api_response(uri) response = _get_api_response(uri)
_parse_response(response) { |resp| _parse_response(response) { |resp|
data = JSON.parse(resp) data = JSON.parse(resp)
@@ -158,7 +158,7 @@ class SummonerModule < SightstoneBaseModule
else else
summoner summoner
end end
uri = "http://prod.api.pvp.net/api/lol/#{region}/v1.3/summoner/#{id}/masteries" uri = "https://prod.api.pvp.net/api/lol/#{region}/v1.3/summoner/#{id}/masteries"
response = _get_api_response(uri) response = _get_api_response(uri)
_parse_response(response) { |resp| _parse_response(response) { |resp|
data = JSON.parse(resp) data = JSON.parse(resp)
@@ -186,7 +186,7 @@ class SummonerModule < SightstoneBaseModule
end end
} }
uri = "http://prod.api.pvp.net/api/lol/#{region}/v1.3/summoner/#{ids.join(',')}/masteries" uri = "https://prod.api.pvp.net/api/lol/#{region}/v1.3/summoner/#{ids.join(',')}/masteries"
response = _get_api_response(uri) response = _get_api_response(uri)
_parse_response(response) { |resp| _parse_response(response) { |resp|
data = JSON.parse(resp) data = JSON.parse(resp)

View File

@@ -0,0 +1,56 @@
require 'spec_helper'
module Sightstone
describe GameModule do
before :each do
@module = GameModule.new(Sightstone.new("api_key", "euw"))
end
describe "#new" do
it "should initialize a GameModule" do
@module.should be_instance_of GameModule
end
end
describe "#recent" do
before :each do
raw_response = File.new("spec/modules/raw_responses/game_v1.3_euw.response")
stub_request(:get, "https://prod.api.pvp.net/api/lol/euw/v1.3/game/by-summoner/summoner_id/recent?api_key=api_key").
with(:headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate', 'User-Agent'=>'Ruby'}).
to_return(raw_response)
end
it "should return a list of recent games for the default region" do
history = @module.recent("summoner_id")
history.should be_instance_of MatchHistory
end
it "should return a recent games for given region" do
@module.instance_variable_set("@sightstone", Sightstone.new("api_key", "na"))
history = @module.recent("summoner_id", {region: "euw"})
history.should be_instance_of MatchHistory
end
it "should evaluate codeblocks" do
games = []
@module.recent("summoner_id") do |history|
games = history.games
end
games.each do |game|
game.should be_instance_of HistoryGame
end
end
end
end
end

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,12 @@
HTTP/1.1 200 OK
Access-Control-Allow-Headers: Content-Type
Access-Control-Allow-Methods: GET, POST, DELETE, PUT
Access-Control-Allow-Origin: *
Content-Type: application/json; charset=UTF-8
Date: Wed, 26 Mar 2014 09:49:05 GMT
Server: Jetty(9.1.1.v20140108)
Vary: Accept-Encoding, User-Agent
Content-Length: 41
Connection: keep-alive
{"30492244":"Pippu","30447079":"danijoo"}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,12 @@
HTTP/1.1 200 OK
Access-Control-Allow-Headers: Content-Type
Access-Control-Allow-Methods: GET, POST, DELETE, PUT
Access-Control-Allow-Origin: *
Content-Type: application/json; charset=UTF-8
Date: Wed, 26 Mar 2014 09:50:46 GMT
Server: Jetty(9.1.1.v20140108)
Vary: Accept-Encoding, User-Agent
Content-Length: 112
Connection: keep-alive
{"danijoo":{"id":30447079,"name":"danijoo","profileIconId":551,"summonerLevel":30,"revisionDate":1395768855000}}

View File

@@ -0,0 +1,12 @@
HTTP/1.1 200 OK
Access-Control-Allow-Headers: Content-Type
Access-Control-Allow-Methods: GET, POST, DELETE, PUT
Access-Control-Allow-Origin: *
Content-Type: application/json; charset=UTF-8
Date: Wed, 26 Mar 2014 09:53:17 GMT
Server: Jetty(9.1.1.v20140108)
Vary: Accept-Encoding, User-Agent
Content-Length: 233
Connection: keep-alive
{"danijoo":{"id":30447079,"name":"danijoo","profileIconId":551,"summonerLevel":30,"revisionDate":1395768855000},"ismirknuelle":{"id":22151489,"name":"ismirknuelle","profileIconId":583,"summonerLevel":30,"revisionDate":1395768855000}}

View File

@@ -0,0 +1,169 @@
require 'spec_helper'
module Sightstone
describe SummonerModule do
before :each do
@module = SummonerModule.new(Sightstone.new("api_key", "euw"))
end
describe "#new" do
it "should initialize a SummonerModule" do
@module.should be_instance_of SummonerModule
end
end
describe "#masterybook" do
before :each do
raw_response = File.new("spec/modules/raw_responses/summoner_v1.3_masterybook.response")
stub_request(:get, "https://prod.api.pvp.net/api/lol/euw/v1.3/summoner/summoner_id/masteries?api_key=api_key").
with(:headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate', 'User-Agent'=>'Ruby'}).
to_return(raw_response)
end
it "should return a mastery book" do
@module.masterybook("summoner_id").should be_instance_of MasteryBook
end
it "should evaluate the codeblock" do
@module.masterybook("summoner_id") { |book|
book.should be_instance_of MasteryBook
}
end
end
describe "#masterybooks" do
before :each do
raw_response = File.new("spec/modules/raw_responses/summoner_v1.3_masterybooks.response")
stub_request(:get, "https://prod.api.pvp.net/api/lol/euw/v1.3/summoner/summonerid1,summonerid2/masteries?api_key=api_key").
with(:headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate', 'User-Agent'=>'Ruby'}).
to_return(raw_response)
end
it "should return the books of 2 summoners" do
books = @module.masterybooks(["summonerid1","summonerid2"])
books.should be_instance_of Hash
books.each do |key, book|
book.should be_instance_of MasteryBook
end
end
it "should evaluate the codeblock" do
@module.masterybooks(["summonerid1", "summonerid2"]) { |books|
books.each do |key, book|
book.should be_instance_of MasteryBook
end
}
end
end
describe "#names" do
before :each do
raw_response = File.new("spec/modules/raw_responses/summoner_v1.3_names.response")
stub_request(:get, "https://prod.api.pvp.net/api/lol/euw/v1.3/summoner/1,2,3/name?api_key=api_key").
with(:headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate', 'User-Agent'=>'Ruby'}).
to_return(raw_response)
end
it "should return a list of names" do
@module.names([1,2,3]).should be_instance_of Hash
@module.names([1,2,3]) { |names|
names.each do |id, name|
id.should be_instance_of Fixnum
name.should be_instance_of String
end
}
end
end
describe "#runebook" do
before :each do
raw_response = File.new("spec/modules/raw_responses/summoner_v1.3_runebook.response")
stub_request(:get, "https://prod.api.pvp.net/api/lol/euw/v1.3/summoner/summoner_id/runes?api_key=api_key").
with(:headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate', 'User-Agent'=>'Ruby'}).
to_return(raw_response)
end
it "should return a rune book" do
@module.runebook("summoner_id").should be_instance_of RuneBook
end
it "should evaluate the codeblock" do
@module.runebook("summoner_id") { |book|
book.should be_instance_of RuneBook
}
end
end
describe "#runebooks" do
before :each do
raw_response = File.new("spec/modules/raw_responses/summoner_v1.3_runebooks.response")
stub_request(:get, "https://prod.api.pvp.net/api/lol/euw/v1.3/summoner/summonerid1,summonerid2/runes?api_key=api_key").
with(:headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate', 'User-Agent'=>'Ruby'}).
to_return(raw_response)
end
it "should return the books of 2 summoners" do
books = @module.runebooks(["summonerid1", "summonerid2"])
books.should be_instance_of Hash
books.each do |key, book|
book.should be_instance_of RuneBook
end
end
it "should evaluate the codeblock" do
@module.runebooks(["summonerid1", "summonerid2"]) { |books|
books.each do |key, book|
book.should be_instance_of RuneBook
end
}
end
end
describe "#summoner" do
before :each do
raw_response = File.new("spec/modules/raw_responses/summoner_v1.3_summoner.response").read
stub_request(:get, "https://prod.api.pvp.net/api/lol/euw/v1.3/summoner/by-name/name?api_key=api_key").
with(:headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate', 'User-Agent'=>'Ruby'}).
to_return(raw_response)
stub_request(:get, "https://prod.api.pvp.net/api/lol/euw/v1.3/summoner/1?api_key=api_key").
with(:headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate', 'User-Agent'=>'Ruby'}).
to_return(raw_response)
end
it "should return a summoner by name" do
@module.summoner("name").should be_instance_of Summoner
end
it "should return a summoner by id" do
@module.summoner(1).should be_instance_of Summoner
end
end
describe "#summoners" do
before :each do
raw_response = File.new("spec/modules/raw_responses/summoner_v1.3_summoners.response")
stub_request(:get, "https://prod.api.pvp.net/api/lol/euw/v1.3/summoner/by-name/name1,name2?api_key=api_key").
with(:headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate', 'User-Agent'=>'Ruby'}).
to_return(raw_response)
end
it "should return multiple summoners" do
@summoners = @module.summoners(['name1', 'name2'])
@summoners.should be_instance_of Hash
@summoners.each do |key, value|
key.should satisfy {|key| (key.is_a? Fixnum or key.is_a? String) }
value.should be_instance_of Summoner
end
end
end
end
end