ruby_api_pack_cloudways 0.1.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -0
- data/lib/ruby_api_pack_cloudways/api/cw_lists.rb +60 -11
- data/lib/ruby_api_pack_cloudways/api/cw_server.rb +105 -2
- data/lib/ruby_api_pack_cloudways/connection/cw_connect.rb +17 -1
- data/lib/ruby_api_pack_cloudways/connection/cw_token.rb +1 -1
- data/lib/ruby_api_pack_cloudways/version.rb +1 -1
- metadata +7 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 55bab48c0d619f7918865a2a4e3f73a8384253844892e29231fe00843e4168b2
|
4
|
+
data.tar.gz: 44054862918fd30db13413b2b8d344e59a44e7f522add84b13d31c93afa5d9e5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 97fbbb96b0ebc20a12ce6af6912e08f1a9962d95c319fe40a6f48c3a4de41c1d45b66ad2fa3b1b2a17402051e700df54f4eb2500664cee3182871b80705f40c9
|
7
|
+
data.tar.gz: 0b85aeeb9211ffab7c946fdf219a4015f8ab3c937274700f356f0e39d5e769e77588a0c172d608e7e05628b5ee6abbed4d98b2f2f82385c19b2713fea555732a
|
data/README.md
CHANGED
@@ -58,6 +58,11 @@ Or install it yourself as:
|
|
58
58
|
```bash
|
59
59
|
$ gem install ruby_api_pack_cloudways
|
60
60
|
```
|
61
|
+
# Documentation Wiki
|
62
|
+
|
63
|
+
- [Home](https://github.com/phcdevworks/ruby_api_pack_cloudways/wiki)
|
64
|
+
- [List Endpoints](https://github.com/phcdevworks/ruby_api_pack_cloudways/wiki/Cloudways-Ruby-List-Endpoints)
|
65
|
+
- [Server Endpoints](https://github.com/phcdevworks/ruby_api_pack_cloudways/wiki/Cloudways-Ruby-Server-Endpoints)
|
61
66
|
|
62
67
|
## Contributing
|
63
68
|
|
@@ -3,27 +3,76 @@
|
|
3
3
|
module RubyApiPackCloudways
|
4
4
|
module Api
|
5
5
|
class CwLists
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
6
|
+
# List endpoints
|
7
|
+
ENDPOINTS = {
|
8
|
+
apps: '/apps',
|
9
|
+
backup_frequencies: '/backup-frequencies',
|
10
|
+
countries: '/countries',
|
11
|
+
monitor_durations: '/monitoring/durations',
|
12
|
+
monitor_targets: '/monitoring/targets',
|
13
|
+
packages: '/packages',
|
14
|
+
providers: '/providers',
|
15
|
+
regions: '/regions',
|
16
|
+
server_sizes: '/server_sizes',
|
17
|
+
settings: '/settings'
|
18
|
+
}.freeze
|
19
|
+
|
20
|
+
# Fetch list of applications available
|
21
|
+
def self.app_list
|
22
|
+
fetch_resource(ENDPOINTS[:apps])['apps']
|
11
23
|
end
|
12
24
|
|
25
|
+
# Fetch list of available backup frequencies
|
26
|
+
def self.backup_frequency_list
|
27
|
+
fetch_resource(ENDPOINTS[:backup_frequencies])['frequencies']
|
28
|
+
end
|
29
|
+
|
30
|
+
# Fetch list of supported countries
|
31
|
+
def self.country_list
|
32
|
+
fetch_resource(ENDPOINTS[:countries])['countries']
|
33
|
+
end
|
34
|
+
|
35
|
+
# Fetch list of monitoring durations
|
36
|
+
def self.monitor_duration_list
|
37
|
+
fetch_resource(ENDPOINTS[:monitor_durations])['durations']
|
38
|
+
end
|
39
|
+
|
40
|
+
# Fetch list of monitoring targets
|
41
|
+
def self.monitor_target_list
|
42
|
+
fetch_resource(ENDPOINTS[:monitor_targets])['targets']
|
43
|
+
end
|
44
|
+
|
45
|
+
# Fetch list of available packages
|
46
|
+
def self.package_list
|
47
|
+
fetch_resource(ENDPOINTS[:packages])['packages']
|
48
|
+
end
|
49
|
+
|
50
|
+
# Fetch list of providers
|
13
51
|
def self.provider_list
|
14
|
-
fetch_resource(
|
52
|
+
fetch_resource(ENDPOINTS[:providers])['providers']
|
53
|
+
end
|
54
|
+
|
55
|
+
# Fetch list of regions
|
56
|
+
def self.region_list
|
57
|
+
fetch_resource(ENDPOINTS[:regions])['regions']
|
15
58
|
end
|
16
59
|
|
60
|
+
# Fetch list of server sizes
|
17
61
|
def self.server_size_list
|
18
|
-
fetch_resource(
|
62
|
+
fetch_resource(ENDPOINTS[:server_sizes])['sizes']
|
19
63
|
end
|
20
64
|
|
21
|
-
|
22
|
-
|
65
|
+
# Fetch list of available settings
|
66
|
+
def self.setting_list
|
67
|
+
fetch_resource(ENDPOINTS[:settings])['settings']
|
23
68
|
end
|
24
69
|
|
25
|
-
|
26
|
-
|
70
|
+
# Private method to fetch resources from a specified endpoint
|
71
|
+
private_class_method def self.fetch_resource(endpoint)
|
72
|
+
Connection::CwConnect.new(
|
73
|
+
RubyApiPackCloudways.configuration.api_url,
|
74
|
+
endpoint
|
75
|
+
).cloudways_api_connection
|
27
76
|
end
|
28
77
|
end
|
29
78
|
end
|
@@ -3,13 +3,116 @@
|
|
3
3
|
module RubyApiPackCloudways
|
4
4
|
module Api
|
5
5
|
class CwServer
|
6
|
+
# Server endpoints
|
7
|
+
ENDPOINTS = {
|
8
|
+
list: '/server',
|
9
|
+
attach_block_storage: '/server/attach_block_storage',
|
10
|
+
clone: '/server/clone',
|
11
|
+
create: '/server/create',
|
12
|
+
delete: '/server/delete',
|
13
|
+
details: '/server/details',
|
14
|
+
disk_usage: '/server/disk_usage',
|
15
|
+
restart: '/server/restart',
|
16
|
+
scale_block_storage: '/server/scale_block_storage',
|
17
|
+
scale_volume_size: '/server/scale_volume_size',
|
18
|
+
start: '/server/start',
|
19
|
+
stop: '/server/stop',
|
20
|
+
update_label: '/server/update_label',
|
21
|
+
upgrade: '/server/upgrade'
|
22
|
+
}.freeze
|
23
|
+
|
24
|
+
# List all servers
|
6
25
|
def self.server_list
|
7
|
-
fetch_list(
|
26
|
+
fetch_list(ENDPOINTS[:list])['servers']
|
27
|
+
end
|
28
|
+
|
29
|
+
# Attach block storage to a server
|
30
|
+
def self.attach_block_storage(server_id, params)
|
31
|
+
post_with_id(ENDPOINTS[:attach_block_storage], server_id, params)
|
32
|
+
end
|
33
|
+
|
34
|
+
# Clone a server
|
35
|
+
def self.clone_server(server_id, params)
|
36
|
+
post_with_id(ENDPOINTS[:clone], server_id, params)
|
37
|
+
end
|
38
|
+
|
39
|
+
# Create a new server
|
40
|
+
def self.create_server(params)
|
41
|
+
post_without_id(ENDPOINTS[:create], params)
|
42
|
+
end
|
43
|
+
|
44
|
+
# Delete a server
|
45
|
+
def self.delete_server(server_id)
|
46
|
+
fetch_with_id(ENDPOINTS[:delete], server_id)
|
47
|
+
end
|
48
|
+
|
49
|
+
# Get disk usage information
|
50
|
+
def self.disk_usage(server_id)
|
51
|
+
fetch_with_id(ENDPOINTS[:disk_usage], server_id)
|
52
|
+
end
|
53
|
+
|
54
|
+
# Restart a server
|
55
|
+
def self.restart_server(server_id)
|
56
|
+
fetch_with_id(ENDPOINTS[:restart], server_id)
|
57
|
+
end
|
58
|
+
|
59
|
+
# Get server details
|
60
|
+
def self.server_details(server_id)
|
61
|
+
fetch_with_id(ENDPOINTS[:details], server_id)
|
62
|
+
end
|
63
|
+
|
64
|
+
# Scale block storage of a server
|
65
|
+
def self.scale_block_storage(server_id, params)
|
66
|
+
post_with_id(ENDPOINTS[:scale_block_storage], server_id, params)
|
8
67
|
end
|
9
68
|
|
10
|
-
|
69
|
+
# Scale volume size of a server
|
70
|
+
def self.scale_volume_size(server_id, params)
|
71
|
+
post_with_id(ENDPOINTS[:scale_volume_size], server_id, params)
|
72
|
+
end
|
73
|
+
|
74
|
+
# Start a server
|
75
|
+
def self.start_server(server_id)
|
76
|
+
fetch_with_id(ENDPOINTS[:start], server_id)
|
77
|
+
end
|
78
|
+
|
79
|
+
# Stop a server
|
80
|
+
def self.stop_server(server_id)
|
81
|
+
fetch_with_id(ENDPOINTS[:stop], server_id)
|
82
|
+
end
|
83
|
+
|
84
|
+
# Update server label
|
85
|
+
def self.update_server_label(server_id, params)
|
86
|
+
post_with_id(ENDPOINTS[:update_label], server_id, params)
|
87
|
+
end
|
88
|
+
|
89
|
+
# Upgrade a server
|
90
|
+
def self.upgrade_server(server_id, params)
|
91
|
+
post_with_id(ENDPOINTS[:upgrade], server_id, params)
|
92
|
+
end
|
93
|
+
|
94
|
+
# Private methods to fetch data
|
95
|
+
private_class_method def self.fetch_list(endpoint)
|
11
96
|
Connection::CwConnect.new(RubyApiPackCloudways.configuration.api_url, endpoint).cloudways_api_connection
|
12
97
|
end
|
98
|
+
|
99
|
+
# Private methods to fetch data with server id
|
100
|
+
private_class_method def self.fetch_with_id(endpoint, server_id)
|
101
|
+
Connection::CwConnect.new(RubyApiPackCloudways.configuration.api_url, "#{endpoint}/#{server_id}")
|
102
|
+
.cloudways_api_connection
|
103
|
+
end
|
104
|
+
|
105
|
+
# Private methods to post data with server id
|
106
|
+
private_class_method def self.post_with_id(endpoint, server_id, params)
|
107
|
+
connection = Connection::CwConnect.new(RubyApiPackCloudways.configuration.api_url, "#{endpoint}/#{server_id}")
|
108
|
+
connection.cloudways_api_post_connection(params)
|
109
|
+
end
|
110
|
+
|
111
|
+
# Private methods to post data without server id
|
112
|
+
private_class_method def self.post_without_id(endpoint, params)
|
113
|
+
connection = Connection::CwConnect.new(RubyApiPackCloudways.configuration.api_url, endpoint)
|
114
|
+
connection.cloudways_api_post_connection(params)
|
115
|
+
end
|
13
116
|
end
|
14
117
|
end
|
15
118
|
end
|
@@ -3,13 +3,16 @@
|
|
3
3
|
module RubyApiPackCloudways
|
4
4
|
module Connection
|
5
5
|
class CwConnect
|
6
|
+
# Initialize Cloudways API URL and path
|
6
7
|
attr_reader :cw_api_url_base, :cw_api_path
|
7
8
|
|
9
|
+
# Initialize Cloudways API URL and path
|
8
10
|
def initialize(cw_api_url_base, cw_api_path)
|
9
11
|
@cw_api_url_base = cw_api_url_base
|
10
12
|
@cw_api_path = cw_api_path
|
11
13
|
end
|
12
14
|
|
15
|
+
# GET request to Cloudways API
|
13
16
|
def cloudways_api_connection
|
14
17
|
token = CwToken.new.cw_api_token
|
15
18
|
response = HTTParty.get(
|
@@ -19,8 +22,20 @@ module RubyApiPackCloudways
|
|
19
22
|
handle_response(response)
|
20
23
|
end
|
21
24
|
|
25
|
+
# POST request to Cloudways API
|
26
|
+
def cloudways_api_post_connection(params)
|
27
|
+
token = CwToken.new.cw_api_token
|
28
|
+
response = HTTParty.post(
|
29
|
+
"#{@cw_api_url_base}#{@cw_api_path}",
|
30
|
+
headers: { 'Authorization' => "Bearer #{token}", 'Content-Type' => 'application/json' },
|
31
|
+
body: params.to_json
|
32
|
+
)
|
33
|
+
handle_response(response)
|
34
|
+
end
|
35
|
+
|
22
36
|
private
|
23
37
|
|
38
|
+
# Handle response from Cloudways API
|
24
39
|
def handle_response(response)
|
25
40
|
case response.code
|
26
41
|
when 200
|
@@ -30,8 +45,9 @@ module RubyApiPackCloudways
|
|
30
45
|
end
|
31
46
|
end
|
32
47
|
|
48
|
+
# Parse response from Cloudways API
|
33
49
|
def parse_response(response)
|
34
|
-
Oj.load(response.body)
|
50
|
+
Oj.load(response.body, mode: :strict)
|
35
51
|
rescue Oj::ParseError => e
|
36
52
|
raise "Error parsing response: #{e.message}"
|
37
53
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby_api_pack_cloudways
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- PHCDevworks
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2024-
|
12
|
+
date: 2024-11-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: httparty
|
@@ -39,7 +39,9 @@ dependencies:
|
|
39
39
|
- - "~>"
|
40
40
|
- !ruby/object:Gem::Version
|
41
41
|
version: '3.16'
|
42
|
-
description:
|
42
|
+
description: |-
|
43
|
+
RubyApiPackCloudways is a Ruby gem for interacting with the Cloudways API. It provides easy access to
|
44
|
+
providers, server sizes, apps, and packages, with built-in OAuth authentication for secure API requests.
|
43
45
|
email:
|
44
46
|
- info@phcdevworks.com
|
45
47
|
- brad.potts@phcdevworks.com
|
@@ -57,12 +59,12 @@ files:
|
|
57
59
|
- lib/ruby_api_pack_cloudways/connection/cw_connect.rb
|
58
60
|
- lib/ruby_api_pack_cloudways/connection/cw_token.rb
|
59
61
|
- lib/ruby_api_pack_cloudways/version.rb
|
60
|
-
homepage: https://
|
62
|
+
homepage: https://github.com/phcdevworks/ruby_api_pack_cloudways/wiki
|
61
63
|
licenses:
|
62
64
|
- MIT
|
63
65
|
metadata:
|
64
66
|
allowed_push_host: https://rubygems.org/
|
65
|
-
homepage_uri: https://
|
67
|
+
homepage_uri: https://github.com/phcdevworks/ruby_api_pack_cloudways/wiki
|
66
68
|
source_code_uri: https://github.com/phcdevworks/ruby_api_pack_cloudways/
|
67
69
|
changelog_uri: https://github.com/phcdevworks/ruby_api_pack_cloudways/releases
|
68
70
|
post_install_message:
|