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