diff --git a/app/controllers/repp/v1/auctions_controller.rb b/app/controllers/repp/v1/auctions_controller.rb index 4a5265d13..676dac266 100644 --- a/app/controllers/repp/v1/auctions_controller.rb +++ b/app/controllers/repp/v1/auctions_controller.rb @@ -3,9 +3,9 @@ module Repp class AuctionsController < ActionController::API def index auctions = Auction.started + @response = { count: auctions.count, auctions: auctions_to_json(auctions) } - render json: { count: auctions.count, - auctions: auctions_to_json(auctions) } + render json: @response end private diff --git a/app/controllers/repp/v1/base_controller.rb b/app/controllers/repp/v1/base_controller.rb index 70b189fc1..73d8c400a 100644 --- a/app/controllers/repp/v1/base_controller.rb +++ b/app/controllers/repp/v1/base_controller.rb @@ -24,10 +24,10 @@ module Repp private def render_success(code: nil, message: nil, data: nil) - resp = { code: code || 1000, message: message || 'Command completed successfully', + @response = { code: code || 1000, message: message || 'Command completed successfully', data: data || {} } - render(json: resp, status: :ok) + render(json: @response, status: :ok) end def epp_errors @@ -64,10 +64,8 @@ module Repp @epp_errors ||= [] @epp_errors << { code: 2304, msg: 'Command failed' } if data != {} - render( - json: { code: @epp_errors[0][:code].to_i, message: @epp_errors[0][:msg], data: data }, - status: status - ) + @response = { code: @epp_errors[0][:code].to_i, message: @epp_errors[0][:msg], data: data } + render(json: @response, status: status) end def basic_token @@ -85,10 +83,8 @@ module Repp raise(ArgumentError) rescue NoMethodError, ArgumentError - render( - json: { code: 2202, message: 'Invalid authorization information' }, - status: :unauthorized - ) + @response = { code: 2202, message: 'Invalid authorization information' } + render(json: @response, status: :unauthorized) end def check_ip_restriction @@ -96,17 +92,14 @@ module Repp return if allowed - render( - json: { - code: 2202, - message: I18n.t('registrar.authorization.ip_not_allowed', ip: request.ip), - }, - status: :unauthorized - ) + @response = { code: 2202, + message: I18n.t('registrar.authorization.ip_not_allowed', ip: request.ip) } + render(json: @response, status: :unauthorized) end def not_found_error - render(json: { code: 2303, message: 'Object does not exist' }, status: :not_found) + @response = { code: 2303, message: 'Object does not exist' } + render(json: @response, status: :not_found) end end end diff --git a/app/controllers/repp/v1/contacts_controller.rb b/app/controllers/repp/v1/contacts_controller.rb index 144be01c6..acf275c47 100644 --- a/app/controllers/repp/v1/contacts_controller.rb +++ b/app/controllers/repp/v1/contacts_controller.rb @@ -9,8 +9,8 @@ module Repp record_count = current_user.registrar.contacts.count contacts = showable_contacts(params[:details], params[:limit] || 200, params[:offset] || 0) - - render(json: { contacts: contacts, total_number_of_records: record_count }, status: :ok) + @response = { contacts: contacts, total_number_of_records: record_count } + render(json: @response, status: :ok) end ## GET /repp/v1/contacts/1 diff --git a/app/controllers/repp/v1/domains/contacts_controller.rb b/app/controllers/repp/v1/domains/contacts_controller.rb index fb5dfb567..75404e0c6 100644 --- a/app/controllers/repp/v1/domains/contacts_controller.rb +++ b/app/controllers/repp/v1/domains/contacts_controller.rb @@ -26,8 +26,8 @@ module Repp return handle_errors if @epp_errors.any? affected, skipped = TechDomainContact.replace(@current_contact, @new_contact) - data = { affected_domains: affected, skipped_domains: skipped } - render_success(data: data) + @response = { affected_domains: affected, skipped_domains: skipped } + render_success(data: @response) end private diff --git a/app/controllers/repp/v1/retained_domains_controller.rb b/app/controllers/repp/v1/retained_domains_controller.rb index c1bb458e9..8edc32f5b 100644 --- a/app/controllers/repp/v1/retained_domains_controller.rb +++ b/app/controllers/repp/v1/retained_domains_controller.rb @@ -3,8 +3,9 @@ module Repp class RetainedDomainsController < ActionController::API def index domains = RetainedDomains.new(query_params) + @response = { count: domains.count, domains: domains.to_jsonable } - render json: { count: domains.count, domains: domains.to_jsonable } + render json: @response end def query_params diff --git a/lib/serializers/repp/contact.rb b/lib/serializers/repp/contact.rb index 8a3cad616..834402359 100644 --- a/lib/serializers/repp/contact.rb +++ b/lib/serializers/repp/contact.rb @@ -8,11 +8,11 @@ module Serializers @show_address = show_address end - def to_json(_obj) - json = { id: contact.code, name: contact.name, ident: ident, - email: contact.email, phone: contact.phone, fax: contact.fax, - auth_info: contact.auth_info, statuses: contact.statuses, - disclosed_attributes: contact.disclosed_attributes } + def to_json(obj = contact) + json = { id: obj.code, name: obj.name, ident: ident, + email: obj.email, phone: obj.phone, fax: obj.fax, + auth_info: obj.auth_info, statuses: obj.statuses, + disclosed_attributes: obj.disclosed_attributes } json[:address] = address if @show_address