ruby_api_pack_cloudways 0.1.0.pre.1 → 0.1.0.pre.4

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: 3de7f67e4fbda00d90fc05e85f484bce584337d5141dca95b1c2d27fd6d0094e
4
- data.tar.gz: 7f252f81ceca0dafc869b9992df00e4d1f36ff42d1446e9e1814c6750000c066
3
+ metadata.gz: 0751f30764c25914fc3e6b08872881efe1e67c34dbbb88f2f578862d94206007
4
+ data.tar.gz: fc3593e06a5172ef3c3cf50e660e1377420a5eb061de25ef090830162e49f4bc
5
5
  SHA512:
6
- metadata.gz: 148bc5b11df8440766a62c217891e312629bbfcc1bcf2b8f2baafb1da2b66c80491fa019143d2159a79a27ffd8f0b5dd8138c8affe9358442e2d3f16dd478607
7
- data.tar.gz: 9a9694d4c3ab236c517532562c7698e8c5d64142ab3eed92e9920ea12ef782c150bbc07064a4515349a9faf45d67cb607e2243b6a4ad1537d2bb46646333b1c7
6
+ metadata.gz: 744c1519f26a70691f11028171db1af66ba7e03931dd29a1a8383ddd53e8ce2116365c365475c2ef988d2b9badf121b25982b012e27e4607a3c3d4b996c7c48d
7
+ data.tar.gz: bc87eae838b78b2f0f6f3bf5c1ead4ab387a8422d0db3b9282d776449cf416d585af0fe2cd33597931be32fd98034b8af84d6f792544cb63e19bf8147e2babbb
data/README.md CHANGED
@@ -1,36 +1,35 @@
1
- ### Ruby API Wrapper - Cloudways
2
-
3
- Early Release. Beta 5.
4
-
5
- Easily connect to your Cloudways account through their API.
6
-
7
- * Secure OAuth Cloudways API Authentication
8
-
9
- #### Step 1 - Add to your application
10
-
11
- gem 'ruby_api_pack_cloudways'
12
- bundle install
13
-
14
- #### Controller Example
15
-
16
- # Load Gems & Files
17
- require "ruby_api_pack_cloudways"
18
-
19
- def index
20
- @provider_list = RubyApiPackCloudways::Api::CwLists.cw_provider_list
21
- end
22
-
23
-
24
- #### Example on Index File
25
-
26
- <% @provider_list.each do |provider| %>
27
-
28
- <%= provider["name"] %>
29
-
30
- <% end %>
31
-
32
-
33
- #### Variables
34
-
35
- PHCDEV_API_CLOUDWAYS_EMAIL = Your Cloudways Email Login
36
- PHCDEV_API_CLOUDWAYS_KEY = API Key Provided by Cloudways
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
+ # Load Gems & Files
15
+ require "ruby_api_pack_cloudways"
16
+
17
+ def index
18
+ @provider_list = RubyApiPackCloudways::Api::CwLists.cw_provider_list
19
+ end
20
+
21
+ #### Example on Index File
22
+
23
+ <% @provider_list.each do |provider| %>
24
+ <%= provider["name"] %>
25
+ <% end %>
26
+
27
+ #### Variables
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
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
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
3
11
 
4
12
  RSpec::Core::RakeTask.new(:spec)
5
13
 
6
- task :default => :spec
14
+ task default: %i[rubocop spec]
@@ -1,31 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../constants'
4
+
1
5
  module RubyApiPackCloudways
2
- module Api
3
- class CwLists
6
+ module Api
7
+ class CwLists
8
+ # PHCDEVONE - Include the RubyApiPackCloudways::Constants module
9
+ include RubyApiPackCloudways::Constants
4
10
 
5
- # List - Providers
6
- def self.cw_provider_list
7
- providers_list = Connection::CwConnect.new(CW_API_URL, "/providers")
8
- return Oj.load(providers_list.cloudways_api_connection.body)["providers"]
9
- end
11
+ # PHCDEVONE - Fetch the list of providers from the Cloudways API
12
+ def self.cw_provider_list
13
+ fetch_list('/providers')['providers']
14
+ end
10
15
 
11
- # List - Server Sizes
12
- def self.cw_server_size_list
13
- server_sizes_list = Connection::CwConnect.new(CW_API_URL, "/server_sizes")
14
- return Oj.load(server_sizes_list.cloudways_api_connection.body)["sizes"]
15
- end
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
16
20
 
17
- # List - App
18
- def self.cw_app_list
19
- app_list = Connection::CwConnect.new(CW_API_URL, "/apps")
20
- return Oj.load(app_list.cloudways_api_connection.body)["apps"]
21
- end
21
+ # PHCDEVONE - Fetch the list of apps from the Cloudways API
22
+ def self.cw_app_list
23
+ fetch_list('/apps')['apps']
24
+ end
22
25
 
23
- # List - Package
24
- def self.cw_package_list
25
- package_list = Connection::CwConnect.new(CW_API_URL, "/packages")
26
- return Oj.load(package_list.cloudways_api_connection.body)["packages"]
27
- end
26
+ # PHCDEVONE - Fetch the list of packages from the Cloudways API
27
+ def self.cw_package_list
28
+ fetch_list('/packages')['packages']
29
+ end
28
30
 
29
- end
30
- end
31
- end
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
- module RubyApiPackCloudways
2
- module Api
3
- class CwServer
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../constants'
4
4
 
5
- # List - Servers
6
- def self.cw_server_list
7
- cw_api_list_server = Connection::CwConnect.new(CW_API_URL, "/server")
8
- return Oj.load(cw_api_list_server.cloudways_api_connection.body)["servers"]
9
- end
5
+ module RubyApiPackCloudways
6
+ module Api
7
+ class CwServer
8
+ # PHCDEVONE - Include the RubyApiPackCloudways::Constants module
9
+ include RubyApiPackCloudways::Constants
10
10
 
11
- end
12
- end
13
- end
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
+ # frozen_string_literal: true
2
+
3
+ require_relative '../constants'
4
+
1
5
  module RubyApiPackCloudways
2
- module Connection
3
- class CwConnect
6
+ module Connection
7
+ class CwConnect
8
+ # PHCDEVONE - Include the RubyApiPackCloudways::Constants module
9
+ include RubyApiPackCloudways::Constants
4
10
 
5
- # Connection - Attributes
6
- attr_accessor :cw_api_url_base, :cw_api_path
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
7
13
 
8
- # Connection - Init
9
- def initialize(cw_api_url_base, cw_api_path)
10
- @cw_api_url_base = cw_api_url_base
11
- @cw_api_path = cw_api_path
12
- end
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
13
20
 
14
- # Connection - API Connection Call
15
- def cloudways_api_connection
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
16
27
 
17
- cw_api_get_token_connection_request = Connection::CwToken.new(CW_API_URL, CW_API_PATH_TOKEN, CW_API_EMAIL, CW_API_KEY)
18
- cw_api_get_token_connection_response = cw_api_get_token_connection_request.cw_api_token
19
-
20
- cw_api_connetion_response = Faraday.new(url: @cw_api_url_base) do |cw_api_connection|
21
- cw_api_connection.request :oauth2, cw_api_get_token_connection_response, token_type: :bearer
22
- cw_api_connection.response :logger
23
- cw_api_connection.adapter Faraday.default_adapter
24
- end
28
+ private
25
29
 
26
- return cw_api_connetion_response.get @cw_api_url_base + @cw_api_path
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
27
34
 
28
- end
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
29
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}"
30
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
31
60
  end
32
- end
61
+ end
62
+ end
@@ -1,47 +1,49 @@
1
- module RubyApiPackCloudways
2
- module Connection
3
- class CwToken
4
-
5
- # Cloudways - Token - Attributes
6
- attr_accessor :cw_api_url_base, :cw_url_path_auth, :cw_user_email, :cw_user_key
7
-
8
- # Cloudways - Token - Init
9
- def initialize(cw_api_url_base, cw_url_path_auth, cw_user_email, cw_user_key)
10
- @cw_api_url_base = cw_api_url_base
11
- @cw_url_path_auth = cw_url_path_auth
12
- @cw_user_email = cw_user_email
13
- @cw_user_key = cw_user_key
14
- end
15
-
16
- # Cloudways - Token - Connection
17
- def cw_api_token_connection
18
-
19
- # Cloudways - Token - Connection via Faraday
20
- Faraday.new url: @cw_api_url_base + @cw_url_path_auth do |cw_token_connection|
21
- cw_token_connection.request :url_encoded
22
- cw_token_connection.response :logger
23
- cw_token_connection.adapter Faraday.default_adapter
24
- end
1
+ # frozen_string_literal: true
25
2
 
26
- end
3
+ require_relative '../constants'
27
4
 
28
- # Cloudways - Token - Request
29
- def cw_api_token
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
30
28
 
31
- # Cloudways - Token - Request From Above Connection Method
32
- cloudways_token_request = cw_api_token_connection.post do |cw_token_request|
33
- cw_token_request.headers["Content-Type"] = "application/x-www-form-urlencoded"
34
- cw_token_request.body = {
35
- email: @cw_user_email,
36
- api_key: @cw_user_key
37
- }
38
- end
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
39
35
 
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"]
36
+ parse_response(response)['access_token']
37
+ end
42
38
 
43
- end
39
+ private
44
40
 
45
- end
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
46
47
  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,24 +1,18 @@
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"]
1
+ # frozen_string_literal: true
6
2
 
7
- module RubyApiPackCloudways
8
- class CwClient
9
-
10
- # Load Required Gems
11
- require "faraday"
12
- require "faraday_middleware"
13
- require "oj"
3
+ require 'faraday'
4
+ require 'oj'
14
5
 
15
- # Load Main Files
16
- require_relative "connection/cw_token"
17
- require_relative "connection/cw_connect"
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'
18
12
 
19
- # Load API Files
20
- require_relative "api/cw_lists"
21
- require_relative "api/cw_server"
22
-
23
- end
24
- end
13
+ module RubyApiPackCloudways
14
+ class CwClient
15
+ # PHCDEVONE - Include the RubyApiPackCloudways::Constants module
16
+ include RubyApiPackCloudways::Constants
17
+ end
18
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RubyApiPackCloudways
2
- VERSION = "0.1.0.pre.1"
4
+ VERSION = '0.1.0.pre.4'
3
5
  end
@@ -1,7 +1,9 @@
1
- require "ruby_api_pack_cloudways/version"
1
+ # frozen_string_literal: true
2
+
3
+ require 'ruby_api_pack_cloudways/version'
4
+ require 'ruby_api_pack_cloudways/cw_client'
2
5
 
3
6
  module RubyApiPackCloudways
7
+ # PHCDEVONE - Define a custom error class for the RubyApiPackCloudways module
4
8
  class Error < StandardError; end
5
-
6
- require_relative "ruby_api_pack_cloudways/cw_client"
7
9
  end
metadata CHANGED
@@ -1,123 +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.1
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: 2021-06-16 00:00:00.000000000 Z
12
+ date: 2024-07-05 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
- name: bundler
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '0'
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
- - - ">="
35
- - !ruby/object:Gem::Version
36
- version: 13.0.3
37
- type: :runtime
38
- prerelease: false
39
- version_requirements: !ruby/object:Gem::Requirement
40
- requirements:
41
- - - "~>"
42
- - !ruby/object:Gem::Version
43
- version: '13.0'
44
- - - ">="
45
- - !ruby/object:Gem::Version
46
- version: 13.0.3
47
- - !ruby/object:Gem::Dependency
48
- name: oj
15
+ name: faraday
49
16
  requirement: !ruby/object:Gem::Requirement
50
17
  requirements:
51
18
  - - "~>"
52
19
  - !ruby/object:Gem::Version
53
- version: '3.11'
20
+ version: '2.9'
54
21
  type: :runtime
55
22
  prerelease: false
56
23
  version_requirements: !ruby/object:Gem::Requirement
57
24
  requirements:
58
25
  - - "~>"
59
26
  - !ruby/object:Gem::Version
60
- version: '3.11'
27
+ version: '2.9'
61
28
  - !ruby/object:Gem::Dependency
62
29
  name: httparty
63
30
  requirement: !ruby/object:Gem::Requirement
64
31
  requirements:
65
32
  - - "~>"
66
33
  - !ruby/object:Gem::Version
67
- version: 0.18.1
34
+ version: 0.22.0
68
35
  type: :runtime
69
36
  prerelease: false
70
37
  version_requirements: !ruby/object:Gem::Requirement
71
38
  requirements:
72
39
  - - "~>"
73
40
  - !ruby/object:Gem::Version
74
- version: 0.18.1
41
+ version: 0.22.0
75
42
  - !ruby/object:Gem::Dependency
76
- name: faraday
77
- requirement: !ruby/object:Gem::Requirement
78
- requirements:
79
- - - "~>"
80
- - !ruby/object:Gem::Version
81
- version: '1.3'
82
- type: :runtime
83
- prerelease: false
84
- version_requirements: !ruby/object:Gem::Requirement
85
- requirements:
86
- - - "~>"
87
- - !ruby/object:Gem::Version
88
- version: '1.3'
89
- - !ruby/object:Gem::Dependency
90
- name: faraday_middleware
43
+ name: oj
91
44
  requirement: !ruby/object:Gem::Requirement
92
45
  requirements:
93
46
  - - "~>"
94
47
  - !ruby/object:Gem::Version
95
- version: '1.0'
48
+ version: '3.16'
96
49
  type: :runtime
97
50
  prerelease: false
98
51
  version_requirements: !ruby/object:Gem::Requirement
99
52
  requirements:
100
53
  - - "~>"
101
54
  - !ruby/object:Gem::Version
102
- version: '1.0'
103
- - !ruby/object:Gem::Dependency
104
- name: rspec
105
- requirement: !ruby/object:Gem::Requirement
106
- requirements:
107
- - - "~>"
108
- - !ruby/object:Gem::Version
109
- version: '3.0'
110
- type: :development
111
- prerelease: false
112
- version_requirements: !ruby/object:Gem::Requirement
113
- requirements:
114
- - - "~>"
115
- - !ruby/object:Gem::Version
116
- version: '3.0'
117
- description: Ruby API wrapper to use with Cloudways API. Can be used alone or part
118
- of the larger PHCDevworks Ruby API Pack.
55
+ version: '3.16'
56
+ description: Ruby API wrapper to use with Cloudways API.
119
57
  email:
120
- - imfo@phcdevworks.com
58
+ - info@phcdevworks.com
59
+ - brad.potts@phcdevworks.com
121
60
  executables: []
122
61
  extensions: []
123
62
  extra_rdoc_files: []
@@ -129,6 +68,7 @@ files:
129
68
  - lib/ruby_api_pack_cloudways/api/cw_server.rb
130
69
  - lib/ruby_api_pack_cloudways/connection/cw_connect.rb
131
70
  - lib/ruby_api_pack_cloudways/connection/cw_token.rb
71
+ - lib/ruby_api_pack_cloudways/constants.rb
132
72
  - lib/ruby_api_pack_cloudways/cw_client.rb
133
73
  - lib/ruby_api_pack_cloudways/version.rb
134
74
  homepage: https://phcdevworks.com/
@@ -147,14 +87,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
147
87
  requirements:
148
88
  - - ">="
149
89
  - !ruby/object:Gem::Version
150
- version: '0'
90
+ version: 2.7.0
151
91
  required_rubygems_version: !ruby/object:Gem::Requirement
152
92
  requirements:
153
93
  - - ">"
154
94
  - !ruby/object:Gem::Version
155
95
  version: 1.3.1
156
96
  requirements: []
157
- rubygems_version: 3.2.20
97
+ rubygems_version: 3.3.27
158
98
  signing_key:
159
99
  specification_version: 4
160
100
  summary: API Pack for Cloudways