smite_ruby 1.4.3 → 1.4.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +60 -0
  3. data/README.md +35 -21
  4. data/lib/smite.rb +18 -14
  5. data/lib/smite/client.rb +95 -13
  6. data/lib/smite/data_transform.rb +8 -8
  7. data/lib/smite/game.rb +43 -30
  8. data/lib/smite/getgods.json +151 -0
  9. data/lib/smite/god.rb +1 -1
  10. data/lib/smite/god_rank.rb +1 -1
  11. data/lib/smite/god_stats.rb +11 -13
  12. data/lib/smite/item.rb +18 -4
  13. data/lib/smite/motd.rb +19 -0
  14. data/lib/smite/object.rb +2 -1
  15. data/lib/smite/player.rb +20 -35
  16. data/lib/smite/queue.rb +19 -0
  17. data/lib/smite/recent_match.rb +18 -0
  18. data/lib/smite/recommended_items.rb +22 -0
  19. data/smite_ruby.gemspec +4 -2
  20. data/spec/ability_spec.rb +7 -0
  21. data/spec/achievements_spec.rb +7 -0
  22. data/spec/client_spec.rb +52 -0
  23. data/spec/data_transform_spec.rb +7 -0
  24. data/spec/friend_spec.rb +7 -0
  25. data/spec/game_spec.rb +200 -0
  26. data/spec/god_rank_spec.rb +7 -0
  27. data/spec/god_spec.rb +57 -0
  28. data/spec/god_stats_spec.rb +7 -0
  29. data/spec/item_effect_spec.rb +7 -0
  30. data/spec/item_spec.rb +85 -0
  31. data/spec/match_spec.rb +7 -0
  32. data/spec/player_spec.rb +76 -0
  33. data/spec/responses/createsession.json +1 -0
  34. data/spec/responses/getachievements.json +11 -0
  35. data/spec/responses/getdataused.json +1 -0
  36. data/spec/responses/getesportsproleaguedetails.json +1 -0
  37. data/spec/responses/getfriends.json +44 -0
  38. data/spec/responses/getgodranks.json +71 -0
  39. data/spec/responses/getgodrecommendeditems.json +1 -0
  40. data/spec/responses/getgods.json +461 -0
  41. data/spec/responses/getitems.json +118 -0
  42. data/spec/responses/getleagueleaderboard.json +1 -0
  43. data/spec/responses/getleagueseasons.json +1 -0
  44. data/spec/responses/getmatchdetails.json +1 -0
  45. data/spec/responses/getmatchhistory.json +61 -0
  46. data/spec/responses/getmatchidsbyqueue.json +1 -0
  47. data/spec/responses/getmatchplayerdetails.json +1 -0
  48. data/spec/responses/getmotd.json +37 -0
  49. data/spec/responses/getplayer.json +57 -0
  50. data/spec/responses/getplayerstatus.json +1 -0
  51. data/spec/responses/getqueuestats.json +1 -0
  52. data/spec/responses/getsearchteams.json +1 -0
  53. data/spec/responses/getteamdetails.json +1 -0
  54. data/spec/responses/getteamplayers.json +1 -0
  55. data/spec/responses/gettopmatches.json +1 -0
  56. data/spec/responses/testsession.json +1 -0
  57. data/spec/shared_examples/smite_object.rb +17 -0
  58. data/spec/spec_helper.rb +51 -0
  59. metadata +75 -2
@@ -0,0 +1,151 @@
1
+ [
2
+ {
3
+ "Ability1" : "Noxious Fumes",
4
+ "Ability2" : "Flame Wave",
5
+ "Ability3" : "Path of Flames",
6
+ "Ability4" : "Rain Fire",
7
+ "Ability5" : "Combustion",
8
+ "AbilityId1" : 7812,
9
+ "AbilityId2" : 7811,
10
+ "AbilityId3" : 7818,
11
+ "AbilityId4" : 7824,
12
+ "AbilityId5" : 7822,
13
+ "Ability_1" :
14
+ {"Description" :
15
+ {"itemDescription" :
16
+ {"cooldown" : "12s",
17
+ "cost" : "60/70/80/90/100",
18
+ "description" :
19
+ "Agni summons a cloud of noxious fumes at his ground target location, doing damage every second. Firing any of Agni's abilities into the fumes detonates the gas, Stunning all enemies in the radius.",
20
+ "menuitems" :
21
+ [{"description" : "Ability:", "value" : "Ground Target"},
22
+ {"description" : "Affects:", "value" : "Enemy"},
23
+ {"description" : "Damage:", "value" : "Magical"},
24
+ {"description" : "Radius:", "value" : "20"}],
25
+ "rankitems" :
26
+ [{"description" : "Damage per Tick:", "value" : "10/20/30/40/50 (+5% of your Magical Power)"},
27
+ {"description" : "Fumes Duration:", "value" : "10s"},
28
+ {"description" : "Stun Duration:", "value" : "1s"}],
29
+ "secondaryDescription" : ""}},
30
+ "Id" : 7812,
31
+ "Summary" : "Noxious Fumes",
32
+ "URL" : "https://hzweb.hi-rezgame.net/smite-web/wp-content/uploads/2015/05/1737_78121.jpg"},
33
+ "Ability_2" :
34
+ {"Description" :
35
+ {"itemDescription" :
36
+ {"cooldown" : "15/14/13/12/11s",
37
+ "cost" : "60/70/80/90/100",
38
+ "description" : "Agni summons a wave of fire in front of him that scorches all enemies in its path. Ignites Noxious Fumes.",
39
+ "menuitems" :
40
+ [{"description" : "Ability:", "value" : "Line"},
41
+ {"description" : "Affects:", "value" : "Enemy"},
42
+ {"description" : "Damage:", "value" : "Magical"}],
43
+ "rankitems" : [{"description" : "Damage:", "value" : "90/140/190/240/290 (+50% of your Magical Power)"}],
44
+ "secondaryDescription" : ""}},
45
+ "Id" : 7811,
46
+ "Summary" : "Flame Wave",
47
+ "URL" : "https://hzweb.hi-rezgame.net/smite-web/wp-content/uploads/2015/05/1737_78111.jpg"},
48
+ "Ability_3" :
49
+ {"Description" :
50
+ {"itemDescription" :
51
+ {"cooldown" : "15s",
52
+ "cost" : "70/75/80/85/90",
53
+ "description" :
54
+ "Agni blazes a path forward in a quick dash, leaving flames trailing behind him. Any enemies passing through the flames catch fire and burn for damage every .5s for 2s. Ignites Noxious Fumes. Agni is immune to Knockback while dashing.",
55
+ "menuitems" :
56
+ [{"description" : "Ability:", "value" : "Dash"},
57
+ {"description" : "Affects:", "value" : "Enemy"},
58
+ {"description" : "Damage:", "value" : "Magical"}],
59
+ "rankitems" :
60
+ [{"description" : "Damage per Tick:", "value" : "20/30/40/50/60 (+15% of your Magical Power)"},
61
+ {"description" : "Path Duration:", "value" : "3s"}],
62
+ "secondaryDescription" : ""}},
63
+ "Id" : 7818,
64
+ "Summary" : "Path of Flames",
65
+ "URL" : "https://hzweb.hi-rezgame.net/smite-web/wp-content/uploads/2015/05/1737_78181.jpg"},
66
+ "Ability_4" :
67
+ {"Description" :
68
+ {"itemDescription" :
69
+ {"cooldown" : "Dependent on Halos",
70
+ "cost" : "0",
71
+ "description" :
72
+ "Every 20 seconds, Agni gains a flaming halo that can be expended to summon a giant meteor at his ground target location. He can summon 1 every .8 seconds. Ignites Noxious Fumes.",
73
+ "menuitems" :
74
+ [{"description" : "Ability:", "value" : "Ground Target"},
75
+ {"description" : "Affects:", "value" : "Enemy"},
76
+ {"description" : "Damage:", "value" : "Magical"},
77
+ {"description" : "Radius:", "value" : "20"}],
78
+ "rankitems" :
79
+ [{"description" : "Damage:", "value" : "160/195/230/265/300 (+60% of your Magical Power)"},
80
+ {"description" : "Max Halos:", "value" : "3"}],
81
+ "secondaryDescription" : ""}},
82
+ "Id" : 7824,
83
+ "Summary" : "Rain Fire",
84
+ "URL" : "https://hzweb.hi-rezgame.net/smite-web/wp-content/uploads/2015/05/1737_78241.jpg"},
85
+ "Ability_5" :
86
+ {"Description" :
87
+ {"itemDescription" :
88
+ {"cooldown" : "",
89
+ "cost" : "",
90
+ "description" :
91
+ "After hitting with 4 Basic Attacks, Agni will gain a Buff. On the next cast of Flame Wave or Rain Fire, all enemies hit by those abilities will be additionally set ablaze, taking damage every .5s for 3s.",
92
+ "menuitems" : [{"description" : "Affects:", "value" : "Enemy"}, {"description" : "Damage:", "value" : "Magical"}],
93
+ "rankitems" : [{"description" : "Damage per Tick:", "value" : "5 (+10% of your Magical Power)"}],
94
+ "secondaryDescription" : ""}},
95
+ "Id" : 7822,
96
+ "Summary" : "Combustion",
97
+ "URL" : "https://hzweb.hi-rezgame.net/smite-web/wp-content/uploads/2015/05/1737_78221.jpg"},
98
+ "AttackSpeed" : 0.86,
99
+ "AttackSpeedPerLevel" : 0.009,
100
+ "Cons" : "",
101
+ "HP5PerLevel" : 0.47,
102
+ "Health" : 360,
103
+ "HealthPerFive" : 7,
104
+ "HealthPerLevel" : 71,
105
+ "Lore" : "There are few elements as destructive or as purifying as fire. Agni, God of Fire, is the embodiment of both of these qualities, with a head for each.\\n\\nThough the source of his origin warrants debate - for there are many tales of his parentage ranging from two simple sticks rubbed together, to the cosmic energy that made all things at the beginning of time - Agni is a pivotal and important God with many duties to the Pantheon. He is the twin brother to Indra, God of the Heavens and Rains and chief among warriors. Conversely, Agni is chief among priests, acting as messenger between mortals and Gods. Every Hindu ritual and prayer is performed in front of a fire of some kind, so Agni carries the words and sacrifices, traveling between the Earth and the Heavens. He is welcome in every home and every hearth and much beloved by the Faithful.\\n\\nThrough his flames, Agni provides heat and light, but also cleanses impurities. Smoke from his pyres create the air and hold the Heavens aloft. The sun, a source of fire itself, brings life-giving energy to the world, and his lightning streaks the sky during storms.\\n\\nFor all his kindness and service, Agni has two faces. One is the face of kindness and purity, turned towards the people and Gods. His other face, grim and resolute, guides the God of Fire, to play his role in the cosmic cycle of creation and destruction, to burn and blacken all the atrocities of the world to ash.",
106
+ "MP5PerLevel" : 0.37,
107
+ "MagicProtection" : 30,
108
+ "MagicProtectionPerLevel" : 0,
109
+ "MagicalPower" : 170,
110
+ "MagicalPowerPerLevel" : 7.5,
111
+ "Mana" : 255,
112
+ "ManaPerFive" : 4.7,
113
+ "ManaPerLevel" : 45,
114
+ "Name" : "Agni",
115
+ "OnFreeRotation" : "",
116
+ "Pantheon" : "Hindu",
117
+ "PhysicalPower" : 0,
118
+ "PhysicalPowerPerLevel" : 0,
119
+ "PhysicalProtection" : 11,
120
+ "PhysicalProtectionPerLevel" : 2.6,
121
+ "Pros" : " High Area Damage",
122
+ "Roles" : " Mage",
123
+ "Speed" : 350,
124
+ "Title" : "God of Fire",
125
+ "Type" : " Ranged, Magical",
126
+ "abilityDescription1" : {},
127
+ "abilityDescription2" : {},
128
+ "abilityDescription3" : {},
129
+ "abilityDescription4" : {},
130
+ "abilityDescription5" : {},
131
+ "basicAttack" :
132
+ {"itemDescription" :
133
+ {"cooldown" : "",
134
+ "cost" : "",
135
+ "description" : "",
136
+ "menuitems" :
137
+ [{"description" : "Damage:", "value" : "34 + 1.5/Lvl (+20% of Magical Power)"}, {"description" : "Progression:", "value" : "None"}],
138
+ "rankitems" : [],
139
+ "secondaryDescription" : ""}},
140
+ "godAbility1_URL" : "https://hzweb.hi-rezgame.net/smite-web/wp-content/uploads/2015/05/1737_78121.jpg",
141
+ "godAbility2_URL" : "https://hzweb.hi-rezgame.net/smite-web/wp-content/uploads/2015/05/1737_78111.jpg",
142
+ "godAbility3_URL" : "https://hzweb.hi-rezgame.net/smite-web/wp-content/uploads/2015/05/1737_78181.jpg",
143
+ "godAbility4_URL" : "https://hzweb.hi-rezgame.net/smite-web/wp-content/uploads/2015/05/1737_78241.jpg",
144
+ "godAbility5_URL" : "https://hzweb.hi-rezgame.net/smite-web/wp-content/uploads/2015/05/1737_78221.jpg",
145
+ "godCard_URL" : "https://hzweb.hi-rezgame.net/smite-web/wp-content/uploads/2015/05/standardagni_card.jpg",
146
+ "godIcon_URL" : "http://hirezstudios.blob.core.windows.net/sitefinity/smite-god-icons/1737.jpg",
147
+ "id" : 1737,
148
+ "latestGod" : "n",
149
+ "ret_msg" : null
150
+ }
151
+ ]
data/lib/smite/god.rb CHANGED
@@ -7,7 +7,7 @@ module Smite
7
7
  end
8
8
 
9
9
  def on_free_rotation?
10
- !on_free_rotation.blank?
10
+ !on_free_rotation.empty?
11
11
  end
12
12
 
13
13
  def ranged?
@@ -1,7 +1,7 @@
1
1
  module Smite
2
2
  class GodRank < Smite::Object
3
3
  def initialize(data)
4
- @data = DataTransform.transform_gods(data)
4
+ super(DataTransform.transform_gods(data))
5
5
  end
6
6
 
7
7
  def level
@@ -1,23 +1,20 @@
1
1
  module Smite
2
2
  class GodStats < Smite::Object
3
- attr_reader :name, :item_bonus
4
- attr_accessor :level, :items
3
+ attr_reader :name, :level, :items
5
4
 
6
- def initialize(god_name, data)
5
+ def initialize(god_name, data, params = { level: 1 })
7
6
  super(data)
8
- @name = god_name
9
- @items = []
10
- @level = 0
11
- @item_bonus = default_bonus
7
+ @name = god_name
8
+ @items = params[:items] || []
9
+ @level = (params[:level].to_i - 1) % 20
12
10
  end
13
11
 
14
- def level=(new_level)
15
- @level = (new_level.to_i - 1) % 20
12
+ def at_level(new_level)
13
+ GodStats.new(name, @data, { level: new_level, items: items })
16
14
  end
17
15
 
18
- def items=(new_items)
19
- @items = new_items
20
- @item_bonus = default_bonus
16
+ def with_items(new_items)
17
+ GodStats.new(name, @data, { level: level, items: new_items })
21
18
  end
22
19
 
23
20
  def movement_speed
@@ -92,8 +89,9 @@ module Smite
92
89
  end
93
90
 
94
91
  def item_bonus
95
- return @item_bonus unless @item_bonus == default_bonus and !items.empty?
92
+ return @item_bonus unless @item_bonus.nil?
96
93
 
94
+ @item_bonus = default_bonus
97
95
  items.map(&:effects).flatten.select do |effect|
98
96
  next unless attributes.include?(effect.attribute)
99
97
  @item_bonus[effect.attribute.to_sym] += effect.amount
data/lib/smite/item.rb CHANGED
@@ -2,10 +2,12 @@ module Smite
2
2
  class Item < Smite::Object
3
3
 
4
4
  def initialize(data)
5
- super
5
+ super(data)
6
6
  effects = @data.delete('item_description')
7
7
  @data['description'] = effects.delete('Description')
8
- @data['effects'] = effects['Menuitems'].map { |eff| ItemEffect.new(device_name, eff)}
8
+ @data['effects'] = effects['Menuitems'].map do |eff|
9
+ ItemEffect.new(device_name, eff)
10
+ end
9
11
  end
10
12
 
11
13
  def active?
@@ -20,12 +22,24 @@ module Smite
20
22
  type == 'Item'
21
23
  end
22
24
 
25
+ def starter?
26
+ starting_item
27
+ end
28
+
29
+ def name
30
+ device_name
31
+ end
32
+
23
33
  def physical?
24
- @physical ||= effects.map(&:attribute).any? { |eff| eff =~ /physical_(power|pen)/ }
34
+ @physical ||= !effects.map(&:attribute).any? do |eff|
35
+ eff =~ /magic(al)?_(power|pen)/
36
+ end
25
37
  end
26
38
 
27
39
  def magic?
28
- !physical?
40
+ @magic ||= !effects.map(&:attribute).any? do |eff|
41
+ eff =~ /physical_(power|pen)/
42
+ end
29
43
  end
30
44
 
31
45
  def inspect
data/lib/smite/motd.rb ADDED
@@ -0,0 +1,19 @@
1
+ module Smite
2
+ class MOTD < Smite::Object
3
+ def initialize(data)
4
+ super(data)
5
+ @data['description'] = @data['description'].scan(/<li>([^<>]+)/).join("\n")
6
+ @data['team1_gods'] = @data.delete('team1_gods_csv').split(/,\s/)
7
+ @data['team2_gods'] = @data.delete('team2_gods_csv').split(/,\s/)
8
+ end
9
+
10
+ def date
11
+ parse = Date.strptime(start_date_time, '%m/%d/%Y %H:%M:%S')
12
+ parse.strftime('%m/%d')
13
+ end
14
+
15
+ def inspect
16
+ "#<Smite::MOTD #{date} #{title}'>"
17
+ end
18
+ end
19
+ end
data/lib/smite/object.rb CHANGED
@@ -4,6 +4,7 @@ module Smite
4
4
 
5
5
  def initialize(data)
6
6
  @data = data.each_with_object({}) do |(k, v), obj|
7
+ next if k == 'ret_msg'
7
8
  obj[ActiveSupport::Inflector.underscore(k)] = v
8
9
  end
9
10
  end
@@ -14,7 +15,7 @@ module Smite
14
15
 
15
16
  def method_missing(method)
16
17
  camel_method = ActiveSupport::Inflector.underscore(method.to_s)
17
- @data[camel_method] || super
18
+ @data.include?(camel_method) ? @data[camel_method] : super
18
19
  end
19
20
  end
20
21
  end
data/lib/smite/player.rb CHANGED
@@ -1,58 +1,43 @@
1
1
  module Smite
2
2
  class Player < Smite::Object
3
- attr_reader :client, :player_name
3
+ attr_reader :player_name
4
4
 
5
- def initialize(client, player_name)
6
- @client = client
5
+ def initialize(player_name)
7
6
  @player_name = player_name
8
- super(get_player)
7
+ super(Smite::Game.client.player(player_name)[0])
9
8
  end
10
9
 
11
10
  def friends
12
- @friends ||= get_friends.reject { |f| f['name'].empty? }.map(&Friend.method(:new))
11
+ return @friends unless @friends.nil?
12
+
13
+ @friends = Smite::Game.client.friends(player_name)
14
+ @friends = @friends.reject { |f| f['name'].empty? }
15
+ @friends.map!(&Friend.method(:new))
13
16
  end
14
17
 
15
18
  def god_ranks
16
- @ranks ||= get_god_ranks.map(&GodRank.method(:new))
19
+ return @ranks unless @ranks.nil?
20
+
21
+ @ranks = Smite::Game.client.god_ranks(player_name)
22
+ @ranks.map!(&GodRank.method(:new))
17
23
  end
18
24
 
19
25
  def match_history
20
- @history ||= get_match_history.map(&Match.method(:new))
26
+ return @history unless @history.nil?
27
+
28
+ @history = Smite::Game.client.match_history(player_name)
29
+ @history.map!(&RecentMatch.method(:new))
21
30
  end
22
31
 
23
32
  def achievements
24
- @achievements ||= Achievements.new(get_achievements)
33
+ return @achievements unless @achievements.nil?
34
+
35
+ achievements = Smite::Game.client.achievements(id)
36
+ @achievements = Achievements.new(achievements)
25
37
  end
26
38
 
27
39
  def inspect
28
40
  "#<Smite::Player '#{name}'>"
29
41
  end
30
-
31
- private
32
-
33
- # /getplayerachievementsjson/{developerId}/{signature}/{session}/{timestamp}/{playerId}
34
- def get_achievements
35
- client.api_call('getplayerachievements', [id])
36
- end
37
-
38
- # /getfriendsjson/{developerId}/{signature}/{session}/{timestamp}/{player}
39
- def get_friends
40
- client.api_call('getfriends', [player_name])
41
- end
42
-
43
- # /getgodranksjson/{developerId}/{signature}/{session}/{timestamp}/{player}
44
- def get_god_ranks
45
- client.api_call('getgodranks', [player_name])
46
- end
47
-
48
- # /getplayerjson/{developerId}/{signature}/{session}/{timestamp}/{player}
49
- def get_player
50
- client.api_call('getplayer', [player_name])[0]
51
- end
52
-
53
- # /getmatchhistoryjson/{developerId}/{signature}/{session}/{timestamp}/{player}
54
- def get_match_history
55
- client.api_call('getmatchhistory', [player_name])
56
- end
57
42
  end
58
43
  end
@@ -0,0 +1,19 @@
1
+ module Smite
2
+ class Queue < Smite::Object
3
+ QUEUES = [
4
+ { 'name' => 'Conquest', 'id' => 426 },
5
+ { 'name' => 'MOTD', 'id' => 434 },
6
+ { 'name' => 'Arena', 'id' => 435 },
7
+ { 'name' => 'JoustLeague', 'id' => 440 },
8
+ { 'name' => 'Assault', 'id' => 445 },
9
+ { 'name' => 'Joust3v3', 'id' => 448 },
10
+ { 'name' => 'ConquestLeague', 'id' => 451 },
11
+ { 'name' => 'MOTD', 'id' => 465 },
12
+ { 'name' => 'Clash', 'id' => 466 },
13
+ ]
14
+
15
+ def inspect
16
+ "#<Smite::Queue #{id} #{name}>"
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,18 @@
1
+ module Smite
2
+ class RecentMatch < Smite::Object
3
+ def initialize(data)
4
+ super
5
+ @data = DataTransform.transform_gods(@data)
6
+ @data = DataTransform.transform_items(@data)
7
+ @data = DataTransform.transform_recent_match(@data)
8
+ end
9
+
10
+ def id
11
+ match
12
+ end
13
+
14
+ def inspect
15
+ "#<Smite::RecentMatch #{match} '#{queue}' (#{win_status})>"
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,22 @@
1
+ module Smite
2
+ class RecommendedItems < Smite::Object
3
+ attr_reader :god_name, :role
4
+ def initialize(god_name, data, role)
5
+ @god_name = god_name
6
+ @role = role.downcase
7
+ new_data = {}
8
+
9
+ data.each do |rec|
10
+ next unless rec['Role'].downcase == @role
11
+
12
+ new_data[rec['Category']] ||= []
13
+ new_data[rec['Category']] << Smite::Game.device(rec['item_id'])
14
+ end
15
+ super(new_data)
16
+ end
17
+
18
+ def inspect
19
+ "#<Smite::RecommendedItems '#{god_name}' Role: '#{role}'>"
20
+ end
21
+ end
22
+ end
data/smite_ruby.gemspec CHANGED
@@ -1,8 +1,8 @@
1
1
  $:.push File.expand_path("../lib", __FILE__)
2
2
  Gem::Specification.new do |s|
3
3
  s.name = 'smite_ruby'
4
- s.version = '1.4.3'
5
- s.date = '2016-01-29'
4
+ s.version = '1.4.5'
5
+ s.date = '2016-02-01'
6
6
  s.summary = 'Ruby Smite API'
7
7
  s.description = 'Ruby Client for consuming the Smite API'
8
8
  s.authors = ['NcUltimate']
@@ -14,4 +14,6 @@ Gem::Specification.new do |s|
14
14
 
15
15
  s.add_runtime_dependency 'httparty'
16
16
  s.add_runtime_dependency 'activesupport'
17
+ s.add_development_dependency 'rspec'
18
+ s.add_development_dependency 'webmock'
17
19
  end