mirror of
https://github.com/internetee/registry.git
synced 2025-06-06 04:37:30 +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 V1
|
||||
module Registrant
|
||||
|
@ -19,7 +21,12 @@ module Api
|
|||
end
|
||||
|
||||
@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
|
||||
|
||||
def show
|
||||
|
@ -67,26 +74,8 @@ module Api
|
|||
contact.registrar.notify(action)
|
||||
end
|
||||
|
||||
render 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 }
|
||||
serializer = Serializers::RegistrantApi::Contact.new(contact)
|
||||
render json: serializer.to_json
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -23,39 +23,32 @@ HTTP/1.1 200
|
|||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"contacts": [
|
||||
"contacts":[
|
||||
{
|
||||
"uuid": "84c62f3d-e56f-40fa-9ca4-dc0137778949",
|
||||
"domain_names": ["example.com"],
|
||||
"code": "REGISTRAR2:SH022086480",
|
||||
"phone": "+372.12345678",
|
||||
"email": "hoyt@deckowbechtelar.net",
|
||||
"fax": null,
|
||||
"created_at": "2015-09-09T09:11:14.130Z",
|
||||
"updated_at": "2015-09-09T09:11:14.130Z",
|
||||
"ident": "37605030299",
|
||||
"ident_type": "priv",
|
||||
"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": [
|
||||
"id":"84c62f3d-e56f-40fa-9ca4-dc0137778949",
|
||||
"name":"Karson Kessler",
|
||||
"code":"REGISTRAR2:SH022086480",
|
||||
"ident":{
|
||||
"code":"37605030299",
|
||||
"type":"priv",
|
||||
"country_code":"EE"
|
||||
},
|
||||
"email":"foo@bar.baz",
|
||||
"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",
|
||||
"statuses":[
|
||||
"ok"
|
||||
],
|
||||
"status_notes": {
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"total_number_of_records": 2
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -77,33 +70,28 @@ HTTP/1.1 200
|
|||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"uuid": "84c62f3d-e56f-40fa-9ca4-dc0137778949",
|
||||
"domain_names": ["example.com"],
|
||||
"id": "84c62f3d-e56f-40fa-9ca4-dc0137778949",
|
||||
"name": "Karson Kessler",
|
||||
"code": "REGISTRAR2:SH022086480",
|
||||
"phone": "+372.12345678",
|
||||
"email": "hoyt@deckowbechtelar.net",
|
||||
"fax": null,
|
||||
"created_at": "2015-09-09T09:11:14.130Z",
|
||||
"updated_at": "2015-09-09T09:11:14.130Z",
|
||||
"ident": "37605030299",
|
||||
"ident_type": "priv",
|
||||
"ident": {
|
||||
"code": "37605030299",
|
||||
"type": "priv",
|
||||
"country_code": "EE"
|
||||
},
|
||||
"email": "foo@bar.baz",
|
||||
"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",
|
||||
"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": [
|
||||
"ok"
|
||||
],
|
||||
"status_notes": {}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -134,16 +122,16 @@ Accept: application/json
|
|||
Content-type: application/json
|
||||
|
||||
{
|
||||
"name": "John Doe",
|
||||
"email": "foo@bar.baz",
|
||||
"phone": "+372.12345671",
|
||||
"fax": "+372.12345672",
|
||||
"address": {
|
||||
"street": "Main Street 123",
|
||||
"zip": "22222",
|
||||
"city": "New City",
|
||||
"state": "New state",
|
||||
"country_code": "LV"
|
||||
"name":"John Doe",
|
||||
"email":"foo@bar.baz",
|
||||
"phone":"+372.12345671",
|
||||
"fax":"+372.12345672",
|
||||
"address":{
|
||||
"street":"Main Street 123",
|
||||
"zip":"22222",
|
||||
"city":"New City",
|
||||
"state":"New state",
|
||||
"country_code":"LV"
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -155,26 +143,26 @@ HTTP/1.1 200
|
|||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"id": "84c62f3d-e56f-40fa-9ca4-dc0137778949",
|
||||
"name": "Karson Kessler0",
|
||||
"code": "REGISTRAR2:SH022086480",
|
||||
"ident": {
|
||||
"code": "37605030299",
|
||||
"type": "priv",
|
||||
"country_code": "EE"
|
||||
"id":"84c62f3d-e56f-40fa-9ca4-dc0137778949",
|
||||
"name":"Karson Kessler",
|
||||
"code":"REGISTRAR2:SH022086480",
|
||||
"ident":{
|
||||
"code":"37605030299",
|
||||
"type":"priv",
|
||||
"country_code":"EE"
|
||||
},
|
||||
"email": "foo@bar.baz",
|
||||
"phone": "+372.12345671",
|
||||
"fax": "+372.12345672",
|
||||
"address": {
|
||||
"street": "Main Street 123",
|
||||
"zip": "22222",
|
||||
"city": "New City",
|
||||
"state": "New state",
|
||||
"country_code": "LV"
|
||||
"email":"foo@bar.baz",
|
||||
"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",
|
||||
"statuses": [
|
||||
"auth_info":"password",
|
||||
"statuses":[
|
||||
"ok"
|
||||
]
|
||||
}
|
||||
|
@ -186,8 +174,10 @@ HTTP/1.1 400
|
|||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"errors": {
|
||||
"phone": ["Phone nr is invalid"]
|
||||
"errors":{
|
||||
"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 'serializers/registrant_api/domain'
|
||||
|
||||
class SerializersRegistrantApiDomainTest < ApplicationIntegrationTest
|
||||
class SerializersRegistrantApiDomainTest < ActiveSupport::TestCase
|
||||
def setup
|
||||
@domain = domains(:airport)
|
||||
@serializer = Serializers::RegistrantApi::Domain.new(@domain)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue