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 1 commit
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
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
version: 2.1

orbs:
ruby: circleci/[email protected].0
ruby: circleci/[email protected].1

jobs:
build_and_test:
Expand All @@ -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
7 changes: 5 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,7 @@ gem 'rake'
group :test do
gem 'rspec', '> 0'
gem 'rspec_junit_formatter', '> 0'
end
end
gem 'dotenv', '~> 3.1'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to be removed


gem 'rubocop', '~> 1.62'
32 changes: 31 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
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)
dotenv (3.1.0)
json (2.7.1)
language_server-protocol (3.17.0.3)
parallel (1.24.0)
parser (3.3.0.5)
ast (~> 2.4.1)
racc
racc (1.7.3)
rainbow (3.1.1)
rake (13.1.0)
regexp_parser (2.9.0)
rexml (3.2.6)
rspec (3.13.0)
rspec-core (~> 3.13.0)
rspec-expectations (~> 3.13.0)
Expand All @@ -23,15 +35,33 @@ GEM
rspec-support (3.13.1)
rspec_junit_formatter (0.6.0)
rspec-core (>= 2, < 4, != 2.12.0)
rubocop (1.62.1)
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.2)
parser (>= 3.3.0.4)
ruby-progressbar (1.13.0)
unicode-display_width (2.5.0)

PLATFORMS
x86_64-darwin-22
x86_64-linux

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

BUNDLED WITH
2.3.23
2 changes: 1 addition & 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
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
4 changes: 2 additions & 2 deletions lib/planethoster_api/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module PlanethosterApi
VERSION = "1.0.0"
end
VERSION = '1.1.0'.freeze
end
14 changes: 5 additions & 9 deletions lib/planethoster_api/world.rb
Original file line number Diff line number Diff line change
@@ -1,26 +1,22 @@
module PlanethosterApi
class World < ApiInterface

BASE_WORLD_PATH = '/world-api'

BASE_WORLD_PATH = '/world-api'.freeze
WORLD_METHODS_PATH = {
get_accounts: [:get, '/get-accounts'],
create_account: [:post, '/create-account'],
suspend_account: [:post, '/suspend-account'],
unsuspend_account: [:post, '/unsuspend-account'],
modify_ressources: [:post, '/modify-ressources'],
upgrade_plan: [:post, '/upgrade-plan'],
}
upgrade_plan: [:post, '/upgrade-plan']
}.freeze

WORLD_METHODS_PATH.each do |function_name, info|
method = info.first
path = "#{BASE_WORLD_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
Loading