smite_ruby 1.4.5 → 1.4.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/smite.rb +20 -18
- data/lib/smite/client.rb +8 -4
- data/lib/smite/competitor.rb +31 -0
- data/lib/smite/data_transform.rb +40 -4
- data/lib/smite/full_match.rb +57 -0
- data/lib/smite/game.rb +5 -4
- data/lib/smite/god_rank.rb +11 -7
- data/lib/smite/god_stats.rb +28 -15
- data/lib/smite/item_effect.rb +2 -2
- data/lib/smite/match_achievements.rb +7 -0
- data/lib/smite/match_summary.rb +31 -0
- data/lib/smite/player.rb +4 -4
- data/smite_ruby.gemspec +2 -2
- data/spec/ability_spec.rb +3 -2
- data/spec/achievements_spec.rb +3 -2
- data/spec/client_spec.rb +2 -5
- data/spec/friend_spec.rb +8 -1
- data/spec/{match_spec.rb → full_match_spec.rb} +1 -1
- data/spec/game_spec.rb +5 -7
- data/spec/god_rank_spec.rb +54 -1
- data/spec/god_spec.rb +0 -2
- data/spec/god_stats_spec.rb +56 -1
- data/spec/item_effect_spec.rb +13 -1
- data/spec/item_spec.rb +0 -2
- data/spec/match_summary_spec.rb +28 -0
- data/spec/player_spec.rb +3 -5
- data/spec/responses/getmatchdetails.json +861 -1
- data/spec/responses/getplayerachievements.json +27 -0
- data/spec/spec_helper.rb +4 -2
- metadata +9 -7
- data/lib/smite/getgods.json +0 -151
- data/lib/smite/match.rb +0 -14
- data/lib/smite/recent_match.rb +0 -18
- data/spec/responses/getachievements.json +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ccff694141365296222915e4cc61decb5162e706
|
4
|
+
data.tar.gz: 38f300318daa9cc1c80cd8e70fce3df846cf148e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a73210acf092f72f83cfa9edf71bf007d383d282c487777e3d6801822a0819c70f2e1d73fbfc17c2e1247162c2ab21f611070391790647bad47e877819422e06
|
7
|
+
data.tar.gz: 658baadac807264383473292c98f37725baceee364111b4e06810a355249727f103074fd3c90407311a048563933591e86a15be677e374bf4631e552e829502f
|
data/lib/smite.rb
CHANGED
@@ -4,21 +4,23 @@ require 'active_support'
|
|
4
4
|
module Smite
|
5
5
|
end
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
7
|
+
require 'smite/object.rb'
|
8
|
+
require 'smite/queue.rb'
|
9
|
+
require 'smite/motd.rb'
|
10
|
+
require 'smite/recommended_items.rb'
|
11
|
+
require 'smite/achievements.rb'
|
12
|
+
require 'smite/ability.rb'
|
13
|
+
require 'smite/god_rank.rb'
|
14
|
+
require 'smite/god_stats.rb'
|
15
|
+
require 'smite/god.rb'
|
16
|
+
require 'smite/item_effect.rb'
|
17
|
+
require 'smite/item.rb'
|
18
|
+
require 'smite/friend.rb'
|
19
|
+
require 'smite/data_transform.rb'
|
20
|
+
require 'smite/match_achievements.rb'
|
21
|
+
require 'smite/competitor.rb'
|
22
|
+
require 'smite/full_match.rb'
|
23
|
+
require 'smite/match_summary.rb'
|
24
|
+
require 'smite/player.rb'
|
25
|
+
require 'smite/game.rb'
|
26
|
+
require 'smite/client.rb'
|
data/lib/smite/client.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module Smite
|
2
2
|
class Client
|
3
|
-
attr_reader :dev_id, :auth_key, :session_id, :lang
|
3
|
+
attr_reader :dev_id, :auth_key, :session_id, :lang, :created
|
4
4
|
include HTTParty
|
5
5
|
base_uri 'http://api.smitegame.com/smiteapi.svc/'
|
6
6
|
|
@@ -8,6 +8,7 @@ module Smite
|
|
8
8
|
@dev_id = dev_id
|
9
9
|
@auth_key = auth_key
|
10
10
|
@lang = [1,2,3,7,9,10,11,12,13].include?(lang) ? lang : 1
|
11
|
+
@created = Time.now - 20 * 60
|
11
12
|
create_session
|
12
13
|
end
|
13
14
|
|
@@ -106,17 +107,20 @@ module Smite
|
|
106
107
|
def create_session
|
107
108
|
return @session_id if valid_session?
|
108
109
|
|
109
|
-
response
|
110
|
-
@session_id
|
110
|
+
response = api_call('createsession', [], false)
|
111
|
+
@session_id = response['session_id']
|
112
|
+
@created = Time.now
|
111
113
|
end
|
112
114
|
|
113
115
|
def valid_session?
|
114
|
-
|
116
|
+
(created + (15 * 60)) > Time.now
|
115
117
|
end
|
116
118
|
|
117
119
|
private
|
118
120
|
|
119
121
|
def api_call(method, params = [], session = true)
|
122
|
+
create_session if !valid_session? && session
|
123
|
+
|
120
124
|
request = request_str(method, params, session)
|
121
125
|
self.class.get(request)
|
122
126
|
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Smite
|
2
|
+
class Competitor < Smite::Object
|
3
|
+
def initialize(data)
|
4
|
+
data['Queue'] = data['name']
|
5
|
+
super
|
6
|
+
@data = DataTransform.transform_items(@data)
|
7
|
+
@data = DataTransform.transform_match_achievements(@data)
|
8
|
+
@data = DataTransform.transform_match_summary(@data)
|
9
|
+
end
|
10
|
+
|
11
|
+
def to_player
|
12
|
+
Smite::Game.player(player_id)
|
13
|
+
end
|
14
|
+
|
15
|
+
def partied?
|
16
|
+
party_id != 0
|
17
|
+
end
|
18
|
+
|
19
|
+
def winner?
|
20
|
+
win_status == 'Winner'
|
21
|
+
end
|
22
|
+
|
23
|
+
def loser?
|
24
|
+
!winner?
|
25
|
+
end
|
26
|
+
|
27
|
+
def inspect
|
28
|
+
"#<Smite::Competitor '#{match}' '#{player_name}'>"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/smite/data_transform.rb
CHANGED
@@ -24,7 +24,8 @@ module Smite
|
|
24
24
|
|
25
25
|
data['abilities'] = ability_fields.values.map do |ability_data|
|
26
26
|
data_attrs = ability_data.slice('Id', 'Summary', 'URL')
|
27
|
-
desc = ability_data['Description']
|
27
|
+
desc = ability_data['Description']
|
28
|
+
desc = desc.nil? ? {} : desc['itemDescription']
|
28
29
|
|
29
30
|
Ability.new(data_attrs.merge(desc))
|
30
31
|
end
|
@@ -32,13 +33,13 @@ module Smite
|
|
32
33
|
data.except(*ability_filter_fields)
|
33
34
|
end
|
34
35
|
|
35
|
-
def
|
36
|
+
def transform_match_summary(data)
|
36
37
|
return data unless data['queue']
|
37
38
|
|
38
39
|
if data['queue'] =~ /League/
|
39
40
|
data
|
40
41
|
else
|
41
|
-
data.except(*
|
42
|
+
data.except(*match_summary_filter_fields)
|
42
43
|
end
|
43
44
|
end
|
44
45
|
|
@@ -67,8 +68,40 @@ module Smite
|
|
67
68
|
data
|
68
69
|
end
|
69
70
|
|
71
|
+
def transform_match_achievements(data)
|
72
|
+
ach_fields = data.slice(*match_achievement_map_fields)
|
73
|
+
return data if ach_fields.empty?
|
74
|
+
|
75
|
+
data['match_achievements'] = MatchAchievements.new(ach_fields)
|
76
|
+
data.except(*match_achievement_filter_fields)
|
77
|
+
end
|
78
|
+
|
70
79
|
private
|
71
80
|
|
81
|
+
def match_achievement_map_fields
|
82
|
+
%w[
|
83
|
+
kills_bot
|
84
|
+
kills_double
|
85
|
+
kills_fire_giant
|
86
|
+
kills_first_blood
|
87
|
+
kills_gold_fury
|
88
|
+
kills_penta
|
89
|
+
kills_phoenix
|
90
|
+
kills_player
|
91
|
+
kills_quadra
|
92
|
+
kills_siege_juggernaut
|
93
|
+
kills_single
|
94
|
+
kills_triple
|
95
|
+
kills_wild_juggernaut
|
96
|
+
player_name
|
97
|
+
match
|
98
|
+
]
|
99
|
+
end
|
100
|
+
|
101
|
+
def match_achievement_filter_fields
|
102
|
+
match_achievement_map_fields - %w(player_name match)
|
103
|
+
end
|
104
|
+
|
72
105
|
def item_map_fields
|
73
106
|
%w(
|
74
107
|
active_id1 active_id2 item_id1 item_id2
|
@@ -80,6 +113,9 @@ module Smite
|
|
80
113
|
item_map_fields + %w(
|
81
114
|
item_1 item_2 item_3 item_4 item_5
|
82
115
|
item_6 active_1 active_2 active_3
|
116
|
+
item_active_1 item_active_2 item_active_3
|
117
|
+
item_purch_1 item_purch_2 item_purch_3
|
118
|
+
item_purch_4 item_purch_5 item_purch_6
|
83
119
|
)
|
84
120
|
end
|
85
121
|
|
@@ -98,7 +134,7 @@ module Smite
|
|
98
134
|
)
|
99
135
|
end
|
100
136
|
|
101
|
-
def
|
137
|
+
def match_summary_filter_fields
|
102
138
|
%w(
|
103
139
|
ban1 ban2 ban3 ban4 ban5 ban6
|
104
140
|
ban1_id ban2_id ban3_id
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module Smite
|
2
|
+
class FullMatch < Smite::Object
|
3
|
+
attr_accessor :queue, :match
|
4
|
+
|
5
|
+
def initialize(data)
|
6
|
+
data = { 'competitors' => data.map { |k, v| Smite::Competitor.new(k) } }
|
7
|
+
super
|
8
|
+
@queue = competitors[0].queue
|
9
|
+
@match = competitors[0].match
|
10
|
+
end
|
11
|
+
|
12
|
+
def teams
|
13
|
+
{ team1: team1, team2: team2 }
|
14
|
+
end
|
15
|
+
|
16
|
+
def parties
|
17
|
+
competitors.group_by(&:party_id)
|
18
|
+
end
|
19
|
+
|
20
|
+
def players
|
21
|
+
competitors
|
22
|
+
end
|
23
|
+
|
24
|
+
def size
|
25
|
+
competitors.count
|
26
|
+
end
|
27
|
+
|
28
|
+
def ranked?
|
29
|
+
queue =~ /Ranked/
|
30
|
+
end
|
31
|
+
|
32
|
+
def size_str
|
33
|
+
"#{size/2} v #{size/2}"
|
34
|
+
end
|
35
|
+
|
36
|
+
def team1
|
37
|
+
competitors[0...size/2]
|
38
|
+
end
|
39
|
+
|
40
|
+
def team2
|
41
|
+
competitors[size/2..-1]
|
42
|
+
end
|
43
|
+
|
44
|
+
def winning_team
|
45
|
+
return @winner unless @winner.nil?
|
46
|
+
|
47
|
+
@winner = teams.find do |team, competitors|
|
48
|
+
competitors.all? { |competitor| competitor.winner? }
|
49
|
+
end
|
50
|
+
@winner = @winner[0]
|
51
|
+
end
|
52
|
+
|
53
|
+
def inspect
|
54
|
+
"#<Smite::FullMatch #{match} #{queue}>"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
data/lib/smite/game.rb
CHANGED
@@ -22,12 +22,13 @@ module Smite
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def match(match_id)
|
25
|
-
|
26
|
-
|
25
|
+
match_data = client.match_details(match_id)
|
26
|
+
match_data.empty? ? nil : FullMatch.new(match_data)
|
27
27
|
end
|
28
28
|
|
29
|
-
def player(
|
30
|
-
|
29
|
+
def player(player_name_or_id)
|
30
|
+
player_data = client.player(player_name_or_id)
|
31
|
+
player_data.empty? ? nil : Player.new(player_data[0])
|
31
32
|
end
|
32
33
|
|
33
34
|
def motd_now
|
data/lib/smite/god_rank.rb
CHANGED
@@ -5,16 +5,11 @@ module Smite
|
|
5
5
|
end
|
6
6
|
|
7
7
|
def level
|
8
|
-
|
9
|
-
when 0 then 'none'
|
10
|
-
when (1..4) then 'gold'
|
11
|
-
when (5..9) then 'legendary'
|
12
|
-
when 10 then 'diamond'
|
13
|
-
end
|
8
|
+
self.class.level(rank)
|
14
9
|
end
|
15
10
|
|
16
11
|
def mastery
|
17
|
-
mastered ? 'mastered' : 'unmastered'
|
12
|
+
mastered? ? 'mastered' : 'unmastered'
|
18
13
|
end
|
19
14
|
|
20
15
|
def mastered?
|
@@ -24,5 +19,14 @@ module Smite
|
|
24
19
|
def inspect
|
25
20
|
"#<Smite::GodRank '#{god.name}' Lvl. #{rank} (#{level})>"
|
26
21
|
end
|
22
|
+
|
23
|
+
def self.level(rank)
|
24
|
+
case rank
|
25
|
+
when 0 then 'none'
|
26
|
+
when (1..4) then 'gold'
|
27
|
+
when (5..9) then 'legendary'
|
28
|
+
when 10 then 'diamond'
|
29
|
+
end
|
30
|
+
end
|
27
31
|
end
|
28
32
|
end
|
data/lib/smite/god_stats.rb
CHANGED
@@ -6,7 +6,7 @@ module Smite
|
|
6
6
|
super(data)
|
7
7
|
@name = god_name
|
8
8
|
@items = params[:items] || []
|
9
|
-
@level = (params[:level].to_i - 1)
|
9
|
+
@level = [[(params[:level].to_i - 1), 19].min, 0].max
|
10
10
|
end
|
11
11
|
|
12
12
|
def at_level(new_level)
|
@@ -18,14 +18,15 @@ module Smite
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def movement_speed
|
21
|
-
from_items =
|
21
|
+
from_items = bonus_from_items[:movement_speed]
|
22
22
|
base = data['movement_speed']
|
23
|
+
scaling = movement_speed_per_level * level
|
23
24
|
|
24
|
-
from_items + base
|
25
|
+
from_items + base + scaling
|
25
26
|
end
|
26
27
|
|
27
28
|
def health
|
28
|
-
from_items =
|
29
|
+
from_items = bonus_from_items[:health]
|
29
30
|
base = data['health']
|
30
31
|
scaling = health_per_level * level
|
31
32
|
|
@@ -33,7 +34,7 @@ module Smite
|
|
33
34
|
end
|
34
35
|
|
35
36
|
def mana
|
36
|
-
from_items =
|
37
|
+
from_items = bonus_from_items[:mana]
|
37
38
|
base = data['mana']
|
38
39
|
scaling = mana_per_level * level
|
39
40
|
|
@@ -41,7 +42,7 @@ module Smite
|
|
41
42
|
end
|
42
43
|
|
43
44
|
def mp5
|
44
|
-
from_items =
|
45
|
+
from_items = bonus_from_items[:mp5]
|
45
46
|
base = data['mp5']
|
46
47
|
scaling = (mp5_per_level * level.to_f).to_i
|
47
48
|
|
@@ -49,7 +50,7 @@ module Smite
|
|
49
50
|
end
|
50
51
|
|
51
52
|
def hp5
|
52
|
-
from_items =
|
53
|
+
from_items = bonus_from_items[:hp5]
|
53
54
|
base = data['hp5']
|
54
55
|
scaling = (hp5_per_level * level.to_f).to_i
|
55
56
|
|
@@ -57,38 +58,46 @@ module Smite
|
|
57
58
|
end
|
58
59
|
|
59
60
|
def attack_speed
|
60
|
-
from_items =
|
61
|
+
from_items = bonus_from_items[:attack_speed]
|
61
62
|
base = data['attack_speed']
|
62
63
|
scaling = (attack_speed_per_level * level.to_f).to_i
|
63
64
|
|
64
65
|
from_items + base + scaling
|
65
66
|
end
|
66
67
|
|
67
|
-
def
|
68
|
-
from_items =
|
69
|
-
base = data['
|
70
|
-
scaling =
|
68
|
+
def magical_power
|
69
|
+
from_items = bonus_from_items[:magical_power]
|
70
|
+
base = data['magical_power']
|
71
|
+
scaling = magical_power_per_level * level
|
71
72
|
|
72
73
|
from_items + base + scaling
|
73
74
|
end
|
74
75
|
|
75
76
|
def magic_protection
|
76
|
-
from_items =
|
77
|
+
from_items = bonus_from_items[:magic_protection]
|
77
78
|
base = data['magic_protection']
|
78
79
|
scaling = (magic_protection_per_level * level.to_f).to_i
|
79
80
|
|
80
81
|
from_items + base + scaling
|
81
82
|
end
|
82
83
|
|
84
|
+
def physical_power
|
85
|
+
from_items = bonus_from_items[:physical_power]
|
86
|
+
base = data['physical_power']
|
87
|
+
scaling = physical_power_per_level * level
|
88
|
+
|
89
|
+
from_items + base + scaling
|
90
|
+
end
|
91
|
+
|
83
92
|
def physical_protection
|
84
|
-
from_items =
|
93
|
+
from_items = bonus_from_items[:physical_protection]
|
85
94
|
base = data['physical_protection']
|
86
95
|
scaling = (physical_protection_per_level * level.to_f).to_i
|
87
96
|
|
88
97
|
from_items + base + scaling
|
89
98
|
end
|
90
99
|
|
91
|
-
def
|
100
|
+
def bonus_from_items
|
92
101
|
return @item_bonus unless @item_bonus.nil?
|
93
102
|
|
94
103
|
@item_bonus = default_bonus
|
@@ -115,5 +124,9 @@ module Smite
|
|
115
124
|
def default_bonus
|
116
125
|
@default_bonus ||= attributes.each_with_object({}) { |attr, hash| hash[attr.to_sym] = 0 }
|
117
126
|
end
|
127
|
+
|
128
|
+
def movement_speed_per_level
|
129
|
+
0
|
130
|
+
end
|
118
131
|
end
|
119
132
|
end
|
data/lib/smite/item_effect.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module Smite
|
2
2
|
class ItemEffect < Smite::Object
|
3
|
-
attr_reader :device_name
|
3
|
+
attr_reader :device_name
|
4
4
|
|
5
5
|
def initialize(item, data)
|
6
6
|
@device_name = item
|
@@ -8,7 +8,7 @@ module Smite
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def percentage?
|
11
|
-
|
11
|
+
!percentage.nil?
|
12
12
|
end
|
13
13
|
|
14
14
|
def inspect
|