brawlstars 1.1.0 → 1.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: db0f7033f39049ef0c73b45795a2785ff919d210c67c4cb13015b87706fb8158
4
- data.tar.gz: 5596769126a3238f5ab7a5cd1aa8d2cfe060f07308aacfd80816286b2e8be229
3
+ metadata.gz: 8902a919795f60723f5a8f77e36569392a9b27e8878fe0e793055d41e3d2712f
4
+ data.tar.gz: 0c17121b5cd27736d9caf1f829c71ad2473180a28ccc2cdd99ecd2aab91cbe9f
5
5
  SHA512:
6
- metadata.gz: 12f0ac279d0d76caa0386b1e33bd4ffa280f9f93d185572d96f65d0eccfd52161378083a11247f9c270e9a1bbeb32d3a4dc474ab2db5deb2ff90eb415e363e51
7
- data.tar.gz: 2ebc2f83106133a9043e33253e2ba03dc9f352acc562efe76c6032a1ed9ae6d1b7f44f5e3516e5ea16a6caf47de966d0815fafde3d77f57dc69374e03b7d91e2
6
+ metadata.gz: 8777330e81cf08f1ab781d2beb0010b4c348ee17251d0399d3a5ae3f27ad9e9bfeaf630c3ebb5ff1b6839ac6219771ce89d9b0e30bc705c87eea52d8f736faa1
7
+ data.tar.gz: 804a12d588385539bd7cdb1a9629e694af9838c556499d75026b8776870d494c3b49c3b94df1fb2ad4ac5eb4bd10b76c4f0593b618fa2b84c23d825ad6332ca5
data/CHANGELOG.md ADDED
@@ -0,0 +1,10 @@
1
+ # Changelog
2
+ ## [1.1.0]
3
+ ### Added
4
+ - Custom Error Types
5
+
6
+ ## [1.0.0]
7
+ Initial version
8
+
9
+ [1.1.0]: https://github.com/Karthik99999/brawlstarsrb/tree/v1.1.0
10
+ [1.0.0]: https://github.com/Karthik99999/brawlstarsrb/tree/v1.0.0
data/brawlstars.gemspec CHANGED
@@ -20,6 +20,12 @@ Gem::Specification.new do |spec|
20
20
  spec.require_paths = ["lib"]
21
21
  spec.required_ruby_version = '>= 2.0.0'
22
22
  spec.post_install_message = "Brawlstarsrb is my name, GETting is my game!"
23
+ spec.metadata = {
24
+ "bug_tracker_uri" => "https://github.com/Karthik99999/brawlstarsrb/issues",
25
+ "changelog_uri" => "https://github.com/Karthik99999/brawlstarsrb/CHANGELOG.md",
26
+ "documentation_uri" => "https://www.rubydoc.info/github/Karthik99999/brawlstarsrb",
27
+ "source_code_uri" => "https://github.com/Karthik99999/brawlstarsrb"
28
+ }
23
29
 
24
30
  spec.add_dependency "httparty", "~> 0.17.0"
25
31
 
data/lib/brawlstars.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require "httparty"
2
2
  require "brawlstars/tag"
3
+ require "brawlstars/region"
3
4
 
4
5
  module Brawlstars
5
6
  class Error
@@ -13,6 +14,11 @@ module Brawlstars
13
14
  'The tag given was invalid.'
14
15
  end
15
16
  end
17
+ class RegionError < StandardError
18
+ def message
19
+ 'The region must be a valid 2 character country code.'
20
+ end
21
+ end
16
22
  class NotFoundError < StandardError
17
23
  def message
18
24
  'The tag given was not found.'
@@ -37,35 +43,7 @@ module Brawlstars
37
43
  class Client
38
44
  def initialize(token: false)
39
45
  raise "No authorization token was given!" if !token
40
- @@token = token
41
- end
42
-
43
- # The method to send GET requests to the API
44
- #
45
- # @param ep [String] the endpoint to get.
46
- # @return [Hash] the response returned by the endpoint.
47
-
48
- def self.get(ep)
49
- url = "https://api.brawlapi.cf/v1#{ep}"
50
- begin
51
- res = HTTParty.get(url, {headers: {"Authorization" => @@token}})
52
- rescue HTTParty::Error => e
53
- puts e
54
- end
55
- case res.code
56
- when 200
57
- res
58
- when 401
59
- raise Error::Unauthorized
60
- when 404
61
- raise Error::NotFoundError
62
- when 429
63
- raise Error::RateLimitError
64
- when 503
65
- raise Error::MaintainanceError
66
- when 500...600
67
- raise Error::ServerError
68
- end
46
+ @token = token
69
47
  end
70
48
 
71
49
  # Get info about the API
@@ -73,7 +51,7 @@ module Brawlstars
73
51
  # @return [Hash] info about the API
74
52
 
75
53
  def about
76
- Client.get("/about")
54
+ get("/about")
77
55
  end
78
56
 
79
57
  # Get a player by their tag
@@ -83,7 +61,7 @@ module Brawlstars
83
61
 
84
62
  def getPlayer(tag)
85
63
  tag = validateTag(tag)
86
- Client.get("/player?tag=#{tag}")
64
+ get("/player?tag=#{tag}")
87
65
  end
88
66
 
89
67
  # Search for players by their name
@@ -92,7 +70,17 @@ module Brawlstars
92
70
  # @return [Hash] players returned by the search.
93
71
 
94
72
  def playerSearch(name)
95
- Client.get("/player/search?name=#{name.gsub(' ', '%20')}")
73
+ get("/player/search?name=#{name.gsub(' ', '%20')}")
74
+ end
75
+
76
+ # Get a player's battle log by their tag
77
+ #
78
+ # @param tag [String] tag of the player to get.
79
+ # @return [Hash] data of the player's battle log that was searched.
80
+
81
+ def getBattleLog(tag)
82
+ tag = validateTag(tag)
83
+ get("/player/battlelog?tag=#{tag}")
96
84
  end
97
85
 
98
86
  # Get a club by its tag
@@ -102,7 +90,7 @@ module Brawlstars
102
90
 
103
91
  def getClub(tag)
104
92
  tag = validateTag(tag)
105
- Client.get("/club?tag=#{tag}")
93
+ get("/club?tag=#{tag}")
106
94
  end
107
95
 
108
96
  # Search for clubs by their name
@@ -111,7 +99,7 @@ module Brawlstars
111
99
  # @return [Hash] clubs returned by the search.
112
100
 
113
101
  def clubSearch(name)
114
- Client.get("/club/search?name=#{name.gsub(' ', '%20')}")
102
+ get("/club/search?name=#{name.gsub(' ', '%20')}")
115
103
  end
116
104
 
117
105
  # Get upcoming events
@@ -119,7 +107,7 @@ module Brawlstars
119
107
  # @return [Hash] upcoming events
120
108
 
121
109
  def getUpcomingEvents
122
- Client.get("/events?type=upcoming")
110
+ get("/events?type=upcoming")
123
111
  end
124
112
 
125
113
  # Get current events
@@ -127,7 +115,7 @@ module Brawlstars
127
115
  # @return [Hash] current events
128
116
 
129
117
  def getCurrentEvents
130
- Client.get("/events?type=current")
118
+ get("/events?type=current")
131
119
  end
132
120
 
133
121
  # Get miscellaneous data, like shop/season reset
@@ -135,30 +123,64 @@ module Brawlstars
135
123
  # @return [Hash] miscellaneous data
136
124
 
137
125
  def getMisc
138
- Client.get("/misc")
126
+ get("/misc")
139
127
  end
140
128
 
141
129
  # Get top global clubs
142
130
  #
143
131
  # @param count [Integer] number of clubs to return.
132
+ # @param region [String] 2 character country code for the region of leaderboard to return.
144
133
  # @return [Hash] clubs in order from 1st rank down.
145
134
 
146
- def getTopClubs(count=200)
135
+ def getTopClubs(count=200, region="global")
147
136
  raise 'Count must be a number.' if !count.is_a? Integer
148
137
  raise 'Count must be between 1 and 200.' if !count.between?(1,200)
149
- Client.get("/leaderboards/clubs?count=#{count}")
138
+ validateRegion(region)
139
+ get("/leaderboards/clubs?count=#{count}&region=#{region}")
150
140
  end
151
141
 
152
142
  # Get top global players
153
143
  #
154
144
  # @param count [Integer] number of players to return.
155
145
  # @param brawler [String] brawler leaderboard to return.
146
+ # @param region [String] 2 character country code for the region of leaderboard to return.
156
147
  # @return [Hash] players in order from 1st rank down.
157
148
 
158
- def getTopPlayers(count=200, brawler="")
149
+ def getTopPlayers(count=200, brawler="", region="global")
159
150
  raise 'Count must be a number.' if !count.is_a? Integer
160
151
  raise 'Count must be between 1 and 200.' if !count.between?(1,200)
161
- Client.get("/leaderboards/players?count=#{count}&brawler=#{brawler}")
152
+ validateRegion(region)
153
+ get("/leaderboards/players?count=#{count}&brawler=#{brawler}&region=#{region}")
154
+ end
155
+
156
+ protected
157
+
158
+ # The method to send GET requests to the API
159
+ #
160
+ # @param ep [String] the endpoint to get.
161
+ # @return [Hash] the response returned by the endpoint.
162
+
163
+ def get(ep)
164
+ url = "https://api.brawlapi.cf/v1#{ep}"
165
+ begin
166
+ res = HTTParty.get(url, {headers: {"Authorization" => @token}})
167
+ rescue HTTParty::Error => e
168
+ puts e
169
+ end
170
+ case res.code
171
+ when 200
172
+ res
173
+ when 401
174
+ raise Error::Unauthorized
175
+ when 404
176
+ raise Error::NotFoundError
177
+ when 429
178
+ raise Error::RateLimitError
179
+ when 503
180
+ raise Error::MaintainanceError
181
+ when 500...600
182
+ raise Error::ServerError
183
+ end
162
184
  end
163
185
  end
164
186
  end
@@ -0,0 +1,3 @@
1
+ def validateRegion(region)
2
+ raise Brawlstars::Error::RegionError if (region != "global" and region.length != 2)
3
+ end
@@ -1,3 +1,3 @@
1
1
  module Brawlstars
2
- VERSION = "1.1.0"
2
+ VERSION = "1.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: brawlstars
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Karthik99999
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-05-24 00:00:00.000000000 Z
11
+ date: 2019-07-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -61,6 +61,7 @@ extensions: []
61
61
  extra_rdoc_files: []
62
62
  files:
63
63
  - ".gitignore"
64
+ - CHANGELOG.md
64
65
  - Gemfile
65
66
  - LICENSE
66
67
  - README.md
@@ -69,12 +70,17 @@ files:
69
70
  - bin/setup
70
71
  - brawlstars.gemspec
71
72
  - lib/brawlstars.rb
73
+ - lib/brawlstars/region.rb
72
74
  - lib/brawlstars/tag.rb
73
75
  - lib/brawlstars/version.rb
74
76
  homepage: https://github.com/Karthik99999/brawlstarsrb
75
77
  licenses:
76
78
  - MIT
77
- metadata: {}
79
+ metadata:
80
+ bug_tracker_uri: https://github.com/Karthik99999/brawlstarsrb/issues
81
+ changelog_uri: https://github.com/Karthik99999/brawlstarsrb/CHANGELOG.md
82
+ documentation_uri: https://www.rubydoc.info/github/Karthik99999/brawlstarsrb
83
+ source_code_uri: https://github.com/Karthik99999/brawlstarsrb
78
84
  post_install_message: Brawlstarsrb is my name, GETting is my game!
79
85
  rdoc_options: []
80
86
  require_paths:
@@ -90,8 +96,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
90
96
  - !ruby/object:Gem::Version
91
97
  version: '0'
92
98
  requirements: []
93
- rubyforge_project:
94
- rubygems_version: 2.7.6
99
+ rubygems_version: 3.0.3
95
100
  signing_key:
96
101
  specification_version: 4
97
102
  summary: BrawlAPI for Ruby