radarcordrb 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.
Files changed (5) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +21 -0
  3. data/README.md +64 -0
  4. data/lib/radarcordrb.rb +105 -0
  5. metadata +72 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 8cee9ff34c9b47e7e1746ad9b0e9d0923af629eab2e1520e88ca80ec6edaa379
4
+ data.tar.gz: b606a508af4cfb19c9b5d147408b7035853a7fe2ca11e2f4d6c73c52e6de64cf
5
+ SHA512:
6
+ metadata.gz: 6a479e5c501ee2c3943e630b7ebb1530e08371f7c25b0d76a5ce4139741c8f97d317eb5ff4f9e0b7e4ea2cddefa2eef31ffa1922bf1c57801ccb2a8143612c3b
7
+ data.tar.gz: 1fbb25c672505837a9e74386781ed266f1dacb98b1321d7686d0f2444769025814c642715087881e71ae8f73ff3595a2365859552244c178681046c94564261a
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Roxanne Wolf
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,64 @@
1
+ # radarcordrb
2
+
3
+ Radarcordrb is a Ruby package (a.k.a. Gem) that allows you to easily interact with the radarcord.net API with the Ruby programming language.
4
+
5
+ Features include posting your Discord bot's stats (guilds/shards) and pinging your bot's uptime to radarcord.
6
+
7
+ ## Setup
8
+
9
+ You can install radarcordrb through the following methods:
10
+
11
+ #### Method 1: Install from Gemfile
12
+
13
+ Add the following to your Gemfile file and run the "[bundle install](https://rubygems.org/gems/radarcordrb)" command:
14
+
15
+ ```ruby
16
+ gem 'radarcordrb'
17
+ ```
18
+
19
+ or add the following to your Gemfile file and run the "bundle install" command:.
20
+
21
+ ```ruby
22
+ gem 'radarcordrb', git: 'https://gitlab.com/roxannewolf/radarcordrb'
23
+ ```
24
+
25
+ ## Usage
26
+
27
+ Here is a basic example of posting your Discord bot's server count to the radarcord.net website through the radarcord API
28
+
29
+ ```ruby
30
+ require 'radarcordrb'
31
+ radarcordapikey = 'RADARCORD_APIKEY'
32
+ bot_id = 'DISCORD_BOTID_HERE'
33
+ client = Radarcord::Client.new(api_key: radarcordapikey)
34
+
35
+ begin
36
+ response = client.poststats(bot_id, guilds: 100)
37
+ puts "Stats updated successfully: #{response}"
38
+ rescue Radarcord::APIError => e
39
+ puts "Error posting stats: #{e.message}"
40
+ end
41
+ ```
42
+
43
+ Here is a basic example for sending an uptime ping through the radarcord API
44
+
45
+ ```ruby
46
+ require 'radarcordrb'
47
+ radarcordapikey = 'RADARCORD_APIKEY'
48
+ bot_id = 'DISCORD_BOTID_HERE'
49
+ client = Radarcord::Client.new(api_key: radarcordapikey)
50
+
51
+ begin
52
+ response = radarclient.postuptime(bot_id)
53
+ puts "Uptime ping successful: #{response}"
54
+ rescue Radarcord::APIError => e
55
+ puts "An error has occured: #{e.message}"
56
+ end
57
+ ```
58
+
59
+ > [!NOTE]
60
+ > Sending the uptime ping to radarcord's API is manual. Keep in mind of radarcord's ratelimit of 2 minutes for the uptime endpoint. Guard rails are added to the package to respect this limit.
61
+
62
+ ## Support and Help
63
+
64
+ If you need help with this ruby package (a.k.a. Gem), feel free to open an issue on our [Gitlab repo](https://gitlab.com/roxannewolf/radarcordrb) or [Codeberg repo](https://codeberg.org/roxannewolf/radarcordrb)
@@ -0,0 +1,105 @@
1
+ require 'json'
2
+ require 'net/http'
3
+ require 'uri'
4
+ require 'time'
5
+
6
+ module Radarcord
7
+ VERSION = '1.0.0'.freeze
8
+ class APIError < StandardError; end
9
+
10
+ class Client
11
+ BASE_URL = 'https://api.radarcord.net'.freeze
12
+ UPTIMEPING_RATELIMIT_SECONDS = 120
13
+
14
+ def initialize(api_key:)
15
+ @api_key = api_key.to_s
16
+ @last_uptime_post_time = nil
17
+ raise ArgumentError, '[Radarcordrb] API key is not provided' if @api_key.empty?
18
+ end
19
+
20
+ def poststats(bot_id, guilds:, shards: nil)
21
+ raise ArgumentError, '[Radarcordrb] Guilds count is required.' unless guilds
22
+ path = "/bot/#{bot_id}/stats"
23
+ body = { guilds: guilds }
24
+ body[:shards] = shards if shards
25
+ _authorized_post(path, body)
26
+ end
27
+
28
+ def postuptime(bot_id)
29
+ if @last_uptime_post_time && (Time.now - @last_uptime_post_time) < UPTIMEPING_RATELIMIT_SECONDS
30
+ seconds_to_wait = (UPTIMEPING_RATELIMIT_SECONDS - (Time.now - @last_uptime_post_time)).ceil
31
+ puts "[Radarcordrb] WARNING: Uptime post was recently called. Skipping request to respect the 2-minute rate limit (wait #{seconds_to_wait}s)."
32
+ return true
33
+ end
34
+
35
+ path = "/bot/#{bot_id}/uptime"
36
+ response = _authorized_post(path, {})
37
+ @last_uptime_post_time = Time.now
38
+ response
39
+ end
40
+
41
+ def post_commands(bot_id, commands)
42
+ path = "/bot/#{bot_id}/commands"
43
+ body = { commands: commands }
44
+ _authorized_post(path, body)
45
+ end
46
+
47
+ def get_botinfo(id_or_vanity)
48
+ path = "/bot/#{id_or_vanity}/"
49
+ _get(path)
50
+ end
51
+
52
+ def get_userinfo(user_id)
53
+ path = "/user/#{user_id}"
54
+ _get(path)
55
+ end
56
+
57
+ def has_voted(user_id, bot_id)
58
+ path = "/hasvoted/#{user_id}/#{bot_id}"
59
+ _get(path)
60
+ end
61
+
62
+ def get_last_voted(user_id, bot_id)
63
+ path = "/lastvoted/#{user_id}/#{bot_id}"
64
+ _get(path)
65
+ end
66
+
67
+ private
68
+
69
+ def _authorized_post(path, body)
70
+ uri = URI.parse("#{BASE_URL}#{path}")
71
+ http = Net::HTTP.new(uri.host, uri.port)
72
+ http.use_ssl = true
73
+ request = Net::HTTP::Post.new(uri.request_uri, 'Content-Type' => 'application/json')
74
+ auth_header = "Bearer #{@api_key}"
75
+ request['Authorization'] = auth_header
76
+ request.body = body.to_json
77
+ _send_request(http, request)
78
+ end
79
+
80
+ def _get(path)
81
+ uri = URI.parse("#{BASE_URL}#{path}")
82
+ http = Net::HTTP.new(uri.host, uri.port)
83
+ http.use_ssl = true
84
+ request = Net::HTTP::Get.new(uri.request_uri)
85
+ _send_request(http, request)
86
+ end
87
+
88
+ def _send_request(http, request)
89
+ response = http.request(request)
90
+ if response.is_a?(Net::HTTPSuccess)
91
+ return JSON.parse(response.body)
92
+ end
93
+
94
+ error_message = "#{response.code} #{response.message}"
95
+ begin
96
+ error_details = JSON.parse(response.body)
97
+ error_message += ": #{error_details['message'] || response.body}"
98
+ rescue JSON::ParserError
99
+ error_message += ": #{response.body}" unless response.body.empty?
100
+ end
101
+
102
+ raise Radarcord::Error, "[Radarcordrb] radarcord API request failed for #{request.path}: #{error_message}"
103
+ end
104
+ end
105
+ end
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: radarcordrb
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Roxanne Studios
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: json
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: 2.13.2
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.2
26
+ - !ruby/object:Gem::Dependency
27
+ name: net-http
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: 0.6.0
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: 0.6.0
40
+ description: radarcordrb is a Ruby gem made to help Ruby bot developers with interacting
41
+ with the radarcord botlist API.
42
+ email:
43
+ - ''
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - LICENSE
49
+ - README.md
50
+ - lib/radarcordrb.rb
51
+ homepage: https://gitlab.com/roxannewolf/radarcordrb
52
+ licenses:
53
+ - MIT
54
+ metadata: {}
55
+ rdoc_options: []
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '3.0'
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ requirements: []
69
+ rubygems_version: 3.6.9
70
+ specification_version: 4
71
+ summary: Ruby gem for interacting with the radarcord API.
72
+ test_files: []