'Create or update a "friend" relationship.
This operation is idempotent. It can be used to add a new
friend, or update an existing friend (e.g., add/change the
note on that friend)'

@require_oauth2_scope('subscribe')
@validate(VUser(), friend=VAccountByName('username'), notes_json=FRIEND_JSON_VALIDATOR)
@api_doc(api_section.users, json_model=FRIEND_JSON_VALIDATOR, uri='/api/v1/me/friends/{username}')
def PUT_friends(self, friend, notes_json):

    err = None
    if (('name' in notes_json) and (notes_json['name'] != friend)):
        err = errors.RedditError('BAD_USERNAME', fields='name')
    if (('note' in notes_json) and (not c.user.gold)):
        err = errors.RedditError('GOLD_REQUIRED', fields='note')
    if err:
        self.on_validation_error(err)
    friend_rel = Account.get_friend(c.user, friend)
    rel_exists = bool(friend_rel)
    if (not friend_rel):
        friend_rel = c.user.add_friend(friend)
        response.status = 201
    if ('note' in notes_json):
        note = (notes_json['note'] or '')
        if (not rel_exists):
            c.user.friend_rels_cache(_update=True)
        c.user.add_friend_note(friend, note)
    rel_view = FriendTableItem(friend_rel)
    return self.api_wrapper(FriendTableItemJsonTemplate().data(rel_view))
