Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add n0c-api endpoints #29

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ workflows:
- build_and_test:
matrix:
parameters:
ruby-version: ["2.6", "2.7", "3.0", "3.1"]
ruby-version: ["2.6", "2.7", "3.0", "3.1", "3.2", "3.3"]
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
/spec/reports/
/tmp/

.idea/

# rspec failure tracking
.rspec_status
.ruby-version
Expand Down
6 changes: 4 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
source "https://rubygems.org"
source 'https://rubygems.org'

gemspec

Expand All @@ -7,4 +7,6 @@ gem 'rake'
group :test do
gem 'rspec', '> 0'
gem 'rspec_junit_formatter', '> 0'
end
end

gem 'rubocop', '~> 1.62'
30 changes: 29 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
PATH
remote: .
specs:
planethoster_api (1.0.0)
planethoster_api (1.1.0)

GEM
remote: https://rubygems.org/
specs:
ast (2.4.2)
diff-lcs (1.5.1)
json (2.7.2)
language_server-protocol (3.17.0.3)
parallel (1.24.0)
parser (3.3.1.0)
ast (~> 2.4.1)
racc
racc (1.7.3)
rainbow (3.1.1)
rake (13.2.1)
regexp_parser (2.9.1)
rexml (3.2.6)
rspec (3.13.0)
rspec-core (~> 3.13.0)
rspec-expectations (~> 3.13.0)
Expand All @@ -23,15 +34,32 @@ GEM
rspec-support (3.13.1)
rspec_junit_formatter (0.6.0)
rspec-core (>= 2, < 4, != 2.12.0)
rubocop (1.63.5)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.31.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.31.3)
parser (>= 3.3.1.0)
ruby-progressbar (1.13.0)
unicode-display_width (2.5.0)

PLATFORMS
x86_64-darwin-22
x86_64-linux

DEPENDENCIES
planethoster_api!
rake
rspec (> 0)
rspec_junit_formatter (> 0)
rubocop (~> 1.62)

BUNDLED WITH
2.3.23
73 changes: 72 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ You need to initialize api credentials.
```ruby
require 'planethoster_api'

PlanethosterApi.configuration do |config|
PlanethosterApi.configure do |config|
config.api_user = API_USER
config.api_key = API_KEY
end
Expand Down Expand Up @@ -82,6 +82,77 @@ PlanethosterApi.world[...] # options down below
.modify_ressources() # Modify the resources associated with a World account.
.upgrade_plan() # Increases resources associated with The World account.
```
### N0C (Hosting)
[What is a N0C hosting?](https://kb.n0c.com/en/what-is-n0c/)
```ruby
PlanethosterApi.n0c[...] # options down below
```
```ruby
.temporary_domain() # Generate a free temporary domain to access your main website.
.disable_temporary_domain() # Disable the temporary domain.
.ssh_keys() # Get SSH keys installed for an account.
.add_ssh_keys() # Add a SSH key to the World account.
.edit_ssh_keys() # Edit an existing SSH key.
.remove_ssh_keys() # Remove an existing SSH key.
.domains() # Get all domains of the account.
.add_domain() # Add a domain to the World account.
.remove_domain() # Remove the domain from the World account.
.add_sub_domain() # Add a sub-domain to the World account.
.suspend_domain() # Suspend one or multiple domains.
.unsuspend_domain() # Unsuspend one or multiple domains.
.change_doc_root() # Change document root for a domain.
.domain_redirections() # Get domain redirections.
.domain_internal_redirection() # Redirection that will force HTTPS or www, for example.
.domain_external_redirection() # Set an external domain redirection.
.domain_delete_redirection() # Delete redirection for a domain.
.waf_logs() # Get domain WAF logs.
.waf_rules() # Get the domain WAF rules.
.update_waf_rules() # Update WAF rules for the domain.
.dns_zone() # Find the complete dns zone.
.reset_dns_zone() # Will add the default values of the dns zone.
.edit_dns_zone() # Allows you to add or modify records on the DNS zone
.emails() # Get all account emails.
.add_email() # Create a new email address.
.remove_email() # Remove an email address.
.email_change_password() # Change the password of an email account.
.email_change_quota() # Change quota of an email account.
.suspend_email() # Suspend multiple email addresses.
.unsuspend_email() # Unsuspend multiple email addresses.
.email_authentication() # List email authentication.
.enable_email_authentication() # Enable email authentication.
.disable_email_authentication() # Disable email authentication.
.databases() # Get World account databases.
.add_database() # Create a new database.
.remove_database() # Remove database.
.database_users() # Get World account database users.
.add_database_users() # Create a new database user.
.remove_database_users() # Remove a database user.
.add_permission_database_users() # Grant access to a database for a user.
.remove_permission_database_users() # Remove access to a database for an user.
.crons() # Get world the cron jobs of the World account.
.add_cron() # Add cron to the World account.
.remove_cron() # Remove an existing cron job.
.set_cron_email() # Set cron email.
.remove_cron_email() # Remove cron email.
.ftp_accounts() # Get all FTP accounts.
.add_ftp_account() # Create an FTP account.
.remove_ftp_account() # Remove an FTP account.
.ftp_account_password() # Change the password of the FTP account.
.ftp_account_path() # Update the path of the FTP account.
.ftp_account_connections() # List all active connections.
.wordpress() # Get Wordpress paths installed.
.add_wordpress() # Wordpress installation
.remove_wordpress() # Removing a wordpress installation
.available_cms() # List the cms available for installation and their versions.
.install_cms() # Start the installation of a CMS
.installed_cms() # List the CMS installed on the hosting
.cms_installations_progress() # List CMS that have recently been installed or are in the process of being installed
.delete_cms() # Delete a CMS installation
.stats_performance() # Retrieve performance data
.stats_disk_usage() # Returns disk space usage (response always in BYTE)
.stats_apache() # Web server statistics (Visits)
.stats_apache_unique() # Web server statistics (Visits)
```

## Development

Expand Down
6 changes: 3 additions & 3 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "bundler/gem_tasks"
require "rspec/core/rake_task"
require 'bundler/gem_tasks'
require 'rspec/core/rake_task'

RSpec::Core::RakeTask.new(:spec)

task :default => :spec
task default: :spec
6 changes: 3 additions & 3 deletions bin/console
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env ruby

require "bundler/setup"
require "planethoster_api"
require 'bundler/setup'
require 'planethoster_api'

# You can add fixtures and/or initialization code here to make experimenting
# with your gem easier. You can also use a different console, if you like.
Expand All @@ -10,5 +10,5 @@ require "planethoster_api"
# require "pry"
# Pry.start

require "irb"
require 'irb'
IRB.start(__FILE__)
14 changes: 12 additions & 2 deletions lib/planethoster_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require 'planethoster_api/api_interface'
require 'planethoster_api/domain'
require 'planethoster_api/world'
require 'planethoster_api/n0c'

module PlanethosterApi
class << self
Expand Down Expand Up @@ -39,12 +40,21 @@ def self.world
end
end

def self.n0c
creds_wrap do
PlanethosterApi::N0C.new(
@configuration.api_user,
@configuration.api_key
)
end
end

private
def self.creds_wrap
if @configuration.nil?
raise "api_key and api_user are not defined - Please refer to documentation and configure credentials: https://github.com/PlanetHoster/planethoster-ruby"
raise 'api_key and api_user are not defined - Please refer to documentation and configure credentials: ' \
'https://github.com/PlanetHoster/planethoster-ruby'
end
yield
end

end
5 changes: 2 additions & 3 deletions lib/planethoster_api/api_interface.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ def initialize(api_user, api_key)
def test_connection
@api_client.call(
:get,
"/reseller-api/test-connection",
'/reseller-api/test-connection',
{}
)
end

end
end
end
7 changes: 3 additions & 4 deletions lib/planethoster_api/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ class Configuration

# Empty strings if not defined
def initialize
@api_user = ""
@api_key = ""
@api_user = ''
@api_key = ''
end

end
end
end
14 changes: 5 additions & 9 deletions lib/planethoster_api/domain.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
module PlanethosterApi
class Domain < ApiInterface

BASE_DOMAIN_PATH = '/reseller-api'

BASE_DOMAIN_PATH = '/reseller-api'.freeze
DOMAINS_METHODS_PATH = {
tld_prices: [:get, '/tld-prices'],
account_info: [:get, '/account-info'],
Expand All @@ -11,7 +9,7 @@ class Domain < ApiInterface
get_contact_details: [:get, '/get-contact-details'],
get_nameservers: [:get, '/get-nameservers'],
get_ph_dns_records: [:get, '/get-ph-dns-records'],
get_registrar_lock: [:get, '/get-registrar-lock '],
get_registrar_lock: [:get, '/get-registrar-lock'],
save_contact_details: [:post, '/save-contact-details'],
save_nameservers: [:post, '/save-nameservers'],
save_ph_dns_records: [:post, '/save-ph-dns-records'],
Expand All @@ -21,17 +19,15 @@ class Domain < ApiInterface
renew_domain: [:post, '/renew-domain'],
transfer_domain: [:post, '/transfer-domain'],
delete_ph_dns_zone: [:post, '/delete-php-dns-zone']
}
}.freeze

DOMAINS_METHODS_PATH.each do |function_name, info|
method = info.first
path = "#{BASE_DOMAIN_PATH}#{info.last}"
params = params || {}

define_method(function_name) do |params|
define_method(function_name) do |params = {}|
@api_client.call(method, path, params)
end
end

end
end
end
90 changes: 90 additions & 0 deletions lib/planethoster_api/n0c.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
module PlanethosterApi
class N0C < ApiInterface
BASE_WORLD_PATH = '/n0c-api'.freeze
N0C_METHODS_PATH = {
# USER
temporary_domain: [:post, '/user/temp-domain'],
disable_temporary_domain: [:post, '/user/disable-temp-domain'],
ssh_keys: [:get, '/user/ssh-keys'],
add_ssh_keys: [:post, '/user/add-ssh-keys'],
edit_ssh_keys: [:post, '/user/edit-ssh-keys'],
remove_ssh_keys: [:post, '/user/remove-ssh-keys'],
# DOMAINS
domains: [:get, '/domains'],
add_domain: [:post, '/domain/add'],
remove_domain: [:post, '/domain/remove'],
add_sub_domain: [:post, '/domain/add-sub-domain'],
suspend_domain: [:post, '/domain/suspend'],
unsuspend_domain: [:post, '/domain/unsuspend'],
change_doc_root: [:post, '/domain/change-doc-root'],
domain_redirections: [:get, '/domain/redirections'],
domain_internal_redirection: [:post, '/domain/redirection'],
domain_external_redirection: [:post, '/domain/external-redirection'],
domain_delete_redirection: [:post, '/domain/delete-redirection'],
waf_logs: [:get, '/domain/waf-logs'],
waf_rules: [:get, '/domain/waf-rules'],
update_waf_rules: [:post, '/domain/update-waf-rules'],
# DNS
dns_zone: [:get, '/dns/get-records'],
reset_dns_zone: [:post, '/dns/reset-zone'],
edit_dns_zone: [:post, '/dns/edit-zone'],
# Email
emails: [:get, '/emails'],
add_email: [:post, '/email/add'],
remove_email: [:post, '/email/remove'],
email_change_password: [:post, '/email/change-password'],
email_change_quota: [:post, '/email/change-quota'],
suspend_email: [:post, '/email/suspend'],
unsuspend_email: [:post, '/email/unsuspend'],
email_authentication: [:get, '/email/auths'],
enable_email_authentication: [:post, '/email/auth/enable'],
disable_email_authentication: [:post, '/email/auth/disable'],
# DATABASE
databases: [:get, '/databases'],
add_database: [:post, '/database/add'],
remove_database: [:post, '/database/remove'],
database_users: [:get, '/database/users'],
add_database_users: [:post, '/database/user/add'],
remove_database_users: [:post, '/database/user/remove'],
add_permission_database_users: [:post, '/database/user/grant-access'],
remove_permission_database_users: [:post, '/database/user/remove-access'],
# CRON
crons: [:get, '/crons'],
add_cron: [:post, '/cron/add'],
remove_cron: [:post, '/cron/remove'],
set_cron_email: [:post, '/cron/email/set'],
remove_cron_email: [:post, '/cron/email/remove'],
# FTP
ftp_accounts: [:get, '/ftp-accounts'],
add_ftp_account: [:post, '/ftp-account/add'],
remove_ftp_account: [:post, '/ftp-account/remove'],
ftp_account_password: [:post, '/ftp-account/password'],
ftp_account_path: [:post, '/ftp-account/update-path'],
ftp_account_connections: [:get, '/ftp-account/active-connection'],
# WORDPRESS
wordpress: [:get, '/wordpress'],
add_wordpress: [:post, '/wordpress/add'],
remove_wordpress: [:post, '/wordpress/remove'],
# CMS
available_cms: [:get, '/cms/list-available'],
install_cms: [:post, '/cms/install'],
installed_cms: [:get, '/cms/list-installed'],
cms_installations_progress: [:get, '/cms/installations-progress'],
delete_cms: [:post, '/cms/delete'],
# STATS
stats_performance: [:post, '/stats/performance'],
stats_disk_usage: [:get, '/stats/disk-usage'],
stats_apache: [:post, '/stats/apache'],
stats_apache_unique: [:post, '/stats/apache/unique']
}.freeze

N0C_METHODS_PATH.each do |function_name, info|
method = info.first
path = "#{BASE_WORLD_PATH}#{info.last}"

define_method(function_name) do |params = {}|
@api_client.call(method, path, params)
end
end
end
end
Loading