mirror of
https://github.com/internetee/registry.git
synced 2025-06-06 20:55:44 +02:00
Use the same serializer for all contact related actions
Also, rerun the response with an RFC4627 formatter
This commit is contained in:
parent
2a7b6c1eb8
commit
94efbbbab0
5 changed files with 146 additions and 105 deletions
|
@ -1,3 +1,5 @@
|
||||||
|
require 'serializers/registrant_api/contact'
|
||||||
|
|
||||||
module Api
|
module Api
|
||||||
module V1
|
module V1
|
||||||
module Registrant
|
module Registrant
|
||||||
|
@ -19,7 +21,12 @@ module Api
|
||||||
end
|
end
|
||||||
|
|
||||||
@contacts = @contacts_pool.limit(limit).offset(offset)
|
@contacts = @contacts_pool.limit(limit).offset(offset)
|
||||||
render json: @contacts
|
serialized_contacts = @contacts.map do |item|
|
||||||
|
serializer = Serializers::RegistrantApi::Contact.new(item)
|
||||||
|
serializer.to_json
|
||||||
|
end
|
||||||
|
|
||||||
|
render json: serialized_contacts
|
||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
|
@ -67,26 +74,8 @@ module Api
|
||||||
contact.registrar.notify(action)
|
contact.registrar.notify(action)
|
||||||
end
|
end
|
||||||
|
|
||||||
render json: { id: contact.uuid,
|
serializer = Serializers::RegistrantApi::Contact.new(contact)
|
||||||
name: contact.name,
|
render json: serializer.to_json
|
||||||
code: contact.code,
|
|
||||||
ident: {
|
|
||||||
code: contact.ident,
|
|
||||||
type: contact.ident_type,
|
|
||||||
country_code: contact.ident_country_code,
|
|
||||||
},
|
|
||||||
email: contact.email,
|
|
||||||
phone: contact.phone,
|
|
||||||
fax: contact.fax,
|
|
||||||
address: {
|
|
||||||
street: contact.street,
|
|
||||||
zip: contact.zip,
|
|
||||||
city: contact.city,
|
|
||||||
state: contact.state,
|
|
||||||
country_code: contact.country_code,
|
|
||||||
},
|
|
||||||
auth_info: contact.auth_info,
|
|
||||||
statuses: contact.statuses }
|
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
@ -23,39 +23,32 @@ HTTP/1.1 200
|
||||||
Content-Type: application/json
|
Content-Type: application/json
|
||||||
|
|
||||||
{
|
{
|
||||||
"contacts": [
|
"contacts":[
|
||||||
{
|
{
|
||||||
"uuid": "84c62f3d-e56f-40fa-9ca4-dc0137778949",
|
"id":"84c62f3d-e56f-40fa-9ca4-dc0137778949",
|
||||||
"domain_names": ["example.com"],
|
"name":"Karson Kessler",
|
||||||
"code": "REGISTRAR2:SH022086480",
|
"code":"REGISTRAR2:SH022086480",
|
||||||
"phone": "+372.12345678",
|
"ident":{
|
||||||
"email": "hoyt@deckowbechtelar.net",
|
"code":"37605030299",
|
||||||
"fax": null,
|
"type":"priv",
|
||||||
"created_at": "2015-09-09T09:11:14.130Z",
|
"country_code":"EE"
|
||||||
"updated_at": "2015-09-09T09:11:14.130Z",
|
},
|
||||||
"ident": "37605030299",
|
"email":"foo@bar.baz",
|
||||||
"ident_type": "priv",
|
"phone":"+372.12345671",
|
||||||
"auth_info": "password",
|
"fax":"+372.12345672",
|
||||||
"name": "Karson Kessler0",
|
"address":{
|
||||||
"org_name": null,
|
"street":"Main Street 123",
|
||||||
"registrar_id": 2,
|
"zip":"22222",
|
||||||
"creator_str": null,
|
"city":"New City",
|
||||||
"updator_str": null,
|
"state":"New state",
|
||||||
"ident_country_code": "EE",
|
"country_code":"LV"
|
||||||
"city": "Tallinn",
|
},
|
||||||
"street": "Short street 11",
|
"auth_info":"password",
|
||||||
"zip": "11111",
|
"statuses":[
|
||||||
"country_code": "EE",
|
|
||||||
"state": null,
|
|
||||||
"legacy_id": null,
|
|
||||||
"statuses": [
|
|
||||||
"ok"
|
"ok"
|
||||||
],
|
]
|
||||||
"status_notes": {
|
|
||||||
}
|
}
|
||||||
}
|
]
|
||||||
],
|
|
||||||
"total_number_of_records": 2
|
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -77,33 +70,28 @@ HTTP/1.1 200
|
||||||
Content-Type: application/json
|
Content-Type: application/json
|
||||||
|
|
||||||
{
|
{
|
||||||
"uuid": "84c62f3d-e56f-40fa-9ca4-dc0137778949",
|
"id": "84c62f3d-e56f-40fa-9ca4-dc0137778949",
|
||||||
"domain_names": ["example.com"],
|
"name": "Karson Kessler",
|
||||||
"code": "REGISTRAR2:SH022086480",
|
"code": "REGISTRAR2:SH022086480",
|
||||||
"phone": "+372.12345678",
|
"ident": {
|
||||||
"email": "hoyt@deckowbechtelar.net",
|
"code": "37605030299",
|
||||||
"fax": null,
|
"type": "priv",
|
||||||
"created_at": "2015-09-09T09:11:14.130Z",
|
"country_code": "EE"
|
||||||
"updated_at": "2015-09-09T09:11:14.130Z",
|
},
|
||||||
"ident": "37605030299",
|
"email": "foo@bar.baz",
|
||||||
"ident_type": "priv",
|
"phone": "+372.12345671",
|
||||||
|
"fax": "+372.12345672",
|
||||||
|
"address": {
|
||||||
|
"street": "Main Street 123",
|
||||||
|
"zip": "22222",
|
||||||
|
"city": "New City",
|
||||||
|
"state": "New state",
|
||||||
|
"country_code": "LV"
|
||||||
|
},
|
||||||
"auth_info": "password",
|
"auth_info": "password",
|
||||||
"name": "Karson Kessler0",
|
|
||||||
"org_name": null,
|
|
||||||
"registrar_id": 2,
|
|
||||||
"creator_str": null,
|
|
||||||
"updator_str": null,
|
|
||||||
"ident_country_code": "EE",
|
|
||||||
"city": "Tallinn",
|
|
||||||
"street": "Short street 11",
|
|
||||||
"zip": "11111",
|
|
||||||
"country_code": "EE",
|
|
||||||
"state": null,
|
|
||||||
"legacy_id": null,
|
|
||||||
"statuses": [
|
"statuses": [
|
||||||
"ok"
|
"ok"
|
||||||
],
|
]
|
||||||
"status_notes": {}
|
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -134,16 +122,16 @@ Accept: application/json
|
||||||
Content-type: application/json
|
Content-type: application/json
|
||||||
|
|
||||||
{
|
{
|
||||||
"name": "John Doe",
|
"name":"John Doe",
|
||||||
"email": "foo@bar.baz",
|
"email":"foo@bar.baz",
|
||||||
"phone": "+372.12345671",
|
"phone":"+372.12345671",
|
||||||
"fax": "+372.12345672",
|
"fax":"+372.12345672",
|
||||||
"address": {
|
"address":{
|
||||||
"street": "Main Street 123",
|
"street":"Main Street 123",
|
||||||
"zip": "22222",
|
"zip":"22222",
|
||||||
"city": "New City",
|
"city":"New City",
|
||||||
"state": "New state",
|
"state":"New state",
|
||||||
"country_code": "LV"
|
"country_code":"LV"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -155,26 +143,26 @@ HTTP/1.1 200
|
||||||
Content-Type: application/json
|
Content-Type: application/json
|
||||||
|
|
||||||
{
|
{
|
||||||
"id": "84c62f3d-e56f-40fa-9ca4-dc0137778949",
|
"id":"84c62f3d-e56f-40fa-9ca4-dc0137778949",
|
||||||
"name": "Karson Kessler0",
|
"name":"Karson Kessler",
|
||||||
"code": "REGISTRAR2:SH022086480",
|
"code":"REGISTRAR2:SH022086480",
|
||||||
"ident": {
|
"ident":{
|
||||||
"code": "37605030299",
|
"code":"37605030299",
|
||||||
"type": "priv",
|
"type":"priv",
|
||||||
"country_code": "EE"
|
"country_code":"EE"
|
||||||
},
|
},
|
||||||
"email": "foo@bar.baz",
|
"email":"foo@bar.baz",
|
||||||
"phone": "+372.12345671",
|
"phone":"+372.12345671",
|
||||||
"fax": "+372.12345672",
|
"fax":"+372.12345672",
|
||||||
"address": {
|
"address":{
|
||||||
"street": "Main Street 123",
|
"street":"Main Street 123",
|
||||||
"zip": "22222",
|
"zip":"22222",
|
||||||
"city": "New City",
|
"city":"New City",
|
||||||
"state": "New state",
|
"state":"New state",
|
||||||
"country_code": "LV"
|
"country_code":"LV"
|
||||||
},
|
},
|
||||||
"auth_info": "password",
|
"auth_info":"password",
|
||||||
"statuses": [
|
"statuses":[
|
||||||
"ok"
|
"ok"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -186,8 +174,10 @@ HTTP/1.1 400
|
||||||
Content-Type: application/json
|
Content-Type: application/json
|
||||||
|
|
||||||
{
|
{
|
||||||
"errors": {
|
"errors":{
|
||||||
"phone": ["Phone nr is invalid"]
|
"phone":[
|
||||||
|
"Phone nr is invalid"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
36
lib/serializers/registrant_api/contact.rb
Normal file
36
lib/serializers/registrant_api/contact.rb
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
module Serializers
|
||||||
|
module RegistrantApi
|
||||||
|
class Contact
|
||||||
|
attr_reader :contact
|
||||||
|
|
||||||
|
def initialize(contact)
|
||||||
|
@contact = contact
|
||||||
|
end
|
||||||
|
|
||||||
|
def to_json
|
||||||
|
{
|
||||||
|
id: contact.uuid,
|
||||||
|
name: contact.name,
|
||||||
|
code: contact.code,
|
||||||
|
ident: {
|
||||||
|
code: contact.ident,
|
||||||
|
type: contact.ident_type,
|
||||||
|
country_code: contact.ident_country_code,
|
||||||
|
},
|
||||||
|
email: contact.email,
|
||||||
|
phone: contact.phone,
|
||||||
|
fax: contact.fax,
|
||||||
|
address: {
|
||||||
|
street: contact.street,
|
||||||
|
zip: contact.zip,
|
||||||
|
city: contact.city,
|
||||||
|
state: contact.state,
|
||||||
|
country_code: contact.country_code,
|
||||||
|
},
|
||||||
|
auth_info: contact.auth_info,
|
||||||
|
statuses: contact.statuses
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
26
test/lib/serializers/registrant_api/contact_test.rb
Normal file
26
test/lib/serializers/registrant_api/contact_test.rb
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
require 'test_helper'
|
||||||
|
require 'serializers/registrant_api/contact'
|
||||||
|
|
||||||
|
class SerializersRegistrantApiContactTest < ActiveSupport::TestCase
|
||||||
|
def setup
|
||||||
|
@contact = contacts(:william)
|
||||||
|
@serializer = Serializers::RegistrantApi::Contact.new(@contact)
|
||||||
|
@json = @serializer.to_json
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_returns_uuid_as_id
|
||||||
|
assert_equal(@contact.uuid, @json[:id])
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_returns_indent_as_separate_object
|
||||||
|
expected_ident = { code: @contact.ident, type: @contact.ident_type,
|
||||||
|
country_code: @contact.ident_country_code }
|
||||||
|
assert_equal(expected_ident, @json[:ident])
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_returns_address_as_separate_object
|
||||||
|
expected_address = { street: @contact.street, zip: @contact.zip, city: @contact.city,
|
||||||
|
state: @contact.state, country_code: @contact.country_code }
|
||||||
|
assert_equal(expected_address, @json[:address])
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,7 +1,7 @@
|
||||||
require 'test_helper'
|
require 'test_helper'
|
||||||
require 'serializers/registrant_api/domain'
|
require 'serializers/registrant_api/domain'
|
||||||
|
|
||||||
class SerializersRegistrantApiDomainTest < ApplicationIntegrationTest
|
class SerializersRegistrantApiDomainTest < ActiveSupport::TestCase
|
||||||
def setup
|
def setup
|
||||||
@domain = domains(:airport)
|
@domain = domains(:airport)
|
||||||
@serializer = Serializers::RegistrantApi::Domain.new(@domain)
|
@serializer = Serializers::RegistrantApi::Domain.new(@domain)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue