dotka 1.2.1 → 1.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/dotka.rb +23 -7
- data/lib/dotka/game_mode.rb +5 -0
- data/lib/dotka/hero.rb +7 -1
- data/lib/dotka/item.rb +6 -0
- data/lib/dotka/lobby.rb +5 -0
- data/lib/dotka/match.rb +20 -4
- data/lib/dotka/player.rb +23 -0
- data/lib/dotka/raw.rb +5 -0
- data/lib/dotka/region.rb +5 -0
- data/lib/dotka/skill.rb +7 -0
- data/lib/dotka/storage.rb +13 -1
- data/spec/dotka_spec.rb +16 -1
- data/spec/game_mode_spec.rb +4 -0
- data/spec/hero_spec.rb +4 -0
- data/spec/item_spec.rb +4 -0
- data/spec/lobby_spec.rb +4 -0
- data/spec/match_spec.rb +10 -1
- data/spec/player_spec.rb +5 -1
- data/spec/region_spec.rb +5 -1
- data/spec/storage_spec.rb +9 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6d435bee22f3983f8dc0165ccf5b8d0cea8bbcf4
|
4
|
+
data.tar.gz: 06279f5006934dcb4bff9b686a7be8879012d43b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9edf1b950ccd2a6b4c0f49fa1a7378d466d8f3c449ba4a1932704424792861a43bc6511a483b392759eb90dba111ba39cd64489c6de703592ef00e9f39425f57
|
7
|
+
data.tar.gz: 722d92f77816abf246b5fafd2af1452330af7b6c4d956e1aed8637a82641bfd8001e3860755f0402727095fd780e7fef61fc5b5e27c426aade0032b6892e463c
|
data/lib/dotka.rb
CHANGED
@@ -1,45 +1,61 @@
|
|
1
|
-
require "rest-client"
|
2
1
|
require_relative "dotka/match"
|
2
|
+
|
3
|
+
require "rest-client"
|
3
4
|
require "json"
|
4
5
|
|
5
|
-
class Dotka
|
6
|
+
class Dotka
|
7
|
+
|
6
8
|
def initialize
|
7
9
|
@key = nil
|
8
10
|
end
|
11
|
+
|
9
12
|
def set_api_key key
|
10
13
|
@key = key
|
11
14
|
end
|
15
|
+
|
12
16
|
def get_api_key
|
13
17
|
@key
|
14
18
|
end
|
19
|
+
|
15
20
|
def match id
|
21
|
+
|
16
22
|
raise "Please set up the API key!" unless not @key.nil?
|
23
|
+
|
17
24
|
response = RestClient.get(
|
18
25
|
"https://api.steampowered.com/IDOTA2Match_570/GetMatchDetails/V001",
|
19
26
|
{"params" => {"key" => @key, "match_id" => id}}
|
20
27
|
)
|
28
|
+
|
21
29
|
raise "Can not load a match with ID #{id}." unless response.code == 200
|
30
|
+
|
22
31
|
DotkaM::Match.new(JSON.parse(response.to_str)["result"])
|
32
|
+
|
23
33
|
end
|
34
|
+
|
24
35
|
def matches account_id, conditions = {}
|
36
|
+
|
25
37
|
raise "Please set up the API key!" unless not @key.nil?
|
38
|
+
|
26
39
|
response = RestClient.get(
|
27
40
|
"https://api.steampowered.com/IDOTA2Match_570/GetMatchHistory/V001",
|
28
|
-
{
|
29
|
-
"params" => {"key" => @key, "account_id" => account_id}.merge(conditions)
|
30
|
-
}
|
41
|
+
{"params" => {"key" => @key, "account_id" => account_id}.merge(conditions)}
|
31
42
|
)
|
43
|
+
|
32
44
|
raise "Can not load matches for account ID #{account_id}." unless response.code == 200
|
45
|
+
|
33
46
|
matches = Array.new
|
47
|
+
|
34
48
|
JSON.parse(response.to_str)["result"]["matches"].each { |match|
|
35
49
|
matches.push DotkaM::Match.new(match)
|
36
|
-
}
|
50
|
+
}
|
51
|
+
|
37
52
|
matches
|
53
|
+
|
38
54
|
end
|
39
55
|
|
40
56
|
# Rather than updating the gemspec every time.
|
41
57
|
def self.version
|
42
|
-
"1.2.
|
58
|
+
"1.2.2"
|
43
59
|
end
|
44
60
|
|
45
61
|
end
|
data/lib/dotka/game_mode.rb
CHANGED
data/lib/dotka/hero.rb
CHANGED
data/lib/dotka/item.rb
CHANGED
data/lib/dotka/lobby.rb
CHANGED
data/lib/dotka/match.rb
CHANGED
@@ -7,44 +7,60 @@ require_relative "storage"
|
|
7
7
|
require_relative "../dotka"
|
8
8
|
|
9
9
|
module DotkaM
|
10
|
+
|
10
11
|
class Match < Raw
|
12
|
+
|
11
13
|
def id
|
12
14
|
@raw["match_id"].to_i
|
13
15
|
end
|
16
|
+
|
14
17
|
def players
|
18
|
+
|
15
19
|
players = Array.new
|
16
|
-
|
17
|
-
|
18
|
-
|
20
|
+
|
21
|
+
@raw["players"].each { |player| players.push Player.new(player) }
|
22
|
+
|
19
23
|
players
|
24
|
+
|
20
25
|
end
|
26
|
+
|
21
27
|
def player account_id
|
22
28
|
players.select { |player| player.account_id == account_id.to_i }.first
|
23
29
|
end
|
30
|
+
|
24
31
|
def winner
|
25
32
|
(!! @raw["radiant_win"]) ? "radiant" : "dire"
|
26
33
|
end
|
34
|
+
|
27
35
|
def duration
|
28
36
|
@raw["duration"].to_i
|
29
37
|
end
|
38
|
+
|
30
39
|
def start_time
|
31
40
|
@raw["start_time"].to_i
|
32
41
|
end
|
42
|
+
|
33
43
|
def lobby
|
34
44
|
Lobby.new Storage.new.get("lobbies", {"id" => @raw["lobby_type"]})
|
35
45
|
end
|
46
|
+
|
36
47
|
def game_mode
|
37
48
|
GameMode.new Storage.new.get("game_modes", {"id" => @raw["game_mode"]})
|
38
49
|
end
|
50
|
+
|
39
51
|
def region
|
40
52
|
Region.new Storage.new.get("regions", {"id" => @raw["cluster"]})
|
41
53
|
end
|
42
54
|
|
43
|
-
# API limitation workaround
|
55
|
+
# API limitation workaround.
|
44
56
|
def load_info dotka
|
57
|
+
|
45
58
|
raise "Expected an instance of Dotka." unless dotka.is_a? Dotka
|
59
|
+
|
46
60
|
@raw = dotka.match(self.id).raw
|
61
|
+
|
47
62
|
end
|
48
63
|
|
49
64
|
end
|
65
|
+
|
50
66
|
end
|
data/lib/dotka/player.rb
CHANGED
@@ -4,15 +4,21 @@ require_relative "hero"
|
|
4
4
|
require_relative "item"
|
5
5
|
|
6
6
|
module DotkaM
|
7
|
+
|
7
8
|
class Player < Raw
|
9
|
+
|
8
10
|
def account_id
|
9
11
|
@raw["account_id"].to_i
|
10
12
|
end
|
13
|
+
|
11
14
|
def hero
|
12
15
|
Hero.new Storage.new.get("heroes", {"id" => @raw["hero_id"]})
|
13
16
|
end
|
17
|
+
|
14
18
|
def items
|
19
|
+
|
15
20
|
storage = Storage.new
|
21
|
+
|
16
22
|
[
|
17
23
|
Item.new(storage.get "items", {"id" => @raw["item_0"]}),
|
18
24
|
Item.new(storage.get "items", {"id" => @raw["item_1"]}),
|
@@ -21,48 +27,65 @@ module DotkaM
|
|
21
27
|
Item.new(storage.get "items", {"id" => @raw["item_4"]}),
|
22
28
|
Item.new(storage.get "items", {"id" => @raw["item_5"]})
|
23
29
|
]
|
30
|
+
|
24
31
|
end
|
32
|
+
|
25
33
|
def kills
|
26
34
|
@raw["kills"].to_i
|
27
35
|
end
|
36
|
+
|
28
37
|
def deaths
|
29
38
|
@raw["deaths"].to_i
|
30
39
|
end
|
40
|
+
|
31
41
|
def assists
|
32
42
|
@raw["assists"].to_i
|
33
43
|
end
|
44
|
+
|
34
45
|
def abandoned?
|
35
46
|
@raw["leaver_status"].to_i == 1
|
36
47
|
end
|
48
|
+
|
37
49
|
def team
|
38
50
|
@raw["player_slot"].to_i > 4 ? "dire" : "radiant"
|
39
51
|
end
|
52
|
+
|
40
53
|
def gold
|
41
54
|
@raw["gold"].to_i + @raw["gold_spent"].to_i
|
42
55
|
end
|
56
|
+
|
43
57
|
def last_hits
|
44
58
|
@raw["last_hits"].to_i
|
45
59
|
end
|
60
|
+
|
46
61
|
def denies
|
47
62
|
@raw["denies"].to_i
|
48
63
|
end
|
64
|
+
|
49
65
|
def gold_per_min
|
50
66
|
@raw["gold_per_min"].to_i
|
51
67
|
end
|
68
|
+
|
52
69
|
def xp_per_min
|
53
70
|
@raw["xp_per_min"].to_i
|
54
71
|
end
|
72
|
+
|
55
73
|
def hero_dmg
|
56
74
|
@raw["hero_damage"].to_i
|
57
75
|
end
|
76
|
+
|
58
77
|
def tower_dmg
|
59
78
|
@raw["tower_damage"].to_i
|
60
79
|
end
|
80
|
+
|
61
81
|
def hero_heal
|
62
82
|
@raw["hero_healing"].to_i
|
63
83
|
end
|
84
|
+
|
64
85
|
def level
|
65
86
|
@raw["level"].to_i
|
66
87
|
end
|
88
|
+
|
67
89
|
end
|
90
|
+
|
68
91
|
end
|
data/lib/dotka/raw.rb
CHANGED
data/lib/dotka/region.rb
CHANGED
data/lib/dotka/skill.rb
CHANGED
data/lib/dotka/storage.rb
CHANGED
@@ -1,21 +1,33 @@
|
|
1
1
|
require "json"
|
2
2
|
|
3
3
|
module DotkaM
|
4
|
+
|
4
5
|
class Storage
|
6
|
+
|
5
7
|
def get file, conditions = {}
|
8
|
+
|
6
9
|
rows = JSON.parse File.read("#{__dir__}/../../data/#{file}.json")
|
10
|
+
|
7
11
|
if not conditions.empty?
|
12
|
+
|
8
13
|
rows.select! { |row|
|
9
14
|
selected = true
|
15
|
+
|
10
16
|
conditions.each { |key, value|
|
11
17
|
if not (row.has_key? key) or not (row[key] == value.to_s)
|
12
18
|
selected = false
|
13
19
|
end
|
14
20
|
}
|
21
|
+
|
15
22
|
selected
|
16
|
-
}
|
23
|
+
}
|
24
|
+
|
17
25
|
end
|
26
|
+
|
18
27
|
rows.length == 1 ? rows.first : rows
|
28
|
+
|
19
29
|
end
|
30
|
+
|
20
31
|
end
|
32
|
+
|
21
33
|
end
|
data/spec/dotka_spec.rb
CHANGED
@@ -1,40 +1,55 @@
|
|
1
1
|
require_relative "../lib/dotka"
|
2
2
|
require_relative "../lib/dotka/match"
|
3
|
+
|
3
4
|
require "rest-client"
|
4
5
|
|
5
6
|
RSpec.describe Dotka do
|
6
7
|
|
7
8
|
before :all do
|
9
|
+
|
8
10
|
@dotka = Dotka.new
|
11
|
+
|
9
12
|
end
|
10
13
|
|
11
14
|
it "sets the API key" do
|
15
|
+
|
12
16
|
@dotka.set_api_key "some-key"
|
17
|
+
|
13
18
|
expect(@dotka.get_api_key).to eq("some-key")
|
19
|
+
|
14
20
|
end
|
15
21
|
|
16
22
|
it "loads a match" do
|
23
|
+
|
17
24
|
allow(RestClient).to receive("get") {
|
18
25
|
FakeResponse.new(200, '{"result": {"match_id": 123456789}}')
|
19
26
|
}
|
27
|
+
|
20
28
|
expect(match = @dotka.match(123456789)).to be_instance_of(DotkaM::Match)
|
21
29
|
expect(match.id).to eq(123456789)
|
30
|
+
|
22
31
|
end
|
23
32
|
|
24
33
|
it "loads a list of matches" do
|
34
|
+
|
25
35
|
allow(RestClient).to receive("get") {
|
26
36
|
FakeResponse.new(200, '{"result": {"matches": [{"match_id": 123456789}]}}')
|
27
37
|
}
|
38
|
+
|
28
39
|
expect(matches = @dotka.matches(987654321)).to be_an(Array)
|
29
40
|
expect(matches.length).to eq(1)
|
30
41
|
expect(matches.first.id).to eq(123456789)
|
42
|
+
|
31
43
|
end
|
32
44
|
|
33
45
|
end
|
34
46
|
|
35
47
|
class FakeResponse
|
36
|
-
|
48
|
+
|
49
|
+
attr_reader "code", "to_str"
|
50
|
+
|
37
51
|
def initialize code, body
|
38
52
|
@code, @to_str = code, body
|
39
53
|
end
|
54
|
+
|
40
55
|
end
|
data/spec/game_mode_spec.rb
CHANGED
@@ -3,15 +3,19 @@ require_relative "../lib/dotka/game_mode"
|
|
3
3
|
RSpec.describe DotkaM::GameMode do
|
4
4
|
|
5
5
|
before :all do
|
6
|
+
|
6
7
|
@game_mode = DotkaM::GameMode.new({
|
7
8
|
"id" => "1",
|
8
9
|
"name" => "All Pick"
|
9
10
|
})
|
11
|
+
|
10
12
|
end
|
11
13
|
|
12
14
|
it "provides data getters" do
|
15
|
+
|
13
16
|
expect(@game_mode.id).to eq(1)
|
14
17
|
expect(@game_mode.localized_name).to eq("All Pick")
|
18
|
+
|
15
19
|
end
|
16
20
|
|
17
21
|
end
|
data/spec/hero_spec.rb
CHANGED
@@ -3,17 +3,21 @@ require_relative "../lib/dotka/hero"
|
|
3
3
|
RSpec.describe DotkaM::Hero do
|
4
4
|
|
5
5
|
before :all do
|
6
|
+
|
6
7
|
@hero = DotkaM::Hero.new({
|
7
8
|
"id" => "1",
|
8
9
|
"name" => "antimage",
|
9
10
|
"localized_name" => "Anti-Mage"
|
10
11
|
})
|
12
|
+
|
11
13
|
end
|
12
14
|
|
13
15
|
it "provides data getters" do
|
16
|
+
|
14
17
|
expect(@hero.id).to eq(1)
|
15
18
|
expect(@hero.name).to eq("antimage")
|
16
19
|
expect(@hero.localized_name).to eq("Anti-Mage")
|
20
|
+
|
17
21
|
end
|
18
22
|
|
19
23
|
end
|
data/spec/item_spec.rb
CHANGED
@@ -3,17 +3,21 @@ require_relative "../lib/dotka/item"
|
|
3
3
|
RSpec.describe DotkaM::Item do
|
4
4
|
|
5
5
|
before :all do
|
6
|
+
|
6
7
|
@item = DotkaM::Item.new({
|
7
8
|
"id" => "1",
|
8
9
|
"name" => "blink",
|
9
10
|
"localized_name" => "Blink Dagger"
|
10
11
|
})
|
12
|
+
|
11
13
|
end
|
12
14
|
|
13
15
|
it "provides data getters" do
|
16
|
+
|
14
17
|
expect(@item.id).to eq(1)
|
15
18
|
expect(@item.name).to eq("blink")
|
16
19
|
expect(@item.localized_name).to eq("Blink Dagger")
|
20
|
+
|
17
21
|
end
|
18
22
|
|
19
23
|
end
|
data/spec/lobby_spec.rb
CHANGED
@@ -3,15 +3,19 @@ require_relative "../lib/dotka/lobby"
|
|
3
3
|
RSpec.describe DotkaM::Lobby do
|
4
4
|
|
5
5
|
before :all do
|
6
|
+
|
6
7
|
@lobby = DotkaM::Lobby.new({
|
7
8
|
"id" => "0",
|
8
9
|
"name" => "Public matchmaking"
|
9
10
|
})
|
11
|
+
|
10
12
|
end
|
11
13
|
|
12
14
|
it "provides data getters" do
|
15
|
+
|
13
16
|
expect(@lobby.id).to eq(0)
|
14
17
|
expect(@lobby.localized_name).to eq("Public matchmaking")
|
18
|
+
|
15
19
|
end
|
16
20
|
|
17
21
|
end
|
data/spec/match_spec.rb
CHANGED
@@ -4,6 +4,7 @@ require_relative "../lib/dotka"
|
|
4
4
|
RSpec.describe DotkaM::Match do
|
5
5
|
|
6
6
|
before :all do
|
7
|
+
|
7
8
|
@match = DotkaM::Match.new({
|
8
9
|
"match_id" => "123456789",
|
9
10
|
"players" => [
|
@@ -16,9 +17,11 @@ RSpec.describe DotkaM::Match do
|
|
16
17
|
"game_mode" => "1",
|
17
18
|
"cluster" => "111"
|
18
19
|
})
|
20
|
+
|
19
21
|
end
|
20
22
|
|
21
23
|
it "provides data getters" do
|
24
|
+
|
22
25
|
expect(@match.id).to eq(123456789)
|
23
26
|
expect(@match.players.first.account_id).to eq(1)
|
24
27
|
expect(@match.player(1).account_id).to eq(1)
|
@@ -27,16 +30,22 @@ RSpec.describe DotkaM::Match do
|
|
27
30
|
expect(@match.start_time).to eq(123456789)
|
28
31
|
expect(@match.lobby.localized_name).to eq("Public matchmaking")
|
29
32
|
expect(@match.game_mode.localized_name).to eq("All Pick")
|
30
|
-
expect(@match.region.localized_name).to eq("US West")
|
33
|
+
expect(@match.region.localized_name).to eq("US West")
|
34
|
+
|
31
35
|
end
|
32
36
|
|
33
37
|
it "provides an API limitation workaround" do
|
38
|
+
|
34
39
|
dotka = Dotka.new
|
40
|
+
|
35
41
|
allow(dotka).to receive("match")
|
36
42
|
.with(123456789)
|
37
43
|
.and_return DotkaM::Match.new({"players" => [{"account_id" => 1234}]})
|
44
|
+
|
38
45
|
@match.load_info dotka
|
46
|
+
|
39
47
|
expect(@match.players.first.account_id).to eq(1234)
|
48
|
+
|
40
49
|
end
|
41
50
|
|
42
51
|
end
|
data/spec/player_spec.rb
CHANGED
@@ -3,6 +3,7 @@ require_relative "../lib/dotka/player"
|
|
3
3
|
RSpec.describe DotkaM::Player do
|
4
4
|
|
5
5
|
before :all do
|
6
|
+
|
6
7
|
@player = DotkaM::Player.new({
|
7
8
|
"account_id" => "123456789",
|
8
9
|
"hero_id" => "1",
|
@@ -27,10 +28,12 @@ RSpec.describe DotkaM::Player do
|
|
27
28
|
"tower_damage" => "1000",
|
28
29
|
"hero_healing" => "3000",
|
29
30
|
"level" => "25"
|
30
|
-
})
|
31
|
+
})
|
32
|
+
|
31
33
|
end
|
32
34
|
|
33
35
|
it "provides data getters" do
|
36
|
+
|
34
37
|
expect(@player.account_id).to eq(123456789)
|
35
38
|
expect(@player.hero.localized_name).to eq("Anti-Mage")
|
36
39
|
expect(@player.items.first.localized_name).to eq("Blink Dagger")
|
@@ -48,6 +51,7 @@ RSpec.describe DotkaM::Player do
|
|
48
51
|
expect(@player.tower_dmg).to eq(1000)
|
49
52
|
expect(@player.hero_heal).to eq(3000)
|
50
53
|
expect(@player.level).to eq(25)
|
54
|
+
|
51
55
|
end
|
52
56
|
|
53
57
|
end
|
data/spec/region_spec.rb
CHANGED
@@ -3,15 +3,19 @@ require_relative "../lib/dotka/region"
|
|
3
3
|
RSpec.describe DotkaM::Region do
|
4
4
|
|
5
5
|
before :all do
|
6
|
+
|
6
7
|
@region = DotkaM::Region.new({
|
7
8
|
"id" => "111",
|
8
9
|
"name" => "US West"
|
9
10
|
})
|
11
|
+
|
10
12
|
end
|
11
13
|
|
12
14
|
it "provides data getters" do
|
15
|
+
|
13
16
|
expect(@region.id).to eq(111)
|
14
|
-
expect(@region.localized_name).to eq("US West")
|
17
|
+
expect(@region.localized_name).to eq("US West")
|
18
|
+
|
15
19
|
end
|
16
20
|
|
17
21
|
end
|
data/spec/storage_spec.rb
CHANGED
@@ -3,22 +3,30 @@ require_relative "../lib/dotka/storage"
|
|
3
3
|
RSpec.describe DotkaM::Storage do
|
4
4
|
|
5
5
|
before :all do
|
6
|
+
|
6
7
|
@storage = DotkaM::Storage.new
|
8
|
+
|
7
9
|
end
|
8
10
|
|
9
11
|
it "returns the entire file contents" do
|
12
|
+
|
10
13
|
items = @storage.get "items"
|
14
|
+
|
11
15
|
expect(items).to be_truthy
|
12
16
|
expect(items).to be_an(Array)
|
17
|
+
|
13
18
|
end
|
14
19
|
|
15
20
|
it "returns a single row" do
|
21
|
+
|
16
22
|
item = @storage.get "items", {"id" => 1}
|
23
|
+
|
17
24
|
expect(item).to eq({
|
18
25
|
"id" => "1",
|
19
26
|
"name" => "blink",
|
20
27
|
"localized_name" => "Blink Dagger"
|
21
|
-
})
|
28
|
+
})
|
29
|
+
|
22
30
|
end
|
23
31
|
|
24
32
|
end
|