gamelocker_api 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 60aa8bf242f8d9b84bfe708fb531d4cc4013e436
4
+ data.tar.gz: a0874a8b28b5311b93c1bc40376ccc10f9a33f19
5
+ SHA512:
6
+ metadata.gz: 155de74f0a503aecc83df7f51fcbaef0316b1fb27007276ad6c24b4bd8fb5f74607de42cd79b132be6f4cbe35d6837e84b9598cb515882fdfde092ec45454bc1
7
+ data.tar.gz: e3a198ace184fa1d971ef48ae9e73db48af3ec3927e3024c90a1df04fbdd25925b1b54842ab77bc1d2df8e329578116f3b01b0bc2d9b16fe366e00f70c465767
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.0
5
+ before_install: gem install bundler -v 1.14.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in gamelocker_api.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Cyberarm
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # GameLockerAPI
2
+
3
+ API client for the VainGlory Developer API (which is currently in alpha)
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem "gamelocker_api"
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install gamelocker_api
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Development
26
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
27
+
28
+ ## Contributing
29
+
30
+ Bug reports and pull requests are welcome on GitHub at https://github.com/cyberarm/gamelocker_api.
31
+
32
+
33
+ ## License
34
+
35
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,35 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'gamelocker_api/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "gamelocker_api"
8
+ spec.version = GameLockerAPI::VERSION
9
+ spec.authors = ["Cyberarm"]
10
+ spec.email = ["matthewlikesrobots@gmail.com"]
11
+
12
+ spec.summary = %q{API client for the VainGlory Developer API}
13
+ spec.description = %q{API client for the VainGlory Developer API}
14
+ spec.homepage = "https://github.com/cyberarm/gamelocker_api"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against " \
23
+ "public gem pushes."
24
+ end
25
+
26
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
+ f.match(%r{^(test|spec|features)/})
28
+ end
29
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ["lib"]
31
+
32
+ spec.add_development_dependency "bundler", "~> 1.14"
33
+ spec.add_development_dependency "rake", "~> 10.0"
34
+ spec.add_development_dependency "minitest", "~> 5.0"
35
+ end
@@ -0,0 +1,208 @@
1
+ class GameLockerAPI
2
+ class AbstractParser
3
+ def self.guess(end_point, data)
4
+ if end_point == "matches"
5
+ match(data)
6
+ elsif end_point.start_with?("matches/")
7
+ match(data, true)
8
+
9
+ elsif end_point == "players"
10
+ player(data)
11
+ elsif end_point.start_with?("players/")
12
+ player(data, true)
13
+
14
+ else
15
+ raise "(0_-)\nCouldn't guess what parser to use, sorry.\nEndpoint was: #{end_point}"
16
+ end
17
+ end
18
+
19
+ # Might only work with MATCHES... []
20
+ def self.match(data, solo = false)
21
+ _matches = []
22
+ temp_match = nil
23
+ unless solo
24
+ data['data'].each do |match|
25
+ temp_match = Match.new
26
+ _matches.push(temp_match)
27
+ temp_match.uuid = match['id']
28
+ temp_match.shard_id = match['attributes']['shardId']
29
+ temp_match.created_at = match['attributes']['createdAt']
30
+ temp_match.duration = match['attributes']['duration']
31
+ temp_match.gamemode = match['attributes']['gameMode']
32
+ temp_match.end_game_reason = match['attributes']['stats']['endGameReason']
33
+ temp_match.rosters = []
34
+ temp_match.red_team = []
35
+ temp_match.blue_team= []
36
+ temp_match.players = []
37
+ temp_match.participants = []
38
+ data['included'].each do |wanted|
39
+ thing = nil
40
+ if wanted['id'] == match['relationships']['rosters']['data'][0]['id']
41
+ thing = match['relationships']['rosters']['data'][0]['id']
42
+ temp_match.rosters << compose_roster(data, thing, temp_match)
43
+ elsif wanted['id'] == match['relationships']['rosters']['data'][1]['id']
44
+ thing = match['relationships']['rosters']['data'][1]['id']
45
+ temp_match.rosters << compose_roster(data, thing, temp_match)
46
+ else
47
+ next
48
+ end
49
+ end
50
+ end
51
+ else
52
+ temp_match = Match.new
53
+ match = data['data']
54
+ temp_match.uuid = match['id']
55
+ temp_match.shard_id = match['attributes']['shardId']
56
+ temp_match.created_at = match['attributes']['createdAt']
57
+ temp_match.duration = match['attributes']['duration']
58
+ temp_match.gamemode = match['attributes']['gameMode']
59
+ temp_match.end_game_reason = match['attributes']['stats']['endGameReason']
60
+ temp_match.rosters = []
61
+ temp_match.red_team = []
62
+ temp_match.blue_team= []
63
+ temp_match.players = []
64
+ temp_match.participants = []
65
+ data['included'].each do |wanted|
66
+ thing = nil
67
+ if wanted['id'] == match['relationships']['rosters']['data'][0]['id']
68
+ thing = match['relationships']['rosters']['data'][0]['id']
69
+ temp_match.rosters << compose_roster(data, thing, temp_match)
70
+ elsif wanted['id'] == match['relationships']['rosters']['data'][1]['id']
71
+ thing = match['relationships']['rosters']['data'][1]['id']
72
+ temp_match.rosters << compose_roster(data, thing, temp_match)
73
+ else
74
+ next
75
+ end
76
+ end
77
+ end
78
+ solo ? temp_match : _matches
79
+ end
80
+
81
+ def self.player(data, solo = false)
82
+ temp_players = []
83
+ temp_player = nil
84
+ unless solo
85
+ data['data'].each do |local_player|
86
+ temp_player = Player.new
87
+
88
+ temp_player.uuid = local_player['id']
89
+ temp_player.level = local_player['attributes']['stats']['level']
90
+ temp_player.lifetime_gold = local_player['attributes']['stats']['lifetimeGold']
91
+ temp_player.loss_streak = local_player['attributes']['stats']['lossStreak']
92
+ temp_player.played = local_player['attributes']['stats']['played']
93
+ temp_player.played_ranked = local_player['attributes']['stats']['played_ranked']
94
+ temp_player.win_streak = local_player['attributes']['stats']['winStreak']
95
+ temp_player.wins = local_player['attributes']['stats']['wins']
96
+ temp_player.xp = local_player['attributes']['stats']['xp']
97
+ temp_player.name = local_player['attributes']['name']
98
+ temp_player.created_at = local_player['attributes']['createdAt']
99
+
100
+ temp_players.push(temp_player)
101
+ end
102
+ else
103
+ temp_player = Player.new
104
+
105
+ local_player = data['data']
106
+ temp_player.uuid = local_player['id']
107
+ temp_player.level = local_player['attributes']['stats']['level']
108
+ temp_player.lifetime_gold = local_player['attributes']['stats']['lifetimeGold']
109
+ temp_player.loss_streak = local_player['attributes']['stats']['lossStreak']
110
+ temp_player.played = local_player['attributes']['stats']['played']
111
+ temp_player.played_ranked = local_player['attributes']['stats']['played_ranked']
112
+ temp_player.win_streak = local_player['attributes']['stats']['winStreak']
113
+ temp_player.wins = local_player['attributes']['stats']['wins']
114
+ temp_player.xp = local_player['attributes']['stats']['xp']
115
+ temp_player.name = local_player['attributes']['name']
116
+ temp_player.created_at = local_player['attributes']['createdAt']
117
+ end
118
+
119
+ solo ? temp_player : temp_players
120
+ end
121
+
122
+ def self.roster(data)
123
+ end
124
+
125
+ # Expects a roster uuid
126
+ def self.participant(roster)
127
+ end
128
+
129
+ private
130
+ def self.compose_roster(data, roster, temp_match)
131
+ temp_roster = Roster.new
132
+ temp_roster.uuid = roster
133
+ temp_roster.participants = []
134
+ data['included'].each do |local_roster|
135
+ next unless local_roster['type'] == "roster"
136
+ if local_roster['id'] == roster
137
+ temp_roster.aces_earned = local_roster['attributes']['stats']['acesEarned']
138
+ temp_roster.gold = local_roster['attributes']['stats']['gold']
139
+ temp_roster.hero_kills = local_roster['attributes']['stats']['heroKills']
140
+ temp_roster.kraken_captures = local_roster['attributes']['stats']['krakenCaptures']
141
+ temp_roster.side = local_roster['attributes']['stats']['side']
142
+ temp_roster.turret_kills = local_roster['attributes']['stats']['turretKills']
143
+ temp_roster.turrets_remaining = local_roster['attributes']['stats']['turretsRemaining']
144
+
145
+ local_roster['relationships']['participants']['data'].each do |pat|
146
+ data['included'].each do |local_participant|
147
+ next unless local_participant['id'] == pat['id']
148
+ temp_participant = Participant.new
149
+ temp_participant.uuid = local_participant['id']
150
+ temp_participant.assists = local_participant['attributes']['stats']['assists']
151
+ temp_participant.crystal_mine_captures = local_participant['attributes']['stats']['crystalMineCaptures']
152
+ temp_participant.deaths = local_participant['attributes']['stats']['deaths']
153
+ temp_participant.farm = local_participant['attributes']['stats']['farm']
154
+ temp_participant.first_afk_time = local_participant['attributes']['stats']['firstAfkTime']
155
+ temp_participant.gold = local_participant['attributes']['stats']['gold']
156
+ temp_participant.gold_mine_captures = local_participant['attributes']['stats']['goldMineCaptures']
157
+ temp_participant.item_grants = local_participant['attributes']['stats']['itemGrants']
158
+ temp_participant.item_sells = local_participant['attributes']['stats']['itemSells']
159
+ temp_participant.item_uses = local_participant['attributes']['stats']['itemUses']
160
+ temp_participant.items = local_participant['attributes']['stats']['items']
161
+ temp_participant.jungle_kills = local_participant['attributes']['stats']['jungleKills']
162
+ temp_participant.karma_level = local_participant['attributes']['stats']['karmaLevel']
163
+ temp_participant.kills = local_participant['attributes']['stats']['kills']
164
+ temp_participant.kraken_captures = local_participant['attributes']['stats']['krakenCaptures']
165
+ temp_participant.level = local_participant['attributes']['stats']['level']
166
+ temp_participant.minion_kills = local_participant['attributes']['stats']['minionKills']
167
+ temp_participant.non_jungle_minion_kills = local_participant['attributes']['stats']['nonJungleMinionKills']
168
+ temp_participant.skill_tier = local_participant['attributes']['stats']['skillTier']
169
+ temp_participant.skin_key = local_participant['attributes']['stats']['skinKey']
170
+ temp_participant.turret_captures = local_participant['attributes']['stats']['turretCaptures']
171
+ temp_participant.went_afk = local_participant['attributes']['stats']['wentAfk']
172
+ temp_participant.winner = local_participant['attributes']['stats']['winner']
173
+ temp_participant.actor = local_participant['attributes']['actor']
174
+
175
+ temp_player = Player.new
176
+ data['included'].each do |local_player|
177
+ next unless local_player['id'] == local_participant['relationships']['player']['data']['id']
178
+ temp_player.uuid = local_player['id']
179
+ temp_player.level = local_player['attributes']['stats']['level']
180
+ temp_player.lifetime_gold = local_player['attributes']['stats']['lifetimeGold']
181
+ temp_player.loss_streak = local_player['attributes']['stats']['lossStreak']
182
+ temp_player.played = local_player['attributes']['stats']['played']
183
+ temp_player.played_ranked = local_player['attributes']['stats']['played_ranked']
184
+ temp_player.win_streak = local_player['attributes']['stats']['winStreak']
185
+ temp_player.wins = local_player['attributes']['stats']['wins']
186
+ temp_player.xp = local_player['attributes']['stats']['xp']
187
+ temp_player.name = local_player['attributes']['name']
188
+ temp_player.created_at = local_player['attributes']['createdAt']
189
+ end
190
+ temp_participant.player = temp_player
191
+ temp_match.players.push(temp_player)
192
+
193
+ temp_match.participants.push(temp_participant)
194
+ temp_roster.participants.push(temp_participant)
195
+ end
196
+ end
197
+ end
198
+ end
199
+
200
+ if temp_roster.side.include?("red")
201
+ temp_match.red_team.push(temp_roster)
202
+ elsif temp_roster.side.include?("blue")
203
+ temp_match.blue_team.push(temp_roster)
204
+ end
205
+ return temp_roster
206
+ end
207
+ end
208
+ end
@@ -0,0 +1,6 @@
1
+ class GameLockerAPI
2
+ class Match
3
+ attr_accessor :uuid, :shard_id, :blue_team, :red_team, :rosters, :participants, :players
4
+ attr_accessor :created_at, :duration, :gamemode, :end_game_reason
5
+ end
6
+ end
@@ -0,0 +1,10 @@
1
+ class GameLockerAPI
2
+ class Participant
3
+ attr_accessor :uuid, :player
4
+ attr_accessor :assists, :crystal_mine_captures, :deaths, :farm, :first_afk_time
5
+ attr_accessor :gold, :gold_mine_captures, :item_grants, :item_sells, :item_uses
6
+ attr_accessor :items, :jungle_kills, :karma_level, :kills, :kraken_captures, :level
7
+ attr_accessor :minion_kills, :non_jungle_minion_kills, :skill_tier, :skin_key
8
+ attr_accessor :turret_captures, :went_afk, :winner, :actor
9
+ end
10
+ end
@@ -0,0 +1,6 @@
1
+ class GameLockerAPI
2
+ class Player
3
+ attr_accessor :uuid, :name, :shard_id, :created_at
4
+ attr_accessor :level, :lifetime_gold, :loss_streak, :win_streak, :played, :played_ranked, :wins, :xp
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ class GameLockerAPI
2
+ class Roster
3
+ attr_accessor :uuid, :aces_earned, :gold, :hero_kills, :kraken_captures, :side, :turret_kills, :turrets_remaining, :participants
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ class GameLockerAPI
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,68 @@
1
+ require_relative "gamelocker_api/abstract_parser"
2
+ require_relative "gamelocker_api/match"
3
+ require_relative "gamelocker_api/player"
4
+ require_relative "gamelocker_api/roster"
5
+ require_relative "gamelocker_api/participant"
6
+
7
+ class GameLockerAPI
8
+ VirtualResponse = Struct.new(:code, :body)
9
+ attr_reader :base_url, :region, :headers
10
+ def initialize(api_key, region = "na")
11
+ @api_key = api_key
12
+ @region = region
13
+ @base_url= "https://api.dc01.gamelockerapp.com/shards/"
14
+ @headers = {}
15
+ end
16
+
17
+ # Probably does not work
18
+ def player(uuid)
19
+ request("players/#{uuid}", {})
20
+ end
21
+
22
+ def players(players_list = [])
23
+ raise "Max of only 6 players" if players_list.count > 6
24
+ string = players_list.join(", ")
25
+ hash = {"filter[playerNames]": string}
26
+ request("players", hash)
27
+ end
28
+
29
+ def match(match_uuid = nil)
30
+ match_uuid ? request("matches/#{match_uuid}") : request("matches")
31
+ end
32
+
33
+ def matches(match_params = {})
34
+ request("matches", match_params)
35
+ end
36
+
37
+ private
38
+ def request(end_point, params = nil)
39
+ api_headers = {
40
+ "X-TITLE-ID": "semc-vainglory",
41
+ "Authorization": @api_key,
42
+ "Accept": "application/vnd.api+json",
43
+ }
44
+
45
+ response = nil
46
+ begin
47
+ if params
48
+ response = RestClient.get(@base_url+@region+"/"+end_point+"?"+URI.encode_www_form(params), api_headers)
49
+ else
50
+ response = RestClient.get(@base_url+@region+"/"+end_point, api_headers)
51
+ end
52
+ @headers = response.headers
53
+ open(Dir.pwd+"/response.dat", "w") do |file|
54
+ file.write(Oj.load(response.body))
55
+ end
56
+ parser(response, end_point)
57
+ rescue RestClient::ExceptionWithResponse => e
58
+ response = VirtualResponse.new(e.response, e.response)
59
+ @headers = e.response.headers
60
+ parser(response, end_point, false)
61
+ end
62
+ end
63
+
64
+ def parser(response, end_point, healthy = true)
65
+ return {response: response, data: GameLockerAPI::AbstractParser.guess(end_point, Oj.load(response.body))} if healthy
66
+ return {response: response, data: "{}"} unless healthy
67
+ end
68
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gamelocker_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Cyberarm
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-04-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.14'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.14'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ description: API client for the VainGlory Developer API
56
+ email:
57
+ - matthewlikesrobots@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".travis.yml"
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - gamelocker_api.gemspec
69
+ - lib/gamelocker_api.rb
70
+ - lib/gamelocker_api/abstract_parser.rb
71
+ - lib/gamelocker_api/match.rb
72
+ - lib/gamelocker_api/participant.rb
73
+ - lib/gamelocker_api/player.rb
74
+ - lib/gamelocker_api/roster.rb
75
+ - lib/gamelocker_api/version.rb
76
+ homepage: https://github.com/cyberarm/gamelocker_api
77
+ licenses:
78
+ - MIT
79
+ metadata:
80
+ allowed_push_host: https://rubygems.org
81
+ post_install_message:
82
+ rdoc_options: []
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ requirements: []
96
+ rubyforge_project:
97
+ rubygems_version: 2.6.11
98
+ signing_key:
99
+ specification_version: 4
100
+ summary: API client for the VainGlory Developer API
101
+ test_files: []