ruby_api_pack_cloudways 0.1.0.pre.5 → 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: 7b502c4da2d913ded7dcfca1bc55ec230870752a73f5a80b5a2d519101da7a1a
4
- data.tar.gz: eef95f114ac2467f27174534007f4f04804ca47c82c47496bbb327368eb63fb6
3
+ metadata.gz: 64e6f4ca33ac70dcd6309f9b74d7f72c3f1b70598756eb35ef54642cc98f5836
4
+ data.tar.gz: 1e83554286f6bc0d6c0803c18e33dd2e7e47706788ccadfa65949cdc81062e94
5
5
  SHA512:
6
- metadata.gz: 6d8c0706ff2b775a0172fa13fe6d9d836f4a3d57354c47e6c0b7e1f50f66a2c57245bab98563d4e33a9beb9f68fa018a86c89bc386858779f1be8d9699e83770
7
- data.tar.gz: 0c40f6a4bf8f8fa2bbdaf23fa5b104cac84450cbd280b0db3d86780a41c860135a95b8199dbe6f2a3f15e6fe8877c0c260c3ec4a5ff7e774b5002ed35f3b1fb9
6
+ metadata.gz: 51f40268262aaed80030f2e9343c4b5f31c8784e8fc5da4cee18b086acc18649d52b5f4e0e3f20d5fcf3c66f07fe9966b38d953e62c7c2b787e521dbff1bb876
7
+ data.tar.gz: e6fd7306e44faa0f0ea3c94799c66c2e40d645675a387bf92ffc88c173fd764eee16f36e95ffc90071cde0ef78764403c5f35d6b60194f54acb591be3775d7cd
data/MIT-LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Copyright Bradley J Potts
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 CHANGED
@@ -1,61 +1,77 @@
1
- ### Ruby API Wrapper - Cloudways
2
-
3
- Easily connect to your Cloudways account through their API.
4
-
5
- * Secure OAuth Cloudways API Authentication
6
-
7
- #### Step 1 - Add to your application
8
-
9
- gem 'ruby_api_pack_cloudways'
10
- bundle install
11
-
12
- #### Controller Example
13
-
14
- def index
15
- @servers = RubyApiPackCloudways::Api::CwServer.cw_server_list
16
- end
17
-
18
- #### Example on Index File
1
+ # PHCDevworks RubyApiPackCloudways
19
2
 
20
- <% @servers.each do |server| %>
21
- <p><%= server %></p>
22
- <% end %>
23
-
24
- #### Intializer
25
-
26
- Set the following initalizer in your application:
27
-
28
- RubyApiPackCloudways.configure do |config|
29
- config.api_url = Rails.application.credentials.dig(:cloudways, :api_url)
30
- config.api_path_token = Rails.application.credentials.dig(:cloudways, :api_path_token)
31
- config.api_email = Rails.application.credentials.dig(:cloudways, :api_email)
32
- config.api_key = Rails.application.credentials.dig(:cloudways, :api_key)
33
- end
34
-
35
- Open your credentials.yml.enc with your editor of choice in this case using VSCode:
3
+ ![Forks](https://img.shields.io/github/forks/phcdevworks/ruby_api_pack_cloudways.svg?style=social)
4
+ ![Stars](https://img.shields.io/github/stars/phcdevworks/ruby_api_pack_cloudways.svg?style=social)
5
+
6
+ ## Overview
7
+
8
+ ![Issues](https://img.shields.io/github/issues/phcdevworks/ruby_api_pack_cloudways.svg)
9
+ ![Dependabot Status](https://img.shields.io/badge/Dependabot-enabled-brightgreen.svg?logo=dependabot)
10
+ [![codecov](https://codecov.io/gh/phcdevworks/ruby_api_pack_cloudways/graph/badge.svg?token=BEEHE8A5D1)](https://codecov.io/gh/phcdevworks/ruby_api_pack_cloudways)
11
+ ![Build Status](https://github.com/phcdevworks/ruby_api_pack_cloudways/actions/workflows/test.yml/badge.svg)
12
+ [![CodeQL](https://github.com/phcdevworks/ruby_api_pack_cloudways/actions/workflows/github-code-scanning/codeql/badge.svg)](https://github.com/phcdevworks/ruby_api_pack_cloudways/actions/workflows/github-code-scanning/codeql)
13
+ ![Gem Version](https://img.shields.io/gem/v/ruby_api_pack_cloudways.svg)
14
+
15
+ RubyApiPackCloudways is a Ruby gem that provides an easy interface for interacting with the Cloudways API. It includes functionality for fetching information about Cloudways providers, server sizes, apps, and packages, as well as managing server connections and authentication tokens.
16
+
17
+ ## Key Features:
18
+
19
+ - **Provider List**: Fetch the list of available Cloudways providers.
20
+ - **Server Sizes**: Retrieve details about available server sizes supported by Cloudways.
21
+ - **App List**: Access a list of Cloudways applications.
22
+ - **Package List**: Fetch the available packages on Cloudways.
23
+ - **Token-Based Authentication**: Secure access to Cloudways API using OAuth tokens.
24
+
25
+ ## Usage
26
+
27
+ ### 1. Set up Cloudways API credentials
28
+
29
+ You will need to configure your Cloudways API credentials in your Ruby environment. Here’s how you can do it:
30
+
31
+ 1. Open your configuration block in the initializer or main application file:
32
+
33
+ ```ruby
34
+ RubyApiPackCloudways.configure do |config|
35
+ config.api_url = 'https://api.cloudways.com/api/v1'
36
+ config.api_path_token = '/oauth/access_token'
37
+ config.api_email = '<your_cloudways_email>'
38
+ config.api_key = '<your_cloudways_api_key>'
39
+ end
40
+ ```
41
+
42
+ 2. Save and restart your application.
43
+
44
+ ## Installation
36
45
 
37
- EDITOR="code --wait" bin/rails credentials:edit
46
+ Add this line to your application's Gemfile:
47
+
48
+ ```ruby
49
+ gem "ruby_api_pack_cloudways"
50
+ ```
51
+
52
+ And then execute:
53
+ ```bash
54
+ $ bundle
55
+ ```
56
+
57
+ Or install it yourself as:
58
+ ```bash
59
+ $ gem install ruby_api_pack_cloudways
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)
65
+
66
+ ## Contributing
67
+
68
+ [![contributors](https://contributors-img.web.app/image?repo=phcdevworks/ruby_api_pack_cloudways)](https://github.com/phcdevworks/ruby_api_pack_cloudways/graphs/contributors)
38
69
 
39
- Add the following to your credentials.yml:
70
+ ![Last Commit](https://img.shields.io/github/last-commit/phcdevworks/ruby_api_pack_cloudways.svg)
71
+ [![All Contributors](https://img.shields.io/badge/all_contributors-1-orange.svg?style=flat-square)](#contributors-)
72
+
73
+ ## License
74
+
75
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
40
76
 
41
- cloudways:
42
- api_url: 'https://api.cloudways.com/api/v1'
43
- api_path_token: '/oauth/access_token'
44
- api_email: 'Your Cloudways Email'
45
- api_key: 'Your Cloudways API Key'
46
-
47
- Some examples using tour editor of choice to open your credentials.yml.enc:
48
-
49
- EDITOR="atom --wait" bin/rails credentials:edit
50
-
51
- EDITOR="gedit --wait" bin/rails credentials:edit
52
-
53
- EDITOR="vim" bin/rails credentials:edit
54
-
55
- EDITOR="nano" bin/rails credentials:edit
56
-
57
- EDITOR="emacs" bin/rails credentials:edit
58
-
59
- EDITOR="subl -n -w" bin/rails credentials:edit
60
-
61
- EDITOR="mate -w" bin/rails credentials:edit
77
+ ![License](https://img.shields.io/github/license/phcdevworks/ruby_api_pack_cloudways.svg)
@@ -3,29 +3,27 @@
3
3
  module RubyApiPackCloudways
4
4
  module Api
5
5
  class CwLists
6
- # Fetch the list of providers from the Cloudways API
7
- def self.cw_provider_list
8
- fetch_list('/providers')['providers']
6
+ def self.fetch_resource(endpoint)
7
+ Connection::CwConnect.new(
8
+ RubyApiPackCloudways.configuration.api_url,
9
+ endpoint
10
+ ).cloudways_api_connection
9
11
  end
10
12
 
11
- # Fetch the list of server sizes from the Cloudways API
12
- def self.cw_server_size_list
13
- fetch_list('/server_sizes')['sizes']
13
+ def self.provider_list
14
+ fetch_resource('/providers')['providers']
14
15
  end
15
16
 
16
- # Fetch the list of apps from the Cloudways API
17
- def self.cw_app_list
18
- fetch_list('/apps')['apps']
17
+ def self.server_size_list
18
+ fetch_resource('/server_sizes')['sizes']
19
19
  end
20
20
 
21
- # Fetch the list of packages from the Cloudways API
22
- def self.cw_package_list
23
- fetch_list('/packages')['packages']
21
+ def self.app_list
22
+ fetch_resource('/apps')['apps']
24
23
  end
25
24
 
26
- # Fetch the list from the Cloudways API based on the given endpoint
27
- def self.fetch_list(endpoint)
28
- Connection::CwConnect.new(RubyApiPackCloudways.configuration.api_url, endpoint).cloudways_api_connection
25
+ def self.package_list
26
+ fetch_resource('/packages')['packages']
29
27
  end
30
28
  end
31
29
  end
@@ -3,14 +3,116 @@
3
3
  module RubyApiPackCloudways
4
4
  module Api
5
5
  class CwServer
6
- # Fetch the list of servers from the Cloudways API
7
- def self.cw_server_list
8
- fetch_list('/server')['servers']
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
25
+ def self.server_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)
9
67
  end
10
68
 
11
- def self.fetch_list(endpoint)
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)
12
96
  Connection::CwConnect.new(RubyApiPackCloudways.configuration.api_url, endpoint).cloudways_api_connection
13
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
14
116
  end
15
117
  end
16
118
  end
@@ -1,17 +1,18 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'httparty'
4
-
5
3
  module RubyApiPackCloudways
6
4
  module Connection
7
5
  class CwConnect
6
+ # Initialize Cloudways API URL and path
8
7
  attr_reader :cw_api_url_base, :cw_api_path
9
8
 
9
+ # Initialize Cloudways API URL and path
10
10
  def initialize(cw_api_url_base, cw_api_path)
11
11
  @cw_api_url_base = cw_api_url_base
12
12
  @cw_api_path = cw_api_path
13
13
  end
14
14
 
15
+ # GET request to Cloudways API
15
16
  def cloudways_api_connection
16
17
  token = CwToken.new.cw_api_token
17
18
  response = HTTParty.get(
@@ -21,8 +22,20 @@ module RubyApiPackCloudways
21
22
  handle_response(response)
22
23
  end
23
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
+
24
36
  private
25
37
 
38
+ # Handle response from Cloudways API
26
39
  def handle_response(response)
27
40
  case response.code
28
41
  when 200
@@ -32,6 +45,7 @@ module RubyApiPackCloudways
32
45
  end
33
46
  end
34
47
 
48
+ # Parse response from Cloudways API
35
49
  def parse_response(response)
36
50
  Oj.load(response.body)
37
51
  rescue Oj::ParseError => e
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'httparty'
4
-
5
3
  module RubyApiPackCloudways
6
4
  module Connection
7
5
  class CwToken
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RubyApiPackCloudways
4
- VERSION = '0.1.0.pre.5'
4
+ VERSION = '0.2.0'
5
5
  end
@@ -1,9 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'faraday'
3
+ require 'httparty'
4
4
  require 'oj'
5
5
 
6
- # Load Configuration and API Files
7
6
  require_relative 'ruby_api_pack_cloudways/configuration'
8
7
  require_relative 'ruby_api_pack_cloudways/connection/cw_token'
9
8
  require_relative 'ruby_api_pack_cloudways/connection/cw_connect'
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.1.0.pre.5
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - PHCDevworks
@@ -9,22 +9,8 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2024-07-10 00:00:00.000000000 Z
12
+ date: 2024-10-30 00:00:00.000000000 Z
13
13
  dependencies:
14
- - !ruby/object:Gem::Dependency
15
- name: faraday
16
- requirement: !ruby/object:Gem::Requirement
17
- requirements:
18
- - - "~>"
19
- - !ruby/object:Gem::Version
20
- version: '2.9'
21
- type: :runtime
22
- prerelease: false
23
- version_requirements: !ruby/object:Gem::Requirement
24
- requirements:
25
- - - "~>"
26
- - !ruby/object:Gem::Version
27
- version: '2.9'
28
14
  - !ruby/object:Gem::Dependency
29
15
  name: httparty
30
16
  requirement: !ruby/object:Gem::Requirement
@@ -53,7 +39,9 @@ dependencies:
53
39
  - - "~>"
54
40
  - !ruby/object:Gem::Version
55
41
  version: '3.16'
56
- description: Ruby API wrapper to use with Cloudways API.
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.
57
45
  email:
58
46
  - info@phcdevworks.com
59
47
  - brad.potts@phcdevworks.com
@@ -61,6 +49,7 @@ executables: []
61
49
  extensions: []
62
50
  extra_rdoc_files: []
63
51
  files:
52
+ - MIT-LICENSE
64
53
  - README.md
65
54
  - Rakefile
66
55
  - lib/ruby_api_pack_cloudways.rb
@@ -70,12 +59,12 @@ files:
70
59
  - lib/ruby_api_pack_cloudways/connection/cw_connect.rb
71
60
  - lib/ruby_api_pack_cloudways/connection/cw_token.rb
72
61
  - lib/ruby_api_pack_cloudways/version.rb
73
- homepage: https://phcdevworks.com/
62
+ homepage: https://github.com/phcdevworks/ruby_api_pack_cloudways/wiki
74
63
  licenses:
75
64
  - MIT
76
65
  metadata:
77
66
  allowed_push_host: https://rubygems.org/
78
- homepage_uri: https://phcdevworks.com/
67
+ homepage_uri: https://github.com/phcdevworks/ruby_api_pack_cloudways/wiki
79
68
  source_code_uri: https://github.com/phcdevworks/ruby_api_pack_cloudways/
80
69
  changelog_uri: https://github.com/phcdevworks/ruby_api_pack_cloudways/releases
81
70
  post_install_message:
@@ -89,9 +78,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
89
78
  version: 2.7.0
90
79
  required_rubygems_version: !ruby/object:Gem::Requirement
91
80
  requirements:
92
- - - ">"
81
+ - - ">="
93
82
  - !ruby/object:Gem::Version
94
- version: 1.3.1
83
+ version: '0'
95
84
  requirements: []
96
85
  rubygems_version: 3.3.27
97
86
  signing_key: