riotgames_api 0.1.0
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.
- checksums.yaml +7 -0
- data/.editorconfig +11 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/Gemfile +4 -0
- data/README.md +43 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/riot_api.rb +21 -0
- data/lib/riot_api/client.rb +77 -0
- data/lib/riot_api/errors.rb +13 -0
- data/lib/riot_api/resources/summoner.rb +41 -0
- data/lib/riot_api/version.rb +3 -0
- data/riotgames_api.gemspec +27 -0
- metadata +100 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1481645dbd958502946a683faf77c8f67acf44912aab1cc194eeb5f8f9e323ed
|
4
|
+
data.tar.gz: 0fb9ffcafc6c5ed285043dfc29af016177c3663deea8bc82b3fd9fc2acbbbf39
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 84f11cc918fc2ec3f917152d0356fe0501454eb13b2b59e3b3298642558e63548b32e5e6cafbfd356cabf92e652c7076ea842b8137321f1acb27950f83aaeeba
|
7
|
+
data.tar.gz: af045e6586c0a4440fe9c8aca3d7600e76008944b2b09371eedf9d989f9c4445c9b1d9b77dcb29d9c1b0556ec7e3698c31bfa0e63b4698fc3784e4a1772ee775
|
data/.editorconfig
ADDED
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# RiotAPI
|
2
|
+
|
3
|
+
The RiotAPI gem allows Ruby developers to programatically access the Riot Games API with a cool DSL. P.S.: Blitzcrank approves!
|
4
|
+
|
5
|
+

|
6
|
+
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem 'riotgames_api'
|
14
|
+
```
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
$ bundle
|
19
|
+
|
20
|
+
Or install it yourself as:
|
21
|
+
|
22
|
+
$ gem install riotgames_api
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
# Do this once in your application startup
|
28
|
+
RiotAPI.configure "your api key"
|
29
|
+
|
30
|
+
# And use it =)
|
31
|
+
RiotAPI::Summoner.find(name: "Mid or Feed", region: :na)
|
32
|
+
# => #<RiotAPI::Summoner:0x00007fffd0a3b9c0 @id="pLIQUh9AUMSSwLMKdlNscoDEkoIYs2fYGAytTIKHkwy5YWg", @account_id=nil, @profile_icon_id=nil, @puuid="7qiWDJqhrCjc2xLDvfEsm2UiZOvo6l7UjBjUuRq7cwtWXRgSh8fGR59YC1Ls3mBZao6nDW_JiQ05gw", @summoner_level=nil, @revision_date=nil>
|
33
|
+
```
|
34
|
+
|
35
|
+
## Development
|
36
|
+
|
37
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
38
|
+
|
39
|
+
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).
|
40
|
+
|
41
|
+
## Contributing
|
42
|
+
|
43
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/vnbrs/riot_api.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "riot_api"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/riot_api.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require "riot_api/version"
|
2
|
+
require "riot_api/client"
|
3
|
+
require "riot_api/errors"
|
4
|
+
require "riot_api/resources/summoner"
|
5
|
+
|
6
|
+
module RiotAPI
|
7
|
+
class << self
|
8
|
+
def configure(api_key)
|
9
|
+
@client = Client.new(api_key)
|
10
|
+
return nil
|
11
|
+
end
|
12
|
+
|
13
|
+
def client
|
14
|
+
if @client
|
15
|
+
@client
|
16
|
+
else
|
17
|
+
raise ClientNotConfiguredError, "You must call RiotAPI.configure with your API key before calling the API"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'uri'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
module RiotAPI
|
6
|
+
class Client
|
7
|
+
attr_accessor :api_key
|
8
|
+
|
9
|
+
BASE_URLS = {
|
10
|
+
# Regional endpoints
|
11
|
+
br: "https://br1.api.riotgames.com",
|
12
|
+
eune: "https://eun1.api.riotgames.com",
|
13
|
+
euw: "https://euw1.api.riotgames.com",
|
14
|
+
jp: "https://jp1.api.riotgames.com",
|
15
|
+
kr: "https://kr.api.riotgames.com",
|
16
|
+
lan: "https://la1.api.riotgames.com",
|
17
|
+
las: "https://la2.api.riotgames.com",
|
18
|
+
na: "https://na1.api.riotgames.com",
|
19
|
+
oce: "https://oc1.api.riotgames.com",
|
20
|
+
tr: "https://tr1.api.riotgames.com",
|
21
|
+
ru: "https://ru.api.riotgames.com",
|
22
|
+
pbe: "https://pbe1.api.riotgames.com",
|
23
|
+
|
24
|
+
# Regional proxies
|
25
|
+
americas: "https://americas.api.riotgames.com",
|
26
|
+
europe: "https://europe.api.riotgames.com",
|
27
|
+
asia: "https://asia.api.riotgames.com"
|
28
|
+
}
|
29
|
+
|
30
|
+
def initialize(api_key)
|
31
|
+
if api_key.nil? || api_key.empty?
|
32
|
+
raise ArgumentError, "The API key must be informed"
|
33
|
+
end
|
34
|
+
|
35
|
+
self.api_key = api_key
|
36
|
+
end
|
37
|
+
|
38
|
+
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?
|
45
|
+
raise RiotAPI::InvalidRequestError, "The informed region is not supported. Select one of the following: #{BASE_URLS.keys}"
|
46
|
+
end
|
47
|
+
url = URI.escape("#{base_url}#{path}")
|
48
|
+
|
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
|
+
|
54
|
+
params.merge!({ api_key: api_key })
|
55
|
+
|
56
|
+
case method
|
57
|
+
when :get
|
58
|
+
request_get(uri, params)
|
59
|
+
else
|
60
|
+
raise RiotAPI::InvalidRequestError, "The method #{method} is not allowed"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
private
|
65
|
+
|
66
|
+
def request_get(uri, params)
|
67
|
+
uri.query = URI.encode_www_form(params)
|
68
|
+
response = Net::HTTP.get_response(uri)
|
69
|
+
|
70
|
+
if response.is_a?(Net::HTTPSuccess)
|
71
|
+
JSON.parse(response.body)
|
72
|
+
else
|
73
|
+
raise RiotAPI::ResponseError, response
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module RiotAPI
|
2
|
+
class InvalidRequestError < StandardError; end
|
3
|
+
class ClientNotConfiguredError < StandardError; end
|
4
|
+
|
5
|
+
class ResponseError < StandardError
|
6
|
+
attr_accessor :response
|
7
|
+
|
8
|
+
def initialize(response)
|
9
|
+
self.response = response
|
10
|
+
super("An error has occurred during the HTTP request. Check the response for more details.")
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module RiotAPI
|
2
|
+
class Summoner
|
3
|
+
attr_accessor :id, :account_id, :profile_icon_id, :puuid, :summoner_level, :revision_date
|
4
|
+
|
5
|
+
def self.find(options = {})
|
6
|
+
mandatory_options = [:region]
|
7
|
+
accepted_filters = [:name, :id, :account_id, :puuid]
|
8
|
+
|
9
|
+
unless (mandatory_options - options.keys).empty?
|
10
|
+
raise ArgumentError, "A required parameter was not informed. The required paramaters are #{mandatory_options}"
|
11
|
+
end
|
12
|
+
|
13
|
+
request_path = (
|
14
|
+
if options.key?(:name)
|
15
|
+
"/lol/summoner/v4/summoners/by-name/#{options[:name]}"
|
16
|
+
elsif options.key?(:id)
|
17
|
+
"/lol/summoner/v4/summoners/#{options[:id]}"
|
18
|
+
elsif options.key?(:account_id)
|
19
|
+
"/lol/summoner/v4/summoners/by-account/#{options[:account_id]}"
|
20
|
+
elsif options.key?(:puuid)
|
21
|
+
"/lol/summoner/v4/summoners/by-puuid/#{options[:puuid]}"
|
22
|
+
else
|
23
|
+
raise ArgumentError, "The informed filter is not accepted. The accepted filters are #{accepted_filters}"
|
24
|
+
end
|
25
|
+
)
|
26
|
+
|
27
|
+
response = RiotAPI.client.request(:get, request_path, options[:region])
|
28
|
+
self.from_json(response)
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.from_json(json)
|
32
|
+
self.new.tap do |s|
|
33
|
+
s.id = json["id"]
|
34
|
+
s.account_id = json["account_id"]
|
35
|
+
s.profile_icon_id = json["profile_icon_id"]
|
36
|
+
s.puuid = json["puuid"]
|
37
|
+
s.summoner_level = json["summoner_level"]
|
38
|
+
s.revision_date = json["revision_date"]
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "riot_api/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "riotgames_api"
|
7
|
+
spec.version = RiotAPI::VERSION
|
8
|
+
spec.authors = ["Vinicius Brasil"]
|
9
|
+
spec.email = ["vnbrs@icloud.com"]
|
10
|
+
|
11
|
+
spec.summary = "RiotAPI is the coolest Riot Games API gem. Blitzcrank approves!"
|
12
|
+
spec.description = "The RiotAPI is a lightweight gem for accessing the Riot Games API using a cool DSL."
|
13
|
+
spec.homepage = "https://github.com/vnbrs/riot_api"
|
14
|
+
|
15
|
+
# Specify which files should be added to the gem when it is released.
|
16
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
17
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
18
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
19
|
+
end
|
20
|
+
spec.bindir = "exe"
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: riotgames_api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Vinicius Brasil
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-03-30 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: '2.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
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: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
description: The RiotAPI is a lightweight gem for accessing the Riot Games API using
|
56
|
+
a cool DSL.
|
57
|
+
email:
|
58
|
+
- vnbrs@icloud.com
|
59
|
+
executables: []
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".editorconfig"
|
64
|
+
- ".gitignore"
|
65
|
+
- ".rspec"
|
66
|
+
- ".travis.yml"
|
67
|
+
- Gemfile
|
68
|
+
- README.md
|
69
|
+
- Rakefile
|
70
|
+
- bin/console
|
71
|
+
- bin/setup
|
72
|
+
- lib/riot_api.rb
|
73
|
+
- lib/riot_api/client.rb
|
74
|
+
- lib/riot_api/errors.rb
|
75
|
+
- lib/riot_api/resources/summoner.rb
|
76
|
+
- lib/riot_api/version.rb
|
77
|
+
- riotgames_api.gemspec
|
78
|
+
homepage: https://github.com/vnbrs/riot_api
|
79
|
+
licenses: []
|
80
|
+
metadata: {}
|
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
|
+
rubygems_version: 3.0.3
|
97
|
+
signing_key:
|
98
|
+
specification_version: 4
|
99
|
+
summary: RiotAPI is the coolest Riot Games API gem. Blitzcrank approves!
|
100
|
+
test_files: []
|