ruby_api_pack_cloudways 0.1.0.pre.4 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/MIT-LICENSE +21 -0
- data/README.md +73 -35
- data/lib/ruby_api_pack_cloudways/api/cw_lists.rb +13 -20
- data/lib/ruby_api_pack_cloudways/api/cw_server.rb +5 -8
- data/lib/ruby_api_pack_cloudways/configuration.rb +14 -0
- data/lib/ruby_api_pack_cloudways/connection/cw_connect.rb +9 -31
- data/lib/ruby_api_pack_cloudways/connection/cw_token.rb +11 -27
- data/lib/ruby_api_pack_cloudways/version.rb +1 -1
- data/lib/ruby_api_pack_cloudways.rb +16 -4
- metadata +6 -20
- data/lib/ruby_api_pack_cloudways/constants.rb +0 -17
- data/lib/ruby_api_pack_cloudways/cw_client.rb +0 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 032f4359de51e5272ede2f343e9da2b2381ff7690ede8e34c6b5c3be75161e16
|
4
|
+
data.tar.gz: bfe23a4dfd1f23abeb3dc12a71fc1190ab2db8354dfd4f3fd23ed6173ce7faa8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: adcd283753e724c24dccc49bc16d5cf8fa0fa222b3c0647c08fb940686355cb7f887e3c042cf78132a05ea6324970ae72e1a2593d770206719370f8bcad8997c
|
7
|
+
data.tar.gz: '09a39d106708fd11d900c6143a210478a1ff330e39ea7b599a284c30ae21d515f00993a99204cdb72d772e68f3317aa7d7706c990f1de870ec73a132974c0c7e'
|
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,35 +1,73 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
1
|
+
# PHCDevworks RubyApiPackCloudways
|
2
|
+
|
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
|
45
|
+
|
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
|
+
|
62
|
+
## Contributing
|
63
|
+
|
64
|
+
[![contributors](https://contributors-img.web.app/image?repo=phcdevworks/ruby_api_pack_cloudways)](https://github.com/phcdevworks/ruby_api_pack_cloudways/graphs/contributors)
|
65
|
+
|
66
|
+
![Last Commit](https://img.shields.io/github/last-commit/phcdevworks/ruby_api_pack_cloudways.svg)
|
67
|
+
[![All Contributors](https://img.shields.io/badge/all_contributors-1-orange.svg?style=flat-square)](#contributors-)
|
68
|
+
|
69
|
+
## License
|
70
|
+
|
71
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
72
|
+
|
73
|
+
![License](https://img.shields.io/github/license/phcdevworks/ruby_api_pack_cloudways.svg)
|
@@ -1,36 +1,29 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative '../constants'
|
4
|
-
|
5
3
|
module RubyApiPackCloudways
|
6
4
|
module Api
|
7
5
|
class CwLists
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
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
|
14
11
|
end
|
15
12
|
|
16
|
-
|
17
|
-
|
18
|
-
fetch_list('/server_sizes')['sizes']
|
13
|
+
def self.provider_list
|
14
|
+
fetch_resource('/providers')['providers']
|
19
15
|
end
|
20
16
|
|
21
|
-
|
22
|
-
|
23
|
-
fetch_list('/apps')['apps']
|
17
|
+
def self.server_size_list
|
18
|
+
fetch_resource('/server_sizes')['sizes']
|
24
19
|
end
|
25
20
|
|
26
|
-
|
27
|
-
|
28
|
-
fetch_list('/packages')['packages']
|
21
|
+
def self.app_list
|
22
|
+
fetch_resource('/apps')['apps']
|
29
23
|
end
|
30
24
|
|
31
|
-
|
32
|
-
|
33
|
-
Connection::CwConnect.new(CW_API_URL, endpoint).cloudways_api_connection
|
25
|
+
def self.package_list
|
26
|
+
fetch_resource('/packages')['packages']
|
34
27
|
end
|
35
28
|
end
|
36
29
|
end
|
@@ -1,17 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative '../constants'
|
4
|
-
|
5
3
|
module RubyApiPackCloudways
|
6
4
|
module Api
|
7
5
|
class CwServer
|
8
|
-
|
9
|
-
|
6
|
+
def self.server_list
|
7
|
+
fetch_list('/server')['servers']
|
8
|
+
end
|
10
9
|
|
11
|
-
|
12
|
-
|
13
|
-
servers = Connection::CwConnect.new(CW_API_URL, '/server').cloudways_api_connection
|
14
|
-
servers['servers']
|
10
|
+
def self.fetch_list(endpoint)
|
11
|
+
Connection::CwConnect.new(RubyApiPackCloudways.configuration.api_url, endpoint).cloudways_api_connection
|
15
12
|
end
|
16
13
|
end
|
17
14
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RubyApiPackCloudways
|
4
|
+
class Configuration
|
5
|
+
attr_accessor :api_url, :api_path_token, :api_email, :api_key
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@api_url = 'https://api.cloudways.com/api/v1'
|
9
|
+
@api_path_token = '/oauth/access_token'
|
10
|
+
@api_email = nil
|
11
|
+
@api_key = nil
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -1,57 +1,35 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative '../constants'
|
4
|
-
|
5
3
|
module RubyApiPackCloudways
|
6
4
|
module Connection
|
7
5
|
class CwConnect
|
8
|
-
|
9
|
-
include RubyApiPackCloudways::Constants
|
10
|
-
|
11
|
-
# PHCDEVONE - Define attribute readers for the base URL, path, and Faraday connection
|
12
|
-
attr_reader :cw_api_url_base, :cw_api_path, :faraday_connection
|
6
|
+
attr_reader :cw_api_url_base, :cw_api_path
|
13
7
|
|
14
|
-
|
15
|
-
def initialize(cw_api_url_base, cw_api_path, faraday_connection = nil)
|
8
|
+
def initialize(cw_api_url_base, cw_api_path)
|
16
9
|
@cw_api_url_base = cw_api_url_base
|
17
10
|
@cw_api_path = cw_api_path
|
18
|
-
@faraday_connection = faraday_connection || Faraday
|
19
11
|
end
|
20
12
|
|
21
|
-
# PHCDEVONE - Establish a connection to the Cloudways API and handle the response
|
22
13
|
def cloudways_api_connection
|
23
|
-
token =
|
24
|
-
response =
|
14
|
+
token = CwToken.new.cw_api_token
|
15
|
+
response = HTTParty.get(
|
16
|
+
"#{@cw_api_url_base}#{@cw_api_path}",
|
17
|
+
headers: { 'Authorization' => "Bearer #{token}" }
|
18
|
+
)
|
25
19
|
handle_response(response)
|
26
20
|
end
|
27
21
|
|
28
22
|
private
|
29
23
|
|
30
|
-
# PHCDEVONE - Fetch the API token using the CwToken class
|
31
|
-
def fetch_token
|
32
|
-
CwToken.new(CW_API_URL, CW_API_PATH_TOKEN, CW_API_EMAIL, CW_API_KEY).cw_api_token
|
33
|
-
end
|
34
|
-
|
35
|
-
# PHCDEVONE - Create a Faraday connection with the given token
|
36
|
-
def create_connection(token)
|
37
|
-
faraday_connection.new(url: @cw_api_url_base) do |conn|
|
38
|
-
conn.request :oauth2, token, token_type: :bearer
|
39
|
-
conn.response :logger
|
40
|
-
conn.adapter Faraday.default_adapter
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
# PHCDEVONE - Handle the response from the API call
|
45
24
|
def handle_response(response)
|
46
|
-
case response.
|
25
|
+
case response.code
|
47
26
|
when 200
|
48
27
|
parse_response(response)
|
49
28
|
else
|
50
|
-
raise "Error: Received status #{response.
|
29
|
+
raise "Error: Received status #{response.code}"
|
51
30
|
end
|
52
31
|
end
|
53
32
|
|
54
|
-
# PHCDEVONE - Parse the API response using Oj
|
55
33
|
def parse_response(response)
|
56
34
|
Oj.load(response.body)
|
57
35
|
rescue Oj::ParseError => e
|
@@ -1,44 +1,28 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative '../constants'
|
4
|
-
|
5
3
|
module RubyApiPackCloudways
|
6
4
|
module Connection
|
7
5
|
class CwToken
|
8
|
-
|
9
|
-
attr_reader :cw_api_url_base, :cw_url_path_auth, :cw_user_email, :cw_user_key, :faraday_connection
|
10
|
-
|
11
|
-
# PHCDEVONE - Initialize the token connection with the given parameters and optional Faraday connection
|
12
|
-
def initialize(cw_api_url_base, cw_url_path_auth, cw_user_email, cw_user_key, faraday_connection = Faraday)
|
13
|
-
@cw_api_url_base = cw_api_url_base
|
14
|
-
@cw_url_path_auth = cw_url_path_auth
|
15
|
-
@cw_user_email = cw_user_email
|
16
|
-
@cw_user_key = cw_user_key
|
17
|
-
@faraday_connection = faraday_connection
|
18
|
-
end
|
6
|
+
attr_reader :cw_api_url_base, :cw_url_path_auth, :cw_user_email, :cw_user_key
|
19
7
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
conn.adapter Faraday.default_adapter
|
26
|
-
end
|
8
|
+
def initialize
|
9
|
+
@cw_api_url_base = RubyApiPackCloudways.configuration.api_url
|
10
|
+
@cw_url_path_auth = RubyApiPackCloudways.configuration.api_path_token
|
11
|
+
@cw_user_email = RubyApiPackCloudways.configuration.api_email
|
12
|
+
@cw_user_key = RubyApiPackCloudways.configuration.api_key
|
27
13
|
end
|
28
14
|
|
29
|
-
# PHCDEVONE - Retrieve the API token from the Cloudways API
|
30
15
|
def cw_api_token
|
31
|
-
response =
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
16
|
+
response = HTTParty.post(
|
17
|
+
"#{@cw_api_url_base}#{@cw_url_path_auth}",
|
18
|
+
headers: { 'Content-Type' => 'application/x-www-form-urlencoded' },
|
19
|
+
body: { email: @cw_user_email, api_key: @cw_user_key }
|
20
|
+
)
|
36
21
|
parse_response(response)['access_token']
|
37
22
|
end
|
38
23
|
|
39
24
|
private
|
40
25
|
|
41
|
-
# PHCDEVONE - Parse the response from the API token request
|
42
26
|
def parse_response(response)
|
43
27
|
Oj.load(response.body)
|
44
28
|
rescue Oj::ParseError => e
|
@@ -1,9 +1,21 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require '
|
4
|
-
require '
|
3
|
+
require 'httparty'
|
4
|
+
require 'oj'
|
5
|
+
|
6
|
+
require_relative 'ruby_api_pack_cloudways/configuration'
|
7
|
+
require_relative 'ruby_api_pack_cloudways/connection/cw_token'
|
8
|
+
require_relative 'ruby_api_pack_cloudways/connection/cw_connect'
|
9
|
+
require_relative 'ruby_api_pack_cloudways/api/cw_lists'
|
10
|
+
require_relative 'ruby_api_pack_cloudways/api/cw_server'
|
5
11
|
|
6
12
|
module RubyApiPackCloudways
|
7
|
-
|
8
|
-
|
13
|
+
class << self
|
14
|
+
attr_accessor :configuration
|
15
|
+
|
16
|
+
def configure
|
17
|
+
self.configuration ||= Configuration.new
|
18
|
+
yield(configuration)
|
19
|
+
end
|
20
|
+
end
|
9
21
|
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.1.0
|
4
|
+
version: 0.1.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-
|
12
|
+
date: 2024-10-27 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
|
@@ -61,15 +47,15 @@ executables: []
|
|
61
47
|
extensions: []
|
62
48
|
extra_rdoc_files: []
|
63
49
|
files:
|
50
|
+
- MIT-LICENSE
|
64
51
|
- README.md
|
65
52
|
- Rakefile
|
66
53
|
- lib/ruby_api_pack_cloudways.rb
|
67
54
|
- lib/ruby_api_pack_cloudways/api/cw_lists.rb
|
68
55
|
- lib/ruby_api_pack_cloudways/api/cw_server.rb
|
56
|
+
- lib/ruby_api_pack_cloudways/configuration.rb
|
69
57
|
- lib/ruby_api_pack_cloudways/connection/cw_connect.rb
|
70
58
|
- lib/ruby_api_pack_cloudways/connection/cw_token.rb
|
71
|
-
- lib/ruby_api_pack_cloudways/constants.rb
|
72
|
-
- lib/ruby_api_pack_cloudways/cw_client.rb
|
73
59
|
- lib/ruby_api_pack_cloudways/version.rb
|
74
60
|
homepage: https://phcdevworks.com/
|
75
61
|
licenses:
|
@@ -90,9 +76,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
90
76
|
version: 2.7.0
|
91
77
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
78
|
requirements:
|
93
|
-
- - "
|
79
|
+
- - ">="
|
94
80
|
- !ruby/object:Gem::Version
|
95
|
-
version:
|
81
|
+
version: '0'
|
96
82
|
requirements: []
|
97
83
|
rubygems_version: 3.3.27
|
98
84
|
signing_key:
|
@@ -1,17 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module RubyApiPackCloudways
|
4
|
-
module Constants
|
5
|
-
# PHCDEVONE - Define the base URL for the Cloudways API
|
6
|
-
CW_API_URL = 'https://api.cloudways.com/api/v1'
|
7
|
-
|
8
|
-
# PHCDEVONE - Define the authentication path for the Cloudways API
|
9
|
-
CW_API_PATH_TOKEN = '/oauth/access_token'
|
10
|
-
|
11
|
-
# PHCDEVONE - Retrieve the Cloudways API email from environment variables
|
12
|
-
CW_API_EMAIL = ENV['PHCDEV_API_CLOUDWAYS_EMAIL']
|
13
|
-
|
14
|
-
# PHCDEVONE - Retrieve the Cloudways API key from environment variables
|
15
|
-
CW_API_KEY = ENV['PHCDEV_API_CLOUDWAYS_KEY']
|
16
|
-
end
|
17
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'faraday'
|
4
|
-
require 'oj'
|
5
|
-
|
6
|
-
# PHCDEVONE - Load API Files
|
7
|
-
require_relative 'connection/cw_token'
|
8
|
-
require_relative 'connection/cw_connect'
|
9
|
-
require_relative 'api/cw_lists'
|
10
|
-
require_relative 'api/cw_server'
|
11
|
-
require_relative 'constants'
|
12
|
-
|
13
|
-
module RubyApiPackCloudways
|
14
|
-
class CwClient
|
15
|
-
# PHCDEVONE - Include the RubyApiPackCloudways::Constants module
|
16
|
-
include RubyApiPackCloudways::Constants
|
17
|
-
end
|
18
|
-
end
|