brawlstars 1.0.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/.gitignore +8 -0
- data/Gemfile +4 -0
- data/LICENSE +21 -0
- data/README.md +41 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/brawlstars.gemspec +26 -0
- data/lib/brawlstars.rb +123 -0
- data/lib/brawlstars/tag.rb +9 -0
- data/lib/brawlstars/version.rb +3 -0
- metadata +97 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b439c0a3393ef502fa11f7dbebf6829bb328c25b9560292645fa341fbc18b15a
|
4
|
+
data.tar.gz: da99ada392dc99c10cc72e0f8501c6dedf7dbdf8646ec93d4ebfc697424e74b1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9d364c8c2055703d946cb7117700899492ae3f389edfff3541f7f94746644c304a0c342fdf4fe60837271fa750135a20bb6252a0a627c9f039a14a5a707df45b
|
7
|
+
data.tar.gz: a47b21ab4c381eaee62ba9d86c5bb555838903a93b23807b50a13bc570e27920dc056edbd38dbf88556351a008d0dbb8f0a66099ace6ae44310538c531a102fc
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 Karthik99999
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# brawlstarsrb
|
2
|
+
|
3
|
+
brawlstarsrb is a Ruby implementation of [BrawlAPI](https://docs.brawlapi.cf), the unofficial Brawl Stars API.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'brawlstars'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install brawlstars
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
Example usage:
|
24
|
+
```ruby
|
25
|
+
require 'brawlstars'
|
26
|
+
|
27
|
+
client = Brawlstars::Client.new(token: "token") # get this from discord.me/BrawlAPI
|
28
|
+
player = client.getPlayer("LQL")
|
29
|
+
puts player["name"]
|
30
|
+
```
|
31
|
+
More documentation can be found at [rubydoc](https://www.rubydoc.info/github/Karthik99999/brawlstarsrb)
|
32
|
+
|
33
|
+
## Development
|
34
|
+
|
35
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
36
|
+
|
37
|
+
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).
|
38
|
+
|
39
|
+
## License
|
40
|
+
|
41
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "brawlapirb"
|
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/brawlstars.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "brawlstars/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "brawlstars"
|
7
|
+
spec.version = Brawlstars::VERSION
|
8
|
+
spec.authors = ["Karthik99999"]
|
9
|
+
spec.email = ["bandagondak0217@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = "BrawlAPI for Ruby"
|
12
|
+
spec.description = "A Ruby implementation for BrawlAPI (https://docs.brawlapi.cf), the unofficial Brawl Stars API."
|
13
|
+
spec.homepage = "https://github.com/Karthik99999/brawlstarsrb"
|
14
|
+
spec.license = "MIT"
|
15
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
16
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
end
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_dependency "httparty", "~> 0.17.0"
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
end
|
data/lib/brawlstars.rb
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
require "httparty"
|
2
|
+
require "brawlstars/tag"
|
3
|
+
|
4
|
+
module Brawlstars
|
5
|
+
class Error < StandardError; end
|
6
|
+
class Client
|
7
|
+
def initialize(token: false)
|
8
|
+
raise "No authorization token was given!" if !token
|
9
|
+
@@token = token
|
10
|
+
end
|
11
|
+
# The method to send GET requests to the API
|
12
|
+
#
|
13
|
+
# @param ep [String] the endpoint to get.
|
14
|
+
# @return [Hash] the response returned by the endpoint.
|
15
|
+
def self.get(ep)
|
16
|
+
url = "https://api.brawlapi.cf/v1#{ep}"
|
17
|
+
begin
|
18
|
+
res = HTTParty.get(url, {headers: {"Authorization" => @@token}})
|
19
|
+
rescue HTTParty::Error => e
|
20
|
+
puts e
|
21
|
+
end
|
22
|
+
case res.code
|
23
|
+
when 200
|
24
|
+
res
|
25
|
+
when 400...600
|
26
|
+
raise "Error on request; Status code: #{res.code}; Message: #{res["message"]}"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# Get info about the API
|
31
|
+
#
|
32
|
+
# @return [Hash] info about the API
|
33
|
+
|
34
|
+
def about
|
35
|
+
Client.get("/about")
|
36
|
+
end
|
37
|
+
|
38
|
+
# Get a player by their tag
|
39
|
+
#
|
40
|
+
# @param tag [String] tag of the player to get.
|
41
|
+
# @return [Hash] data of the player that was searched.
|
42
|
+
|
43
|
+
def getPlayer(tag)
|
44
|
+
tag = validateTag(tag)
|
45
|
+
Client.get("/player?tag=#{tag}")
|
46
|
+
end
|
47
|
+
|
48
|
+
# Search for players by their name
|
49
|
+
#
|
50
|
+
# @param name [String] name to search for.
|
51
|
+
# @return [Hash] players returned by the search.
|
52
|
+
|
53
|
+
def playerSearch(name)
|
54
|
+
Client.get("/player/search?name=#{name.gsub(' ', '%20')}")
|
55
|
+
end
|
56
|
+
|
57
|
+
# Get a club by its tag
|
58
|
+
#
|
59
|
+
# @param tag [String] tag of the club to get.
|
60
|
+
# @return [Hash] data of the club that was searched.
|
61
|
+
|
62
|
+
def getClub(tag)
|
63
|
+
tag = validateTag(tag)
|
64
|
+
Client.get("/club?tag=#{tag}")
|
65
|
+
end
|
66
|
+
|
67
|
+
# Search for clubs by their name
|
68
|
+
#
|
69
|
+
# @param name [String] name to search for.
|
70
|
+
# @return [Hash] clubs returned by the search.
|
71
|
+
|
72
|
+
def clubSearch(name)
|
73
|
+
Client.get("/club/search?name=#{name.gsub(' ', '%20')}")
|
74
|
+
end
|
75
|
+
|
76
|
+
# Get upcoming events
|
77
|
+
#
|
78
|
+
# @return [Hash] upcoming events
|
79
|
+
|
80
|
+
def getUpcomingEvents
|
81
|
+
Client.get("/events?type=upcoming")
|
82
|
+
end
|
83
|
+
|
84
|
+
# Get current events
|
85
|
+
#
|
86
|
+
# @return [Hash] current events
|
87
|
+
|
88
|
+
def getCurrentEvents
|
89
|
+
Client.get("/events?type=current")
|
90
|
+
end
|
91
|
+
|
92
|
+
# Get miscellaneous data, like shop/season reset
|
93
|
+
#
|
94
|
+
# @return [Hash] miscellaneous data
|
95
|
+
|
96
|
+
def getMisc
|
97
|
+
Client.get("/misc")
|
98
|
+
end
|
99
|
+
|
100
|
+
# Get top global clubs
|
101
|
+
#
|
102
|
+
# @param count [Integer] number of clubs to return.
|
103
|
+
# @return [Hash] clubs in order from 1st rank down.
|
104
|
+
|
105
|
+
def getTopClubs(count=200)
|
106
|
+
raise 'Count must be a number.' if !count.is_a? Integer
|
107
|
+
raise 'Count must be between 1 and 200.' if !count.between?(1,200)
|
108
|
+
Client.get("/leaderboards/clubs?count=#{count}")
|
109
|
+
end
|
110
|
+
|
111
|
+
# Get top global clubs
|
112
|
+
#
|
113
|
+
# @param count [Integer] number of clubs to return.
|
114
|
+
# @param brawler [String] brawler leaderboard to return.
|
115
|
+
# @return [Hash] players in order from 1st rank down.
|
116
|
+
|
117
|
+
def getTopPlayers(count=200, brawler="")
|
118
|
+
raise 'Count must be a number.' if !count.is_a? Integer
|
119
|
+
raise 'Count must be between 1 and 200.' if !count.between?(1,200)
|
120
|
+
Client.get("/leaderboards/players?count=#{count}&brawler=#{brawler}")
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
metadata
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: brawlstars
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Karthik99999
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-05-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: httparty
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.17.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.17.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
description: A Ruby implementation for BrawlAPI (https://docs.brawlapi.cf), the unofficial
|
56
|
+
Brawl Stars API.
|
57
|
+
email:
|
58
|
+
- bandagondak0217@gmail.com
|
59
|
+
executables: []
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".gitignore"
|
64
|
+
- Gemfile
|
65
|
+
- LICENSE
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- bin/console
|
69
|
+
- bin/setup
|
70
|
+
- brawlstars.gemspec
|
71
|
+
- lib/brawlstars.rb
|
72
|
+
- lib/brawlstars/tag.rb
|
73
|
+
- lib/brawlstars/version.rb
|
74
|
+
homepage: https://github.com/Karthik99999/brawlstarsrb
|
75
|
+
licenses:
|
76
|
+
- MIT
|
77
|
+
metadata: {}
|
78
|
+
post_install_message:
|
79
|
+
rdoc_options: []
|
80
|
+
require_paths:
|
81
|
+
- lib
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
requirements: []
|
93
|
+
rubygems_version: 3.0.3
|
94
|
+
signing_key:
|
95
|
+
specification_version: 4
|
96
|
+
summary: BrawlAPI for Ruby
|
97
|
+
test_files: []
|