valorant 0.1.3 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
data/lib/api/misc.rb CHANGED
@@ -3,6 +3,7 @@
3
3
  require_relative 'utils/articles'
4
4
  require_relative 'utils/leader_board'
5
5
  require_relative 'utils/utilities'
6
+ require_relative 'utils/content'
6
7
 
7
8
  module Valorant
8
9
  # This class is used to fetch data from the Valorant API -> ENDPOINTS: /v1/website/, /v1/leaderboard/,
@@ -17,7 +18,7 @@ module Valorant
17
18
  end
18
19
 
19
20
  def self.content
20
- fetch_resposne('v1/content')
21
+ Content.new(fetch_resposne('v1/content'))
21
22
  end
22
23
 
23
24
  def self.server_status(region)
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ # This class is used to create an Asset object
4
+ class Asset
5
+ attr_reader :name, :id, :asset_name, :localized_names, :type
6
+
7
+ def initialize(data, type)
8
+ @data = data
9
+ @type = type
10
+ @name = @data['name']
11
+ @id = @data['id']
12
+ @asset_name = @data['assetName']
13
+
14
+ fetch_localized_names
15
+ remove_instance_variable(:@data)
16
+ end
17
+
18
+ private
19
+
20
+ def fetch_localized_names
21
+ @localized_names = @data['localizedNames'].transform_keys(&:to_sym)
22
+ end
23
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'asset'
4
+
5
+ # This class is used to create a Content object
6
+ class Content
7
+ attr_reader :assets
8
+
9
+ def initialize(data)
10
+ @data = data
11
+ @assets = fetch_assets
12
+ remove_instance_variable(:@data)
13
+ end
14
+
15
+ def find_asset_by_name(name)
16
+ @assets.find { |asset| asset.name == name }
17
+ end
18
+
19
+ def agent_images(name)
20
+ agent = @assets.find { |asset| asset.name == name }
21
+ { display_icon: "https://media.valorant-api.com/agents/#{agent.id}/displayicon.png",
22
+ display_icon_small: "https://media.valorant-api.com/agents/#{agent.id}/displayiconsmall.png",
23
+ bust_portrait: "https://media.valorant-api.com/agents/#{agent.id}/fullportrait.png",
24
+ full_portrait: "https://media.valorant-api.com/agents/#{agent.id}/fullportrait.png",
25
+ full_portrait_v2: "https://media.valorant-api.com/agents/#{agent.id}/fullportrait.png",
26
+ killfeed_portrait: "https://media.valorant-api.com/agents/#{agent.id}/killfeedportrait.png",
27
+ background: "https://media.valorant-api.com/agents/#{agent.id}/background.png" }
28
+ end
29
+
30
+ private
31
+
32
+ def fetch_assets
33
+ @assets = []
34
+ @data.each_key do |type|
35
+ next if type == 'version'
36
+
37
+ @data[type].each do |asset|
38
+ @assets << Asset.new(asset, type)
39
+ end
40
+ end
41
+ @assets
42
+ end
43
+ end
@@ -23,17 +23,3 @@ class Leader
23
23
  @is_anonymized = data['IsAnonymized']
24
24
  end
25
25
  end
26
-
27
- # DOCUMENTATION
28
-
29
- # @PlayerCardID
30
- # @TitleID
31
- # @IsBanned
32
- # @IsAnonymized
33
- # @puuid
34
- # @gameName
35
- # @tagLine
36
- # @leaderboardRank
37
- # @rankedRating
38
- # @numberOfWins
39
- # @competitiveTier
@@ -33,6 +33,11 @@ class Match
33
33
  @blue_team.max_by(&:score)
34
34
  end
35
35
 
36
+ def accuracy(name, tag)
37
+ result = @all_players.select { |player| player.name.gsub(' ', '') == name.gsub(' ', '') && player.tag == tag }
38
+ [result[0].headshots, result[0].bodyshots, result[0].legshots]
39
+ end
40
+
36
41
  def fetch_game_info
37
42
  @game_version = @meta_data['game_version']
38
43
  @game_start_patched = @meta_data['game_start_patched']
@@ -10,6 +10,34 @@ class MatcheshHistory
10
10
  @matches = fetch_matches(hash['data'])
11
11
  end
12
12
 
13
+ def accuracy(name, tag)
14
+ body_shots = 0
15
+ head_shots = 0
16
+ leg_shots = 0
17
+
18
+ @matches.each do |match|
19
+ headshots, bodyshots, legshots = match.accuracy(name, tag)
20
+
21
+ head_shots += headshots
22
+ body_shots += bodyshots
23
+ leg_shots += legshots
24
+ end
25
+
26
+ [head_shots, body_shots, leg_shots]
27
+ end
28
+
29
+ def most_played(name, tag)
30
+ most_played = []
31
+ @matches.each do |match|
32
+ match.all_players.each do |player|
33
+ next unless player.name == name && player.tag == tag
34
+
35
+ most_played << player.character
36
+ end
37
+ end
38
+ most_played.max_by { |i| most_played.count(i) }
39
+ end
40
+
13
41
  private
14
42
 
15
43
  def fetch_matches(matches_json)
@@ -26,6 +26,10 @@ class Player
26
26
  (@kills.to_f / @deaths).round(2)
27
27
  end
28
28
 
29
+ def accuracy
30
+ [@headshots, @bodyshots, @legshots]
31
+ end
32
+
29
33
  private
30
34
 
31
35
  def fetch_general_data
@@ -43,14 +47,14 @@ class Player
43
47
  def fetch_aesthetics_data
44
48
  @player_card = @data['player_card']
45
49
  @player_title = @data['player_title']
46
- @assets_card = keys_to_sim(@data['assets']['card']) # This is a hash
47
- @assets_agent = keys_to_sim(@data['assets']['agent']) # This is a hash
50
+ @assets_card = keys_to_sym(@data['assets']['card']) # This is a hash
51
+ @assets_agent = keys_to_sym(@data['assets']['agent']) # This is a hash
48
52
  end
49
53
 
50
54
  def fetch_session_data
51
55
  @session_playtime = @data['session_playtime']['seconds'].to_i
52
- @behavior = keys_to_sim(@data['behavior']) # This is a hash
53
- @ability_casts = keys_to_sim(@data['ability_casts']) # This is a hash
56
+ @behavior = keys_to_sym(@data['behavior']) # This is a hash
57
+ @ability_casts = keys_to_sym(@data['ability_casts']) # This is a hash
54
58
  end
55
59
 
56
60
  def fetch_performance_data
@@ -81,7 +85,7 @@ class Player
81
85
  "#{platform["tpye"]} #{platform["os"].values.join(" ")}"
82
86
  end
83
87
 
84
- def keys_to_sim(hash)
88
+ def keys_to_sym(hash)
85
89
  hash.transform_keys(&:to_sym)
86
90
  end
87
91
  end
data/lib/api/version.rb CHANGED
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Valorant
4
4
  class Api
5
- VERSION = '0.1.3'
5
+ VERSION = '0.1.5'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: valorant
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gerard Hernandez
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-11-26 00:00:00.000000000 Z
11
+ date: 2022-11-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fast_jsonparser
@@ -52,12 +52,15 @@ files:
52
52
  - Rakefile
53
53
  - bin/console
54
54
  - bin/setup
55
+ - garbage.json
55
56
  - lib/api/account.rb
56
57
  - lib/api/match.rb
57
58
  - lib/api/misc.rb
58
59
  - lib/api/mmr.rb
59
60
  - lib/api/utils/article.rb
60
61
  - lib/api/utils/articles.rb
62
+ - lib/api/utils/asset.rb
63
+ - lib/api/utils/content.rb
61
64
  - lib/api/utils/leader.rb
62
65
  - lib/api/utils/leader_board.rb
63
66
  - lib/api/utils/match.rb