riotgames_api 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,110 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>
7
+ Top Level Namespace
8
+
9
+ &mdash; Documentation by YARD 0.9.18
10
+
11
+ </title>
12
+
13
+ <link rel="stylesheet" href="css/style.css" type="text/css" charset="utf-8" />
14
+
15
+ <link rel="stylesheet" href="css/common.css" type="text/css" charset="utf-8" />
16
+
17
+ <script type="text/javascript" charset="utf-8">
18
+ pathId = "";
19
+ relpath = '';
20
+ </script>
21
+
22
+
23
+ <script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
24
+
25
+ <script type="text/javascript" charset="utf-8" src="js/app.js"></script>
26
+
27
+
28
+ </head>
29
+ <body>
30
+ <div class="nav_wrap">
31
+ <iframe id="nav" src="class_list.html?1"></iframe>
32
+ <div id="resizer"></div>
33
+ </div>
34
+
35
+ <div id="main" tabindex="-1">
36
+ <div id="header">
37
+ <div id="menu">
38
+
39
+ <a href="_index.html">Index</a> &raquo;
40
+
41
+
42
+ <span class="title">Top Level Namespace</span>
43
+
44
+ </div>
45
+
46
+ <div id="search">
47
+
48
+ <a class="full_list_link" id="class_list_link"
49
+ href="class_list.html">
50
+
51
+ <svg width="24" height="24">
52
+ <rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
53
+ <rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
54
+ <rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
55
+ </svg>
56
+ </a>
57
+
58
+ </div>
59
+ <div class="clear"></div>
60
+ </div>
61
+
62
+ <div id="content"><h1>Top Level Namespace
63
+
64
+
65
+
66
+ </h1>
67
+ <div class="box_info">
68
+
69
+
70
+
71
+
72
+
73
+
74
+
75
+
76
+
77
+
78
+
79
+ </div>
80
+
81
+ <h2>Defined Under Namespace</h2>
82
+ <p class="children">
83
+
84
+
85
+ <strong class="modules">Modules:</strong> <span class='object_link'><a href="RiotAPI.html" title="RiotAPI (module)">RiotAPI</a></span>
86
+
87
+
88
+
89
+
90
+ </p>
91
+
92
+
93
+
94
+
95
+
96
+
97
+
98
+
99
+
100
+ </div>
101
+
102
+ <div id="footer">
103
+ Generated on Mon Apr 1 18:45:16 2019 by
104
+ <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
105
+ 0.9.18 (ruby-2.6.2).
106
+ </div>
107
+
108
+ </div>
109
+ </body>
110
+ </html>
@@ -2,19 +2,29 @@ require "riot_api/version"
2
2
  require "riot_api/client"
3
3
  require "riot_api/errors"
4
4
  require "riot_api/resources/summoner"
5
+ require "riot_api/resources/champion_mastery"
5
6
 
6
7
  module RiotAPI
7
8
  class << self
9
+ # Sets up the initial configuration for the client to work
10
+ # @param [String] api_key The Riot Games API key
8
11
  def configure(api_key)
9
12
  @client = Client.new(api_key)
10
- return nil
11
13
  end
12
14
 
15
+ # Resets any configuration set by +RiotAPI.configure+
16
+ def reset!
17
+ @client = nil
18
+ end
19
+
20
+ # Gets the instance of +RiotAPI::Client+. If the client hasn't been configured yet, it throws a
21
+ # +RiotAPI::ClientNotConfiguredError+.
22
+ # @return [RiotAPI::Client] The singleton instance of the client
13
23
  def client
14
- if @client
15
- @client
16
- else
24
+ if @client.nil?
17
25
  raise ClientNotConfiguredError, "You must call RiotAPI.configure with your API key before calling the API"
26
+ else
27
+ @client
18
28
  end
19
29
  end
20
30
  end
@@ -3,8 +3,10 @@ require 'uri'
3
3
  require 'json'
4
4
 
5
5
  module RiotAPI
6
+ # The +RiotAPI::Client+ class is resposible to handle HTTP requests between the library and the
7
+ # Riot Games API.
6
8
  class Client
7
- attr_accessor :api_key
9
+ attr_reader :api_key
8
10
 
9
11
  BASE_URLS = {
10
12
  # Regional endpoints
@@ -32,30 +34,29 @@ module RiotAPI
32
34
  raise ArgumentError, "The API key must be informed"
33
35
  end
34
36
 
35
- self.api_key = api_key
37
+ @api_key = api_key
36
38
  end
37
39
 
40
+ # Makes an HTTP request to the Riot Games API, based on the selected +region+. If the response
41
+ # status is different than HTTP 200, it will raise a +RiotAPI::ResponseError+ exception.
42
+ #
43
+ # @param [Symbol] method The HTTP method to use, e.g.: +:get+, +:post+, etc.
44
+ # @param [String] path The request path, e.g.: +/matches/1+
45
+ # @param [Symbol] region The League of Legends region to request. The supported list of regions are listed on +RiotAPI::Client::BASE_URLS+.
46
+ # @param [Hash] params The request parameters, e.g.: +{ name: "Example" }+
47
+ # @return [Hash] The request response
38
48
  def request(method, path, region, params = {})
39
- if api_key.nil? || api_key.empty?
40
- raise RiotAPI::InvalidRequestError, "The API key must be informed"
41
- end
42
-
43
- base_url = BASE_URLS[region]
44
- if base_url.nil?
49
+ unless BASE_URLS.key?(region)
45
50
  raise RiotAPI::InvalidRequestError, "The informed region is not supported. Select one of the following: #{BASE_URLS.keys}"
46
51
  end
47
- url = URI.escape("#{base_url}#{path}")
48
52
 
49
- uri = URI.parse(url)
50
- unless uri.is_a?(URI::HTTPS)
51
- raise RiotAPI::InvalidRequestError, "The request URL must be HTTPS"
52
- end
53
+ url = URI.escape("#{BASE_URLS[region]}#{path}")
53
54
 
54
- params.merge!({ api_key: api_key })
55
+ params.merge!({ api_key: @api_key })
55
56
 
56
57
  case method
57
58
  when :get
58
- request_get(uri, params)
59
+ request_get(URI(url), params)
59
60
  else
60
61
  raise RiotAPI::InvalidRequestError, "The method #{method} is not allowed"
61
62
  end
@@ -0,0 +1,99 @@
1
+ module RiotAPI
2
+ class ChampionMastery
3
+ # Is chest granted for this champion or not in current season.
4
+ attr_accessor :chest_granted
5
+
6
+ # Champion level for specified player and champion combination.
7
+ attr_accessor :champion_level
8
+
9
+ # Total number of champion points for this player and champion combination - they are used to determine championLevel.
10
+ attr_accessor :champion_points
11
+
12
+ # Champion ID for this entry.
13
+ attr_accessor :champion_id
14
+
15
+ # Number of points needed to achieve next level. Zero if player reached maximum champion level for this champion.
16
+ attr_accessor :champion_points_until_next_level
17
+
18
+ # Last time this champion was played by this player - in Unix milliseconds time format.
19
+ attr_accessor :last_play_time
20
+
21
+ # The token earned for this champion to levelup.
22
+ attr_accessor :tokens_earned
23
+
24
+ # Number of points earned since current level has been achieved.
25
+ attr_accessor :champion_points_since_last_level
26
+
27
+ # Summoner ID for this entry. (Encrypted)
28
+ attr_accessor :summoner_id
29
+
30
+ # Finds the summoner mastery for a specific champion.
31
+ # @example Find a summoner's mastery info with Irelia
32
+ # RiotAPI::ChampionMastery.find(region: :br, summoner_id: summoner.id, champion_id: 23)
33
+ # @param [Hash] options The options and filters to find the mastery info
34
+ # @option options [String] :region The League of Legends region associated with the account (e.g. +:br+, +:na+, etc)
35
+ # @option options [String] :summoner_id The encrypted summoner ID
36
+ # @option options [String] :champion_id The champion ID
37
+ # @return [RiotAPI::ChampionMastery] The champion mastery info
38
+ def self.find(options = {})
39
+ mandatory_options = [:region, :summoner_id, :champion_id]
40
+ unless (mandatory_options - options.keys).empty?
41
+ raise ArgumentError, "A required parameter was not informed. The required paramaters are #{mandatory_options}"
42
+ end
43
+
44
+ request_url = "/lol/champion-mastery/v4/champion-masteries/by-summoner/#{options[:summoner_id]}/by-champion/#{options[:champion_id]}"
45
+ response = RiotAPI.client.request(:get, request_url, options[:region])
46
+ self.from_json(response)
47
+ end
48
+
49
+ # Finds all champion mastery information for a specific summoner.
50
+ # @example Find a summoner's list of champion mastery
51
+ # RiotAPI::ChampionMastery.where(region: :br, summoner_id: summoner.id)
52
+ # @param [Hash] options The options and filters to find the mastery info
53
+ # @option options [String] :region The League of Legends region associated with the account (e.g. +:br+, +:na+, etc)
54
+ # @option options [String] :summoner_id The encrypted summoner ID
55
+ # @return [Array<RiotAPI::ChampionMastery>] A list of mastery info for each champion
56
+ def self.where(options = {})
57
+ mandatory_options = [:region, :summoner_id]
58
+ unless (mandatory_options - options.keys).empty?
59
+ raise ArgumentError, "A required parameter was not informed. The required paramaters are #{mandatory_options}"
60
+ end
61
+
62
+ request_url = "/lol/champion-mastery/v4/champion-masteries/by-summoner/#{options[:summoner_id]}"
63
+ response = RiotAPI.client.request(:get, request_url, options[:region])
64
+ response.map { |raw| self.from_json(raw) }
65
+ end
66
+
67
+
68
+ # Get a player's total champion mastery score, which is the sum of individual champion mastery levels.
69
+ # @example Find a summoner total champion mastery score
70
+ # RiotAPI::ChampionMastery.point_sum(region: :br, summoner_id: summoner.id)
71
+ # @param [Hash] options The options and filters to find the mastery points sum
72
+ # @option options [String] :region The League of Legends region associated with the account (e.g. +:br+, +:na+, etc)
73
+ # @option options [String] :summoner_id The encrypted summoner ID
74
+ # @return [Integer] The player's total champion mastery score
75
+ def self.score_sum(options = {})
76
+ mandatory_options = [:region, :summoner_id]
77
+ unless (mandatory_options - options.keys).empty?
78
+ raise ArgumentError, "A required parameter was not informed. The required paramaters are #{mandatory_options}"
79
+ end
80
+
81
+ request_url = "/lol/champion-mastery/v4/scores/by-summoner/#{options[:summoner_id]}"
82
+ response = RiotAPI.client.request(:get, request_url, options[:region])
83
+ end
84
+
85
+ def self.from_json(json)
86
+ self.new.tap do |s|
87
+ s.chest_granted = json["chestGranted"]
88
+ s.champion_level = json["championLevel"]
89
+ s.champion_points = json["championPoints"]
90
+ s.champion_id = json["championId"]
91
+ s.champion_points_until_next_level = json["championPointsUntilNextLevel"]
92
+ s.last_play_time = json["lastPlayTime"]
93
+ s.tokens_earned = json["tokensEarned"]
94
+ s.champion_points_since_last_level = json["championPointsSinceLastLevel"]
95
+ s.summoner_id = json["summonerId"]
96
+ end
97
+ end
98
+ end
99
+ end
@@ -1,7 +1,39 @@
1
1
  module RiotAPI
2
2
  class Summoner
3
- attr_accessor :id, :account_id, :profile_icon_id, :puuid, :summoner_level, :revision_date
3
+ # Encrypted summoner ID. Max length 63 characters.
4
+ attr_accessor :id
4
5
 
6
+ # Encrypted account ID. Max length 56 characters.
7
+ attr_accessor :account_id
8
+
9
+ # ID of the summoner icon associated with the summoner.
10
+ attr_accessor :profile_icon_id
11
+
12
+ # Encrypted PUUID. Exact length of 78 characters.
13
+ attr_accessor :puuid
14
+
15
+ # Summoner name.
16
+ attr_accessor :name
17
+
18
+ # Summoner level associated with the summoner.
19
+ attr_accessor :summoner_level
20
+
21
+ # Date summoner was last modified specified as epoch milliseconds. The following events will update this timestamp: profile icon change, playing the tutorial or advanced tutorial, finishing a game, summoner name change
22
+ attr_accessor :revision_date
23
+
24
+ # The summoner associated region, e.g.: +:br+, +:na+
25
+ attr_accessor :region
26
+
27
+ # Finds a summoner using the Riot Games API.
28
+ # @example Find a summoner by name
29
+ # RiotAPI::Summoner.find(region: :br, name: "Your Name")
30
+ # @param [Hash] options The options and filters to find the summoner
31
+ # @option options [String] :region The League of Legends region associated with the account (e.g. +:br+, +:na+, etc)
32
+ # @option options [String] :name The summoner name
33
+ # @option options [String] :id The encrypted summoner ID
34
+ # @option options [String] :account_id The encrypted account ID
35
+ # @option options [String] :puuid The encrypted PUUID
36
+ # @return [RiotAPI::Summoner] The summoner that was found
5
37
  def self.find(options = {})
6
38
  mandatory_options = [:region]
7
39
  accepted_filters = [:name, :id, :account_id, :puuid]
@@ -25,7 +57,9 @@ module RiotAPI
25
57
  )
26
58
 
27
59
  response = RiotAPI.client.request(:get, request_path, options[:region])
28
- self.from_json(response)
60
+ instance = self.from_json(response)
61
+ instance.region = options[:region]
62
+ instance
29
63
  end
30
64
 
31
65
  def self.from_json(json)
@@ -34,9 +68,16 @@ module RiotAPI
34
68
  s.account_id = json["account_id"]
35
69
  s.profile_icon_id = json["profile_icon_id"]
36
70
  s.puuid = json["puuid"]
71
+ s.name = json["name"]
37
72
  s.summoner_level = json["summoner_level"]
38
73
  s.revision_date = json["revision_date"]
39
74
  end
40
75
  end
76
+
77
+ # Returns a list of champion mastery for each champion
78
+ # @return [Array<RiotAPI::ChampionMastery>]
79
+ def masteries
80
+ ChampionMastery.where(region: self.region, summoner_id: self.id)
81
+ end
41
82
  end
42
83
  end
@@ -1,3 +1,3 @@
1
1
  module RiotAPI
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -24,4 +24,7 @@ Gem::Specification.new do |spec|
24
24
  spec.add_development_dependency "bundler", "~> 2.0"
25
25
  spec.add_development_dependency "rake", "~> 10.0"
26
26
  spec.add_development_dependency "rspec", "~> 3.0"
27
+ spec.add_development_dependency "yard"
28
+ spec.add_development_dependency "redcarpet"
29
+ spec.add_development_dependency "github-markup"
27
30
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: riotgames_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vinicius Brasil
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-03-30 00:00:00.000000000 Z
11
+ date: 2019-04-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,48 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: yard
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: redcarpet
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: github-markup
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
55
97
  description: The RiotAPI is a lightweight gem for accessing the Riot Games API using
56
98
  a cool DSL.
57
99
  email:
@@ -64,14 +106,38 @@ files:
64
106
  - ".gitignore"
65
107
  - ".rspec"
66
108
  - ".travis.yml"
109
+ - ".yardopts"
67
110
  - Gemfile
111
+ - LICENSE
68
112
  - README.md
69
113
  - Rakefile
70
114
  - bin/console
71
115
  - bin/setup
116
+ - docs/RiotAPI.html
117
+ - docs/RiotAPI/ChampionMastery.html
118
+ - docs/RiotAPI/Client.html
119
+ - docs/RiotAPI/ClientNotConfiguredError.html
120
+ - docs/RiotAPI/InvalidRequestError.html
121
+ - docs/RiotAPI/ResponseError.html
122
+ - docs/RiotAPI/Summoner.html
123
+ - docs/_index.html
124
+ - docs/class_list.html
125
+ - docs/css/common.css
126
+ - docs/css/full_list.css
127
+ - docs/css/style.css
128
+ - docs/file.README.html
129
+ - docs/file_list.html
130
+ - docs/frames.html
131
+ - docs/index.html
132
+ - docs/js/app.js
133
+ - docs/js/full_list.js
134
+ - docs/js/jquery.js
135
+ - docs/method_list.html
136
+ - docs/top-level-namespace.html
72
137
  - lib/riot_api.rb
73
138
  - lib/riot_api/client.rb
74
139
  - lib/riot_api/errors.rb
140
+ - lib/riot_api/resources/champion_mastery.rb
75
141
  - lib/riot_api/resources/summoner.rb
76
142
  - lib/riot_api/version.rb
77
143
  - riotgames_api.gemspec