ruby_api_pack_cloudways 0.1.0.pre.3 → 0.1.0.pre.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +12 -13
- data/Rakefile +14 -6
- data/lib/ruby_api_pack_cloudways/api/cw_lists.rb +37 -31
- data/lib/ruby_api_pack_cloudways/api/cw_server.rb +18 -13
- data/lib/ruby_api_pack_cloudways/connection/cw_connect.rb +62 -32
- data/lib/ruby_api_pack_cloudways/connection/cw_token.rb +49 -47
- data/lib/ruby_api_pack_cloudways/constants.rb +17 -0
- data/lib/ruby_api_pack_cloudways/cw_client.rb +18 -23
- data/lib/ruby_api_pack_cloudways/version.rb +5 -3
- data/lib/ruby_api_pack_cloudways.rb +9 -6
- metadata +17 -57
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0751f30764c25914fc3e6b08872881efe1e67c34dbbb88f2f578862d94206007
|
4
|
+
data.tar.gz: fc3593e06a5172ef3c3cf50e660e1377420a5eb061de25ef090830162e49f4bc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 744c1519f26a70691f11028171db1af66ba7e03931dd29a1a8383ddd53e8ce2116365c365475c2ef988d2b9badf121b25982b012e27e4607a3c3d4b996c7c48d
|
7
|
+
data.tar.gz: bc87eae838b78b2f0f6f3bf5c1ead4ab387a8422d0db3b9282d776449cf416d585af0fe2cd33597931be32fd98034b8af84d6f792544cb63e19bf8147e2babbb
|
data/README.md
CHANGED
@@ -1,11 +1,9 @@
|
|
1
1
|
### Ruby API Wrapper - Cloudways
|
2
|
-
|
3
|
-
Early Release. Beta 5.
|
4
2
|
|
5
3
|
Easily connect to your Cloudways account through their API.
|
6
|
-
|
4
|
+
|
7
5
|
* Secure OAuth Cloudways API Authentication
|
8
|
-
|
6
|
+
|
9
7
|
#### Step 1 - Add to your application
|
10
8
|
|
11
9
|
gem 'ruby_api_pack_cloudways'
|
@@ -19,18 +17,19 @@ Easily connect to your Cloudways account through their API.
|
|
19
17
|
def index
|
20
18
|
@provider_list = RubyApiPackCloudways::Api::CwLists.cw_provider_list
|
21
19
|
end
|
22
|
-
|
23
|
-
|
20
|
+
|
24
21
|
#### Example on Index File
|
25
22
|
|
26
23
|
<% @provider_list.each do |provider| %>
|
27
|
-
|
28
|
-
<%= provider["name"] %>
|
29
|
-
|
24
|
+
<%= provider["name"] %>
|
30
25
|
<% end %>
|
31
|
-
|
32
26
|
|
33
27
|
#### Variables
|
34
|
-
|
35
|
-
|
36
|
-
|
28
|
+
|
29
|
+
Set the following environment variables in your application:
|
30
|
+
|
31
|
+
export PHCDEV_API_CLOUDWAYS_EMAIL=your_cloudways_email_login
|
32
|
+
export PHCDEV_API_CLOUDWAYS_KEY=api_key_provided_by_cloudways
|
33
|
+
|
34
|
+
These variables should be configured with your Cloudways email login and API key provided by Cloudways.
|
35
|
+
|
data/Rakefile
CHANGED
@@ -1,6 +1,14 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rake'
|
4
|
+
require 'bundler/gem_tasks'
|
5
|
+
require 'rubocop/rake_task'
|
6
|
+
require 'rspec/core/rake_task'
|
7
|
+
|
8
|
+
RuboCop::RakeTask.new do |task|
|
9
|
+
task.patterns = ['lib/**/*.rb', 'spec/**/*.rb', '*.gemspec', 'Rakefile']
|
10
|
+
end
|
11
|
+
|
12
|
+
RSpec::Core::RakeTask.new(:spec)
|
13
|
+
|
14
|
+
task default: %i[rubocop spec]
|
@@ -1,31 +1,37 @@
|
|
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
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../constants'
|
4
|
+
|
5
|
+
module RubyApiPackCloudways
|
6
|
+
module Api
|
7
|
+
class CwLists
|
8
|
+
# PHCDEVONE - Include the RubyApiPackCloudways::Constants module
|
9
|
+
include RubyApiPackCloudways::Constants
|
10
|
+
|
11
|
+
# PHCDEVONE - Fetch the list of providers from the Cloudways API
|
12
|
+
def self.cw_provider_list
|
13
|
+
fetch_list('/providers')['providers']
|
14
|
+
end
|
15
|
+
|
16
|
+
# PHCDEVONE - Fetch the list of server sizes from the Cloudways API
|
17
|
+
def self.cw_server_size_list
|
18
|
+
fetch_list('/server_sizes')['sizes']
|
19
|
+
end
|
20
|
+
|
21
|
+
# PHCDEVONE - Fetch the list of apps from the Cloudways API
|
22
|
+
def self.cw_app_list
|
23
|
+
fetch_list('/apps')['apps']
|
24
|
+
end
|
25
|
+
|
26
|
+
# PHCDEVONE - Fetch the list of packages from the Cloudways API
|
27
|
+
def self.cw_package_list
|
28
|
+
fetch_list('/packages')['packages']
|
29
|
+
end
|
30
|
+
|
31
|
+
# PHCDEVONE - Fetch the list from the Cloudways API based on the given endpoint
|
32
|
+
def self.fetch_list(endpoint)
|
33
|
+
Connection::CwConnect.new(CW_API_URL, endpoint).cloudways_api_connection
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -1,13 +1,18 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../constants'
|
4
|
+
|
5
|
+
module RubyApiPackCloudways
|
6
|
+
module Api
|
7
|
+
class CwServer
|
8
|
+
# PHCDEVONE - Include the RubyApiPackCloudways::Constants module
|
9
|
+
include RubyApiPackCloudways::Constants
|
10
|
+
|
11
|
+
# PHCDEVONE - Fetch the list of servers from the Cloudways API
|
12
|
+
def self.cw_server_list
|
13
|
+
servers = Connection::CwConnect.new(CW_API_URL, '/server').cloudways_api_connection
|
14
|
+
servers['servers']
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -1,32 +1,62 @@
|
|
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
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../constants'
|
4
|
+
|
5
|
+
module RubyApiPackCloudways
|
6
|
+
module Connection
|
7
|
+
class CwConnect
|
8
|
+
# PHCDEVONE - Include the RubyApiPackCloudways::Constants module
|
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
|
13
|
+
|
14
|
+
# PHCDEVONE - Initialize the connection with the given URL, path, and optional Faraday connection
|
15
|
+
def initialize(cw_api_url_base, cw_api_path, faraday_connection = nil)
|
16
|
+
@cw_api_url_base = cw_api_url_base
|
17
|
+
@cw_api_path = cw_api_path
|
18
|
+
@faraday_connection = faraday_connection || Faraday
|
19
|
+
end
|
20
|
+
|
21
|
+
# PHCDEVONE - Establish a connection to the Cloudways API and handle the response
|
22
|
+
def cloudways_api_connection
|
23
|
+
token = fetch_token
|
24
|
+
response = create_connection(token).get(@cw_api_path)
|
25
|
+
handle_response(response)
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
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
|
+
def handle_response(response)
|
46
|
+
case response.status
|
47
|
+
when 200
|
48
|
+
parse_response(response)
|
49
|
+
else
|
50
|
+
raise "Error: Received status #{response.status}"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
# PHCDEVONE - Parse the API response using Oj
|
55
|
+
def parse_response(response)
|
56
|
+
Oj.load(response.body)
|
57
|
+
rescue Oj::ParseError => e
|
58
|
+
raise "Error parsing response: #{e.message}"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -1,47 +1,49 @@
|
|
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
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../constants'
|
4
|
+
|
5
|
+
module RubyApiPackCloudways
|
6
|
+
module Connection
|
7
|
+
class CwToken
|
8
|
+
# PHCDEVONE - Define attribute readers for API URL base, auth path, user email, user key, and Faraday connection
|
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
|
19
|
+
|
20
|
+
# PHCDEVONE - Create a Faraday connection for the API token
|
21
|
+
def cw_api_token_connection
|
22
|
+
faraday_connection.new(url: "#{@cw_api_url_base}#{@cw_url_path_auth}") do |conn|
|
23
|
+
conn.request :url_encoded
|
24
|
+
conn.response :logger
|
25
|
+
conn.adapter Faraday.default_adapter
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# PHCDEVONE - Retrieve the API token from the Cloudways API
|
30
|
+
def cw_api_token
|
31
|
+
response = cw_api_token_connection.post do |req|
|
32
|
+
req.headers['Content-Type'] = 'application/x-www-form-urlencoded'
|
33
|
+
req.body = { email: @cw_user_email, api_key: @cw_user_key }
|
34
|
+
end
|
35
|
+
|
36
|
+
parse_response(response)['access_token']
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
# PHCDEVONE - Parse the response from the API token request
|
42
|
+
def parse_response(response)
|
43
|
+
Oj.load(response.body)
|
44
|
+
rescue Oj::ParseError => e
|
45
|
+
raise "Error parsing response: #{e.message}"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,17 @@
|
|
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,23 +1,18 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
require_relative "api/cw_lists"
|
20
|
-
require_relative "api/cw_server"
|
21
|
-
|
22
|
-
end
|
23
|
-
end
|
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
|
@@ -1,6 +1,9 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'ruby_api_pack_cloudways/version'
|
4
|
+
require 'ruby_api_pack_cloudways/cw_client'
|
5
|
+
|
6
|
+
module RubyApiPackCloudways
|
7
|
+
# PHCDEVONE - Define a custom error class for the RubyApiPackCloudways module
|
8
|
+
class Error < StandardError; end
|
9
|
+
end
|
metadata
CHANGED
@@ -1,103 +1,62 @@
|
|
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.
|
4
|
+
version: 0.1.0.pre.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- PHCDevworks
|
8
|
+
- Brad Potts
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date:
|
12
|
+
date: 2024-07-05 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '2.3'
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '2.3'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: rake
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - "~>"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '13.0'
|
34
|
-
type: :runtime
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - "~>"
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '13.0'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: oj
|
15
|
+
name: faraday
|
43
16
|
requirement: !ruby/object:Gem::Requirement
|
44
17
|
requirements:
|
45
18
|
- - "~>"
|
46
19
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
20
|
+
version: '2.9'
|
48
21
|
type: :runtime
|
49
22
|
prerelease: false
|
50
23
|
version_requirements: !ruby/object:Gem::Requirement
|
51
24
|
requirements:
|
52
25
|
- - "~>"
|
53
26
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
27
|
+
version: '2.9'
|
55
28
|
- !ruby/object:Gem::Dependency
|
56
29
|
name: httparty
|
57
30
|
requirement: !ruby/object:Gem::Requirement
|
58
31
|
requirements:
|
59
32
|
- - "~>"
|
60
33
|
- !ruby/object:Gem::Version
|
61
|
-
version: 0.
|
34
|
+
version: 0.22.0
|
62
35
|
type: :runtime
|
63
36
|
prerelease: false
|
64
37
|
version_requirements: !ruby/object:Gem::Requirement
|
65
38
|
requirements:
|
66
39
|
- - "~>"
|
67
40
|
- !ruby/object:Gem::Version
|
68
|
-
version: 0.
|
41
|
+
version: 0.22.0
|
69
42
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
43
|
+
name: oj
|
71
44
|
requirement: !ruby/object:Gem::Requirement
|
72
45
|
requirements:
|
73
46
|
- - "~>"
|
74
47
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
48
|
+
version: '3.16'
|
76
49
|
type: :runtime
|
77
50
|
prerelease: false
|
78
51
|
version_requirements: !ruby/object:Gem::Requirement
|
79
52
|
requirements:
|
80
53
|
- - "~>"
|
81
54
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
83
|
-
|
84
|
-
name: rspec
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - "~>"
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: '3.10'
|
90
|
-
type: :development
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - "~>"
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: '3.10'
|
97
|
-
description: Ruby API wrapper to use with Cloudways API. Can be used alone or part
|
98
|
-
of the larger PHCDevworks Ruby API Pack.
|
55
|
+
version: '3.16'
|
56
|
+
description: Ruby API wrapper to use with Cloudways API.
|
99
57
|
email:
|
100
|
-
-
|
58
|
+
- info@phcdevworks.com
|
59
|
+
- brad.potts@phcdevworks.com
|
101
60
|
executables: []
|
102
61
|
extensions: []
|
103
62
|
extra_rdoc_files: []
|
@@ -109,6 +68,7 @@ files:
|
|
109
68
|
- lib/ruby_api_pack_cloudways/api/cw_server.rb
|
110
69
|
- lib/ruby_api_pack_cloudways/connection/cw_connect.rb
|
111
70
|
- lib/ruby_api_pack_cloudways/connection/cw_token.rb
|
71
|
+
- lib/ruby_api_pack_cloudways/constants.rb
|
112
72
|
- lib/ruby_api_pack_cloudways/cw_client.rb
|
113
73
|
- lib/ruby_api_pack_cloudways/version.rb
|
114
74
|
homepage: https://phcdevworks.com/
|
@@ -127,14 +87,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
127
87
|
requirements:
|
128
88
|
- - ">="
|
129
89
|
- !ruby/object:Gem::Version
|
130
|
-
version:
|
90
|
+
version: 2.7.0
|
131
91
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
132
92
|
requirements:
|
133
93
|
- - ">"
|
134
94
|
- !ruby/object:Gem::Version
|
135
95
|
version: 1.3.1
|
136
96
|
requirements: []
|
137
|
-
rubygems_version: 3.
|
97
|
+
rubygems_version: 3.3.27
|
138
98
|
signing_key:
|
139
99
|
specification_version: 4
|
140
100
|
summary: API Pack for Cloudways
|