ruby_api_pack_cloudways 0.1.0 → 0.2.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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 64e6f4ca33ac70dcd6309f9b74d7f72c3f1b70598756eb35ef54642cc98f5836
|
4
|
+
data.tar.gz: 1e83554286f6bc0d6c0803c18e33dd2e7e47706788ccadfa65949cdc81062e94
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 51f40268262aaed80030f2e9343c4b5f31c8784e8fc5da4cee18b086acc18649d52b5f4e0e3f20d5fcf3c66f07fe9966b38d953e62c7c2b787e521dbff1bb876
|
7
|
+
data.tar.gz: e6fd7306e44faa0f0ea3c94799c66c2e40d645675a387bf92ffc88c173fd764eee16f36e95ffc90071cde0ef78764403c5f35d6b60194f54acb591be3775d7cd
|
data/README.md
CHANGED
@@ -58,6 +58,10 @@ 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
|
+
- [Server Endpoints](https://github.com/phcdevworks/ruby_api_pack_cloudways/wiki/Cloudways-API-Ruby-Server-Endpoint-Client)
|
61
65
|
|
62
66
|
## Contributing
|
63
67
|
|
@@ -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
|
+
details: '/server/details',
|
10
|
+
attach_block_storage: '/server/attach_block_storage',
|
11
|
+
clone: '/server/clone',
|
12
|
+
create: '/server/create',
|
13
|
+
delete: '/server/delete',
|
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
|
+
# Get server details
|
30
|
+
def self.server_details(server_id)
|
31
|
+
fetch_with_id(ENDPOINTS[:details], server_id)
|
32
|
+
end
|
33
|
+
|
34
|
+
# Attach block storage to a server
|
35
|
+
def self.attach_block_storage(server_id, params)
|
36
|
+
post_with_id(ENDPOINTS[:attach_block_storage], server_id, params)
|
37
|
+
end
|
38
|
+
|
39
|
+
# Clone a server
|
40
|
+
def self.clone_server(server_id, params)
|
41
|
+
post_with_id(ENDPOINTS[:clone], server_id, params)
|
42
|
+
end
|
43
|
+
|
44
|
+
# Create a new server
|
45
|
+
def self.create_server(params)
|
46
|
+
post_without_id(ENDPOINTS[:create], params)
|
47
|
+
end
|
48
|
+
|
49
|
+
# Delete a server
|
50
|
+
def self.delete_server(server_id)
|
51
|
+
fetch_with_id(ENDPOINTS[:delete], server_id)
|
52
|
+
end
|
53
|
+
|
54
|
+
# Get disk usage information
|
55
|
+
def self.disk_usage(server_id)
|
56
|
+
fetch_with_id(ENDPOINTS[:disk_usage], server_id)
|
57
|
+
end
|
58
|
+
|
59
|
+
# Restart a server
|
60
|
+
def self.restart_server(server_id)
|
61
|
+
fetch_with_id(ENDPOINTS[:restart], 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,6 +45,7 @@ module RubyApiPackCloudways
|
|
30
45
|
end
|
31
46
|
end
|
32
47
|
|
48
|
+
# Parse response from Cloudways API
|
33
49
|
def parse_response(response)
|
34
50
|
Oj.load(response.body)
|
35
51
|
rescue Oj::ParseError => e
|
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.2.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-10-
|
12
|
+
date: 2024-10-30 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:
|