Class: RubyApiPackCloudways::Connection::CwConnect
- Inherits:
-
Object
- Object
- RubyApiPackCloudways::Connection::CwConnect
- Defined in:
- lib/ruby_api_pack_cloudways/connection/cw_connect.rb
Instance Attribute Summary collapse
-
#cw_api_path ⇒ Object
readonly
Initialize Cloudways API URL and path.
-
#cw_api_url_base ⇒ Object
readonly
Initialize Cloudways API URL and path.
Instance Method Summary collapse
-
#cloudways_api_connection ⇒ Object
GET request to Cloudways API.
-
#cloudways_api_post_connection(params) ⇒ Object
POST request to Cloudways API.
-
#initialize(cw_api_url_base, cw_api_path) ⇒ CwConnect
constructor
Initialize Cloudways API URL and path.
Constructor Details
#initialize(cw_api_url_base, cw_api_path) ⇒ CwConnect
Initialize Cloudways API URL and path
14 15 16 17 |
# File 'lib/ruby_api_pack_cloudways/connection/cw_connect.rb', line 14 def initialize(cw_api_url_base, cw_api_path) @cw_api_url_base = cw_api_url_base @cw_api_path = cw_api_path end |
Instance Attribute Details
#cw_api_path ⇒ Object (readonly)
Initialize Cloudways API URL and path
11 12 13 |
# File 'lib/ruby_api_pack_cloudways/connection/cw_connect.rb', line 11 def cw_api_path @cw_api_path end |
#cw_api_url_base ⇒ Object (readonly)
Initialize Cloudways API URL and path
11 12 13 |
# File 'lib/ruby_api_pack_cloudways/connection/cw_connect.rb', line 11 def cw_api_url_base @cw_api_url_base end |
Instance Method Details
#cloudways_api_connection ⇒ Object
GET request to Cloudways API
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/ruby_api_pack_cloudways/connection/cw_connect.rb', line 20 def cloudways_api_connection token = CwToken.new.cw_api_token response = HTTParty.get( "#{@cw_api_url_base}#{@cw_api_path}", headers: { 'Authorization' => "Bearer #{token}" }, ssl_version: :TLSv1_2, debug_output: $stdout ) handle_response(response) rescue RuntimeError => e raise unless e..include?('Rate limit exceeded') sleep(60) retry end |
#cloudways_api_post_connection(params) ⇒ Object
POST request to Cloudways API
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/ruby_api_pack_cloudways/connection/cw_connect.rb', line 37 def cloudways_api_post_connection(params) token = CwToken.new.cw_api_token response = HTTParty.post( "#{@cw_api_url_base}#{@cw_api_path}", headers: { 'Authorization' => "Bearer #{token}", 'Content-Type' => 'application/json' }, body: params.to_json, ssl_version: :TLSv1_2, debug_output: $stdout ) handle_response(response) end |