Created
December 23, 2011 00:21
-
-
Save amites/1512462 to your computer and use it in GitHub Desktop.
Simple method for connecting to Solve360 API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import base64 | |
import httplib | |
import logging | |
import string | |
try: | |
import simplejson as json | |
except ImportError: | |
import json | |
class settings: | |
SOLVE360_USER = "[email protected]" | |
SOLVE360_PASS = "API-KEY" | |
SOLVE360_SERVER = "secure.solve360.com" | |
verb = 'GET' | |
uri = '/contacts/categories/' | |
body = '' | |
conn = httplib.HTTPSConnection(settings.SOLVE360_SERVER) | |
conn.set_debuglevel(1) | |
headers = { | |
'Authorization': 'Basic %s' % base64.encodestring(":".join([settings.SOLVE360_USER, settings.SOLVE360_PASS]).encode('utf-8')).replace('\n', ''), | |
'Content-Type': 'application/json', | |
'Accept': 'application/json', | |
} | |
if not verb in ['GET', 'POST', 'PUT', 'DELETE']: | |
print 'ERROR: Invalid verb for Solve360 %s' % verb | |
exit() | |
conn.request(verb, uri, body, headers) | |
response = conn.getresponse() | |
if response.status != 200: | |
print 'ERROR: Unable to post to Solve360 at %s - %s:%s\nPayload: %s' % (uri, response.status, response.reason, body) | |
else: | |
print response.read() | |
conn.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Updated line 24 to 'Content-Type' from 'Content-type'