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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c5d5c0dbd540fefe913e29f48ec5b2b4d13ec85defba36dc543bdb919f0bba69
4
- data.tar.gz: f5c0c3726f3633a98d401a070885ed9b554c6d6e39d71d6119082b38907605ff
3
+ metadata.gz: 0751f30764c25914fc3e6b08872881efe1e67c34dbbb88f2f578862d94206007
4
+ data.tar.gz: fc3593e06a5172ef3c3cf50e660e1377420a5eb061de25ef090830162e49f4bc
5
5
  SHA512:
6
- metadata.gz: 4fcf9c96ec828c8756960021f3b349c52ded473df0b7f4535bd3dd669fc2a33de2a4a506c61b93fc1ce2a878e593befed1e8be82c48d7d30445314c927e28ea4
7
- data.tar.gz: 83dc4c10e916dfe74ddf293fd781fde36c94ec3b77839ba65c58cb28cc25b7f6607e883f1f8df8ff497ea8591a1c3b7238fb9aeb8886cec7158deb1baa3cdb79
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
- PHCDEV_API_CLOUDWAYS_EMAIL = Your Cloudways Email Login
36
- PHCDEV_API_CLOUDWAYS_KEY = API Key Provided by Cloudways
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"
3
-
4
- RSpec::Core::RakeTask.new(:spec)
5
-
6
- task :default => :spec
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
- module RubyApiPackCloudways
2
- module Api
3
- class CwLists
4
-
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
10
-
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
-
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
22
-
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
28
-
29
- end
30
- end
31
- end
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
- module RubyApiPackCloudways
2
- module Api
3
- class CwServer
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
10
-
11
- end
12
- end
13
- end
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
- module RubyApiPackCloudways
2
- module Connection
3
- class CwConnect
4
-
5
- # Connection - Attributes
6
- attr_accessor :cw_api_url_base, :cw_api_path
7
-
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
13
-
14
- # Connection - API Connection Call
15
- def cloudways_api_connection
16
-
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
25
-
26
- return cw_api_connetion_response.get @cw_api_url_base + @cw_api_path
27
-
28
- end
29
-
30
- end
31
- end
32
- end
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
- 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
25
-
26
- end
27
-
28
- # Cloudways - Token - Request
29
- def cw_api_token
30
-
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
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_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
- # 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
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,3 +1,5 @@
1
- module RubyApiPackCloudways
2
- VERSION = "0.1.0.pre.3"
3
- end
1
+ # frozen_string_literal: true
2
+
3
+ module RubyApiPackCloudways
4
+ VERSION = '0.1.0.pre.4'
5
+ end
@@ -1,6 +1,9 @@
1
- require "ruby_api_pack_cloudways/version"
2
-
3
- module RubyApiPackCloudways
4
- class Error < StandardError; end
5
- require_relative "ruby_api_pack_cloudways/cw_client"
6
- end
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.3
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: 2022-09-17 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: '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: '3.13'
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: '3.13'
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.20.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.20.0
41
+ version: 0.22.0
69
42
  - !ruby/object:Gem::Dependency
70
- name: faraday
43
+ name: oj
71
44
  requirement: !ruby/object:Gem::Requirement
72
45
  requirements:
73
46
  - - "~>"
74
47
  - !ruby/object:Gem::Version
75
- version: '2.5'
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: '2.5'
83
- - !ruby/object:Gem::Dependency
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
- - imfo@phcdevworks.com
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: '0'
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.0.3.1
97
+ rubygems_version: 3.3.27
138
98
  signing_key:
139
99
  specification_version: 4
140
100
  summary: API Pack for Cloudways