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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f7cc4f043f27ebe004f8229cced90833f57b4a9d
4
- data.tar.gz: e5da84e81525ac97b6eb90a7e9328ddbccd02149
3
+ metadata.gz: 25feb61882b2f684c7b2c3a719151693dd57f673
4
+ data.tar.gz: 935a446bc3a1d8688d254de67faf4c8a43c1d9a8
5
5
  SHA512:
6
- metadata.gz: c8c26832c6684d221ee1fb1a996d1a13115ea28e184be0f4a1ccd02b6e3ddf83efbb4d0862be79b94eaeef14aca0610dacad19f4f81989be57c53125a60ed137
7
- data.tar.gz: 7c3a974eb29097b4798f47340c28da5af0379c39217ae5ec47d4e68bfba3dfad1c0a78120f792d7e95481f649eb50568ed705faf7e7da0b03be09c20db15b4e2
6
+ metadata.gz: ccccf5f6c6bc2c47de9ad36bfba1a811a794d958fe4a92c1762d79b65ca91f406d4919b9cfd54443ab9e31398d0b614235a5d7e877002db765f08a9610139c96
7
+ data.tar.gz: d82637008babe01c8a05129083c20dcb69a10918bd0b2ce5faf42431e8eb75e3b45c74337834f372d917b03847f65b18a3d86e48e71732e55c808721919539d5
data/Gemfile.lock ADDED
@@ -0,0 +1,60 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ smite_ruby (1.4.5)
5
+ activesupport
6
+ httparty
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ activesupport (4.2.3)
12
+ i18n (~> 0.7)
13
+ json (~> 1.7, >= 1.7.7)
14
+ minitest (~> 5.1)
15
+ thread_safe (~> 0.3, >= 0.3.4)
16
+ tzinfo (~> 1.1)
17
+ addressable (2.3.8)
18
+ crack (0.4.3)
19
+ safe_yaml (~> 1.0.0)
20
+ diff-lcs (1.2.5)
21
+ hashdiff (0.2.3)
22
+ httparty (0.13.5)
23
+ json (~> 1.8)
24
+ multi_xml (>= 0.5.2)
25
+ i18n (0.7.0)
26
+ json (1.8.3)
27
+ minitest (5.8.3)
28
+ multi_xml (0.5.5)
29
+ rspec (3.3.0)
30
+ rspec-core (~> 3.3.0)
31
+ rspec-expectations (~> 3.3.0)
32
+ rspec-mocks (~> 3.3.0)
33
+ rspec-core (3.3.1)
34
+ rspec-support (~> 3.3.0)
35
+ rspec-expectations (3.3.0)
36
+ diff-lcs (>= 1.2.0, < 2.0)
37
+ rspec-support (~> 3.3.0)
38
+ rspec-mocks (3.3.1)
39
+ diff-lcs (>= 1.2.0, < 2.0)
40
+ rspec-support (~> 3.3.0)
41
+ rspec-support (3.3.0)
42
+ safe_yaml (1.0.4)
43
+ thread_safe (0.3.5)
44
+ tzinfo (1.2.2)
45
+ thread_safe (~> 0.1)
46
+ webmock (1.22.6)
47
+ addressable (>= 2.3.6)
48
+ crack (>= 0.3.2)
49
+ hashdiff
50
+
51
+ PLATFORMS
52
+ ruby
53
+
54
+ DEPENDENCIES
55
+ rspec
56
+ smite_ruby!
57
+ webmock
58
+
59
+ BUNDLED WITH
60
+ 1.10.5
data/README.md CHANGED
@@ -1,15 +1,32 @@
1
1
  # Smite API Client for Ruby
2
2
  ---
3
+ A simple gem for consuming Smite's API data that includes a lightweight client (Smite::Client) and a slightly heavier object wrapper (Smite::Game)
3
4
  1. `gem install smite_ruby`
4
5
  2. `require 'smite'`
5
6
 
6
- # Examples -- Smite::Game
7
+ ## Examples -- Smite::Game
7
8
  ---
8
9
 
9
10
  ### Creating a session
11
+ A session can be created through `Smite::Client` to manipulate API data directly in its raw form.
12
+ ```
13
+ > client = Smite::Client.new(<dev_id>, <auth_key>)
14
+ #<Smite::Client:0x007fca3343c948
15
+ @auth_key="<auth_key>",
16
+ @dev_id=<dev_id>,
17
+ @session_id="<session_id>">
18
+
19
+ > client.test_session
20
+ "This was a successful test with the following parameters added: developer: <dev_id> time: 1/30/2016 6:14:25 PM signature: <signature> session: <session_id>"
21
+
22
+ > client.get_gods
23
+ (huge amount of json/xml god data)
24
+ ```
25
+
26
+ You can also create a session through `Smite::Game`, which will provide extensive convenience methods for manipulating the data. The rest of this documentation will assume authentication was done in this way.
10
27
  ```
11
28
  > Smite::Game.authenticate!(<dev_id>, <auth_key>)
12
- Smite::Game
29
+ true
13
30
  ```
14
31
 
15
32
  ### Finding a player
@@ -49,7 +66,7 @@ Smite::Game
49
66
  > Smite::Game.item(7526)
50
67
  #<Smite::Item 'Iron Mail'>
51
68
  ```
52
- # Examples -- Smite::Player
69
+ ## Examples -- Smite::Player
53
70
  ---
54
71
  ```
55
72
  > player = Smite::Game.player('adapting')
@@ -86,20 +103,17 @@ Smite::Game
86
103
  ...]
87
104
  ```
88
105
 
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}
106
+ ### Listing achievements
107
+ ```
108
+ > achievements = player.achievements
109
+ #<Smite::Achievements 'Adapting'>
110
+
111
+ > achievements.double_kills
112
+ 5280
113
+ > achievements.penta_kills
114
+ 21
101
115
  ```
102
- ### Listing match history
116
+ ### Listing match history
103
117
  ```
104
118
  > player.match_history
105
119
  [#<Smite::Match 'Leagues: Conquest' 'Win'>,
@@ -109,8 +123,8 @@ Smite::Game
109
123
  #<Smite::Match 'Leagues: Conquest' 'Loss'>,
110
124
  #<Smite::Match 'Leagues: Conquest' 'Win'>,
111
125
  ... ]
112
- ```
113
- # Examples -- Smite::Match
126
+ ```
127
+ ## Examples -- Smite::Match
114
128
  ---
115
129
  ```
116
130
  > match = player.match_history[0]
@@ -132,7 +146,7 @@ Smite::Game
132
146
  > match.killing_spree
133
147
  2
134
148
  ```
135
- # Examples -- Smite::God
149
+ ## Examples -- Smite::God
136
150
  ---
137
151
  ```
138
152
  > merc = Smite::Game.god('Mercury')
@@ -148,7 +162,7 @@ Smite::Game
148
162
  > merc.speed
149
163
  375
150
164
  ```
151
- # Examples -- Smite::GodRank
165
+ ## Examples -- Smite::GodRank
152
166
  ---
153
167
  ```
154
168
  > rank = player.god_ranks[0]
@@ -163,7 +177,7 @@ Smite::Game
163
177
  > rank.worshippers
164
178
  4517
165
179
  ```
166
- # Examples -- Smite::Item
180
+ ## Examples -- Smite::Item
167
181
  ---
168
182
  ```
169
183
  > bov = Smite::Game.item('Breastplate of Valor')
data/lib/smite.rb CHANGED
@@ -4,17 +4,21 @@ require 'active_support'
4
4
  module Smite
5
5
  end
6
6
 
7
- require 'smite/object.rb'
8
- require 'smite/achievements.rb'
9
- require 'smite/ability.rb'
10
- require 'smite/god_rank.rb'
11
- require 'smite/god_stats.rb'
12
- require 'smite/god.rb'
13
- require 'smite/item_effect.rb'
14
- require 'smite/item.rb'
15
- require 'smite/friend.rb'
16
- require 'smite/data_transform.rb'
17
- require 'smite/match.rb'
18
- require 'smite/player.rb'
19
- require 'smite/game.rb'
20
- require 'smite/client.rb'
7
+ require_relative './smite/object.rb'
8
+ require_relative './smite/queue.rb'
9
+ require_relative './smite/motd.rb'
10
+ require_relative './smite/recommended_items.rb'
11
+ require_relative './smite/achievements.rb'
12
+ require_relative './smite/ability.rb'
13
+ require_relative './smite/god_rank.rb'
14
+ require_relative './smite/god_stats.rb'
15
+ require_relative './smite/god.rb'
16
+ require_relative './smite/item_effect.rb'
17
+ require_relative './smite/item.rb'
18
+ require_relative './smite/friend.rb'
19
+ require_relative './smite/data_transform.rb'
20
+ require_relative './smite/match.rb'
21
+ require_relative './smite/recent_match.rb'
22
+ require_relative './smite/player.rb'
23
+ require_relative './smite/game.rb'
24
+ require_relative './smite/client.rb'
data/lib/smite/client.rb CHANGED
@@ -1,26 +1,108 @@
1
1
  module Smite
2
2
  class Client
3
- attr_reader :dev_id, :auth_key, :session_id
3
+ attr_reader :dev_id, :auth_key, :session_id, :lang
4
4
  include HTTParty
5
5
  base_uri 'http://api.smitegame.com/smiteapi.svc/'
6
6
 
7
- def initialize(dev_id, auth_key)
7
+ def initialize(dev_id, auth_key, lang = 1)
8
8
  @dev_id = dev_id
9
9
  @auth_key = auth_key
10
+ @lang = [1,2,3,7,9,10,11,12,13].include?(lang) ? lang : 1
10
11
  create_session
11
12
  end
12
13
 
13
- # /testsessionjson/{developerId}/{signature}/{session}/{timestamp}
14
+ def esports_pro_league_details
15
+ api_call('getesportsproleaguedetails')
16
+ end
17
+
18
+ def god_recommended_items(god_id)
19
+ api_call('getgodrecommendeditems', [god_id, lang])
20
+ end
21
+
22
+ def match_player_details(match_id)
23
+ api_call('getmatchplayerdetails', [match_id])
24
+ end
25
+
26
+ def match_ids_by_queue(queue, date, hour)
27
+ api_call('getmatchidsbyqueue', [queue, date, hour])
28
+ end
29
+
30
+ def league_seasons(queue)
31
+ api_call('getleagueseasons', [queue])
32
+ end
33
+
34
+ def league_leaderboard(queue, tier, season)
35
+ api_call('getleagueleaderboard', [queue, tier, season])
36
+ end
37
+
38
+ def motd
39
+ api_call('getmotd')
40
+ end
41
+
42
+ def player_status(player_name)
43
+ api_call('getplayerstatus', [player_name])
44
+ end
45
+
46
+ def queue_stats(player_name, queue)
47
+ api_call('getqueuestats', [player_name, queue])
48
+ end
49
+
50
+ def team_details(clan_id)
51
+ api_call('getteamdetails', [clan_id])
52
+ end
53
+
54
+ def team_players(clan_id)
55
+ api_call('getteamplayers', [clan_id])
56
+ end
57
+
58
+ def top_matches
59
+ api_call('gettopmatches')
60
+ end
61
+
62
+ def match_details(match_id)
63
+ api_call('getmatchdetails', [match_id])
64
+ end
65
+
66
+ def gods
67
+ api_call('getgods', [lang])
68
+ end
69
+
70
+ def items
71
+ api_call('getitems', [lang])
72
+ end
73
+
74
+ def achievements(player_id)
75
+ api_call('getplayerachievements', [player_id])
76
+ end
77
+
78
+ def friends(player_name)
79
+ api_call('getfriends', [player_name])
80
+ end
81
+
82
+ def god_ranks(player_name)
83
+ api_call('getgodranks', [player_name])
84
+ end
85
+
86
+ def player(player_name)
87
+ api_call('getplayer', [player_name])
88
+ end
89
+
90
+ def match_history(player_name)
91
+ api_call('getmatchhistory', [player_name])
92
+ end
93
+
94
+ def search_teams(team_name)
95
+ api_call('searchteams', [team_name])
96
+ end
97
+
14
98
  def test_session
15
- api_call('testsession', [])
99
+ api_call('testsession')
16
100
  end
17
101
 
18
- # /getdatausedjson/{developerId}/{signature}/{session}/{timestamp}
19
- def get_data_used
20
- api_call('getdataused', [])
102
+ def data_used
103
+ api_call('getdataused')
21
104
  end
22
105
 
23
- # /createsessionjson/{developerId}/{signature}/{timestamp}
24
106
  def create_session
25
107
  return @session_id if valid_session?
26
108
 
@@ -28,17 +110,17 @@ module Smite
28
110
  @session_id = response['session_id']
29
111
  end
30
112
 
31
- def api_call(method, params = [], session = true)
32
- request = request_str(method, params, session)
33
- self.class.get(request)
34
- end
35
-
36
113
  def valid_session?
37
114
  !!(test_session =~ /successful/i)
38
115
  end
39
116
 
40
117
  private
41
118
 
119
+ def api_call(method, params = [], session = true)
120
+ request = request_str(method, params, session)
121
+ self.class.get(request)
122
+ end
123
+
42
124
  def signature(method)
43
125
  Digest::MD5.hexdigest("#{dev_id}#{method}#{auth_key}#{timestamp}")
44
126
  end
@@ -6,7 +6,7 @@ module Smite
6
6
  item_fields = data.slice(*item_map_fields)
7
7
  return data if item_fields.empty?
8
8
 
9
- data['items'] = item_fields.values.map { |id| Smite::Game.item(id.to_i) }
9
+ data['items'] = item_fields.values.map { |id| Smite::Game.item(id) }
10
10
  data.except(*item_filter_fields)
11
11
  end
12
12
 
@@ -14,7 +14,7 @@ module Smite
14
14
  god_fields = data.slice(*god_map_fields)
15
15
  return data if god_fields.empty?
16
16
 
17
- data['god'] = god_fields.values.map { |id| Smite::Game.god(id.to_i) }[0]
17
+ data['god'] = god_fields.values.map { |id| Smite::Game.god(id) }[0]
18
18
  data.except(*god_filter_fields)
19
19
  end
20
20
 
@@ -32,13 +32,13 @@ module Smite
32
32
  data.except(*ability_filter_fields)
33
33
  end
34
34
 
35
- def transform_match(data)
36
- return data unless data['Queue']
35
+ def transform_recent_match(data)
36
+ return data unless data['queue']
37
37
 
38
- if data['Queue'] =~ /League/
38
+ if data['queue'] =~ /League/
39
39
  data
40
40
  else
41
- data.except(*match_filter_fields)
41
+ data.except(*recent_match_filter_fields)
42
42
  end
43
43
  end
44
44
 
@@ -98,7 +98,7 @@ module Smite
98
98
  )
99
99
  end
100
100
 
101
- def match_filter_fields
101
+ def recent_match_filter_fields
102
102
  %w(
103
103
  ban1 ban2 ban3 ban4 ban5 ban6
104
104
  ban1_id ban2_id ban3_id
@@ -129,7 +129,7 @@ module Smite
129
129
  end
130
130
 
131
131
  def god_filter_fields
132
- god_map_fields + %w(god)
132
+ god_map_fields
133
133
  end
134
134
  end
135
135
  end
data/lib/smite/game.rb CHANGED
@@ -1,39 +1,67 @@
1
1
  module Smite
2
2
  class Game
3
3
  class << self
4
- attr_reader :client, :lang_code
4
+ attr_reader :client
5
5
 
6
- def authenticate!(dev_id, auth_key, lang_code = 1)
7
- @client = Smite::Client.new(dev_id, auth_key)
8
- @lang_code = lang_code
9
- !client.session_id.empty?
6
+ def authenticate!(dev_id, auth_key, format = 'json', lang = 1)
7
+ @client = Smite::Client.new(dev_id, auth_key, lang)
8
+ !client.session_id.nil?
10
9
  end
11
10
 
12
11
  def device(name_or_id)
13
- devices[device_hash[name_or_id]]
12
+ idx = device_hash[name_or_id.to_s.downcase]
13
+ idx.nil? ? nil : devices[idx]
14
14
  end
15
15
  alias_method :item, :device
16
16
  alias_method :consumable, :device
17
17
  alias_method :active, :device
18
18
 
19
19
  def god(name_or_id)
20
- gods[god_hash[name_or_id]]
20
+ idx = god_hash[name_or_id.to_s.downcase]
21
+ idx.nil? ? nil : gods[idx]
21
22
  end
22
23
 
23
24
  def match(match_id)
24
- Match.new(match_details(match_id))
25
+ @matches ||= {}
26
+ @matches[match_id] ||= Match.new(client.match_details(match_id))
25
27
  end
26
28
 
27
29
  def player(player_name)
28
- Player.new(client, player_name)
30
+ Player.new(player_name)
31
+ end
32
+
33
+ def motd_now
34
+ motd_list[0]
35
+ end
36
+
37
+ def motd_list
38
+ @motds ||= client.motd.map(&MOTD.method(:new))
39
+ end
40
+
41
+ def queues
42
+ @queues ||= Smite::Queue::QUEUES.map(&Queue.method(:new))
43
+ end
44
+
45
+ def god_recommended_items(name_or_id)
46
+ god = god(name_or_id)
47
+ @rec_items ||= {}
48
+ return @rec_items[god.id] unless @rec_items[god.id].nil?
49
+
50
+ @rec_items[god.id] = []
51
+ recommended = client.god_recommended_items(god.id)
52
+ recommended.group_by { |r| r['Role'] }.each do |role, items|
53
+ @rec_items[god.id] << Smite::RecommendedItems.new(god.name, items, role)
54
+ end
55
+
56
+ @rec_items[god.id]
29
57
  end
30
58
 
31
59
  def gods
32
- @gods ||= get_gods.map(&God.method(:new))
60
+ @gods ||= client.gods.map(&God.method(:new))
33
61
  end
34
62
 
35
63
  def devices
36
- @devices ||= get_items.map(&Item.method(:new))
64
+ @devices ||= client.items.map(&Item.method(:new))
37
65
  end
38
66
 
39
67
  def items
@@ -52,32 +80,17 @@ module Smite
52
80
 
53
81
  def device_hash
54
82
  @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
83
+ hash[devices[idx].item_id.to_s] = idx
84
+ hash[devices[idx].device_name.downcase] = idx
57
85
  end
58
86
  end
59
87
 
60
88
  def god_hash
61
89
  @god_hash ||= (0...gods.count).each_with_object({}) do |idx, hash|
62
- hash[gods[idx].id] = idx
63
- hash[gods[idx].name] = idx
90
+ hash[gods[idx].id.to_s] = idx
91
+ hash[gods[idx].name.downcase] = idx
64
92
  end
65
93
  end
66
-
67
- # /getmatchdetails[ResponseFormat]/{developerId}/{signature}/{session}/{timestamp}/{match_id}
68
- def match_details(match_id)
69
- client.api_call('getmatchdetails', [match_id])
70
- end
71
-
72
- # /getgodsjson/{developerId}/{signature}/{session}/{timestamp}/{languageCode}
73
- def get_gods
74
- client.api_call('getgods', [lang_code])
75
- end
76
-
77
- # /getitemsjson/{developerId}/{signature}/{session}/{timestamp}/{languagecode}
78
- def get_items
79
- client.api_call('getitems', [lang_code])
80
- end
81
94
  end
82
95
  end
83
96
  end