<s> import datetime <EOL> import time <EOL> from sbs . tools import Tools <EOL> import pycurl <EOL> import json <EOL> class HTTPRequest ( ) : <EOL> debug = False <EOL> logFile = '<STR_LIT>' <EOL> apiKey = '<STR_LIT>' <EOL> contentType = '<STR_LIT:application/json>' <EOL> url = '<STR_LIT>' <EOL> instance = None <EOL> class __HTTPRequest : <EOL> def __init__ ( self ) : <EOL> pass <EOL> def __str__ ( self ) : <EOL> return repr ( self ) + self . val <EOL> def __init__ ( self ) : <EOL> if not HTTPRequest . instance : <EOL> HTTPRequest . instance = HTTPRequest . __HTTPRequest ( ) <EOL> else : <EOL> pass <EOL> def __getattr__ ( self , name ) : <EOL> return getattr ( self . instance , name ) <EOL> def __setattr__ ( self , name ) : <EOL> return setattr ( self . instance , name ) <EOL> @ classmethod <EOL> def init ( self , apiKey , contentType , url ) : <EOL> self . apiKey = apiKey <EOL> self . contentType = contentType <EOL> self . url = url <EOL> @ classmethod <EOL> def send ( self , data ) : <EOL> c = pycurl . Curl ( ) <EOL> c . setopt ( c . URL , self . url ) <EOL> body = json . dumps ( data ) <EOL> Tools . log ( '<STR_LIT>' % data ) <EOL> try : <EOL> c . setopt ( pycurl . HTTPHEADER , [ ( '<STR_LIT>' % self . apiKey ) , '<STR_LIT>' % self . contentType ] ) <EOL> c . setopt ( c . POSTFIELDS , body ) <EOL> c . perform ( ) <EOL> response_code = c . getinfo ( c . RESPONSE_CODE ) <EOL> if ( response_code == <NUM_LIT:200> ) : <EOL> Tools . log ( '<STR_LIT>' % c . getinfo ( c . TOTAL_TIME ) , <NUM_LIT:2> ) <EOL> else : <EOL> Tools . log ( '<STR_LIT>' % response_code , <NUM_LIT:2> ) <EOL> except Exception , e : <EOL> Tools . log ( '<STR_LIT>' % e , <NUM_LIT:1> ) <EOL> pass <EOL> return response_code </s>
