open_dota_api 0.0.3 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 10283b2823ec6879ee2cbc78d3e7a17455a3a806
4
- data.tar.gz: eff45f3ecc4dfef96d2d915fa2fee43a0ebfa606
3
+ metadata.gz: 46e4d4e73a745680d8a4c2e06fa6e300886ccb53
4
+ data.tar.gz: 60b2b5404aa7125b2a805c9a69bc59ae0ad949e1
5
5
  SHA512:
6
- metadata.gz: 30840cf124f3c4ef6f24e862d222cab56dfe20e118b9bf262b7715e126172c3d97bdae6ea02dfbafe99d05d0068c6c894a6847904c5fe48b83e7f1e49e391566
7
- data.tar.gz: f956ca55c5f2f13d14b3a613b2f8d28020d6680542ed4c71eddc0909aa93786d3970ce5ea92fc0f73c8e6dc7109403c8edc31c61832cf930428bff40d47e2ac9
6
+ metadata.gz: 6b2fac68e691847a93f71fdfa20e80dd3fab5aeeecc925600ce71076d396510f47fd7573e3e63ada57de605b9874cbd2cecd74f6e6d9e9e1e467f7da4c233777
7
+ data.tar.gz: c9d7a4c6122c944e09569c69e7f608b3f8ea6f4de9f770d4b3b3a812e1af89dd5acdebfb9a8678b36bd46da945a74434944794334ce3f10660cf44a1dd161d5a
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
data/lib/open_dota_api.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'open_dota_api/client'
2
+ require 'open_dota_api/version'
2
3
 
3
4
  module OpenDotaApi
4
5
  extend SingleForwardable
@@ -3,8 +3,15 @@ require 'hashable'
3
3
 
4
4
  module OpenDotaApi
5
5
  class Entity
6
+ include Entities::Instantiatable
6
7
  include ::Hashable
7
8
 
9
+ def self.define_adder(attributes)
10
+ attributes.each do |attribute|
11
+ define_method(attribute) { data[attribute] }
12
+ end
13
+ end
14
+
8
15
  def initialize(data)
9
16
  @data = data
10
17
  end
@@ -2,36 +2,7 @@ require 'open_dota_api/entity'
2
2
 
3
3
  module OpenDotaApi
4
4
  class Hero < Entity
5
- include Entities::Instantiatable
6
-
7
5
  ENDPOINT = 'heroes'.freeze
8
-
9
- def id
10
- data['id']
11
- end
12
-
13
- def name
14
- data['name']
15
- end
16
-
17
- def localized_name
18
- data['localized_name']
19
- end
20
-
21
- def primary_attr
22
- data['primary_attr']
23
- end
24
-
25
- def attack_type
26
- data['attack_type']
27
- end
28
-
29
- def roles
30
- data['roles']
31
- end
32
-
33
- def legs
34
- data['legs']
35
- end
6
+ define_adder(%w[id name localized_name primary_attr attack_type roles legs])
36
7
  end
37
8
  end
@@ -2,8 +2,6 @@ require 'open_dota_api/entity'
2
2
 
3
3
  module OpenDotaApi
4
4
  class League < Entity
5
- include Entities::Instantiatable
6
-
7
5
  ENDPOINT = 'leagues'.freeze
8
6
 
9
7
  def league_id
@@ -5,6 +5,10 @@ module OpenDotaApi
5
5
  class Match < Entity
6
6
  ENDPOINT = 'matches'.freeze
7
7
 
8
+ def self.instantiate(_ = nil)
9
+ raise NotImplementedError
10
+ end
11
+
8
12
  def match_id
9
13
  data['match_id']
10
14
  end
@@ -62,7 +66,7 @@ module OpenDotaApi
62
66
  end
63
67
 
64
68
  def players
65
- data['players'].map { |player| Player.new(player) }
69
+ Player.instantiate(data['players'])
66
70
  end
67
71
 
68
72
  class Player < Matches::Player; end
@@ -2,36 +2,7 @@ require 'open_dota_api/entity'
2
2
 
3
3
  module OpenDotaApi
4
4
  class Team < Entity
5
- include Entities::Instantiatable
6
-
7
5
  ENDPOINT = 'teams'.freeze
8
-
9
- def team_id
10
- data['team_id']
11
- end
12
-
13
- def rating
14
- data['rating']
15
- end
16
-
17
- def wins
18
- data['wins']
19
- end
20
-
21
- def losses
22
- data['losses']
23
- end
24
-
25
- def last_match_time
26
- data['last_match_time']
27
- end
28
-
29
- def name
30
- data['name']
31
- end
32
-
33
- def tag
34
- data['tag']
35
- end
6
+ define_adder(%w[team_id rating wins losses last_match_time name tag])
36
7
  end
37
8
  end
@@ -1,3 +1,3 @@
1
1
  module OpenDotaApi
2
- VERSION = '0.0.3'.freeze
2
+ VERSION = '0.1.0'.freeze
3
3
  end
@@ -30,8 +30,8 @@ describe OpenDotaApi::Match do
30
30
  expect(match).to be_a OpenDotaApi::Entity
31
31
  end
32
32
 
33
- it 'is instantiable' do
34
- expect(match).to_not be_a OpenDotaApi::Entities::Instantiatable
33
+ it 'is not instantiable' do
34
+ expect{ described_class.instantiate }.to raise_error NotImplementedError
35
35
  end
36
36
 
37
37
  describe 'default attributes' do
@@ -34,7 +34,7 @@ describe OpenDotaApi::Matches::Player do
34
34
  end
35
35
 
36
36
  it 'is instantiable' do
37
- expect(player).to_not be_a OpenDotaApi::Entities::Instantiatable
37
+ expect(player).to be_a OpenDotaApi::Entities::Instantiatable
38
38
  end
39
39
 
40
40
  describe 'default attributes' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: open_dota_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yaroslav Oslavskiy
@@ -108,6 +108,20 @@ dependencies:
108
108
  - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rake
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
111
125
  description: Ruby wrapper for Open Dota API
112
126
  email:
113
127
  - osyaroslav@gmail.com.com
@@ -116,6 +130,7 @@ extensions: []
116
130
  extra_rdoc_files: []
117
131
  files:
118
132
  - MIT-LICENSE
133
+ - Rakefile
119
134
  - lib/open_dota_api.rb
120
135
  - lib/open_dota_api/client.rb
121
136
  - lib/open_dota_api/connection.rb
@@ -160,7 +175,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
160
175
  version: '0'
161
176
  requirements: []
162
177
  rubyforge_project:
163
- rubygems_version: 2.6.12
178
+ rubygems_version: 2.5.1
164
179
  signing_key:
165
180
  specification_version: 4
166
181
  summary: Ruby wrapper for Open Dota API