'Entry point for REST API
@param r: the S3Request
@param attr: controller parameters for the request'

def apply_method(self, r, **attr):

    if (r.http != 'GET'):
        r.error(405, current.ERROR.BAD_METHOD)
    record = r.record
    if (not record):
        r.error(404, current.ERROR.BAD_RECORD)
    allow_create = current.auth.s3_has_permission('update', 'pr_person', record_id=record.id)
    widget_id = 'pr-contacts'
    pe_id = record.pe_id
    contents = DIV(_id=widget_id, _class='pr-contacts-wrapper    medium-8    small-12    columns')
    contacts = self.contacts(r, pe_id, allow_create=allow_create, method=r.method)
    if contacts:
        contents.append(contacts)
    emergency = self.emergency(pe_id, allow_create=allow_create)
    if emergency:
        contents.append(emergency)
    response = current.response
    s3 = response.s3
    if s3.debug:
        s3.scripts.append(URL(c='static', f='scripts', args=['S3', 's3.ui.contacts.js']))
    else:
        s3.scripts.append(URL(c='static', f='scripts', args=['S3', 's3.ui.contacts.min.js']))
    T = current.T
    if (r.method == 'private_contacts'):
        access = 1
    elif (r.method == 'public_contacts'):
        access = 2
    else:
        access = None
    widget_opts = {'controller': r.controller, 'personID': record.id, 'access': access, 'cancelButtonText': str(T('Cancel'))}
    script = ('$("#%s").personcontacts(%s)' % (widget_id, json.dumps(widget_opts)))
    s3.jquery_ready.append(script)
    response.view = 'pr/contacts.html'
    title = self.crud_string(r.tablename, 'title_display')
    return {'contents': contents, 'title': title}
