brawlstars 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b439c0a3393ef502fa11f7dbebf6829bb328c25b9560292645fa341fbc18b15a
4
- data.tar.gz: da99ada392dc99c10cc72e0f8501c6dedf7dbdf8646ec93d4ebfc697424e74b1
3
+ metadata.gz: db0f7033f39049ef0c73b45795a2785ff919d210c67c4cb13015b87706fb8158
4
+ data.tar.gz: 5596769126a3238f5ab7a5cd1aa8d2cfe060f07308aacfd80816286b2e8be229
5
5
  SHA512:
6
- metadata.gz: 9d364c8c2055703d946cb7117700899492ae3f389edfff3541f7f94746644c304a0c342fdf4fe60837271fa750135a20bb6252a0a627c9f039a14a5a707df45b
7
- data.tar.gz: a47b21ab4c381eaee62ba9d86c5bb555838903a93b23807b50a13bc570e27920dc056edbd38dbf88556351a008d0dbb8f0a66099ace6ae44310538c531a102fc
6
+ metadata.gz: 12f0ac279d0d76caa0386b1e33bd4ffa280f9f93d185572d96f65d0eccfd52161378083a11247f9c270e9a1bbeb32d3a4dc474ab2db5deb2ff90eb415e363e51
7
+ data.tar.gz: 2ebc2f83106133a9043e33253e2ba03dc9f352acc562efe76c6032a1ed9ae6d1b7f44f5e3516e5ea16a6caf47de966d0815fafde3d77f57dc69374e03b7d91e2
@@ -18,6 +18,8 @@ Gem::Specification.new do |spec|
18
18
  spec.bindir = "exe"
19
19
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
20
  spec.require_paths = ["lib"]
21
+ spec.required_ruby_version = '>= 2.0.0'
22
+ spec.post_install_message = "Brawlstarsrb is my name, GETting is my game!"
21
23
 
22
24
  spec.add_dependency "httparty", "~> 0.17.0"
23
25
 
@@ -2,16 +2,49 @@ require "httparty"
2
2
  require "brawlstars/tag"
3
3
 
4
4
  module Brawlstars
5
- class Error < StandardError; end
5
+ class Error
6
+ class Unauthorized < StandardError
7
+ def message
8
+ 'The API token given was invalid or blocked.'
9
+ end
10
+ end
11
+ class TagError < StandardError
12
+ def message
13
+ 'The tag given was invalid.'
14
+ end
15
+ end
16
+ class NotFoundError < StandardError
17
+ def message
18
+ 'The tag given was not found.'
19
+ end
20
+ end
21
+ class RateLimitError < StandardError
22
+ def message
23
+ 'The rate limit has been hit.'
24
+ end
25
+ end
26
+ class MaintainanceError < StandardError
27
+ def message
28
+ 'There is a maintainance break. Try again later.'
29
+ end
30
+ end
31
+ class ServerError < StandardError
32
+ def message
33
+ 'The API is down. Try again later.'
34
+ end
35
+ end
36
+ end
6
37
  class Client
7
38
  def initialize(token: false)
8
39
  raise "No authorization token was given!" if !token
9
40
  @@token = token
10
41
  end
42
+
11
43
  # The method to send GET requests to the API
12
44
  #
13
45
  # @param ep [String] the endpoint to get.
14
46
  # @return [Hash] the response returned by the endpoint.
47
+
15
48
  def self.get(ep)
16
49
  url = "https://api.brawlapi.cf/v1#{ep}"
17
50
  begin
@@ -22,8 +55,16 @@ module Brawlstars
22
55
  case res.code
23
56
  when 200
24
57
  res
25
- when 400...600
26
- raise "Error on request; Status code: #{res.code}; Message: #{res["message"]}"
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
27
68
  end
28
69
  end
29
70
 
@@ -108,9 +149,9 @@ module Brawlstars
108
149
  Client.get("/leaderboards/clubs?count=#{count}")
109
150
  end
110
151
 
111
- # Get top global clubs
152
+ # Get top global players
112
153
  #
113
- # @param count [Integer] number of clubs to return.
154
+ # @param count [Integer] number of players to return.
114
155
  # @param brawler [String] brawler leaderboard to return.
115
156
  # @return [Hash] players in order from 1st rank down.
116
157
 
@@ -4,6 +4,6 @@ end
4
4
 
5
5
  def validateTag(tag)
6
6
  tag = cleanTag(tag)
7
- raise "An invalid tag was given!" if !tag.match(/^[0289CGJLPQRUVY]+$/)
7
+ raise Brawlstars::Error::TagError if !tag.match(/^[0289CGJLPQRUVY]+$/)
8
8
  tag
9
9
  end
@@ -1,3 +1,3 @@
1
1
  module Brawlstars
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.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.0.0
4
+ version: 1.1.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-21 00:00:00.000000000 Z
11
+ date: 2019-05-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -75,7 +75,7 @@ homepage: https://github.com/Karthik99999/brawlstarsrb
75
75
  licenses:
76
76
  - MIT
77
77
  metadata: {}
78
- post_install_message:
78
+ post_install_message: Brawlstarsrb is my name, GETting is my game!
79
79
  rdoc_options: []
80
80
  require_paths:
81
81
  - lib
@@ -83,14 +83,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
83
83
  requirements:
84
84
  - - ">="
85
85
  - !ruby/object:Gem::Version
86
- version: '0'
86
+ version: 2.0.0
87
87
  required_rubygems_version: !ruby/object:Gem::Requirement
88
88
  requirements:
89
89
  - - ">="
90
90
  - !ruby/object:Gem::Version
91
91
  version: '0'
92
92
  requirements: []
93
- rubygems_version: 3.0.3
93
+ rubyforge_project:
94
+ rubygems_version: 2.7.6
94
95
  signing_key:
95
96
  specification_version: 4
96
97
  summary: BrawlAPI for Ruby