dotka 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,12 @@
1
+ require_relative "raw"
2
+
3
+ module DotkaM
4
+ class Region < Raw
5
+ def id
6
+ @raw["id"].to_i
7
+ end
8
+ def localized_name
9
+ @raw["name"]
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,16 @@
1
+ module DotkaM
2
+ class Skill
3
+ def self.any
4
+ 0
5
+ end
6
+ def self.normal
7
+ 1
8
+ end
9
+ def self.high
10
+ 2
11
+ end
12
+ def self.very_high
13
+ 3
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,21 @@
1
+ require "json"
2
+
3
+ module DotkaM
4
+ class Storage
5
+ def get file, conditions = {}
6
+ rows = JSON.parse File.read("#{__dir__}/../../data/#{file}.json")
7
+ if not conditions.empty?
8
+ rows.select! { |row|
9
+ selected = true
10
+ conditions.each { |key, value|
11
+ if not (row.has_key? key) or not (row[key] == value.to_s)
12
+ selected = false
13
+ end
14
+ }
15
+ selected
16
+ }
17
+ end
18
+ rows.length == 1 ? rows.first : rows
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,40 @@
1
+ require_relative "../lib/dotka"
2
+ require_relative "../lib/dotka/match"
3
+ require "rest-client"
4
+
5
+ RSpec.describe Dotka do
6
+
7
+ before :all do
8
+ @dotka = Dotka.new
9
+ end
10
+
11
+ it "sets the API key" do
12
+ @dotka.set_api_key "some-key"
13
+ expect(@dotka.get_api_key).to eq("some-key")
14
+ end
15
+
16
+ it "loads a match" do
17
+ allow(RestClient).to receive("get") {
18
+ FakeResponse.new(200, '{"result": {"match_id": 123456789}}')
19
+ }
20
+ expect(match = @dotka.match(123456789)).to be_instance_of(DotkaM::Match)
21
+ expect(match.id).to eq(123456789)
22
+ end
23
+
24
+ it "loads a list of matches" do
25
+ allow(RestClient).to receive("get") {
26
+ FakeResponse.new(200, '{"result": {"matches": [{"match_id": 123456789}]}}')
27
+ }
28
+ expect(matches = @dotka.matches(987654321)).to be_an(Array)
29
+ expect(matches.length).to eq(1)
30
+ expect(matches.first.id).to eq(123456789)
31
+ end
32
+
33
+ end
34
+
35
+ class FakeResponse
36
+ attr_reader "code", "to_str"
37
+ def initialize code, body
38
+ @code, @to_str = code, body
39
+ end
40
+ end
@@ -0,0 +1,17 @@
1
+ require_relative "../lib/dotka/game_mode"
2
+
3
+ RSpec.describe DotkaM::GameMode do
4
+
5
+ before :all do
6
+ @game_mode = DotkaM::GameMode.new({
7
+ "id" => "1",
8
+ "name" => "All Pick"
9
+ })
10
+ end
11
+
12
+ it "provides data getters" do
13
+ expect(@game_mode.id).to eq(1)
14
+ expect(@game_mode.localized_name).to eq("All Pick")
15
+ end
16
+
17
+ end
@@ -0,0 +1,19 @@
1
+ require_relative "../lib/dotka/hero"
2
+
3
+ RSpec.describe DotkaM::Hero do
4
+
5
+ before :all do
6
+ @hero = DotkaM::Hero.new({
7
+ "id" => "1",
8
+ "name" => "antimage",
9
+ "localized_name" => "Anti-Mage"
10
+ })
11
+ end
12
+
13
+ it "provides data getters" do
14
+ expect(@hero.id).to eq(1)
15
+ expect(@hero.name).to eq("antimage")
16
+ expect(@hero.localized_name).to eq("Anti-Mage")
17
+ end
18
+
19
+ end
@@ -0,0 +1,19 @@
1
+ require_relative "../lib/dotka/item"
2
+
3
+ RSpec.describe DotkaM::Item do
4
+
5
+ before :all do
6
+ @item = DotkaM::Item.new({
7
+ "id" => "1",
8
+ "name" => "blink",
9
+ "localized_name" => "Blink Dagger"
10
+ })
11
+ end
12
+
13
+ it "provides data getters" do
14
+ expect(@item.id).to eq(1)
15
+ expect(@item.name).to eq("blink")
16
+ expect(@item.localized_name).to eq("Blink Dagger")
17
+ end
18
+
19
+ end
@@ -0,0 +1,17 @@
1
+ require_relative "../lib/dotka/lobby"
2
+
3
+ RSpec.describe DotkaM::Lobby do
4
+
5
+ before :all do
6
+ @lobby = DotkaM::Lobby.new({
7
+ "id" => "0",
8
+ "name" => "Public matchmaking"
9
+ })
10
+ end
11
+
12
+ it "provides data getters" do
13
+ expect(@lobby.id).to eq(0)
14
+ expect(@lobby.localized_name).to eq("Public matchmaking")
15
+ end
16
+
17
+ end
@@ -0,0 +1,31 @@
1
+ require_relative "../lib/dotka/match"
2
+
3
+ RSpec.describe DotkaM::Match do
4
+
5
+ before :all do
6
+ @match = DotkaM::Match.new({
7
+ "match_id" => "123456789",
8
+ "players" => [
9
+ {"account_id" => "1"}
10
+ ],
11
+ "radiant_win" => false,
12
+ "duration" => "3600",
13
+ "start_time" => "123456789",
14
+ "lobby_type" => "0",
15
+ "game_mode" => "1",
16
+ "cluster" => "111"
17
+ })
18
+ end
19
+
20
+ it "provides data getters" do
21
+ expect(@match.id).to eq(123456789)
22
+ expect(@match.players.first.account_id).to eq(1)
23
+ expect(@match.winner).to eq("dire")
24
+ expect(@match.duration).to eq(3600)
25
+ expect(@match.start_time).to eq(123456789)
26
+ expect(@match.lobby.localized_name).to eq("Public matchmaking")
27
+ expect(@match.game_mode.localized_name).to eq("All Pick")
28
+ expect(@match.region.localized_name).to eq("US West")
29
+ end
30
+
31
+ end
@@ -0,0 +1,53 @@
1
+ require_relative "../lib/dotka/player"
2
+
3
+ RSpec.describe DotkaM::Player do
4
+
5
+ before :all do
6
+ @player = DotkaM::Player.new({
7
+ "account_id" => "123456789",
8
+ "hero_id" => "1",
9
+ "item_0" => "1",
10
+ "item_1" => "1",
11
+ "item_2" => "1",
12
+ "item_3" => "1",
13
+ "item_4" => "1",
14
+ "item_5" => "1",
15
+ "kills" => "20",
16
+ "deaths" => "0",
17
+ "assists" => "30",
18
+ "leaver_status" => "1",
19
+ "player_slot" => "5",
20
+ "gold_spent" => "2000",
21
+ "gold" => "1000",
22
+ "last_hits" => "500",
23
+ "denies" => "100",
24
+ "gold_per_min" => "800",
25
+ "xp_per_min" => "700",
26
+ "hero_damage" => "10000",
27
+ "tower_damage" => "1000",
28
+ "hero_healing" => "3000",
29
+ "level" => "25"
30
+ })
31
+ end
32
+
33
+ it "provides data getters" do
34
+ expect(@player.account_id).to eq(123456789)
35
+ expect(@player.hero.localized_name).to eq("Anti-Mage")
36
+ expect(@player.items.first.localized_name).to eq("Blink Dagger")
37
+ expect(@player.kills).to eq(20)
38
+ expect(@player.deaths).to eq(0)
39
+ expect(@player.assists).to eq(30)
40
+ expect(@player.abandoned?).to be_truthy
41
+ expect(@player.team).to eq("dire")
42
+ expect(@player.gold).to eq(3000)
43
+ expect(@player.last_hits).to eq(500)
44
+ expect(@player.denies).to eq(100)
45
+ expect(@player.gold_per_min).to eq(800)
46
+ expect(@player.xp_per_min).to eq(700)
47
+ expect(@player.hero_dmg).to eq(10000)
48
+ expect(@player.tower_dmg).to eq(1000)
49
+ expect(@player.hero_heal).to eq(3000)
50
+ expect(@player.level).to eq(25)
51
+ end
52
+
53
+ end
@@ -0,0 +1,17 @@
1
+ require_relative "../lib/dotka/region"
2
+
3
+ RSpec.describe DotkaM::Region do
4
+
5
+ before :all do
6
+ @region = DotkaM::Region.new({
7
+ "id" => "111",
8
+ "name" => "US West"
9
+ })
10
+ end
11
+
12
+ it "provides data getters" do
13
+ expect(@region.id).to eq(111)
14
+ expect(@region.localized_name).to eq("US West")
15
+ end
16
+
17
+ end
@@ -0,0 +1,24 @@
1
+ require_relative "../lib/dotka/storage"
2
+
3
+ RSpec.describe DotkaM::Storage do
4
+
5
+ before :all do
6
+ @storage = DotkaM::Storage.new
7
+ end
8
+
9
+ it "returns the entire file contents" do
10
+ items = @storage.get "items"
11
+ expect(items).to be_truthy
12
+ expect(items).to be_an(Array)
13
+ end
14
+
15
+ it "returns a single row" do
16
+ item = @storage.get "items", {"id" => 1}
17
+ expect(item).to eq({
18
+ "id" => "1",
19
+ "name" => "blink",
20
+ "localized_name" => "Blink Dagger"
21
+ })
22
+ end
23
+
24
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dotka
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - bound1ess
@@ -16,7 +16,39 @@ executables: []
16
16
  extensions: []
17
17
  extra_rdoc_files: []
18
18
  files:
19
+ - ".gitignore"
20
+ - Gemfile
21
+ - Gemfile.lock
22
+ - LICENSE
23
+ - README.md
24
+ - Rakefile
25
+ - data/game_modes.json
26
+ - data/heroes.json
27
+ - data/items.json
28
+ - data/lobbies.json
29
+ - data/regions.json
30
+ - docs/todo.md
31
+ - dotka.gemspec
19
32
  - lib/dotka.rb
33
+ - lib/dotka/game_mode.rb
34
+ - lib/dotka/hero.rb
35
+ - lib/dotka/item.rb
36
+ - lib/dotka/lobby.rb
37
+ - lib/dotka/match.rb
38
+ - lib/dotka/player.rb
39
+ - lib/dotka/raw.rb
40
+ - lib/dotka/region.rb
41
+ - lib/dotka/skill.rb
42
+ - lib/dotka/storage.rb
43
+ - spec/dotka_spec.rb
44
+ - spec/game_mode_spec.rb
45
+ - spec/hero_spec.rb
46
+ - spec/item_spec.rb
47
+ - spec/lobby_spec.rb
48
+ - spec/match_spec.rb
49
+ - spec/player_spec.rb
50
+ - spec/region_spec.rb
51
+ - spec/storage_spec.rb
20
52
  homepage: https://github.com/bound1ess/dotka
21
53
  licenses:
22
54
  - MIT