Add response to REPP log

This commit is contained in:
Karl Erik Õunapuu 2020-11-17 13:00:47 +02:00
parent 7edf48c885
commit a41abf8176
No known key found for this signature in database
GPG key ID: C9DD647298A34764
6 changed files with 24 additions and 30 deletions

View file

@ -3,9 +3,9 @@ module Repp
class AuctionsController < ActionController::API class AuctionsController < ActionController::API
def index def index
auctions = Auction.started auctions = Auction.started
@response = { count: auctions.count, auctions: auctions_to_json(auctions) }
render json: { count: auctions.count, render json: @response
auctions: auctions_to_json(auctions) }
end end
private private

View file

@ -24,10 +24,10 @@ module Repp
private private
def render_success(code: nil, message: nil, data: nil) 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 || {} } data: data || {} }
render(json: resp, status: :ok) render(json: @response, status: :ok)
end end
def epp_errors def epp_errors
@ -64,10 +64,8 @@ module Repp
@epp_errors ||= [] @epp_errors ||= []
@epp_errors << { code: 2304, msg: 'Command failed' } if data != {} @epp_errors << { code: 2304, msg: 'Command failed' } if data != {}
render( @response = { code: @epp_errors[0][:code].to_i, message: @epp_errors[0][:msg], data: data }
json: { code: @epp_errors[0][:code].to_i, message: @epp_errors[0][:msg], data: data }, render(json: @response, status: status)
status: status
)
end end
def basic_token def basic_token
@ -85,10 +83,8 @@ module Repp
raise(ArgumentError) raise(ArgumentError)
rescue NoMethodError, ArgumentError rescue NoMethodError, ArgumentError
render( @response = { code: 2202, message: 'Invalid authorization information' }
json: { code: 2202, message: 'Invalid authorization information' }, render(json: @response, status: :unauthorized)
status: :unauthorized
)
end end
def check_ip_restriction def check_ip_restriction
@ -96,17 +92,14 @@ module Repp
return if allowed return if allowed
render( @response = { code: 2202,
json: { message: I18n.t('registrar.authorization.ip_not_allowed', ip: request.ip) }
code: 2202, render(json: @response, status: :unauthorized)
message: I18n.t('registrar.authorization.ip_not_allowed', ip: request.ip),
},
status: :unauthorized
)
end end
def not_found_error 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 end
end end

View file

@ -9,8 +9,8 @@ module Repp
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,
params[:offset] || 0) params[:offset] || 0)
@response = { contacts: contacts, total_number_of_records: record_count }
render(json: { contacts: contacts, total_number_of_records: record_count }, status: :ok) render(json: @response, status: :ok)
end end
## GET /repp/v1/contacts/1 ## GET /repp/v1/contacts/1

View file

@ -26,8 +26,8 @@ module Repp
return handle_errors if @epp_errors.any? return handle_errors if @epp_errors.any?
affected, skipped = TechDomainContact.replace(@current_contact, @new_contact) affected, skipped = TechDomainContact.replace(@current_contact, @new_contact)
data = { affected_domains: affected, skipped_domains: skipped } @response = { affected_domains: affected, skipped_domains: skipped }
render_success(data: data) render_success(data: @response)
end end
private private

View file

@ -3,8 +3,9 @@ module Repp
class RetainedDomainsController < ActionController::API class RetainedDomainsController < ActionController::API
def index def index
domains = RetainedDomains.new(query_params) 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 end
def query_params def query_params

View file

@ -8,11 +8,11 @@ module Serializers
@show_address = show_address @show_address = show_address
end end
def to_json(_obj) def to_json(obj = contact)
json = { id: contact.code, name: contact.name, ident: ident, json = { id: obj.code, name: obj.name, ident: ident,
email: contact.email, phone: contact.phone, fax: contact.fax, email: obj.email, phone: obj.phone, fax: obj.fax,
auth_info: contact.auth_info, statuses: contact.statuses, auth_info: obj.auth_info, statuses: obj.statuses,
disclosed_attributes: contact.disclosed_attributes } disclosed_attributes: obj.disclosed_attributes }
json[:address] = address if @show_address json[:address] = address if @show_address