#!/usr/bin/env python

from jsontester.shell import Script
from jsontester.request import JSONRequest,JSONRequestError,response_code_text

script = Script(description='Send a HTTP DELETE request to given URL as JSON')
script.add_argument('urls', nargs='*', help='URLs to delete')
args = script.parse_args()

request = JSONRequest(browser=args.browser, verify=args.insecure)

for url in args.urls:
    script.log.debug('Submitting DELETE request to %s' % url)

    try:
        res = request.delete(url)
    except JSONRequestError,emsg:
        script.exit(1,emsg)

    res_text = response_code_text(res.status_code)
    if res.status_code != 204:
        script.error('RESPONSE CODE: %s' % res_text)
        script.error('ERROR deleting JSON resource')
        continue

    if args.debug:
        script.error('RESPONSE CODE: %s' % res_text)

    if res.content.strip():
        script.message(res.content)

