Skip to content

Instantly share code, notes, and snippets.

@jordanorelli
Created January 6, 2012 19:11
Show Gist options
  • Save jordanorelli/1571963 to your computer and use it in GitHub Desktop.
Save jordanorelli/1571963 to your computer and use it in GitHub Desktop.
recurly API test tool
#!/usr/bin/env python
import requests
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('-d', '--data', type=argparse.FileType('r'))
parser.add_argument('-X', '--method', default='GET', nargs='?')
parser.add_argument('url')
args = parser.parse_args()
api_key = ''
base_url = 'https://api.recurly.com/v2/'
content_type = 'application/xml; charset=utf-8'
accept = 'application/xml'
url = base_url + args.url
if args.data and args.method == 'GET':
args.method = 'POST'
meth = {'GET': requests.get,
'POST': requests.post,
'PUT': requests.put,
'DELETE': requests.delete,
'HEAD': requests.head}[args.method]
data = args.data and args.data.read() or ''
response = meth(url, data=data, auth=(api_key, ''))
print response.content
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment