rito 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.
Files changed (40) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +30 -0
  3. data/LICENSE +21 -0
  4. data/README.md +182 -0
  5. data/lib/rito/client.rb +118 -0
  6. data/lib/rito/connection.rb +39 -0
  7. data/lib/rito/endpoints/account_v1.rb +45 -0
  8. data/lib/rito/endpoints/base.rb +35 -0
  9. data/lib/rito/endpoints/lol/challenges_v1.rb +31 -0
  10. data/lib/rito/endpoints/lol/champion_mastery_v4.rb +33 -0
  11. data/lib/rito/endpoints/lol/champion_v3.rb +17 -0
  12. data/lib/rito/endpoints/lol/clash_v1.rb +27 -0
  13. data/lib/rito/endpoints/lol/league_v4.rb +58 -0
  14. data/lib/rito/endpoints/lol/match_v5.rb +34 -0
  15. data/lib/rito/endpoints/lol/spectator_v5.rb +22 -0
  16. data/lib/rito/endpoints/lol/status_v4.rb +15 -0
  17. data/lib/rito/endpoints/lol/summoner_v4.rb +35 -0
  18. data/lib/rito/endpoints/lol/tournament_v5.rb +69 -0
  19. data/lib/rito/endpoints/lor.rb +95 -0
  20. data/lib/rito/endpoints/tft.rb +123 -0
  21. data/lib/rito/endpoints/valorant.rb +92 -0
  22. data/lib/rito/errors.rb +55 -0
  23. data/lib/rito/instrumentation.rb +17 -0
  24. data/lib/rito/middleware/authentication.rb +21 -0
  25. data/lib/rito/middleware/rate_limit_observe.rb +32 -0
  26. data/lib/rito/middleware/rate_limit_throttle.rb +58 -0
  27. data/lib/rito/middleware/riot_errors.rb +81 -0
  28. data/lib/rito/models/account.rb +38 -0
  29. data/lib/rito/models/lol.rb +80 -0
  30. data/lib/rito/models/match.rb +71 -0
  31. data/lib/rito/models/summoner.rb +23 -0
  32. data/lib/rito/rate_limiting/adaptive_limiter.rb +71 -0
  33. data/lib/rito/rate_limiting/bucket.rb +83 -0
  34. data/lib/rito/rate_limiting/header_parser.rb +53 -0
  35. data/lib/rito/rate_limiting/null_limiter.rb +11 -0
  36. data/lib/rito/rate_limiting/redis_limiter.rb +153 -0
  37. data/lib/rito/routing.rb +79 -0
  38. data/lib/rito/version.rb +5 -0
  39. data/lib/rito.rb +71 -0
  40. metadata +109 -0
@@ -0,0 +1,79 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rito
4
+ module Routing
5
+ PLATFORMS = %w[
6
+ br1 eun1 euw1 jp1 kr la1 la2 me1 na1 oc1 ph2 ru sg2 th2 tr1 tw2 vn2
7
+ ].freeze
8
+ REGIONALS = %w[americas asia europe sea].freeze
9
+
10
+ CLUSTERS = {
11
+ 'americas' => %w[na1 br1 la1 la2],
12
+ 'europe' => %w[euw1 eun1 tr1 ru me1],
13
+ 'asia' => %w[kr jp1],
14
+ 'sea' => %w[oc1 sg2 tw2 vn2 ph2 th2]
15
+ }.freeze
16
+
17
+ ACCOUNT_REGIONALS = %w[americas asia europe].freeze
18
+
19
+ VALORANT_PLATFORMS = %w[na1 eu ap kr latam br].freeze
20
+ VALORANT_CONSOLE_PLATFORMS = %w[na eu ap].freeze
21
+
22
+ class << self
23
+ def platform?(value)
24
+ PLATFORMS.include?(normalize(value))
25
+ end
26
+
27
+ def regional?(value)
28
+ REGIONALS.include?(normalize(value))
29
+ end
30
+
31
+ def normalize(value)
32
+ value.to_s.downcase
33
+ end
34
+
35
+ def host_for(value)
36
+ v = normalize(value)
37
+ case v
38
+ when *PLATFORMS, *REGIONALS, *VALORANT_PLATFORMS, *VALORANT_CONSOLE_PLATFORMS
39
+ "#{v}.api.riotgames.com"
40
+ else
41
+ raise ArgumentError, "unknown routing value: #{value.inspect}"
42
+ end
43
+ end
44
+
45
+ def resolve(routing_kind, value)
46
+ v = normalize(value)
47
+ case routing_kind
48
+ when :valorant_platform
49
+ return v if VALORANT_PLATFORMS.include?(v)
50
+
51
+ raise ArgumentError, "#{value.inspect} is not usable as a VALORANT platform routing value"
52
+ when :valorant_console_platform
53
+ return v if VALORANT_CONSOLE_PLATFORMS.include?(v)
54
+
55
+ raise ArgumentError, "#{value.inspect} is not usable as a VALORANT console platform routing value"
56
+ end
57
+
58
+ return v if routing_kind == :platform && platform?(v)
59
+ return v if routing_kind == :regional && regional?(v)
60
+
61
+ if routing_kind == :regional && platform?(v)
62
+ CLUSTERS.each do |regional, platforms|
63
+ return regional if platforms.include?(v)
64
+ end
65
+ end
66
+
67
+ raise ArgumentError, "#{value.inspect} is not usable as a #{routing_kind} routing value"
68
+ end
69
+
70
+ def regional_for_account(value)
71
+ v = normalize(value)
72
+ return v if ACCOUNT_REGIONALS.include?(v)
73
+ return 'asia' if v == 'sea'
74
+
75
+ resolve(:regional, v)
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rito
4
+ VERSION = '0.1.0'
5
+ end
data/lib/rito.rb ADDED
@@ -0,0 +1,71 @@
1
+ # frozen_string_literal: true
2
+
3
+ # stdlib
4
+ require 'json'
5
+ require 'uri'
6
+ require 'erb/util'
7
+
8
+ # dependencies
9
+ require 'faraday'
10
+ require 'faraday/retry'
11
+
12
+ # modules
13
+ require_relative 'rito/routing'
14
+ require_relative 'rito/errors'
15
+ require_relative 'rito/rate_limiting/header_parser'
16
+ require_relative 'rito/rate_limiting/bucket'
17
+ require_relative 'rito/rate_limiting/null_limiter'
18
+ require_relative 'rito/rate_limiting/adaptive_limiter'
19
+ require_relative 'rito/rate_limiting/redis_limiter'
20
+ require_relative 'rito/middleware/authentication'
21
+ require_relative 'rito/middleware/rate_limit_throttle'
22
+ require_relative 'rito/middleware/rate_limit_observe'
23
+ require_relative 'rito/middleware/riot_errors'
24
+ require_relative 'rito/connection'
25
+ require_relative 'rito/instrumentation'
26
+ require_relative 'rito/client'
27
+ require_relative 'rito/models/account'
28
+ require_relative 'rito/models/summoner'
29
+ require_relative 'rito/models/match'
30
+ require_relative 'rito/models/lol'
31
+ require_relative 'rito/endpoints/base'
32
+ require_relative 'rito/endpoints/account_v1'
33
+ require_relative 'rito/endpoints/lol/summoner_v4'
34
+ require_relative 'rito/endpoints/lol/match_v5'
35
+ require_relative 'rito/endpoints/lol/champion_mastery_v4'
36
+ require_relative 'rito/endpoints/lol/champion_v3'
37
+ require_relative 'rito/endpoints/lol/league_v4'
38
+ require_relative 'rito/endpoints/lol/spectator_v5'
39
+ require_relative 'rito/endpoints/lol/status_v4'
40
+ require_relative 'rito/endpoints/lol/clash_v1'
41
+ require_relative 'rito/endpoints/lol/challenges_v1'
42
+ require_relative 'rito/endpoints/lol/tournament_v5'
43
+ require_relative 'rito/endpoints/tft'
44
+ require_relative 'rito/endpoints/valorant'
45
+ require_relative 'rito/endpoints/lor'
46
+ require_relative 'rito/version'
47
+
48
+ module Rito
49
+ class << self
50
+ attr_accessor :api_key, :bearer_token, :region, :rate_limiter, :max_retries,
51
+ :open_timeout, :timeout, :adapter
52
+
53
+ def configure
54
+ yield self
55
+ self
56
+ end
57
+
58
+ def client(**options)
59
+ Client.new(**options)
60
+ end
61
+ end
62
+
63
+ self.api_key = ENV['RIOT_API_KEY']
64
+ self.bearer_token = ENV['RIOT_RSO_TOKEN']
65
+ self.region = :na1
66
+ self.rate_limiter = nil
67
+ self.max_retries = 3
68
+ self.open_timeout = 2
69
+ self.timeout = 10
70
+ self.adapter = Faraday.default_adapter
71
+ end
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rito
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - kodbilenadam
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: faraday
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '2.13'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: '2.13'
26
+ - !ruby/object:Gem::Dependency
27
+ name: faraday-retry
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: '2.2'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '2.2'
40
+ description: Full-coverage Ruby client for the Riot Games API (League of Legends,
41
+ TFT, VALORANT, Legends of Runeterra, Riot Account) with adaptive rate limiting.
42
+ executables: []
43
+ extensions: []
44
+ extra_rdoc_files: []
45
+ files:
46
+ - CHANGELOG.md
47
+ - LICENSE
48
+ - README.md
49
+ - lib/rito.rb
50
+ - lib/rito/client.rb
51
+ - lib/rito/connection.rb
52
+ - lib/rito/endpoints/account_v1.rb
53
+ - lib/rito/endpoints/base.rb
54
+ - lib/rito/endpoints/lol/challenges_v1.rb
55
+ - lib/rito/endpoints/lol/champion_mastery_v4.rb
56
+ - lib/rito/endpoints/lol/champion_v3.rb
57
+ - lib/rito/endpoints/lol/clash_v1.rb
58
+ - lib/rito/endpoints/lol/league_v4.rb
59
+ - lib/rito/endpoints/lol/match_v5.rb
60
+ - lib/rito/endpoints/lol/spectator_v5.rb
61
+ - lib/rito/endpoints/lol/status_v4.rb
62
+ - lib/rito/endpoints/lol/summoner_v4.rb
63
+ - lib/rito/endpoints/lol/tournament_v5.rb
64
+ - lib/rito/endpoints/lor.rb
65
+ - lib/rito/endpoints/tft.rb
66
+ - lib/rito/endpoints/valorant.rb
67
+ - lib/rito/errors.rb
68
+ - lib/rito/instrumentation.rb
69
+ - lib/rito/middleware/authentication.rb
70
+ - lib/rito/middleware/rate_limit_observe.rb
71
+ - lib/rito/middleware/rate_limit_throttle.rb
72
+ - lib/rito/middleware/riot_errors.rb
73
+ - lib/rito/models/account.rb
74
+ - lib/rito/models/lol.rb
75
+ - lib/rito/models/match.rb
76
+ - lib/rito/models/summoner.rb
77
+ - lib/rito/rate_limiting/adaptive_limiter.rb
78
+ - lib/rito/rate_limiting/bucket.rb
79
+ - lib/rito/rate_limiting/header_parser.rb
80
+ - lib/rito/rate_limiting/null_limiter.rb
81
+ - lib/rito/rate_limiting/redis_limiter.rb
82
+ - lib/rito/routing.rb
83
+ - lib/rito/version.rb
84
+ homepage: https://github.com/kodbilenadam/rito
85
+ licenses:
86
+ - MIT
87
+ metadata:
88
+ homepage_uri: https://github.com/kodbilenadam/rito
89
+ source_code_uri: https://github.com/kodbilenadam/rito
90
+ changelog_uri: https://github.com/kodbilenadam/rito/blob/main/CHANGELOG.md
91
+ rubygems_mfa_required: 'true'
92
+ rdoc_options: []
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '3.2'
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ requirements: []
106
+ rubygems_version: 4.0.20
107
+ specification_version: 4
108
+ summary: A modern, production-ready Ruby client for the Riot Games API.
109
+ test_files: []