smite_ruby 1.4.3 → 1.4.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +60 -0
- data/README.md +35 -21
- data/lib/smite.rb +18 -14
- data/lib/smite/client.rb +95 -13
- data/lib/smite/data_transform.rb +8 -8
- data/lib/smite/game.rb +43 -30
- data/lib/smite/getgods.json +151 -0
- data/lib/smite/god.rb +1 -1
- data/lib/smite/god_rank.rb +1 -1
- data/lib/smite/god_stats.rb +11 -13
- data/lib/smite/item.rb +18 -4
- data/lib/smite/motd.rb +19 -0
- data/lib/smite/object.rb +2 -1
- data/lib/smite/player.rb +20 -35
- data/lib/smite/queue.rb +19 -0
- data/lib/smite/recent_match.rb +18 -0
- data/lib/smite/recommended_items.rb +22 -0
- data/smite_ruby.gemspec +4 -2
- data/spec/ability_spec.rb +7 -0
- data/spec/achievements_spec.rb +7 -0
- data/spec/client_spec.rb +52 -0
- data/spec/data_transform_spec.rb +7 -0
- data/spec/friend_spec.rb +7 -0
- data/spec/game_spec.rb +200 -0
- data/spec/god_rank_spec.rb +7 -0
- data/spec/god_spec.rb +57 -0
- data/spec/god_stats_spec.rb +7 -0
- data/spec/item_effect_spec.rb +7 -0
- data/spec/item_spec.rb +85 -0
- data/spec/match_spec.rb +7 -0
- data/spec/player_spec.rb +76 -0
- data/spec/responses/createsession.json +1 -0
- data/spec/responses/getachievements.json +11 -0
- data/spec/responses/getdataused.json +1 -0
- data/spec/responses/getesportsproleaguedetails.json +1 -0
- data/spec/responses/getfriends.json +44 -0
- data/spec/responses/getgodranks.json +71 -0
- data/spec/responses/getgodrecommendeditems.json +1 -0
- data/spec/responses/getgods.json +461 -0
- data/spec/responses/getitems.json +118 -0
- data/spec/responses/getleagueleaderboard.json +1 -0
- data/spec/responses/getleagueseasons.json +1 -0
- data/spec/responses/getmatchdetails.json +1 -0
- data/spec/responses/getmatchhistory.json +61 -0
- data/spec/responses/getmatchidsbyqueue.json +1 -0
- data/spec/responses/getmatchplayerdetails.json +1 -0
- data/spec/responses/getmotd.json +37 -0
- data/spec/responses/getplayer.json +57 -0
- data/spec/responses/getplayerstatus.json +1 -0
- data/spec/responses/getqueuestats.json +1 -0
- data/spec/responses/getsearchteams.json +1 -0
- data/spec/responses/getteamdetails.json +1 -0
- data/spec/responses/getteamplayers.json +1 -0
- data/spec/responses/gettopmatches.json +1 -0
- data/spec/responses/testsession.json +1 -0
- data/spec/shared_examples/smite_object.rb +17 -0
- data/spec/spec_helper.rb +51 -0
- metadata +75 -2
data/spec/client_spec.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe Smite::Client do
|
4
|
+
let(:dev_id) { 1234 }
|
5
|
+
let(:auth_key) { 'ABCD' }
|
6
|
+
|
7
|
+
describe '#initialize' do
|
8
|
+
it 'accepts only valid languages' do
|
9
|
+
[1,2,3,7,9,10,11,12,13].each do |lang|
|
10
|
+
client = described_class.new(dev_id, auth_key, lang)
|
11
|
+
expect(client.lang).to eq(lang)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'defaults the langauge to English' do
|
16
|
+
[14..20].each do |lang|
|
17
|
+
client = described_class.new(dev_id, auth_key, lang)
|
18
|
+
expect(client.lang).to eq(1)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '#valid_session?' do
|
24
|
+
let(:client) { described_class.new(dev_id, auth_key) }
|
25
|
+
|
26
|
+
it 'returns true if the session is created' do
|
27
|
+
expect(client.valid_session?).to eq(true)
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'returns false if the session is not created' do
|
31
|
+
allow(client).to receive(:test_session).and_return('failure')
|
32
|
+
expect(client.valid_session?).to eq(false)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe '#create_session' do
|
37
|
+
let(:client) { described_class.new(dev_id, auth_key) }
|
38
|
+
|
39
|
+
it 'sets the session_id if unset' do
|
40
|
+
allow(client).to receive(:valid_session?).and_return(false)
|
41
|
+
expect(client.session_id).to be_nil
|
42
|
+
client.create_session
|
43
|
+
expect(client.session_id).not_to be_nil
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'returns the session_id if set' do
|
47
|
+
allow(client).to receive(:valid_session?).and_return(true)
|
48
|
+
expect(client).not_to receive(:api_call)
|
49
|
+
client.create_session
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
data/spec/friend_spec.rb
ADDED
data/spec/game_spec.rb
ADDED
@@ -0,0 +1,200 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe Smite::Game do
|
4
|
+
let(:dev_id) { 1234 }
|
5
|
+
let(:auth_key) { 'ABCD' }
|
6
|
+
|
7
|
+
before { Smite::Game.authenticate!(dev_id, auth_key) }
|
8
|
+
|
9
|
+
describe '#authenticate!' do
|
10
|
+
it 'returns true if the client initialized a session' do
|
11
|
+
client = Smite::Client.new(dev_id, auth_key)
|
12
|
+
allow(client).to receive(:session_id).and_return('ABCDE')
|
13
|
+
allow(Smite::Client).to receive(:new).and_return(client)
|
14
|
+
|
15
|
+
expect(Smite::Game.authenticate!(dev_id, auth_key)).to eq(true)
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'returns false if the client did not initialize a session' do
|
19
|
+
client = Smite::Client.new(dev_id, auth_key)
|
20
|
+
allow(client).to receive(:session_id).and_return(nil)
|
21
|
+
allow(Smite::Client).to receive(:new).and_return(client)
|
22
|
+
|
23
|
+
expect(Smite::Game.authenticate!(dev_id, auth_key)).to eq(false)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe '#devices' do
|
28
|
+
it 'returns a list of Smite::Items' do
|
29
|
+
expect(Smite::Game.devices.count).to eq(3)
|
30
|
+
Smite::Game.devices.each do |device|
|
31
|
+
expect(device.class).to eq(Smite::Item)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'caches the devices' do
|
36
|
+
Smite::Game.devices
|
37
|
+
expect(Smite::Item).not_to receive(:new)
|
38
|
+
Smite::Game.devices
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe '#items' do
|
43
|
+
it 'only returns Items from the device list' do
|
44
|
+
Smite::Game.items.each do |item|
|
45
|
+
expect(item.type).to eq('Item')
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'caches the items' do
|
50
|
+
Smite::Game.items
|
51
|
+
expect(Smite::Game.devices).not_to receive(:select)
|
52
|
+
Smite::Game.items
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe '#consumables' do
|
57
|
+
it 'only returns Consumables from the device list' do
|
58
|
+
Smite::Game.consumables.each do |consumable|
|
59
|
+
expect(consumable.type).to eq('Consumable')
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'caches the consumables' do
|
64
|
+
Smite::Game.consumables
|
65
|
+
expect(Smite::Game.devices).not_to receive(:select)
|
66
|
+
Smite::Game.consumables
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe '#actives' do
|
71
|
+
it 'only returns Actives from the device list' do
|
72
|
+
Smite::Game.actives.each do |active|
|
73
|
+
expect(active.type).to eq('Active')
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'caches the actives' do
|
78
|
+
Smite::Game.actives
|
79
|
+
expect(Smite::Game.devices).not_to receive(:select)
|
80
|
+
Smite::Game.actives
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
describe '#gods' do
|
85
|
+
it 'returns a list of Smite::God' do
|
86
|
+
expect(Smite::Game.gods.count).to eq(1)
|
87
|
+
Smite::Game.gods.each do |god|
|
88
|
+
expect(god.class).to eq(Smite::God)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
it 'caches the gods' do
|
93
|
+
Smite::Game.gods
|
94
|
+
expect(Smite::God).not_to receive(:new)
|
95
|
+
Smite::Game.gods
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
describe '#motd_list' do
|
100
|
+
it 'returns a list of Smite::MOTDs' do
|
101
|
+
expect(Smite::Game.motd_list.count).to eq(3)
|
102
|
+
Smite::Game.motd_list.each do |motd|
|
103
|
+
expect(motd.class).to eq(Smite::MOTD)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
it 'is in sorted order by date' do
|
108
|
+
motds = Smite::Game.motd_list
|
109
|
+
(0..motds.count - 2).each do |k|
|
110
|
+
expect(motds[k].date).to be > motds[k+1].date
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
it 'caches the motd_list' do
|
115
|
+
Smite::Game.motd_list
|
116
|
+
expect(Smite::MOTD).not_to receive(:new)
|
117
|
+
Smite::Game.motd_list
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
describe '#motd_now' do
|
122
|
+
it 'returns the most recent MOTD' do
|
123
|
+
expect(Smite::Game.motd_now).to eq(Smite::Game.motd_list[0])
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
describe '#god' do
|
128
|
+
it 'returns a god that matches by name' do
|
129
|
+
%w[agni AgNi AGNI].each do |name|
|
130
|
+
god = Smite::Game.god(name)
|
131
|
+
expect(god.name).to eq('Agni')
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
it 'returns a god that matches by id' do
|
136
|
+
[1737, '1737'].each do |id|
|
137
|
+
god = Smite::Game.god(id)
|
138
|
+
expect(god.name).to eq('Agni')
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
it 'returns nil for a god that doesnt exist' do
|
143
|
+
['jesus', [], {'Alabama' => :AL }].each do |thing|
|
144
|
+
god = Smite::Game.god(thing)
|
145
|
+
expect(god).to eq(nil)
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
describe '#item' do
|
151
|
+
it 'returns an item that matches by name' do
|
152
|
+
%w[SOverEIGnty sovereignty SOVEREIGNTY].each do |name|
|
153
|
+
item = Smite::Game.item(name)
|
154
|
+
expect(item.name).to eq('Sovereignty')
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
it 'returns an item that matches by id' do
|
159
|
+
[7528, '7528'].each do |id|
|
160
|
+
item = Smite::Game.item(id)
|
161
|
+
expect(item.name).to eq('Sovereignty')
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
it 'returns nil for an item that doesnt exist' do
|
166
|
+
['jesus', [], {'Alabama' => :AL }].each do |thing|
|
167
|
+
item = Smite::Game.item(thing)
|
168
|
+
expect(item).to eq(nil)
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
describe '#player' do
|
174
|
+
it 'instantiates a new Smite::Player' do
|
175
|
+
expect(Smite::Player).to receive(:new)
|
176
|
+
Smite::Game.player('adapting')
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
describe '#queues' do
|
181
|
+
it 'returns a list of queues' do
|
182
|
+
expect(Smite::Game.queues.count).to eq(9)
|
183
|
+
Smite::Game.queues.each do |queue|
|
184
|
+
expect(queue.class).to eq(Smite::Queue)
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
it 'caches the queue list' do
|
189
|
+
Smite::Game.queues
|
190
|
+
expect(Smite::Queue).not_to receive(:new)
|
191
|
+
Smite::Game.queues
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
describe '#match' do
|
196
|
+
it 'instantiates a new Smite::Match' do
|
197
|
+
# pending
|
198
|
+
end
|
199
|
+
end
|
200
|
+
end
|
data/spec/god_spec.rb
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe Smite::God do
|
4
|
+
let(:osiris) { Smite::Game.god('Osiris') }
|
5
|
+
let(:sobek) { Smite::Game.god('Sobek') }
|
6
|
+
let(:agni) { Smite::Game.god('Agni') }
|
7
|
+
let(:smite_obj) { agni }
|
8
|
+
|
9
|
+
before { Smite::Game.authenticate!(1234, 'ABCD') }
|
10
|
+
|
11
|
+
describe '#on_free_rotation?' do
|
12
|
+
it 'returns true if not empty' do
|
13
|
+
expect(agni.on_free_rotation?).to eq(true)
|
14
|
+
end
|
15
|
+
it 'returns false if empty' do
|
16
|
+
expect(sobek.on_free_rotation?).to eq(false)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '#ranged?' do
|
21
|
+
it 'returns true if type contains Ranged' do
|
22
|
+
expect(agni.ranged?).to eq(true)
|
23
|
+
end
|
24
|
+
it 'returns false if type does not contain Ranged' do
|
25
|
+
expect(sobek.ranged?).to eq(false)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe '#melee?' do
|
30
|
+
it 'returns true if type contains Melee' do
|
31
|
+
expect(sobek.melee?).to eq(true)
|
32
|
+
end
|
33
|
+
it 'returns false if type does not contain Melee' do
|
34
|
+
expect(agni.melee?).to eq(false)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe '#magic?' do
|
39
|
+
it 'returns true if type contains Magic' do
|
40
|
+
expect(agni.magic?).to eq(true)
|
41
|
+
end
|
42
|
+
it 'returns false if type does not contain Magic' do
|
43
|
+
expect(osiris.magic?).to eq(false)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe '#physical?' do
|
48
|
+
it 'returns true if type contains Physical' do
|
49
|
+
expect(osiris.physical?).to eq(true)
|
50
|
+
end
|
51
|
+
it 'returns false if type does not contain Physical' do
|
52
|
+
expect(agni.physical?).to eq(false)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
it_behaves_like 'a Smite::Object'
|
57
|
+
end
|
data/spec/item_spec.rb
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe Smite::Item do
|
4
|
+
let(:vampiric_shroud) { Smite::Game.item("Vampiric Shroud") }
|
5
|
+
let(:shifters_shield) { Smite::Game.item("Shifter's Shield") }
|
6
|
+
let(:soul_reaver) { Smite::Game.item('Soul Reaver') }
|
7
|
+
let(:sovereignty) { Smite::Game.item('Sovereignty') }
|
8
|
+
let(:aegis) { Smite::Game.item('Improved Aegis') }
|
9
|
+
let(:potion) { Smite::Game.item('Potion of Magical Might') }
|
10
|
+
let(:smite_obj) { sovereignty }
|
11
|
+
|
12
|
+
before { Smite::Game.authenticate!(1234, 'ABCD') }
|
13
|
+
|
14
|
+
describe '#active?' do
|
15
|
+
it 'returns true if the device is an active' do
|
16
|
+
expect(aegis.active?).to eq(true)
|
17
|
+
end
|
18
|
+
it 'returns false if the device is not an active' do
|
19
|
+
expect(sovereignty.active?).to eq(false)
|
20
|
+
expect(potion.active?).to eq(false)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '#consumable?' do
|
25
|
+
it 'returns true if the device is a consumable' do
|
26
|
+
expect(potion.consumable?).to eq(true)
|
27
|
+
end
|
28
|
+
it 'returns false if the device is not a consumable' do
|
29
|
+
expect(sovereignty.consumable?).to eq(false)
|
30
|
+
expect(aegis.consumable?).to eq(false)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe '#item?' do
|
35
|
+
it 'returns true if the device is an item' do
|
36
|
+
expect(sovereignty.item?).to eq(true)
|
37
|
+
end
|
38
|
+
it 'returns false if the device is not an item' do
|
39
|
+
expect(potion.item?).to eq(false)
|
40
|
+
expect(aegis.item?).to eq(false)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe '#physical?' do
|
45
|
+
it 'returns true if the device is a physical item' do
|
46
|
+
expect(sovereignty.physical?).to eq(true)
|
47
|
+
expect(shifters_shield.physical?).to eq(true)
|
48
|
+
end
|
49
|
+
it 'returns true if the device is an active or potion' do
|
50
|
+
expect(potion.physical?).to eq(true)
|
51
|
+
expect(aegis.physical?).to eq(true)
|
52
|
+
end
|
53
|
+
it 'returns false if the device is physical' do
|
54
|
+
expect(soul_reaver.physical?).to eq(false)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe '#magic?' do
|
59
|
+
it 'returns true if the device is a magic item' do
|
60
|
+
expect(soul_reaver.magic?).to eq(true)
|
61
|
+
expect(sovereignty.magic?).to eq(true)
|
62
|
+
end
|
63
|
+
it 'returns true if the device is an active or potion' do
|
64
|
+
expect(potion.physical?).to eq(true)
|
65
|
+
expect(aegis.physical?).to eq(true)
|
66
|
+
end
|
67
|
+
it 'returns false if the device is magic' do
|
68
|
+
expect(shifters_shield.magic?).to eq(false)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe '#starter?' do
|
73
|
+
it 'returns true if the device is a starter item' do
|
74
|
+
expect(vampiric_shroud.starter?).to eq(true)
|
75
|
+
end
|
76
|
+
it 'returns false otherwise' do
|
77
|
+
expect(potion.starter?).to eq(false)
|
78
|
+
expect(aegis.starter?).to eq(false)
|
79
|
+
expect(soul_reaver.starter?).to eq(false)
|
80
|
+
expect(sovereignty.starter?).to eq(false)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
it_behaves_like 'a Smite::Object'
|
85
|
+
end
|