1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
|
// OpenRDAP
// Copyright 2017 Tom Harwood
// MIT License, see the LICENSE file.
package rdap_test
import (
"fmt"
"github.com/openrdap/rdap"
)
func Example() {
var jsonBlob = []byte(`
{
"objectClassName": "domain",
"rdapConformance": ["rdap_level_0"],
"handle": "EXAMPLECOM",
"ldhName": "example.com",
"status": ["active"],
"entities": [
{
"objectClassName": "entity",
"handle": "EXAMPLECOMREG",
"roles": ["registrant"],
"vcardArray": [
"vcard",
[
["version", {}, "text", "4.0"],
["fn", {}, "text", "John Smith"],
["adr", {}, "text",
[
"Box 1",
"Suite 29",
"1234 Fake St",
"Toronto",
"ON",
"M5E 1W5",
"Canada"
]
],
["tel", {}, "uri", "tel:+1-555-555-5555"],
["email", {}, "text", "hi@example.com"]
]
]
}
]
}
`)
// Decode the response.
d := rdap.NewDecoder(jsonBlob)
result, err := d.Decode()
// Print the response.
if err != nil {
fmt.Printf("%s\n", err)
} else {
domain := result.(*rdap.Domain)
PrintDomain(domain)
}
// Output:
// Handle=EXAMPLECOM
// LDHName=example.com
// Status=[active]
// Contact 0, roles: [registrant]:
// Name : 'John Smith'
// POBox : 'Box 1'
// Ext : 'Suite 29'
// Street : '1234 Fake St'
// Locality : 'Toronto'
// Region : 'ON'
// PostalCode: 'M5E 1W5'
// Country : 'Canada'
// Tel : 'tel:+1-555-555-5555'
// Fax : ''
// Email : 'hi@example.com'
}
// PrintDomain prints some basic rdap.Domain fields.
func PrintDomain(d *rdap.Domain) {
// Registry unique identifier for the domain. Here, "example.cz".
fmt.Printf("Handle=%s\n", d.Handle)
// Domain name (LDH = letters, digits, hyphen). Here, "example.cz".
fmt.Printf("LDHName=%s\n", d.LDHName)
// Domain registration status. Here, "active".
// See https://tools.ietf.org/html/rfc7483#section-10.2.2.
fmt.Printf("Status=%v\n", d.Status)
// Contact information.
for i, e := range d.Entities {
// Contact roles, such as "registrant", "administrative", "billing".
// See https://tools.ietf.org/html/rfc7483#section-10.2.4.
fmt.Printf("Contact %d, roles: %v:\n", i, e.Roles)
// RDAP uses VCard for contact information, including name, address,
// telephone, and e-mail address.
if e.VCard != nil {
v := e.VCard
// Name.
fmt.Printf(" Name : '%s'\n", v.Name())
// Address.
fmt.Printf(" POBox : '%s'\n", v.POBox())
fmt.Printf(" Ext : '%s'\n", v.ExtendedAddress())
fmt.Printf(" Street : '%s'\n", v.StreetAddress())
fmt.Printf(" Locality : '%s'\n", v.Locality())
fmt.Printf(" Region : '%s'\n", v.Region())
fmt.Printf(" PostalCode: '%s'\n", v.PostalCode())
fmt.Printf(" Country : '%s'\n", v.Country())
// Phone numbers.
fmt.Printf(" Tel : '%s'\n", v.Tel())
fmt.Printf(" Fax : '%s'\n", v.Fax())
// Email address.
fmt.Printf(" Email : '%s'\n", v.Email())
// The raw VCard fields are also accessible.
}
}
}
|