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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c5d5c0dbd540fefe913e29f48ec5b2b4d13ec85defba36dc543bdb919f0bba69
4
- data.tar.gz: f5c0c3726f3633a98d401a070885ed9b554c6d6e39d71d6119082b38907605ff
3
+ metadata.gz: 7b502c4da2d913ded7dcfca1bc55ec230870752a73f5a80b5a2d519101da7a1a
4
+ data.tar.gz: eef95f114ac2467f27174534007f4f04804ca47c82c47496bbb327368eb63fb6
5
5
  SHA512:
6
- metadata.gz: 4fcf9c96ec828c8756960021f3b349c52ded473df0b7f4535bd3dd669fc2a33de2a4a506c61b93fc1ce2a878e593befed1e8be82c48d7d30445314c927e28ea4
7
- data.tar.gz: 83dc4c10e916dfe74ddf293fd781fde36c94ec3b77839ba65c58cb28cc25b7f6607e883f1f8df8ff497ea8591a1c3b7238fb9aeb8886cec7158deb1baa3cdb79
6
+ metadata.gz: 6d8c0706ff2b775a0172fa13fe6d9d836f4a3d57354c47e6c0b7e1f50f66a2c57245bab98563d4e33a9beb9f68fa018a86c89bc386858779f1be8d9699e83770
7
+ data.tar.gz: 0c40f6a4bf8f8fa2bbdaf23fa5b104cac84450cbd280b0db3d86780a41c860135a95b8199dbe6f2a3f15e6fe8877c0c260c3ec4a5ff7e774b5002ed35f3b1fb9
data/README.md CHANGED
@@ -1,36 +1,61 @@
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
+ 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
- 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,32 @@
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
+ 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
- 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
+ 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
- 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 '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
- 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 '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,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.5'
5
+ end
@@ -1,6 +1,22 @@
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 '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.3
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: 2022-09-17 00:00:00.000000000 Z
12
+ date: 2024-07-10 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: []
@@ -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: '0'
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.0.3.1
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