mirror of
https://github.com/internetee/registry.git
synced 2025-06-06 20:55:44 +02:00
REPP: Update ApiDoc
This commit is contained in:
parent
fda58e9a41
commit
454433cf10
8 changed files with 67 additions and 24 deletions
|
@ -1,6 +1,9 @@
|
||||||
module Repp
|
module Repp
|
||||||
module V1
|
module V1
|
||||||
class AccountsController < BaseController
|
class AccountsController < BaseController
|
||||||
|
|
||||||
|
api :GET, '/repp/v1/accounts/balance'
|
||||||
|
desc "Get account's balance"
|
||||||
def balance
|
def balance
|
||||||
resp = { balance: current_user.registrar.cash_account.balance,
|
resp = { balance: current_user.registrar.cash_account.balance,
|
||||||
currency: current_user.registrar.cash_account.currency }
|
currency: current_user.registrar.cash_account.currency }
|
||||||
|
|
|
@ -4,7 +4,8 @@ module Repp
|
||||||
class ContactsController < BaseController
|
class ContactsController < BaseController
|
||||||
before_action :find_contact, only: %i[show update destroy]
|
before_action :find_contact, only: %i[show update destroy]
|
||||||
|
|
||||||
## GET /repp/v1/contacts
|
api :get, '/repp/v1/contacts'
|
||||||
|
desc 'Get all existing contacts'
|
||||||
def index
|
def index
|
||||||
record_count = current_user.registrar.contacts.count
|
record_count = current_user.registrar.contacts.count
|
||||||
contacts = showable_contacts(params[:details], params[:limit] || 200,
|
contacts = showable_contacts(params[:details], params[:limit] || 200,
|
||||||
|
@ -13,14 +14,16 @@ module Repp
|
||||||
render(json: @response, status: :ok)
|
render(json: @response, status: :ok)
|
||||||
end
|
end
|
||||||
|
|
||||||
## GET /repp/v1/contacts/1
|
api :get, '/repp/v1/contacts/:contact_code'
|
||||||
|
desc 'Get a specific contact'
|
||||||
def show
|
def show
|
||||||
serializer = ::Serializers::Repp::Contact.new(@contact,
|
serializer = ::Serializers::Repp::Contact.new(@contact,
|
||||||
show_address: Contact.address_processing?)
|
show_address: Contact.address_processing?)
|
||||||
render_success(data: serializer.to_json)
|
render_success(data: serializer.to_json)
|
||||||
end
|
end
|
||||||
|
|
||||||
## GET /repp/v1/contacts/check/1
|
api :get, '/repp/v1/contacts/check/:contact_code'
|
||||||
|
desc 'Check contact code availability'
|
||||||
def check
|
def check
|
||||||
contact = Epp::Contact.find_by(code: params[:id])
|
contact = Epp::Contact.find_by(code: params[:id])
|
||||||
data = { contact: { id: params[:id], available: contact.nil? } }
|
data = { contact: { id: params[:id], available: contact.nil? } }
|
||||||
|
@ -28,7 +31,8 @@ module Repp
|
||||||
render_success(data: data)
|
render_success(data: data)
|
||||||
end
|
end
|
||||||
|
|
||||||
## POST /repp/v1/contacts
|
api :POST, '/repp/v1/contacts'
|
||||||
|
desc 'Create a new contact'
|
||||||
def create
|
def create
|
||||||
@contact = Epp::Contact.new(contact_params_with_address, current_user.registrar, epp: false)
|
@contact = Epp::Contact.new(contact_params_with_address, current_user.registrar, epp: false)
|
||||||
action = Actions::ContactCreate.new(@contact, params[:legal_document],
|
action = Actions::ContactCreate.new(@contact, params[:legal_document],
|
||||||
|
@ -42,7 +46,8 @@ module Repp
|
||||||
render_success(create_update_success_body)
|
render_success(create_update_success_body)
|
||||||
end
|
end
|
||||||
|
|
||||||
## PUT /repp/v1/contacts/1
|
api :PUT, '/repp/v1/contacts/:contact_code'
|
||||||
|
desc 'Update existing contact'
|
||||||
def update
|
def update
|
||||||
action = Actions::ContactUpdate.new(@contact, contact_params_with_address(required: false),
|
action = Actions::ContactUpdate.new(@contact, contact_params_with_address(required: false),
|
||||||
params[:legal_document],
|
params[:legal_document],
|
||||||
|
@ -56,6 +61,8 @@ module Repp
|
||||||
render_success(create_update_success_body)
|
render_success(create_update_success_body)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
api :DELETE, '/repp/v1/contacts/:contact_code'
|
||||||
|
desc 'Delete a specific contact'
|
||||||
def destroy
|
def destroy
|
||||||
action = Actions::ContactDelete.new(@contact, params[:legal_document])
|
action = Actions::ContactDelete.new(@contact, params[:legal_document])
|
||||||
unless action.call
|
unless action.call
|
||||||
|
|
|
@ -5,7 +5,7 @@ module Repp
|
||||||
before_action :set_domain, only: %i[index create destroy]
|
before_action :set_domain, only: %i[index create destroy]
|
||||||
|
|
||||||
api :GET, '/repp/v1/domains/:domain_name/dnssec'
|
api :GET, '/repp/v1/domains/:domain_name/dnssec'
|
||||||
desc "View all domain's DNSSEC keys"
|
desc "View specific domain's DNSSEC keys"
|
||||||
def index
|
def index
|
||||||
dnssec_keys = @domain.dnskeys
|
dnssec_keys = @domain.dnskeys
|
||||||
data = { dns_keys: dnssec_keys.as_json(only: %i[flags alg protocol public_key]) }
|
data = { dns_keys: dnssec_keys.as_json(only: %i[flags alg protocol public_key]) }
|
||||||
|
@ -13,7 +13,7 @@ module Repp
|
||||||
end
|
end
|
||||||
|
|
||||||
api :POST, '/repp/v1/domains/:domain_name/dnssec'
|
api :POST, '/repp/v1/domains/:domain_name/dnssec'
|
||||||
desc 'Add new DNSSEC key(s) to domain'
|
desc 'Create a new DNSSEC key(s) for domain'
|
||||||
param :dns_keys, Array, required: true, desc: 'Array of new DNSSEC keys' do
|
param :dns_keys, Array, required: true, desc: 'Array of new DNSSEC keys' do
|
||||||
param :flags, String, required: true, desc: '256 (KSK) or 257 (ZSK)'
|
param :flags, String, required: true, desc: '256 (KSK) or 257 (ZSK)'
|
||||||
param :protocol, String, required: true, desc: 'Key protocol (3)'
|
param :protocol, String, required: true, desc: 'Key protocol (3)'
|
||||||
|
|
|
@ -6,7 +6,7 @@ module Repp
|
||||||
before_action :set_nameserver, only: %i[destroy]
|
before_action :set_nameserver, only: %i[destroy]
|
||||||
|
|
||||||
api :POST, '/repp/v1/domains/:domain_name/nameservers'
|
api :POST, '/repp/v1/domains/:domain_name/nameservers'
|
||||||
desc 'Creates new nameserver for domain'
|
desc 'Create new nameserver for domain'
|
||||||
param :nameservers, Array, required: true, desc: 'Array of new nameservers' do
|
param :nameservers, Array, required: true, desc: 'Array of new nameservers' do
|
||||||
param :hostname, String, required: true, desc: 'Nameserver hostname'
|
param :hostname, String, required: true, desc: 'Nameserver hostname'
|
||||||
param :ipv4, Array, required: false, desc: 'Array of IPv4 values'
|
param :ipv4, Array, required: false, desc: 'Array of IPv4 values'
|
||||||
|
@ -24,16 +24,8 @@ module Repp
|
||||||
render_success(data: { domain: { name: @domain.name } })
|
render_success(data: { domain: { name: @domain.name } })
|
||||||
end
|
end
|
||||||
|
|
||||||
api :PUT, '/repp/v1/domains/:domain/nameservers/:nameserver'
|
|
||||||
desc 'Modify nameserver for domain'
|
|
||||||
param :nameserver, Hash, required: true, desc: 'Nameserver parameters' do
|
|
||||||
param :hostname, String, required: true, desc: 'Nameserver hostname'
|
|
||||||
param :ipv4, Array, required: false, desc: 'Array of IPv4 values'
|
|
||||||
param :ipv6, Array, required: false, desc: 'Array of IPv6 values'
|
|
||||||
end
|
|
||||||
|
|
||||||
api :DELETE, '/repp/v1/domains/:domain/nameservers/:nameserver'
|
api :DELETE, '/repp/v1/domains/:domain/nameservers/:nameserver'
|
||||||
desc 'Delete nameserver for domain'
|
desc 'Delete specific nameserver from domain'
|
||||||
def destroy
|
def destroy
|
||||||
nameserver = { nameservers: [{ hostname: params[:id], action: 'rem' }] }
|
nameserver = { nameservers: [{ hostname: params[:id], action: 'rem' }] }
|
||||||
action = Actions::DomainUpdate.new(@domain, nameserver, current_user)
|
action = Actions::DomainUpdate.new(@domain, nameserver, current_user)
|
||||||
|
|
|
@ -4,6 +4,24 @@ module Repp
|
||||||
class RenewsController < BaseController
|
class RenewsController < BaseController
|
||||||
before_action :validate_renew_period, only: [:bulk_renew]
|
before_action :validate_renew_period, only: [:bulk_renew]
|
||||||
before_action :select_renewable_domains, only: [:bulk_renew]
|
before_action :select_renewable_domains, only: [:bulk_renew]
|
||||||
|
before_action :set_domain, only: [:create]
|
||||||
|
|
||||||
|
api :POST, 'repp/v1/domains/:domain_name/renew'
|
||||||
|
desc 'Renew domain'
|
||||||
|
param :renew, Hash, required: true, desc: 'Renew parameters' do
|
||||||
|
param :renew_period, Integer, required: true, desc: 'Renew period. Month (m) or year (y)'
|
||||||
|
param :period_unit, String, required: true, desc: 'For how many months or years to renew'
|
||||||
|
end
|
||||||
|
def create
|
||||||
|
action = Actions::DomainUpdate.new(@domain, renew_params[:renew], current_user)
|
||||||
|
|
||||||
|
unless action.call
|
||||||
|
handle_errors(@domain)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
render_success(data: { domain: { name: @domain.name } })
|
||||||
|
end
|
||||||
|
|
||||||
def bulk_renew
|
def bulk_renew
|
||||||
renew = run_bulk_renew_task(@domains, bulk_renew_params[:renew_period])
|
renew = run_bulk_renew_task(@domains, bulk_renew_params[:renew_period])
|
||||||
|
@ -16,6 +34,18 @@ module Repp
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def set_domain
|
||||||
|
registrar = current_user.registrar
|
||||||
|
@domain = Epp::Domain.find_by(registrar: registrar, name: params[:domain_id])
|
||||||
|
@domain ||= Epp::Domain.find_by!(registrar: registrar, name_puny: params[:domain_id])
|
||||||
|
|
||||||
|
@domain
|
||||||
|
end
|
||||||
|
|
||||||
|
def renew_params
|
||||||
|
params.permit!
|
||||||
|
end
|
||||||
|
|
||||||
def validate_renew_period
|
def validate_renew_period
|
||||||
@epp_errors ||= []
|
@epp_errors ||= []
|
||||||
periods = Depp::Domain::PERIODS.map { |p| p[1] }
|
periods = Depp::Domain::PERIODS.map { |p| p[1] }
|
||||||
|
|
|
@ -6,6 +6,8 @@ module Repp
|
||||||
before_action :forward_registrar_id, only: %i[create]
|
before_action :forward_registrar_id, only: %i[create]
|
||||||
before_action :set_domain, only: %i[show update]
|
before_action :set_domain, only: %i[show update]
|
||||||
|
|
||||||
|
api :GET, '/repp/v1/domains'
|
||||||
|
desc 'Get all existing domains'
|
||||||
def index
|
def index
|
||||||
records = current_user.registrar.domains
|
records = current_user.registrar.domains
|
||||||
domains = records.limit(limit).offset(offset)
|
domains = records.limit(limit).offset(offset)
|
||||||
|
@ -14,12 +16,14 @@ module Repp
|
||||||
render_success(data: { domains: domains, total_number_of_records: records.count })
|
render_success(data: { domains: domains, total_number_of_records: records.count })
|
||||||
end
|
end
|
||||||
|
|
||||||
|
api :GET, '/repp/v1/domains/:domain_name'
|
||||||
|
desc 'Get a specific domain'
|
||||||
def show
|
def show
|
||||||
render_success(data: { domain: Serializers::RegistrantApi::Domain.new(@domain).to_json })
|
render_success(data: { domain: Serializers::RegistrantApi::Domain.new(@domain).to_json })
|
||||||
end
|
end
|
||||||
|
|
||||||
api :POST, '/repp/v1/domains'
|
api :POST, '/repp/v1/domains'
|
||||||
desc 'Creates new domain'
|
desc 'Create a new domain'
|
||||||
param :domain, Hash, required: true, desc: 'Parameters for new domain' do
|
param :domain, Hash, required: true, desc: 'Parameters for new domain' do
|
||||||
param :name, String, required: true, desc: 'Domain name to be registered'
|
param :name, String, required: true, desc: 'Domain name to be registered'
|
||||||
param :registrant_id, String, required: true, desc: 'Registrant contact code'
|
param :registrant_id, String, required: true, desc: 'Registrant contact code'
|
||||||
|
@ -58,7 +62,8 @@ module Repp
|
||||||
render_success(data: { domain: { name: @domain.name } })
|
render_success(data: { domain: { name: @domain.name } })
|
||||||
end
|
end
|
||||||
|
|
||||||
api :PUT, 'repp/v1/domains/:id'
|
api :PUT, '/repp/v1/domains/:domain_name'
|
||||||
|
desc 'Update existing domain'
|
||||||
param :id, String, desc: 'Domain name in IDN / Puny format'
|
param :id, String, desc: 'Domain name in IDN / Puny format'
|
||||||
param :domain, Hash, required: true, desc: 'Changes of domain object' do
|
param :domain, Hash, required: true, desc: 'Changes of domain object' do
|
||||||
param :registrant, Hash, required: false, desc: 'New registrant object' do
|
param :registrant, Hash, required: false, desc: 'New registrant object' do
|
||||||
|
@ -78,6 +83,8 @@ module Repp
|
||||||
render_success(data: { domain: { name: @domain.name } })
|
render_success(data: { domain: { name: @domain.name } })
|
||||||
end
|
end
|
||||||
|
|
||||||
|
api :GET, '/repp/v1/domains/:domain_name/transfer_info'
|
||||||
|
desc "Retrieve specific domain's transfer info"
|
||||||
def transfer_info
|
def transfer_info
|
||||||
contact_fields = %i[code name ident ident_type ident_country_code phone email street city
|
contact_fields = %i[code name ident ident_type ident_country_code phone email street city
|
||||||
zip country_code statuses]
|
zip country_code statuses]
|
||||||
|
@ -92,6 +99,8 @@ module Repp
|
||||||
render_success(data: data)
|
render_success(data: data)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
api :POST, '/repp/v1/domains/:domain_name/transfer'
|
||||||
|
desc 'Transfer specific domain'
|
||||||
def transfer
|
def transfer
|
||||||
@errors ||= []
|
@errors ||= []
|
||||||
@successful = []
|
@successful = []
|
||||||
|
@ -103,6 +112,8 @@ module Repp
|
||||||
render_success(data: { success: @successful, failed: @errors })
|
render_success(data: { success: @successful, failed: @errors })
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
def initiate_transfer(transfer)
|
def initiate_transfer(transfer)
|
||||||
domain = Epp::Domain.find_or_initialize_by(name: transfer[:domain_name])
|
domain = Epp::Domain.find_or_initialize_by(name: transfer[:domain_name])
|
||||||
action = Actions::DomainTransfer.new(domain, transfer[:transfer_code],
|
action = Actions::DomainTransfer.new(domain, transfer[:transfer_code],
|
||||||
|
@ -116,8 +127,6 @@ module Repp
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
def transfer_params
|
def transfer_params
|
||||||
params.require(:data).require(:domain_transfers).each do |t|
|
params.require(:data).require(:domain_transfers).each do |t|
|
||||||
t.require(:domain_name)
|
t.require(:domain_name)
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
Apipie.configure do |config|
|
Apipie.configure do |config|
|
||||||
config.app_name = "DomainNameRegistry"
|
config.app_name = "Estonian Internet Foundation's REST EPP"
|
||||||
config.validate = true
|
config.validate = true
|
||||||
config.translate = false
|
config.translate = false
|
||||||
config.api_base_url = "/api"
|
config.api_base_url = "/api"
|
||||||
config.doc_base_url = "/apipie"
|
config.doc_base_url = "/apipie"
|
||||||
|
config.swagger_content_type_input = :json
|
||||||
# where is your API defined?
|
# where is your API defined?
|
||||||
config.api_controllers_matcher = "#{Rails.root}/app/controllers/**/*.rb"
|
config.api_controllers_matcher = "#{Rails.root}/app/controllers/**/*.rb"
|
||||||
end
|
end
|
||||||
|
|
|
@ -63,6 +63,7 @@ Rails.application.routes.draw do
|
||||||
resources :nameservers, only: %i[create destroy], constraints: { id: /.*/ }, controller: 'domains/nameservers'
|
resources :nameservers, only: %i[create destroy], constraints: { id: /.*/ }, controller: 'domains/nameservers'
|
||||||
resources :dnssec, only: %i[index create], constraints: { id: /.*/ }, controller: 'domains/dnssec'
|
resources :dnssec, only: %i[index create], constraints: { id: /.*/ }, controller: 'domains/dnssec'
|
||||||
resources :contacts, only: %i[index create], constraints: { id: /.*/ }, controller: 'domains/contacts'
|
resources :contacts, only: %i[index create], constraints: { id: /.*/ }, controller: 'domains/contacts'
|
||||||
|
resources :renew, only: %i[create], constraints: { id: /.*/ }, controller: 'domains/renews'
|
||||||
match "dnssec", to: "domains/dnssec#destroy", via: "delete", defaults: { id: nil }
|
match "dnssec", to: "domains/dnssec#destroy", via: "delete", defaults: { id: nil }
|
||||||
match "contacts", to: "domains/contacts#destroy", via: "delete", defaults: { id: nil }
|
match "contacts", to: "domains/contacts#destroy", via: "delete", defaults: { id: nil }
|
||||||
collection do
|
collection do
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue