discloud 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 6d03d0d7da77e364684084dd9626ee2d86afd873959dbdec07bbfc08a8701a13
4
+ data.tar.gz: 01b8520f7bb353f43a4afa0cbd32ef008a8ee4a3c40e2a06e6817231300516a8
5
+ SHA512:
6
+ metadata.gz: bbdeda81225ff3981a52d00a36f2c8110e3c5901157222a667520e9257a6a76d55c815d5c733ad63f9eae0021964754343fa830da70d52a8748e1b5f9a4fc6f7
7
+ data.tar.gz: 1f8dc1f0892fa2603832e55b5caeb9ed454a7d54367f225400220e9716e6707d654f2515828ac313805daa69be1269358deddf70710b7caabdab51687404a7d3
data/README.md ADDED
@@ -0,0 +1,196 @@
1
+ # DISCLOUD SDK RUBY
2
+
3
+ ---
4
+ ## Installation
5
+ ```sh
6
+ gem install discloud
7
+ ```
8
+ ---
9
+ ## Links
10
+
11
+ [Documentation](https://discloud.github.io/discloud-rb)
12
+ [Github](https://github.com/discloud/discloud-rb)
13
+ [Discloud Server](https://discord.discloudbot.com)
14
+ ---
15
+ ## Usage Examples
16
+
17
+ > API > User
18
+ ```ruby
19
+ require "discloud"
20
+
21
+ client = Discloud::Client.new(token: "API-TOKEN")
22
+ user = Discloud::Resources::User.new(client)
23
+
24
+ puts "== USER INFO =="
25
+ begin
26
+ response = user.info
27
+ pp response.parsed_response
28
+ rescue => e
29
+ puts "[Error getting user information] \#{e.message}"
30
+ end
31
+
32
+ puts "\n== SET LOCALE =="
33
+ begin
34
+ locale_response = user.set_locale("en-US")
35
+ pp locale_response.parsed_response
36
+ rescue => e
37
+ puts "[Error changing locale] \#{e.message}"
38
+ end
39
+ ```
40
+ > API > App
41
+ ```ruby
42
+ require "discloud"
43
+
44
+ client = Discloud::Client.new(token: "API-TOKEN")
45
+ app = Discloud::Resources::App.new(client)
46
+
47
+ app_id = "YOUR_APP_ID"
48
+ zip_path = "path/to/app.zip"
49
+
50
+ puts "== APP INFO =="
51
+ begin
52
+ response = app.info(app_id)
53
+ pp response.parsed_response
54
+ rescue => e
55
+ puts "[Error getting app info] \#{e.message}"
56
+ end
57
+
58
+ puts "\n== APP STATUS =="
59
+ begin
60
+ response = app.status(app_id)
61
+ pp response.parsed_response
62
+ rescue => e
63
+ puts "[Error getting app status] \#{e.message}"
64
+ end
65
+
66
+ puts "\n== APP LOGS =="
67
+ begin
68
+ response = app.logs(app_id)
69
+ pp response.parsed_response
70
+ rescue => e
71
+ puts "[Error fetching app logs] \#{e.message}"
72
+ end
73
+
74
+ puts "\n== APP BACKUP =="
75
+ begin
76
+ response = app.backup(app_id)
77
+ pp response.parsed_response
78
+ rescue => e
79
+ puts "[Error downloading app backup] \#{e.message}"
80
+ end
81
+
82
+ puts "\n== START APP =="
83
+ begin
84
+ response = app.start(app_id)
85
+ pp response.parsed_response
86
+ rescue => e
87
+ puts "[Error starting app] \#{e.message}"
88
+ end
89
+
90
+ puts "\n== RESTART APP =="
91
+ begin
92
+ response = app.restart(app_id)
93
+ pp response.parsed_response
94
+ rescue => e
95
+ puts "[Error restarting app] \#{e.message}"
96
+ end
97
+
98
+ puts "\n== STOP APP =="
99
+ begin
100
+ response = app.stop(app_id)
101
+ pp response.parsed_response
102
+ rescue => e
103
+ puts "[Error stopping app] \#{e.message}"
104
+ end
105
+
106
+ puts "\n== CHANGE APP RAM =="
107
+ begin
108
+ response = app.change_ram(app_id, 512)
109
+ pp response.parsed_response
110
+ rescue => e
111
+ puts "[Error changing RAM] \#{e.message}"
112
+ end
113
+
114
+ puts "\n== COMMIT APP =="
115
+ begin
116
+ response = app.commit(app_id, zip_path)
117
+ pp response.parsed_response
118
+ rescue => e
119
+ puts "[Error committing app] \#{e.message}"
120
+ end
121
+
122
+ puts "\n== UPLOAD APP =="
123
+ begin
124
+ response = app.upload(zip_path)
125
+ pp response.parsed_response
126
+ rescue => e
127
+ puts "[Error uploading app] \#{e.message}"
128
+ end
129
+
130
+ puts "\n== DELETE APP =="
131
+ begin
132
+ response = app.delete(app_id)
133
+ pp response.parsed_response
134
+ rescue => e
135
+ puts "[Error deleting app] \#{e.message}"
136
+ end
137
+
138
+ puts "\n== LIST ALL APPS =="
139
+ begin
140
+ response = app.list_all
141
+ pp response.parsed_response
142
+ rescue => e
143
+ puts "[Error listing apps] \#{e.message}"
144
+ end
145
+ ```
146
+ > API > Team
147
+ ```ruby
148
+ require "discloud"
149
+
150
+ client = Discloud::Client.new(token: "API-TOKEN")
151
+ team = Discloud::Resources::Team.new(client)
152
+
153
+ app_id = "YOUR_APP_ID"
154
+ mod_id = "MOD_USER_ID"
155
+
156
+ puts "== TEAM INFO =="
157
+ begin
158
+ response = team.info(app_id)
159
+ pp response.parsed_response
160
+ rescue => e
161
+ puts "[Error getting team info] \#{e.message}"
162
+ end
163
+
164
+ puts "\n== ADDING MEMBER =="
165
+ begin
166
+ response = team.add_member(app_id, mod_id, ["start_app", "stop_app"])
167
+ pp response.parsed_response
168
+ rescue => e
169
+ puts "[Add member failed] \#{e.message}"
170
+ end
171
+
172
+ puts "\n== EDITING MEMBER PERMISSIONS =="
173
+ begin
174
+ response = team.edit_member(app_id, mod_id, [
175
+ "backup_app",
176
+ "commit_app",
177
+ "edit_ram",
178
+ "logs_app",
179
+ "restart_app",
180
+ "start_app",
181
+ "status_app",
182
+ "stop_app",
183
+ ])
184
+ pp response.parsed_response
185
+ rescue => e
186
+ puts "[Edit member failed] \#{e.message}"
187
+ end
188
+
189
+ puts "\n== REMOVING MEMBER =="
190
+ begin
191
+ response = team.remove_member(app_id, mod_id)
192
+ pp response.parsed_response
193
+ rescue => e
194
+ puts "[Remove member failed] \#{e.message}"
195
+ end
196
+ ```
@@ -0,0 +1,71 @@
1
+ require "httparty"
2
+
3
+ module Discloud
4
+ class Client
5
+ include HTTParty
6
+
7
+ base_uri "https://api.discloud.app/v2"
8
+ default_timeout 300
9
+
10
+ def initialize(token:)
11
+ @headers = {
12
+ "api-token" => token
13
+ }
14
+ end
15
+
16
+ def get(path)
17
+ with_rescue { self.class.get(path, headers: @headers) }
18
+ end
19
+
20
+ def post(path, body = {}, extra_headers = {})
21
+ with_rescue { self.class.post(path, headers: @headers.merge(extra_headers), body: body) }
22
+ end
23
+
24
+ def put(path, body = {}, extra_headers = {})
25
+ with_rescue { self.class.put(path, headers: @headers.merge(extra_headers), body: body) }
26
+ end
27
+
28
+ def delete(path)
29
+ with_rescue { self.class.delete(path, headers: @headers) }
30
+ end
31
+
32
+ private
33
+
34
+ def with_rescue(max_retries = 5, delay = 10)
35
+ retries = 0
36
+ begin
37
+ yield
38
+ rescue Net::ReadTimeout, Net::OpenTimeout, Errno::ECONNRESET, SocketError => e
39
+ retries += 1
40
+ if retries <= max_retries
41
+ puts "[Warning] Timeout or connection error: #{e.class}. Retrying (#{retries}/#{max_retries}) in #{delay}s..."
42
+ sleep delay
43
+ retry
44
+ else
45
+ puts "[Fatal] Connection failed after #{max_retries} retries."
46
+ raise e
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
52
+
53
+ # require "httparty"
54
+
55
+ # module Discloud
56
+ # class Client
57
+ # include HTTParty
58
+ # base_uri "https://api.discloud.app/v2"
59
+
60
+ # def initialize(token:)
61
+ # @headers = {
62
+ # 'api-token' => token
63
+ # }
64
+ # end
65
+
66
+ # def get(path) = self.class.get(path, headers: @headers)
67
+ # def post(path, body = {}) = self.class.post(path, headers: @headers, body: body)
68
+ # def put(path, body = {}) = self.class.put(path, headers: @headers, body: body)
69
+ # def delete(path) = self.class.delete(path, headers: @headers)
70
+ # end
71
+ # end
@@ -0,0 +1,84 @@
1
+ module Discloud
2
+ module Resources
3
+ class App
4
+ def initialize(client)
5
+ @client = client
6
+ end
7
+
8
+ def info(app_id)
9
+ @client.get(Routes::App.info(app_id))
10
+ end
11
+
12
+ def status(app_id)
13
+ @client.get(Routes::App.status(app_id))
14
+ end
15
+
16
+ def logs(app_id)
17
+ @client.get(Routes::App.logs(app_id))
18
+ end
19
+
20
+ def backup(app_id)
21
+ @client.get(Routes::App.backup(app_id))
22
+ end
23
+
24
+ def start(app_id)
25
+ @client.put(Routes::App.start(app_id))
26
+ end
27
+
28
+ def restart(app_id)
29
+ @client.put(Routes::App.restart(app_id))
30
+ end
31
+
32
+ def stop(app_id)
33
+ @client.put(Routes::App.stop(app_id))
34
+ end
35
+
36
+ def change_ram(app_id, ram_mb)
37
+ unless ram_mb.is_a?(Integer) && ram_mb > 0
38
+ raise ArgumentError, "RAM must be a positive integer"
39
+ end
40
+
41
+ body = { ramMB: ram_mb }.to_json
42
+ headers = { "Content-Type" => "application/json" }
43
+
44
+ @client.put(Routes::App.ram(app_id), body, headers)
45
+ end
46
+
47
+ def commit(app_id, file_path)
48
+ validate_file!(file_path)
49
+
50
+ File.open(file_path, "rb") do |file|
51
+ body = { file: file }
52
+ @client.put(Routes::App.commit(app_id), body)
53
+ end
54
+ end
55
+
56
+ def upload(file_path)
57
+ validate_file!(file_path)
58
+
59
+ File.open(file_path, "rb") do |file|
60
+ body = { file: file }
61
+ @client.post(Routes::App.upload, body)
62
+ end
63
+ end
64
+
65
+ def delete(app_id)
66
+ @client.delete(Routes::App.delete(app_id))
67
+ end
68
+
69
+ def list_all
70
+ @client.delete(Routes::App.list_all)
71
+ end
72
+
73
+ def validate_file!(file_path)
74
+ unless File.exist?(file_path)
75
+ raise ArgumentError, "File not found: #{file_path}"
76
+ end
77
+
78
+ unless File.extname(file_path) == ".zip"
79
+ raise ArgumentError, "Only .zip files are supported for upload or commit"
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,31 @@
1
+ require 'json'
2
+
3
+ module Discloud
4
+ module Resources
5
+ class Team
6
+ def initialize(client)
7
+ @client = client
8
+ end
9
+
10
+ def info(app_id)
11
+ @client.get(Routes::Team.get(app_id))
12
+ end
13
+
14
+ def add_member(app_id, mod_id, perms = [])
15
+ body = { modID: mod_id, perms: perms }.to_json
16
+ headers = { "Content-Type" => "application/json" }
17
+ @client.post(Routes::Team.add(app_id), body, headers)
18
+ end
19
+
20
+ def edit_member(app_id, mod_id, perms = [])
21
+ body = { modID: mod_id, perms: perms }.to_json
22
+ headers = { "Content-Type" => "application/json" }
23
+ @client.put(Routes::Team.edit(app_id), body, headers)
24
+ end
25
+
26
+ def remove_member(app_id, mod_id)
27
+ @client.delete(Routes::Team.remove(app_id, mod_id))
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,17 @@
1
+ module Discloud
2
+ module Resources
3
+ class User
4
+ def initialize(client)
5
+ @client = client
6
+ end
7
+
8
+ def info
9
+ @client.get(Routes::User.info)
10
+ end
11
+
12
+ def set_locale(locale)
13
+ @client.put(Routes::User.set_locale(locale))
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,20 @@
1
+ module Discloud
2
+ module Routes
3
+ module App
4
+ class << self
5
+ def info(app_id) = "/app/#{app_id}"
6
+ def status(app_id) = "/app/#{app_id}/status"
7
+ def logs(app_id) = "/app/#{app_id}/logs"
8
+ def backup(app_id) = "/app/#{app_id}/backup"
9
+ def start(app_id) = "/app/#{app_id}/start"
10
+ def restart(app_id) = "/app/#{app_id}/restart"
11
+ def stop(app_id) = "/app/#{app_id}/stop"
12
+ def ram(app_id) = "/app/#{app_id}/ram"
13
+ def commit(app_id) = "/app/#{app_id}/commit"
14
+ def delete(app_id) = "/app/#{app_id}/delete"
15
+ def list_all = "/app/all/getApps"
16
+ def upload = "/upload"
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,23 @@
1
+ module Discloud
2
+ module Routes
3
+ module Team
4
+ class << self
5
+ def get(app_id)
6
+ "/app/#{app_id}/team"
7
+ end
8
+
9
+ def add(app_id)
10
+ "/app/#{app_id}/team"
11
+ end
12
+
13
+ def edit(app_id)
14
+ "/app/#{app_id}/team"
15
+ end
16
+
17
+ def remove(app_id, mod_id)
18
+ "/app/#{app_id}/team/#{mod_id}"
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,16 @@
1
+ module Discloud
2
+ module Routes
3
+ module User
4
+ locales = ['pt-BR', 'en-US']
5
+
6
+ def self.info = "/user"
7
+
8
+ def self.set_locale(locale)
9
+ unless locales.include?(locale)
10
+ raise ArgumentError, "Invalid Location. Available values: #{locales.join(', ')}"
11
+ end
12
+ "/v2/locale/#{locale}"
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,3 @@
1
+ module Discloud
2
+ VERSION = "0.0.1"
3
+ end
data/lib/discloud.rb ADDED
@@ -0,0 +1,8 @@
1
+ require "discloud/version"
2
+ require "discloud/client"
3
+ require "discloud/routes/user"
4
+ require "discloud/routes/app"
5
+ require "discloud/routes/team"
6
+ require "discloud/resources/user"
7
+ require "discloud/resources/app"
8
+ require "discloud/resources/team"
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: discloud
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - 1gcw
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2025-09-08 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.21'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.21'
27
+ description: Ruby SDK Discloud (https://discloud.com)
28
+ email:
29
+ - failed@discloud.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - README.md
35
+ - lib/discloud.rb
36
+ - lib/discloud/client.rb
37
+ - lib/discloud/resources/app.rb
38
+ - lib/discloud/resources/team.rb
39
+ - lib/discloud/resources/user.rb
40
+ - lib/discloud/routes/app.rb
41
+ - lib/discloud/routes/team.rb
42
+ - lib/discloud/routes/user.rb
43
+ - lib/discloud/version.rb
44
+ homepage: https://discloud.com
45
+ licenses:
46
+ - MIT
47
+ metadata: {}
48
+ post_install_message:
49
+ rdoc_options: []
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '2.5'
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ requirements: []
63
+ rubygems_version: 3.5.22
64
+ signing_key:
65
+ specification_version: 4
66
+ summary: Ruby module to facilitate the use of the Discloud API
67
+ test_files: []