ruby_api_pack_cloudways 0.1.0.pre.3 → 0.1.0.pre.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +61 -36
- data/Rakefile +14 -6
- data/lib/ruby_api_pack_cloudways/api/cw_lists.rb +32 -31
- data/lib/ruby_api_pack_cloudways/api/cw_server.rb +16 -13
- data/lib/ruby_api_pack_cloudways/configuration.rb +14 -0
- data/lib/ruby_api_pack_cloudways/connection/cw_connect.rb +42 -32
- data/lib/ruby_api_pack_cloudways/connection/cw_token.rb +35 -47
- data/lib/ruby_api_pack_cloudways/version.rb +5 -3
- data/lib/ruby_api_pack_cloudways.rb +22 -6
- metadata +17 -58
- data/lib/ruby_api_pack_cloudways/cw_client.rb +0 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7b502c4da2d913ded7dcfca1bc55ec230870752a73f5a80b5a2d519101da7a1a
|
4
|
+
data.tar.gz: eef95f114ac2467f27174534007f4f04804ca47c82c47496bbb327368eb63fb6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6d8c0706ff2b775a0172fa13fe6d9d836f4a3d57354c47e6c0b7e1f50f66a2c57245bab98563d4e33a9beb9f68fa018a86c89bc386858779f1be8d9699e83770
|
7
|
+
data.tar.gz: 0c40f6a4bf8f8fa2bbdaf23fa5b104cac84450cbd280b0db3d86780a41c860135a95b8199dbe6f2a3f15e6fe8877c0c260c3ec4a5ff7e774b5002ed35f3b1fb9
|
data/README.md
CHANGED
@@ -1,36 +1,61 @@
|
|
1
|
-
### Ruby API Wrapper - Cloudways
|
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
|
-
|
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
|
19
|
+
|
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:
|
36
|
+
|
37
|
+
EDITOR="code --wait" bin/rails credentials:edit
|
38
|
+
|
39
|
+
Add the following to your credentials.yml:
|
40
|
+
|
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
|
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,32 @@
|
|
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
|
-
end
|
31
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RubyApiPackCloudways
|
4
|
+
module Api
|
5
|
+
class CwLists
|
6
|
+
# Fetch the list of providers from the Cloudways API
|
7
|
+
def self.cw_provider_list
|
8
|
+
fetch_list('/providers')['providers']
|
9
|
+
end
|
10
|
+
|
11
|
+
# Fetch the list of server sizes from the Cloudways API
|
12
|
+
def self.cw_server_size_list
|
13
|
+
fetch_list('/server_sizes')['sizes']
|
14
|
+
end
|
15
|
+
|
16
|
+
# Fetch the list of apps from the Cloudways API
|
17
|
+
def self.cw_app_list
|
18
|
+
fetch_list('/apps')['apps']
|
19
|
+
end
|
20
|
+
|
21
|
+
# Fetch the list of packages from the Cloudways API
|
22
|
+
def self.cw_package_list
|
23
|
+
fetch_list('/packages')['packages']
|
24
|
+
end
|
25
|
+
|
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
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -1,13 +1,16 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RubyApiPackCloudways
|
4
|
+
module Api
|
5
|
+
class CwServer
|
6
|
+
# Fetch the list of servers from the Cloudways API
|
7
|
+
def self.cw_server_list
|
8
|
+
fetch_list('/server')['servers']
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.fetch_list(endpoint)
|
12
|
+
Connection::CwConnect.new(RubyApiPackCloudways.configuration.api_url, endpoint).cloudways_api_connection
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
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,32 +1,42 @@
|
|
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
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'httparty'
|
4
|
+
|
5
|
+
module RubyApiPackCloudways
|
6
|
+
module Connection
|
7
|
+
class CwConnect
|
8
|
+
attr_reader :cw_api_url_base, :cw_api_path
|
9
|
+
|
10
|
+
def initialize(cw_api_url_base, cw_api_path)
|
11
|
+
@cw_api_url_base = cw_api_url_base
|
12
|
+
@cw_api_path = cw_api_path
|
13
|
+
end
|
14
|
+
|
15
|
+
def cloudways_api_connection
|
16
|
+
token = CwToken.new.cw_api_token
|
17
|
+
response = HTTParty.get(
|
18
|
+
"#{@cw_api_url_base}#{@cw_api_path}",
|
19
|
+
headers: { 'Authorization' => "Bearer #{token}" }
|
20
|
+
)
|
21
|
+
handle_response(response)
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def handle_response(response)
|
27
|
+
case response.code
|
28
|
+
when 200
|
29
|
+
parse_response(response)
|
30
|
+
else
|
31
|
+
raise "Error: Received status #{response.code}"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def parse_response(response)
|
36
|
+
Oj.load(response.body)
|
37
|
+
rescue Oj::ParseError => e
|
38
|
+
raise "Error parsing response: #{e.message}"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -1,47 +1,35 @@
|
|
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
|
-
api_key: @cw_user_key
|
37
|
-
}
|
38
|
-
end
|
39
|
-
|
40
|
-
# Cloudways - Token - Request Isolate and Get Token from Response via OJ
|
41
|
-
return cw_api_token = Oj.load(cloudways_token_request.body)["access_token"]
|
42
|
-
|
43
|
-
end
|
44
|
-
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'httparty'
|
4
|
+
|
5
|
+
module RubyApiPackCloudways
|
6
|
+
module Connection
|
7
|
+
class CwToken
|
8
|
+
attr_reader :cw_api_url_base, :cw_url_path_auth, :cw_user_email, :cw_user_key
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
@cw_api_url_base = RubyApiPackCloudways.configuration.api_url
|
12
|
+
@cw_url_path_auth = RubyApiPackCloudways.configuration.api_path_token
|
13
|
+
@cw_user_email = RubyApiPackCloudways.configuration.api_email
|
14
|
+
@cw_user_key = RubyApiPackCloudways.configuration.api_key
|
15
|
+
end
|
16
|
+
|
17
|
+
def cw_api_token
|
18
|
+
response = HTTParty.post(
|
19
|
+
"#{@cw_api_url_base}#{@cw_url_path_auth}",
|
20
|
+
headers: { 'Content-Type' => 'application/x-www-form-urlencoded' },
|
21
|
+
body: { email: @cw_user_email, api_key: @cw_user_key }
|
22
|
+
)
|
23
|
+
parse_response(response)['access_token']
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def parse_response(response)
|
29
|
+
Oj.load(response.body)
|
30
|
+
rescue Oj::ParseError => e
|
31
|
+
raise "Error parsing response: #{e.message}"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -1,6 +1,22 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'faraday'
|
4
|
+
require 'oj'
|
5
|
+
|
6
|
+
# Load Configuration and API Files
|
7
|
+
require_relative 'ruby_api_pack_cloudways/configuration'
|
8
|
+
require_relative 'ruby_api_pack_cloudways/connection/cw_token'
|
9
|
+
require_relative 'ruby_api_pack_cloudways/connection/cw_connect'
|
10
|
+
require_relative 'ruby_api_pack_cloudways/api/cw_lists'
|
11
|
+
require_relative 'ruby_api_pack_cloudways/api/cw_server'
|
12
|
+
|
13
|
+
module RubyApiPackCloudways
|
14
|
+
class << self
|
15
|
+
attr_accessor :configuration
|
16
|
+
|
17
|
+
def configure
|
18
|
+
self.configuration ||= Configuration.new
|
19
|
+
yield(configuration)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
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.5
|
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-10 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: []
|
@@ -107,9 +66,9 @@ files:
|
|
107
66
|
- lib/ruby_api_pack_cloudways.rb
|
108
67
|
- lib/ruby_api_pack_cloudways/api/cw_lists.rb
|
109
68
|
- lib/ruby_api_pack_cloudways/api/cw_server.rb
|
69
|
+
- lib/ruby_api_pack_cloudways/configuration.rb
|
110
70
|
- lib/ruby_api_pack_cloudways/connection/cw_connect.rb
|
111
71
|
- lib/ruby_api_pack_cloudways/connection/cw_token.rb
|
112
|
-
- lib/ruby_api_pack_cloudways/cw_client.rb
|
113
72
|
- lib/ruby_api_pack_cloudways/version.rb
|
114
73
|
homepage: https://phcdevworks.com/
|
115
74
|
licenses:
|
@@ -127,14 +86,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
127
86
|
requirements:
|
128
87
|
- - ">="
|
129
88
|
- !ruby/object:Gem::Version
|
130
|
-
version:
|
89
|
+
version: 2.7.0
|
131
90
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
132
91
|
requirements:
|
133
92
|
- - ">"
|
134
93
|
- !ruby/object:Gem::Version
|
135
94
|
version: 1.3.1
|
136
95
|
requirements: []
|
137
|
-
rubygems_version: 3.
|
96
|
+
rubygems_version: 3.3.27
|
138
97
|
signing_key:
|
139
98
|
specification_version: 4
|
140
99
|
summary: API Pack for Cloudways
|
@@ -1,23 +0,0 @@
|
|
1
|
-
# Variables
|
2
|
-
CW_API_URL = "https://api.cloudways.com/api/v1"
|
3
|
-
CW_API_PATH_TOKEN = "/oauth/access_token"
|
4
|
-
CW_API_EMAIL = ENV["PHCDEV_API_CLOUDWAYS_EMAIL"]
|
5
|
-
CW_API_KEY = ENV["PHCDEV_API_CLOUDWAYS_KEY"]
|
6
|
-
|
7
|
-
module RubyApiPackCloudways
|
8
|
-
class CwClient
|
9
|
-
|
10
|
-
# Load Required Gems
|
11
|
-
require "faraday"
|
12
|
-
require "oj"
|
13
|
-
|
14
|
-
# Load Main Files
|
15
|
-
require_relative "connection/cw_token"
|
16
|
-
require_relative "connection/cw_connect"
|
17
|
-
|
18
|
-
# Load API Files
|
19
|
-
require_relative "api/cw_lists"
|
20
|
-
require_relative "api/cw_server"
|
21
|
-
|
22
|
-
end
|
23
|
-
end
|