smite_ruby 1.4.9 → 1.5.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: 4fcad5bd4774d5cf3f1c76a330ea0e8f791093ab
4
- data.tar.gz: 85a1e44fb48a152dae28a493c8582184d55c965d
3
+ metadata.gz: 9f9a4cc076631a270e034c469e8e3f22ce095373
4
+ data.tar.gz: 9f9839c006db93cb1df653ac77df88863f8a38dd
5
5
  SHA512:
6
- metadata.gz: be93cc0b126c2a2073a8385c73695127b5d21ffe98b99317ec9eba583e63a1c26f72bba065bc58e683e1642493e7d8588633e928e7e0a292190762f2ab35fc82
7
- data.tar.gz: 3aa1b5acac28193f68a3cc30db75e4cf1599d575a724457fe5e4a3b2f03e052032548051b100e834f4c16ce6237bfb8b77a052ddf4e0c07131fec198fbf2638f
6
+ metadata.gz: 00aa0449f24960adb8bb5f91234e52cfc5b295b684eaed8243ccf01ad9a5e70f6b0538093b63ce55f0423955338028350713719d6681580af9e317fd3d225b45
7
+ data.tar.gz: 1ed19147cd0c392b5fa8c9baea2dd797c662c113f72fd21b7d941c1d8c35df64153a9310a62578741057bd9caf0433f4b4d9210cb7572ea8335ca1cce9e6d7b4
@@ -8,7 +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
+ @created = Time.new(0)
12
12
  create_session
13
13
  end
14
14
 
@@ -108,14 +108,23 @@ module Smite
108
108
  return @session_id if valid_session?
109
109
 
110
110
  response = api_call('createsession', [], false)
111
+ unless response && response['ret_msg'] == 'Approved'
112
+ return @session_id = nil
113
+ end
114
+
111
115
  @session_id = response['session_id']
112
116
  @created = Time.now
117
+ @session_id
113
118
  end
114
119
 
115
120
  def valid_session?
116
121
  (created + (15 * 60)) > Time.now
117
122
  end
118
123
 
124
+ def ping
125
+ self.class.get('/pingjson')
126
+ end
127
+
119
128
  private
120
129
 
121
130
  def api_call(method, params = [], session = true)
@@ -9,7 +9,8 @@ module Smite
9
9
  end
10
10
 
11
11
  def device(name_or_id)
12
- idx = device_hash[name_or_id.to_s.downcase]
12
+ key = name_or_id.to_s.downcase.gsub(/[^\w]/,'')
13
+ idx = device_hash[key]
13
14
  idx.nil? ? nil : devices[idx]
14
15
  end
15
16
  alias_method :item, :device
@@ -17,7 +18,8 @@ module Smite
17
18
  alias_method :active, :device
18
19
 
19
20
  def god(name_or_id)
20
- idx = god_hash[name_or_id.to_s.downcase]
21
+ key = name_or_id.to_s.downcase.gsub(/[^\w]/,'')
22
+ idx = god_hash[key]
21
23
  idx.nil? ? nil : gods[idx]
22
24
  end
23
25
 
@@ -93,15 +95,18 @@ module Smite
93
95
 
94
96
  def device_hash
95
97
  @device_hash ||= (0...devices.count).each_with_object({}) do |idx, hash|
96
- hash[devices[idx].item_id.to_s] = idx
97
- hash[devices[idx].device_name.downcase] = idx
98
+ name_key = devices[idx].name.downcase.gsub(/[^\w]/,'')
99
+
100
+ hash[devices[idx].item_id.to_s] = idx
101
+ hash[name_key] = idx
98
102
  end
99
103
  end
100
104
 
101
105
  def god_hash
102
106
  @god_hash ||= (0...gods.count).each_with_object({}) do |idx, hash|
103
- hash[gods[idx].id.to_s] = idx
104
- hash[gods[idx].name.downcase] = idx
107
+ name_key = gods[idx].name.downcase.gsub(/[^\w]/,'')
108
+ hash[gods[idx].id.to_s] = idx
109
+ hash[name_key] = idx
105
110
  end
106
111
  end
107
112
  end
@@ -4,26 +4,43 @@ module Smite
4
4
 
5
5
  def initialize(god_name, data, params = { level: 0 })
6
6
  super(data)
7
- @name = god_name
7
+ @name = god_name
8
+ @items = params[:items] || []
9
+
10
+ # make sure level is between 0 and 20 (0 for base stats)
11
+ @level = [[params[:level].to_i, 20].min, 0].max
12
+ @stacks = params[:stacks] || {}
13
+ end
14
+
15
+ def items
16
+ return @filtered_items unless @filtered_items.nil?
17
+
18
+ # only allow items
19
+ @items.select!(&:item?)
8
20
 
9
21
  # make sure ratatoskr only has 1 acorn and items are unique
10
- @items = (params[:items] || []).uniq do |a|
22
+ @items = @items.uniq do |a|
11
23
  a.name =~ /acorn/i ? 'acorn' : a.name
12
24
  end
13
25
 
14
- # make sure only 6 items total
26
+ # make sure there are only 6 items total
15
27
  @items = @items[0..5]
16
28
 
17
29
  # make sure ratatoskr has at least 1 acorn
18
- if god_name.downcase == 'ratatoskr'
30
+ if @name.downcase == 'ratatoskr'
19
31
  if !@items.any? { |i| i.name =~ /acorn/i }
20
32
  @items[0] = Smite::Game.item('magic acorn')
21
33
  end
34
+ else
35
+ # and that everyone else has none
36
+ @items.reject! { |item| item.name =~ /acorn/i }
22
37
  end
23
38
 
24
- # make sure level is between 0 and 20 (0 for base stats)
25
- @level = [[params[:level].to_i, 20].min, 0].max
26
- @stacks = params[:stacks] || {}
39
+ # only accept physical items for physical gods and vice versa
40
+ physical = Smite::Game.god(@name).physical?
41
+ @filtered_items = @items.select do |item|
42
+ physical ? item.physical? : item.magic?
43
+ end
27
44
  end
28
45
 
29
46
  def at_level(new_level)
@@ -41,12 +58,6 @@ module Smite
41
58
  @item_bonus = {}
42
59
  @item_bonus[:flat] = default_bonus.dup
43
60
  @item_bonus[:perc] = default_bonus.dup
44
-
45
- # only accept physical items for physical gods and vice versa
46
- physical = Smite::Game.god(@name).physical?
47
- @items = @items.select do |item|
48
- physical ? item.physical? : item.magic?
49
- end
50
61
  return @item_bonus if items.empty?
51
62
 
52
63
  bonus_from_active_item_effects
@@ -167,11 +178,11 @@ module Smite
167
178
  case name
168
179
  when 'Scylla'
169
180
  case level
170
- when 0..7 then 0
171
- when 8..12 then 20
172
- when 13..16 then 40
173
- when 17..18 then 60
174
- when 19 then 80
181
+ when 0..8 then 0
182
+ when 9..13 then 20
183
+ when 14..17 then 40
184
+ when 18..19 then 60
185
+ when 20 then 80
175
186
  end
176
187
  when 'Ares'
177
188
  30 * items.count(&:aura?)
@@ -12,7 +12,7 @@ module Smite
12
12
  end
13
13
 
14
14
  def self.physical_item_trees
15
- [7573, 7827, 7922, 8268, 9624, 9812, 9825, 9830, 9833, 10190, 10662, 11468, 12667, 12671]
15
+ [7573, 7827, 7922, 8268, 9624, 9812, 9825, 9830, 9833, 10190, 10662, 11122, 11468, 12667, 12671]
16
16
  end
17
17
 
18
18
  def self.magical_item_trees
@@ -17,7 +17,7 @@ module Smite
17
17
  value = data.delete('Value')
18
18
  @percentage = value[/%/]
19
19
 
20
- value = value.tr('+', '').to_i
20
+ value = value.tr('+', '').to_f
21
21
  @amount = value
22
22
  end
23
23
 
@@ -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.9'
5
- s.date = '2016-02-18'
4
+ s.version = '1.5.0'
5
+ s.date = '2016-02-22'
6
6
  s.summary = 'Ruby Smite API'
7
7
  s.description = 'Ruby Client for consuming the Smite API'
8
8
  s.authors = ['NcUltimate']
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.4.9
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - NcUltimate
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-18 00:00:00.000000000 Z
11
+ date: 2016-02-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty