smite_ruby 1.0.0 → 1.4.3

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: ffc0afcaab87a86ac938f41c576b59b220c64c6e
4
- data.tar.gz: 77a44fdc4fe805474748ffdd6200d49828d9f65e
3
+ metadata.gz: f7cc4f043f27ebe004f8229cced90833f57b4a9d
4
+ data.tar.gz: e5da84e81525ac97b6eb90a7e9328ddbccd02149
5
5
  SHA512:
6
- metadata.gz: 1e8c917914fe5444416b85db26896b1dff98f2642f2c3a6c53d923f3e83e164d3fbd9b1ae9515b529ec5a52ee9e97a824574ef336410aba3d5052a86ca1bc826
7
- data.tar.gz: e0fd9755561013dc80ade5073c54127f545a27738006fd57f2bf0c318018c0d533ea109f51925b220fb6d24c883091c9fb970ced732e0abc1e00ec542dea45e7
6
+ metadata.gz: c8c26832c6684d221ee1fb1a996d1a13115ea28e184be0f4a1ccd02b6e3ddf83efbb4d0862be79b94eaeef14aca0610dacad19f4f81989be57c53125a60ed137
7
+ data.tar.gz: 7c3a974eb29097b4798f47340c28da5af0379c39217ae5ec47d4e68bfba3dfad1c0a78120f792d7e95481f649eb50568ed705faf7e7da0b03be09c20db15b4e2
data/README.md ADDED
@@ -0,0 +1,190 @@
1
+ # Smite API Client for Ruby
2
+ ---
3
+ 1. `gem install smite_ruby`
4
+ 2. `require 'smite'`
5
+
6
+ # Examples -- Smite::Game
7
+ ---
8
+
9
+ ### Creating a session
10
+ ```
11
+ > Smite::Game.authenticate!(<dev_id>, <auth_key>)
12
+ Smite::Game
13
+ ```
14
+
15
+ ### Finding a player
16
+ ```
17
+ > Smite::Game.player('adapting')
18
+ #<Smite::Player '[Epsi]Adapting'>
19
+ ```
20
+
21
+ ### Listing/finding gods
22
+ ```
23
+ > Smite::Game.gods
24
+ [#<Smite::God 'Agni'>,
25
+ #<Smite::God 'Ah Muzen Cab'>,
26
+ #<Smite::God 'Ah Puch'>,
27
+ #<Smite::God 'Amaterasu'>,
28
+ ...]
29
+
30
+ > Smite::Game.god('Agni')
31
+ #<Smite::God 'Agni'>
32
+
33
+ > Smite::Game.god(2065)
34
+ #<Smite::God 'Ravana'>
35
+ ```
36
+
37
+ ### Listing/finding items
38
+ ```
39
+ > Smite::Game.items
40
+ [#<Smite::Item 'Iron Mail'>,
41
+ #<Smite::Item 'Steel Mail'>,
42
+ #<Smite::Item 'Sovereignty'>,
43
+ #<Smite::Item 'Mystical Mail'>,
44
+ ...]
45
+
46
+ > Smite::Game.item('Gem of Isolation')
47
+ #<Smite::Item 'Gem of Isolation'>
48
+
49
+ > Smite::Game.item(7526)
50
+ #<Smite::Item 'Iron Mail'>
51
+ ```
52
+ # Examples -- Smite::Player
53
+ ---
54
+ ```
55
+ > player = Smite::Game.player('adapting')
56
+ #<Smite::Player '[Epsi]Adapting'>
57
+
58
+ > player.mastery_level
59
+ 66
60
+ ```
61
+
62
+
63
+ ### Listing friends
64
+ ```
65
+ > player.friends
66
+ [#<Smite::Friend 'aBROcalypse'>,
67
+ #<Smite::Friend 'Adopting'>,
68
+ #<Smite::Friend 'Advert'>,
69
+ #<Smite::Friend 'Aengy'>,
70
+ #<Smite::Friend 'Aiurz'>,
71
+ ...]
72
+
73
+ > player.friends[0].to_player
74
+ #<Smite::Player '[Aluma]aBROcalypse'>
75
+ ```
76
+
77
+ ### Listing god ranks
78
+ ```
79
+ > player.god_ranks
80
+ [#<Smite::GodRank 'Thor' Lvl. 10 (diamond)>,
81
+ #<Smite::GodRank 'Mercury' Lvl. 10 (diamond)>,
82
+ #<Smite::GodRank 'Freya' Lvl. 10 (diamond)>,
83
+ #<Smite::GodRank 'Hun Batz' Lvl. 10 (diamond)>,
84
+ #<Smite::GodRank 'Kali' Lvl. 10 (diamond)>,
85
+ #<Smite::GodRank 'Poseidon' Lvl. 10 (diamond)>,
86
+ ...]
87
+ ```
88
+
89
+ ### Listing achievements (WIP)
90
+ ```
91
+ > player.achievements
92
+ {"DoubleKills"=>5275,
93
+ "FirstBloods"=>1430,
94
+ "Id"=>2784051,
95
+ "Name"=>"Adapting",
96
+ "PentaKills"=>21,
97
+ "QuadraKills"=>137,
98
+ "TowerKills"=>5183,
99
+ "TripleKills"=>803,
100
+ "ret_msg"=>nil}
101
+ ```
102
+ ### Listing match history
103
+ ```
104
+ > player.match_history
105
+ [#<Smite::Match 'Leagues: Conquest' 'Win'>,
106
+ #<Smite::Match 'Leagues: Conquest' 'Loss'>,
107
+ #<Smite::Match 'Leagues: Conquest' 'Win'>,
108
+ #<Smite::Match 'Leagues: Conquest' 'Win'>,
109
+ #<Smite::Match 'Leagues: Conquest' 'Loss'>,
110
+ #<Smite::Match 'Leagues: Conquest' 'Win'>,
111
+ ... ]
112
+ ```
113
+ # Examples -- Smite::Match
114
+ ---
115
+ ```
116
+ > match = player.match_history[0]
117
+ #<Smite::Match 'Leagues: Conquest' 'Win'>
118
+
119
+ > match.god
120
+ #<Smite::God 'Ne Zha'>
121
+
122
+ > match.items
123
+ [#<Smite::Item 'Purification Beads'>,
124
+ #<Smite::Item 'Aegis Amulet'>,
125
+ #<Smite::Item 'Bumba's Mask'>,
126
+ #<Smite::Item 'Warrior Tabi'>,
127
+ #<Smite::Item 'Jotunn's Wrath'>,
128
+ #<Smite::Item 'Deathbringer'>,
129
+ nil,
130
+ nil]
131
+
132
+ > match.killing_spree
133
+ 2
134
+ ```
135
+ # Examples -- Smite::God
136
+ ---
137
+ ```
138
+ > merc = Smite::Game.god('Mercury')
139
+ #<Smite::God 'Mercury'>
140
+
141
+ > merc.abilities
142
+ [#<Smite::Ability 'Made You Look'>,
143
+ #<Smite::Ability 'Maximum Velocity'>,
144
+ #<Smite::Ability 'Special Delivery'>,
145
+ #<Smite::Ability 'Sonic Boom'>,
146
+ #<Smite::Ability 'Fastest God Alive'>]
147
+
148
+ > merc.speed
149
+ 375
150
+ ```
151
+ # Examples -- Smite::GodRank
152
+ ---
153
+ ```
154
+ > rank = player.god_ranks[0]
155
+ #<Smite::GodRank 'Thor' Lvl. 10 (diamond)>
156
+
157
+ > rank.mastered?
158
+ true
159
+ > rank.level
160
+ "diamond"
161
+ > rank.rank
162
+ 10
163
+ > rank.worshippers
164
+ 4517
165
+ ```
166
+ # Examples -- Smite::Item
167
+ ---
168
+ ```
169
+ > bov = Smite::Game.item('Breastplate of Valor')
170
+ #<Smite::Item 'Breastplate of Valor'>
171
+
172
+ > bov.item_tier
173
+ 3
174
+ > bov.short_desc
175
+ "Reduces ability Cooldowns."
176
+
177
+
178
+
179
+
180
+
181
+
182
+
183
+
184
+
185
+
186
+
187
+
188
+
189
+
190
+
data/lib/smite.rb CHANGED
@@ -5,9 +5,12 @@ module Smite
5
5
  end
6
6
 
7
7
  require 'smite/object.rb'
8
+ require 'smite/achievements.rb'
8
9
  require 'smite/ability.rb'
9
10
  require 'smite/god_rank.rb'
11
+ require 'smite/god_stats.rb'
10
12
  require 'smite/god.rb'
13
+ require 'smite/item_effect.rb'
11
14
  require 'smite/item.rb'
12
15
  require 'smite/friend.rb'
13
16
  require 'smite/data_transform.rb'
@@ -0,0 +1,7 @@
1
+ module Smite
2
+ class Achievements < Smite::Object
3
+ def inspect
4
+ "#<Smite::Achievements '#{name}'>"
5
+ end
6
+ end
7
+ end
data/lib/smite/client.rb CHANGED
@@ -33,6 +33,10 @@ module Smite
33
33
  self.class.get(request)
34
34
  end
35
35
 
36
+ def valid_session?
37
+ !!(test_session =~ /successful/i)
38
+ end
39
+
36
40
  private
37
41
 
38
42
  def signature(method)
@@ -44,10 +48,6 @@ module Smite
44
48
  Time.now.utc.strftime('%Y%m%d%H%M%S')
45
49
  end
46
50
 
47
- def valid_session?
48
- test_session =~ /successful/i
49
- end
50
-
51
51
  def request_str(method, params, session)
52
52
  base = base_str(method)
53
53
  parm = param_str(params)
@@ -1,91 +1,136 @@
1
1
  module Smite
2
2
  class DataTransform
3
+ class << self
3
4
 
4
- def self.transform(data)
5
- new_data = data.dup
6
- new_data = transform_items(new_data)
7
- new_data = transform_gods(new_data)
8
- new_data = transform_abilities(new_data)
9
- transform_match(new_data)
10
- end
5
+ def transform_items(data)
6
+ item_fields = data.slice(*item_map_fields)
7
+ return data if item_fields.empty?
11
8
 
12
- def self.transform_items(data)
13
- item_fields = data.slice(*item_map_fields)
14
- return data if item_fields.empty?
9
+ data['items'] = item_fields.values.map { |id| Smite::Game.item(id.to_i) }
10
+ data.except(*item_filter_fields)
11
+ end
15
12
 
16
- data['items'] = item_fields.values.map { |id| Smite::Game.item(id.to_i) }
17
- data.except(*item_filter_fields)
18
- end
13
+ def transform_gods(data)
14
+ god_fields = data.slice(*god_map_fields)
15
+ return data if god_fields.empty?
19
16
 
20
- def self.transform_gods(data)
21
- god_fields = data.slice(*god_map_fields)
22
- return data if god_fields.empty?
17
+ data['god'] = god_fields.values.map { |id| Smite::Game.god(id.to_i) }[0]
18
+ data.except(*god_filter_fields)
19
+ end
23
20
 
24
- data['god'] = god_fields.values.map { |id| Smite::Game.god(id.to_i) }[0]
25
- data.except(*god_filter_fields)
26
- end
21
+ def transform_abilities(data)
22
+ ability_fields = data.slice(*ability_map_fields)
23
+ return data if ability_fields.empty?
27
24
 
28
- def self.transform_abilities(data)
29
- ability_fields = data.slice(*ability_map_fields)
30
- return data if ability_fields.empty?
25
+ data['abilities'] = ability_fields.values.map do |ability_data|
26
+ data_attrs = ability_data.slice('Id', 'Summary', 'URL')
27
+ desc = ability_data['Description']['itemDescription']
31
28
 
32
- data['abilities'] = ability_fields.values.map do |ability_data|
33
- data_attrs = ability_data.slice('Id', 'Summary', 'URL')
34
- desc = ability_data['Description']['itemDescription']
29
+ Ability.new(data_attrs.merge(desc))
30
+ end
35
31
 
36
- Ability.new(data_attrs.merge(desc))
32
+ data.except(*ability_filter_fields)
37
33
  end
38
34
 
39
- data.except(*ability_filter_fields)
40
- end
35
+ def transform_match(data)
36
+ return data unless data['Queue']
37
+
38
+ if data['Queue'] =~ /League/
39
+ data
40
+ else
41
+ data.except(*match_filter_fields)
42
+ end
43
+ end
41
44
 
42
- def self.transform_match(data)
43
- return data unless data['Queue']
45
+ def transform_stats(data)
46
+ stat_fields = data.slice(*stats_map_fields)
47
+ return data if stat_fields.empty?
44
48
 
45
- if data['Queue'] =~ /League/
49
+ stat_fields['movement_speed'] = stat_fields.delete('speed')
50
+ stat_fields['mp5'] = stat_fields.delete('mana_per_five')
51
+ stat_fields['hp5'] = stat_fields.delete('health_per_five')
52
+ data['stats'] = GodStats.new(data['name'], stat_fields)
53
+ data.except(*stats_filter_fields)
54
+ end
55
+
56
+ def transform_item_effect(data)
57
+ return unless data['Description'] and data['Value']
58
+
59
+ effect = data.delete('Description').tr(' ','')
60
+ effect = ActiveSupport::Inflector.underscore(effect)
61
+ data['attribute'] = effect
62
+
63
+ value = data.delete('Value')
64
+ @percentage = value[/%/]
65
+ value = value.tr('+', '').to_i
66
+ data['amount'] = value
46
67
  data
47
- else
48
- data.except(*match_filter_fields)
49
68
  end
50
- end
51
69
 
52
- def self.item_map_fields
53
- %w( ActiveId1 ActiveId2 ItemId1 ItemId2 ItemId3 ItemId4 ItemId5 ItemId6 )
54
- end
70
+ private
55
71
 
56
- def self.item_filter_fields
57
- item_map_fields + %w(
58
- Item_1 Item_2 Item_3 Item_4 Item_5 Item_6 Active_1 Active_2 Active_3
59
- )
60
- end
72
+ def item_map_fields
73
+ %w(
74
+ active_id1 active_id2 item_id1 item_id2
75
+ item_id3 item_id4 item_id5 item_id6
76
+ )
77
+ end
61
78
 
62
- def self.ability_map_fields
63
- %w( Ability_1 Ability_2 Ability_3 Ability_4 Ability_5 )
64
- end
79
+ def item_filter_fields
80
+ item_map_fields + %w(
81
+ item_1 item_2 item_3 item_4 item_5
82
+ item_6 active_1 active_2 active_3
83
+ )
84
+ end
65
85
 
66
- def self.ability_filter_fields
67
- ability_map_fields + %w(
68
- Ability1 Ability2 Ability3 Ability4 Ability5
69
- AbilityId1 AbilityId2 AbilityId3 AbilityId4 AbilityId5
70
- abilityDescription1 abilityDescription2
71
- abilityDescription3 abilityDescription4
72
- abilityDescription5
73
- )
74
- end
86
+ def ability_map_fields
87
+ %w( ability_1 ability_2 ability_3 ability_4 ability_5 )
88
+ end
75
89
 
76
- def self.match_filter_fields
77
- %w(
78
- Ban1 Ban2 Ban3 Ban4 Ban5 Ban6
79
- Ban1Id Ban2Id Ban3Id Ban4Id Ban5Id Ban6Id
80
- )
81
- end
90
+ def ability_filter_fields
91
+ ability_map_fields + %w(
92
+ ability1 ability2 ability3 ability4 ability5
93
+ ability_id1 ability_id2 ability_id3 ability_id4 ability_id5
94
+ ability_description1 ability_description2
95
+ ability_description3 ability_description4
96
+ ability_description5 god_ability1_url god_ability2_url
97
+ god_ability3_url god_ability4_url god_ability5_url
98
+ )
99
+ end
82
100
 
83
- def self.god_map_fields
84
- %w(GodId god_id)
85
- end
101
+ def match_filter_fields
102
+ %w(
103
+ ban1 ban2 ban3 ban4 ban5 ban6
104
+ ban1_id ban2_id ban3_id
105
+ ban4_id ban5_id ban6_id
106
+ )
107
+ end
86
108
 
87
- def self.god_filter_fields
88
- god_map_fields + %w(God)
109
+ def stats_map_fields
110
+ %w(
111
+ speed attack_speed attack_speed_per_level
112
+ health health_per_level
113
+ mana mana_per_level
114
+ mana_per_five mp5_per_level
115
+ health_per_five hp5_per_level
116
+ magical_power magical_power_per_level
117
+ physical_power physical_power_per_level
118
+ magic_protection magic_protection_per_level
119
+ physical_protection physical_protection_per_level
120
+ )
121
+ end
122
+
123
+ def stats_filter_fields
124
+ stats_map_fields
125
+ end
126
+
127
+ def god_map_fields
128
+ %w(god_id)
129
+ end
130
+
131
+ def god_filter_fields
132
+ god_map_fields + %w(god)
133
+ end
89
134
  end
90
135
  end
91
136
  end
data/lib/smite/game.rb CHANGED
@@ -1,22 +1,23 @@
1
1
  module Smite
2
2
  class Game
3
3
  class << self
4
- attr_reader :client,:lang_code
4
+ attr_reader :client, :lang_code
5
5
 
6
6
  def authenticate!(dev_id, auth_key, lang_code = 1)
7
7
  @client = Smite::Client.new(dev_id, auth_key)
8
8
  @lang_code = lang_code
9
- self
9
+ !client.session_id.empty?
10
10
  end
11
11
 
12
- def item(name_or_id)
13
- id_to_item[name_or_id] ||
14
- id_to_item[name_to_itemid[name_or_id]]
12
+ def device(name_or_id)
13
+ devices[device_hash[name_or_id]]
15
14
  end
15
+ alias_method :item, :device
16
+ alias_method :consumable, :device
17
+ alias_method :active, :device
16
18
 
17
19
  def god(name_or_id)
18
- id_to_god[name_or_id] ||
19
- id_to_god[name_to_godid[name_or_id]]
20
+ gods[god_hash[name_or_id]]
20
21
  end
21
22
 
22
23
  def match(match_id)
@@ -28,49 +29,39 @@ module Smite
28
29
  end
29
30
 
30
31
  def gods
31
- id_to_god.values
32
+ @gods ||= get_gods.map(&God.method(:new))
32
33
  end
33
34
 
34
- def items
35
- id_to_item.values
35
+ def devices
36
+ @devices ||= get_items.map(&Item.method(:new))
36
37
  end
37
38
 
38
- private
39
-
40
- def id_to_item
41
- return @id_to_item unless @id_to_item.nil?
42
-
43
- @id_to_item = get_items.map do |item_data|
44
- [item_data['ItemId'], Item.new(item_data)]
45
- end
46
- @id_to_item = Hash[@id_to_item]
39
+ def items
40
+ @items ||= devices.select(&:item?)
47
41
  end
48
42
 
49
- def id_to_god
50
- return @id_to_god unless @id_to_god.nil?
43
+ def consumables
44
+ @consumables ||= devices.select(&:consumable?)
45
+ end
51
46
 
52
- @id_to_god = get_gods.map do |god_data|
53
- [god_data['id'], God.new(god_data)]
54
- end
55
- @id_to_god = Hash[@id_to_god]
47
+ def actives
48
+ @actives ||= devices.select(&:active?)
56
49
  end
57
50
 
58
- def name_to_itemid
59
- return @name_to_itemid unless @name_to_itemid.nil?
51
+ private
60
52
 
61
- @name_to_itemid = id_to_item.map do |id, item|
62
- [item.device_name, id]
53
+ def device_hash
54
+ @device_hash ||= (0...devices.count).each_with_object({}) do |idx, hash|
55
+ hash[devices[idx].item_id] = idx
56
+ hash[devices[idx].device_name] = idx
63
57
  end
64
- @name_to_itemid = Hash[@name_to_itemid]
65
58
  end
66
59
 
67
- def name_to_godid
68
- return @name_to_godid unless @name_to_godid.nil?
69
-
70
- @name_to_godid = id_to_god.map do |id, god|
71
- [god.name, id]
60
+ def god_hash
61
+ @god_hash ||= (0...gods.count).each_with_object({}) do |idx, hash|
62
+ hash[gods[idx].id] = idx
63
+ hash[gods[idx].name] = idx
72
64
  end
73
- @name_to_godid = Hash[@name_to_godid]
74
65
  end
75
66
 
76
67
  # /getmatchdetails[ResponseFormat]/{developerId}/{signature}/{session}/{timestamp}/{match_id}
data/lib/smite/god.rb CHANGED
@@ -1,11 +1,33 @@
1
1
  module Smite
2
2
  class God < Smite::Object
3
3
  def initialize(data)
4
- @data = DataTransform.transform_abilities(data)
4
+ super
5
+ @data = DataTransform.transform_abilities(@data)
6
+ @data = DataTransform.transform_stats(@data)
7
+ end
8
+
9
+ def on_free_rotation?
10
+ !on_free_rotation.blank?
11
+ end
12
+
13
+ def ranged?
14
+ !!(type =~ /Ranged/i)
15
+ end
16
+
17
+ def melee?
18
+ !ranged?
19
+ end
20
+
21
+ def physical?
22
+ !!(type =~ /Physical/i)
23
+ end
24
+
25
+ def magic?
26
+ !physical?
5
27
  end
6
28
 
7
29
  def inspect
8
- "#<Smite::God '#{name}'>"
30
+ "#<Smite::God #{id} '#{name}'>"
9
31
  end
10
32
  end
11
33
  end
@@ -0,0 +1,121 @@
1
+ module Smite
2
+ class GodStats < Smite::Object
3
+ attr_reader :name, :item_bonus
4
+ attr_accessor :level, :items
5
+
6
+ def initialize(god_name, data)
7
+ super(data)
8
+ @name = god_name
9
+ @items = []
10
+ @level = 0
11
+ @item_bonus = default_bonus
12
+ end
13
+
14
+ def level=(new_level)
15
+ @level = (new_level.to_i - 1) % 20
16
+ end
17
+
18
+ def items=(new_items)
19
+ @items = new_items
20
+ @item_bonus = default_bonus
21
+ end
22
+
23
+ def movement_speed
24
+ from_items = item_bonus[:movement_speed]
25
+ base = data['movement_speed']
26
+
27
+ from_items + base
28
+ end
29
+
30
+ def health
31
+ from_items = item_bonus[:health]
32
+ base = data['health']
33
+ scaling = health_per_level * level
34
+
35
+ from_items + base + scaling
36
+ end
37
+
38
+ def mana
39
+ from_items = item_bonus[:mana]
40
+ base = data['mana']
41
+ scaling = mana_per_level * level
42
+
43
+ from_items + base + scaling
44
+ end
45
+
46
+ def mp5
47
+ from_items = item_bonus[:mp5]
48
+ base = data['mp5']
49
+ scaling = (mp5_per_level * level.to_f).to_i
50
+
51
+ from_items + base + scaling
52
+ end
53
+
54
+ def hp5
55
+ from_items = item_bonus[:hp5]
56
+ base = data['hp5']
57
+ scaling = (hp5_per_level * level.to_f).to_i
58
+
59
+ from_items + base + scaling
60
+ end
61
+
62
+ def attack_speed
63
+ from_items = item_bonus[:attack_speed]
64
+ base = data['attack_speed']
65
+ scaling = (attack_speed_per_level * level.to_f).to_i
66
+
67
+ from_items + base + scaling
68
+ end
69
+
70
+ def magic_power
71
+ from_items = item_bonus[:magic_power]
72
+ base = data['magic_power']
73
+ scaling = magic_power_per_level * level
74
+
75
+ from_items + base + scaling
76
+ end
77
+
78
+ def magic_protection
79
+ from_items = item_bonus[:magic_protection]
80
+ base = data['magic_protection']
81
+ scaling = (magic_protection_per_level * level.to_f).to_i
82
+
83
+ from_items + base + scaling
84
+ end
85
+
86
+ def physical_protection
87
+ from_items = item_bonus[:physical_protection]
88
+ base = data['physical_protection']
89
+ scaling = (physical_protection_per_level * level.to_f).to_i
90
+
91
+ from_items + base + scaling
92
+ end
93
+
94
+ def item_bonus
95
+ return @item_bonus unless @item_bonus == default_bonus and !items.empty?
96
+
97
+ items.map(&:effects).flatten.select do |effect|
98
+ next unless attributes.include?(effect.attribute)
99
+ @item_bonus[effect.attribute.to_sym] += effect.amount
100
+ end
101
+
102
+ @item_bonus
103
+ end
104
+
105
+ def summary
106
+ attributes.each_with_object({}) do |attr, hash|
107
+ hash[attr.to_sym] = send(attr.to_sym)
108
+ end
109
+ end
110
+
111
+ def inspect
112
+ "#<Smite::GodStats '#{name}' Level #{level + 1}>"
113
+ end
114
+
115
+ private
116
+
117
+ def default_bonus
118
+ @default_bonus ||= attributes.each_with_object({}) { |attr, hash| hash[attr.to_sym] = 0 }
119
+ end
120
+ end
121
+ end
data/lib/smite/item.rb CHANGED
@@ -1,7 +1,35 @@
1
1
  module Smite
2
2
  class Item < Smite::Object
3
+
4
+ def initialize(data)
5
+ super
6
+ effects = @data.delete('item_description')
7
+ @data['description'] = effects.delete('Description')
8
+ @data['effects'] = effects['Menuitems'].map { |eff| ItemEffect.new(device_name, eff)}
9
+ end
10
+
11
+ def active?
12
+ type == 'Active'
13
+ end
14
+
15
+ def consumable?
16
+ type == 'Consumable'
17
+ end
18
+
19
+ def item?
20
+ type == 'Item'
21
+ end
22
+
23
+ def physical?
24
+ @physical ||= effects.map(&:attribute).any? { |eff| eff =~ /physical_(power|pen)/ }
25
+ end
26
+
27
+ def magic?
28
+ !physical?
29
+ end
30
+
3
31
  def inspect
4
- "#<Smite::Item '#{device_name}'>"
32
+ "#<Smite::Item #{item_id} '#{device_name}'>"
5
33
  end
6
34
  end
7
35
  end
@@ -0,0 +1,18 @@
1
+ module Smite
2
+ class ItemEffect < Smite::Object
3
+ attr_reader :device_name, :percentage
4
+
5
+ def initialize(item, data)
6
+ @device_name = item
7
+ super(DataTransform.transform_item_effect(data))
8
+ end
9
+
10
+ def percentage?
11
+ !@percentage.nil?
12
+ end
13
+
14
+ def inspect
15
+ "#<Smite::ItemEffect '#{device_name}' #{attribute} +#{amount}#{percentage}>"
16
+ end
17
+ end
18
+ end
data/lib/smite/match.rb CHANGED
@@ -1,7 +1,10 @@
1
1
  module Smite
2
2
  class Match < Smite::Object
3
3
  def initialize(data)
4
- @data = DataTransform.transform(data)
4
+ super
5
+ @data = DataTransform.transform_gods(@data)
6
+ @data = DataTransform.transform_items(@data)
7
+ @data = DataTransform.transform_match(@data)
5
8
  end
6
9
 
7
10
  def inspect
data/lib/smite/object.rb CHANGED
@@ -3,21 +3,18 @@ module Smite
3
3
  attr_reader :data
4
4
 
5
5
  def initialize(data)
6
- @data = data
6
+ @data = data.each_with_object({}) do |(k, v), obj|
7
+ obj[ActiveSupport::Inflector.underscore(k)] = v
8
+ end
7
9
  end
8
10
 
9
11
  def attributes
10
- @data.keys.map(&ActiveSupport::Inflector.method(:underscore))
12
+ @data.keys
11
13
  end
12
14
 
13
15
  def method_missing(method)
14
- key = @data.keys.find do |attribute|
15
- camel_attr = ActiveSupport::Inflector.underscore(attribute)
16
- camel_method = ActiveSupport::Inflector.underscore(method.to_s)
17
- camel_attr == camel_method
18
- end
19
-
20
- key ? @data[key] : super
16
+ camel_method = ActiveSupport::Inflector.underscore(method.to_s)
17
+ @data[camel_method] || super
21
18
  end
22
19
  end
23
20
  end
data/lib/smite/player.rb CHANGED
@@ -5,7 +5,7 @@ module Smite
5
5
  def initialize(client, player_name)
6
6
  @client = client
7
7
  @player_name = player_name
8
- @data = get_player
8
+ super(get_player)
9
9
  end
10
10
 
11
11
  def friends
@@ -21,7 +21,7 @@ module Smite
21
21
  end
22
22
 
23
23
  def achievements
24
- @achievements ||= get_achievements
24
+ @achievements ||= Achievements.new(get_achievements)
25
25
  end
26
26
 
27
27
  def inspect
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.0.0'
5
- s.date = '2016-01-28'
4
+ s.version = '1.4.3'
5
+ s.date = '2016-01-29'
6
6
  s.summary = 'Ruby Smite API'
7
7
  s.description = 'Ruby Client for consuming the Smite API'
8
8
  s.authors = ['NcUltimate']
@@ -10,7 +10,7 @@ Gem::Specification.new do |s|
10
10
  s.files = `git ls-files`.split($/)
11
11
  s.require_paths = ["lib"]
12
12
  s.license = 'MIT'
13
- s.homepage = 'https://rubygems.org/gems/smite-ruby'
13
+ s.homepage = 'https://rubygems.org/gems/smite_ruby'
14
14
 
15
15
  s.add_runtime_dependency 'httparty'
16
16
  s.add_runtime_dependency 'activesupport'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smite_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - NcUltimate
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-28 00:00:00.000000000 Z
11
+ date: 2016-01-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -47,20 +47,24 @@ files:
47
47
  - .DS_Store
48
48
  - .gitignore
49
49
  - Gemfile
50
+ - README.md
50
51
  - lib/smite.rb
51
52
  - lib/smite/ability.rb
53
+ - lib/smite/achievements.rb
52
54
  - lib/smite/client.rb
53
55
  - lib/smite/data_transform.rb
54
56
  - lib/smite/friend.rb
55
57
  - lib/smite/game.rb
56
58
  - lib/smite/god.rb
57
59
  - lib/smite/god_rank.rb
60
+ - lib/smite/god_stats.rb
58
61
  - lib/smite/item.rb
62
+ - lib/smite/item_effect.rb
59
63
  - lib/smite/match.rb
60
64
  - lib/smite/object.rb
61
65
  - lib/smite/player.rb
62
66
  - smite_ruby.gemspec
63
- homepage: https://rubygems.org/gems/smite-ruby
67
+ homepage: https://rubygems.org/gems/smite_ruby
64
68
  licenses:
65
69
  - MIT
66
70
  metadata: {}