diff --git a/Makefile b/Makefile index 7dab126..b56daed 100644 --- a/Makefile +++ b/Makefile @@ -3,4 +3,9 @@ update-trans: pybabel update --input-file messages.pot --output-dir translations/ --locale ja --domain messages compile-trans: - pybabel compile --directory translations/ --domain messages \ No newline at end of file + pybabel compile --directory translations/ --domain messages + +appengine-deploy: + # Note: If you are on OS X, and you are using homebrew python, + # you are going to get a weird error. + pip install -r requirements.txt -t lib \ No newline at end of file diff --git a/app.wsgi b/app.wsgi index ed393d1..dbab0be 100644 --- a/app.wsgi +++ b/app.wsgi @@ -30,14 +30,28 @@ class Config(object): with open(file, 'r') as f: self.cfg = json.load(f) - for section in ['OCTAV', 'REDIS_INFO', 'GITHUB', 'GOOGLE_MAP']: + sections = { + 'OCTAV': ['debug', 'endpoint', 'key', 'secret'], + 'REDIS_INFO': ['host','port', 'db'], + 'GITHUB': ['client_id', 'client_secret'], + 'GOOGLE_MAP': ['api_key'] + } + for section in sections.keys(): if not self.cfg.get(section): raise Exception( "missing section '" + section + "' in config file '" + file + "'" ) if self.cfg.get('OCTAV').get('BASE_URI'): raise Exception( 'DEPRECATED: {"OCTAV":{"BASE_URI"}} in config.json is deprecated.\ Please use {"OCTAV":{"endpoint"}} instead and remove {"OCTAV":{"BASE_URI"}}.' - ) + ) + + # Allow settings to be derived from environment + for section, subsections in sections.items(): + for subsection in subsections: + v = os.getenv('%s_%s' % (section,subsection.upper()), None) + if not v: + continue + self.cfg[section][subsection] = v def section(self, name): return self.cfg.get(name) @@ -110,10 +124,14 @@ def index(): key = "conferences.lang." + lang conferences = cache.get(key) if not conferences: + print("fetching..") conferences = octav.list_conference(lang=lang) + print(conferences) if conferences is None: raise HTTPError(status=500, body=octav.last_error()) cache.set(key, conferences, 600) + + print("rendering...") return template('index.tpl', { 'pagetitle': 'top', 'conferences': conferences, diff --git a/appengine_config.py b/appengine_config.py new file mode 100644 index 0000000..56e77ad --- /dev/null +++ b/appengine_config.py @@ -0,0 +1,2 @@ +import vendor +vendor.add('lib') \ No newline at end of file diff --git a/octav.py b/octav.py index 55c8ba5..a5bc2de 100644 --- a/octav.py +++ b/octav.py @@ -1,9 +1,13 @@ """OCTAV Client Library""" -"""DO NOT EDIT: This file was generated from ../spec/v1/api.json on Tue Jul 26 06:47:00 2016""" +"""DO NOT EDIT: This file was generated from ../spec/v1/api.json on Sat Jul 30 18:12:21 2016""" import json import os -import requests + +if os.getenv('SERVER_SOFTWARE', '').startswith('Google App Engine/') or os.getenv('SERVER_SOFTWARE', '').startswith('Development/'): + from urllib3.contrib.appengine import AppEngineManager as PoolManager +else: + from urllib3 import PoolManager class Octav(object): def __init__(self, endpoint, key, secret, debug=False): @@ -16,10 +20,9 @@ def __init__(self, endpoint, key, secret, debug=False): self.debug = debug self.endpoint = endpoint self.error = None + self.http = PoolManager() self.key = key self.secret = secret - self.session = requests.Session() - self.session.mount('http://', requests.adapters.HTTPAdapter(max_retries=0)) def extract_error(self, r): try: @@ -32,1298 +35,1815 @@ def last_error(self): return self.error def create_user (self, auth_user_id, auth_via, nickname, avatar_url=None, email=None, first_name=None, last_name=None, tshirt_size=None): - payload = {} - if auth_user_id is None: + try: + payload = {} + if auth_user_id is None: raise 'property auth_user_id must be provided' - payload['auth_user_id'] = auth_user_id - if auth_via is None: - raise 'property auth_via must be provided' - payload['auth_via'] = auth_via - if nickname is None: - raise 'property nickname must be provided' - payload['nickname'] = nickname - if auth_user_id is not None: payload['auth_user_id'] = auth_user_id - if auth_via is not None: + if auth_via is None: + raise 'property auth_via must be provided' payload['auth_via'] = auth_via - if avatar_url is not None: - payload['avatar_url'] = avatar_url - if email is not None: - payload['email'] = email - if first_name is not None: - payload['first_name'] = first_name - if last_name is not None: - payload['last_name'] = last_name - if nickname is not None: + if nickname is None: + raise 'property nickname must be provided' payload['nickname'] = nickname - if tshirt_size is not None: - payload['tshirt_size'] = tshirt_size - uri = self.endpoint + "/user/create" - if self.debug: - print("POST " + uri) - res = self.session.post(uri, auth=(self.key, self.secret), json=payload) - if res.status_code != 200: - self.extract_error(res) + if auth_user_id is not None: + payload['auth_user_id'] = auth_user_id + if auth_via is not None: + payload['auth_via'] = auth_via + if avatar_url is not None: + payload['avatar_url'] = avatar_url + if email is not None: + payload['email'] = email + if first_name is not None: + payload['first_name'] = first_name + if last_name is not None: + payload['last_name'] = last_name + if nickname is not None: + payload['nickname'] = nickname + if tshirt_size is not None: + payload['tshirt_size'] = tshirt_size + uri = '%s/user/create' % self.endpoint + if self.debug: + print('POST %s' % uri) + hdrs = urllib3.util.make_headers( + basic_auth='%s:%s' % (self.key, self.secret), + ) + hdrs['Content-Type']= 'application/json' + res = self.http.request('POST', uri, headers=hdrs, body=json.dumps(payload)) + if self.debug: + print(res) + if res.status != 200: + self.extract_error(res) + return None + return json.loads(res.data) + except BaseException, e: + if self.debug: + print("error during http access: " + repr(e)) + self.error = repr(e) return None - return res.json() def lookup_user (self, id): - payload = {} - if id is None: + try: + payload = {} + if id is None: raise 'property id must be provided' - payload['id'] = id - if id is not None: payload['id'] = id - uri = self.endpoint + "/user/lookup" - if self.debug: - print("GET " + uri) - res = self.session.get(uri, params=payload) - if res.status_code != 200: - self.extract_error(res) + if id is not None: + payload['id'] = id + uri = '%s/user/lookup' % self.endpoint + if self.debug: + print("GET " + uri) + res = self.http.request('GET', uri, body=json.dumps(payload)) + if self.debug: + print(res) + if res.status != 200: + self.extract_error(res) + return None + return json.loads(res.data) + except BaseException, e: + if self.debug: + print("error during http access: " + repr(e)) + self.error = repr(e) return None - return res.json() def lookup_user_by_auth_user_id (self, auth_user_id, auth_via): - payload = {} - if auth_user_id is None: + try: + payload = {} + if auth_user_id is None: raise 'property auth_user_id must be provided' - payload['auth_user_id'] = auth_user_id - if auth_via is None: - raise 'property auth_via must be provided' - payload['auth_via'] = auth_via - if auth_user_id is not None: payload['auth_user_id'] = auth_user_id - if auth_via is not None: + if auth_via is None: + raise 'property auth_via must be provided' payload['auth_via'] = auth_via - uri = self.endpoint + "/user/lookup_by_auth_user_id" - if self.debug: - print("GET " + uri) - res = self.session.get(uri, params=payload) - if res.status_code != 200: - self.extract_error(res) + if auth_user_id is not None: + payload['auth_user_id'] = auth_user_id + if auth_via is not None: + payload['auth_via'] = auth_via + uri = '%s/user/lookup_by_auth_user_id' % self.endpoint + if self.debug: + print("GET " + uri) + res = self.http.request('GET', uri, body=json.dumps(payload)) + if self.debug: + print(res) + if res.status != 200: + self.extract_error(res) + return None + return json.loads(res.data) + except BaseException, e: + if self.debug: + print("error during http access: " + repr(e)) + self.error = repr(e) return None - return res.json() def update_user (self, id, user_id, email=None, first_name=None, last_name=None, nickname=None, tshirt_size=None): - payload = {} - if id is None: + try: + payload = {} + if id is None: raise 'property id must be provided' - payload['id'] = id - if user_id is None: - raise 'property user_id must be provided' - payload['user_id'] = user_id - if email is not None: - payload['email'] = email - if first_name is not None: - payload['first_name'] = first_name - if id is not None: payload['id'] = id - if last_name is not None: - payload['last_name'] = last_name - if nickname is not None: - payload['nickname'] = nickname - if tshirt_size is not None: - payload['tshirt_size'] = tshirt_size - if user_id is not None: + if user_id is None: + raise 'property user_id must be provided' payload['user_id'] = user_id - uri = self.endpoint + "/user/update" - if self.debug: - print("POST " + uri) - res = self.session.post(uri, auth=(self.key, self.secret), json=payload) - if res.status_code != 200: - self.extract_error(res) + if email is not None: + payload['email'] = email + if first_name is not None: + payload['first_name'] = first_name + if id is not None: + payload['id'] = id + if last_name is not None: + payload['last_name'] = last_name + if nickname is not None: + payload['nickname'] = nickname + if tshirt_size is not None: + payload['tshirt_size'] = tshirt_size + if user_id is not None: + payload['user_id'] = user_id + uri = '%s/user/update' % self.endpoint + if self.debug: + print('POST %s' % uri) + hdrs = urllib3.util.make_headers( + basic_auth='%s:%s' % (self.key, self.secret), + ) + hdrs['Content-Type']= 'application/json' + res = self.http.request('POST', uri, headers=hdrs, body=json.dumps(payload)) + if self.debug: + print(res) + if res.status != 200: + self.extract_error(res) + return None + return True + except BaseException, e: + if self.debug: + print("error during http access: " + repr(e)) + self.error = repr(e) return None - return True def delete_user (self, id, user_id): - payload = {} - if id is None: + try: + payload = {} + if id is None: raise 'property id must be provided' - payload['id'] = id - if user_id is None: - raise 'property user_id must be provided' - payload['user_id'] = user_id - if id is not None: payload['id'] = id - if user_id is not None: + if user_id is None: + raise 'property user_id must be provided' payload['user_id'] = user_id - uri = self.endpoint + "/user/delete" - if self.debug: - print("POST " + uri) - res = self.session.post(uri, auth=(self.key, self.secret), json=payload) - if res.status_code != 200: - self.extract_error(res) + if id is not None: + payload['id'] = id + if user_id is not None: + payload['user_id'] = user_id + uri = '%s/user/delete' % self.endpoint + if self.debug: + print('POST %s' % uri) + hdrs = urllib3.util.make_headers( + basic_auth='%s:%s' % (self.key, self.secret), + ) + hdrs['Content-Type']= 'application/json' + res = self.http.request('POST', uri, headers=hdrs, body=json.dumps(payload)) + if self.debug: + print(res) + if res.status != 200: + self.extract_error(res) + return None + return True + except BaseException, e: + if self.debug: + print("error during http access: " + repr(e)) + self.error = repr(e) return None - return True def list_user (self, lang=None, limit=None, since=None): - payload = {} - if lang is not None: - payload['lang'] = lang - if limit is not None: - payload['limit'] = limit - if since is not None: - payload['since'] = since - uri = self.endpoint + "/user/list" - if self.debug: - print("GET " + uri) - res = self.session.get(uri, params=payload) - if res.status_code != 200: - self.extract_error(res) + try: + payload = {} + if lang is not None: + payload['lang'] = lang + if limit is not None: + payload['limit'] = limit + if since is not None: + payload['since'] = since + uri = '%s/user/list' % self.endpoint + if self.debug: + print("GET " + uri) + res = self.http.request('GET', uri, body=json.dumps(payload)) + if self.debug: + print(res) + if res.status != 200: + self.extract_error(res) + return None + return json.loads(res.data) + except BaseException, e: + if self.debug: + print("error during http access: " + repr(e)) + self.error = repr(e) return None - return res.json() def create_venue (self, address, name, user_id, latitude=None, longitude=None): - payload = {} - if address is None: + try: + payload = {} + if address is None: raise 'property address must be provided' - payload['address'] = address - if name is None: - raise 'property name must be provided' - payload['name'] = name - if user_id is None: - raise 'property user_id must be provided' - payload['user_id'] = user_id - if address is not None: payload['address'] = address - if latitude is not None: - payload['latitude'] = latitude - if longitude is not None: - payload['longitude'] = longitude - if name is not None: + if name is None: + raise 'property name must be provided' payload['name'] = name - if user_id is not None: + if user_id is None: + raise 'property user_id must be provided' payload['user_id'] = user_id - uri = self.endpoint + "/venue/create" - if self.debug: - print("POST " + uri) - res = self.session.post(uri, auth=(self.key, self.secret), json=payload) - if res.status_code != 200: - self.extract_error(res) + if address is not None: + payload['address'] = address + if latitude is not None: + payload['latitude'] = latitude + if longitude is not None: + payload['longitude'] = longitude + if name is not None: + payload['name'] = name + if user_id is not None: + payload['user_id'] = user_id + uri = '%s/venue/create' % self.endpoint + if self.debug: + print('POST %s' % uri) + hdrs = urllib3.util.make_headers( + basic_auth='%s:%s' % (self.key, self.secret), + ) + hdrs['Content-Type']= 'application/json' + res = self.http.request('POST', uri, headers=hdrs, body=json.dumps(payload)) + if self.debug: + print(res) + if res.status != 200: + self.extract_error(res) + return None + return json.loads(res.data) + except BaseException, e: + if self.debug: + print("error during http access: " + repr(e)) + self.error = repr(e) return None - return res.json() def list_venue (self, lang=None, limit=None, since=None): - payload = {} - if lang is not None: - payload['lang'] = lang - if limit is not None: - payload['limit'] = limit - if since is not None: - payload['since'] = since - uri = self.endpoint + "/venue/list" - if self.debug: - print("GET " + uri) - res = self.session.get(uri, params=payload) - if res.status_code != 200: - self.extract_error(res) + try: + payload = {} + if lang is not None: + payload['lang'] = lang + if limit is not None: + payload['limit'] = limit + if since is not None: + payload['since'] = since + uri = '%s/venue/list' % self.endpoint + if self.debug: + print("GET " + uri) + res = self.http.request('GET', uri, body=json.dumps(payload)) + if self.debug: + print(res) + if res.status != 200: + self.extract_error(res) + return None + return json.loads(res.data) + except BaseException, e: + if self.debug: + print("error during http access: " + repr(e)) + self.error = repr(e) return None - return res.json() def lookup_venue (self, id): - payload = {} - if id is None: + try: + payload = {} + if id is None: raise 'property id must be provided' - payload['id'] = id - if id is not None: payload['id'] = id - uri = self.endpoint + "/venue/lookup" - if self.debug: - print("GET " + uri) - res = self.session.get(uri, params=payload) - if res.status_code != 200: - self.extract_error(res) + if id is not None: + payload['id'] = id + uri = '%s/venue/lookup' % self.endpoint + if self.debug: + print("GET " + uri) + res = self.http.request('GET', uri, body=json.dumps(payload)) + if self.debug: + print(res) + if res.status != 200: + self.extract_error(res) + return None + return json.loads(res.data) + except BaseException, e: + if self.debug: + print("error during http access: " + repr(e)) + self.error = repr(e) return None - return res.json() def update_venue (self, id, user_id): - payload = {} - if id is None: + try: + payload = {} + if id is None: raise 'property id must be provided' - payload['id'] = id - if user_id is None: - raise 'property user_id must be provided' - payload['user_id'] = user_id - if id is not None: payload['id'] = id - if user_id is not None: + if user_id is None: + raise 'property user_id must be provided' payload['user_id'] = user_id - uri = self.endpoint + "/venue/update" - if self.debug: - print("POST " + uri) - res = self.session.post(uri, auth=(self.key, self.secret), json=payload) - if res.status_code != 200: - self.extract_error(res) + if id is not None: + payload['id'] = id + if user_id is not None: + payload['user_id'] = user_id + uri = '%s/venue/update' % self.endpoint + if self.debug: + print('POST %s' % uri) + hdrs = urllib3.util.make_headers( + basic_auth='%s:%s' % (self.key, self.secret), + ) + hdrs['Content-Type']= 'application/json' + res = self.http.request('POST', uri, headers=hdrs, body=json.dumps(payload)) + if self.debug: + print(res) + if res.status != 200: + self.extract_error(res) + return None + return True + except BaseException, e: + if self.debug: + print("error during http access: " + repr(e)) + self.error = repr(e) return None - return True def delete_venue (self, id, user_id): - payload = {} - if id is None: + try: + payload = {} + if id is None: raise 'property id must be provided' - payload['id'] = id - if user_id is None: - raise 'property user_id must be provided' - payload['user_id'] = user_id - if id is not None: payload['id'] = id - if user_id is not None: + if user_id is None: + raise 'property user_id must be provided' payload['user_id'] = user_id - uri = self.endpoint + "/venue/delete" - if self.debug: - print("POST " + uri) - res = self.session.post(uri, auth=(self.key, self.secret), json=payload) - if res.status_code != 200: - self.extract_error(res) + if id is not None: + payload['id'] = id + if user_id is not None: + payload['user_id'] = user_id + uri = '%s/venue/delete' % self.endpoint + if self.debug: + print('POST %s' % uri) + hdrs = urllib3.util.make_headers( + basic_auth='%s:%s' % (self.key, self.secret), + ) + hdrs['Content-Type']= 'application/json' + res = self.http.request('POST', uri, headers=hdrs, body=json.dumps(payload)) + if self.debug: + print(res) + if res.status != 200: + self.extract_error(res) + return None + return True + except BaseException, e: + if self.debug: + print("error during http access: " + repr(e)) + self.error = repr(e) return None - return True def create_room (self, name, user_id, venue_id, capacity=None): - payload = {} - if name is None: + try: + payload = {} + if name is None: raise 'property name must be provided' - payload['name'] = name - if user_id is None: - raise 'property user_id must be provided' - payload['user_id'] = user_id - if venue_id is None: - raise 'property venue_id must be provided' - payload['venue_id'] = venue_id - if capacity is not None: - payload['capacity'] = capacity - if name is not None: payload['name'] = name - if user_id is not None: + if user_id is None: + raise 'property user_id must be provided' payload['user_id'] = user_id - if venue_id is not None: + if venue_id is None: + raise 'property venue_id must be provided' payload['venue_id'] = venue_id - uri = self.endpoint + "/room/create" - if self.debug: - print("POST " + uri) - res = self.session.post(uri, auth=(self.key, self.secret), json=payload) - if res.status_code != 200: - self.extract_error(res) + if capacity is not None: + payload['capacity'] = capacity + if name is not None: + payload['name'] = name + if user_id is not None: + payload['user_id'] = user_id + if venue_id is not None: + payload['venue_id'] = venue_id + uri = '%s/room/create' % self.endpoint + if self.debug: + print('POST %s' % uri) + hdrs = urllib3.util.make_headers( + basic_auth='%s:%s' % (self.key, self.secret), + ) + hdrs['Content-Type']= 'application/json' + res = self.http.request('POST', uri, headers=hdrs, body=json.dumps(payload)) + if self.debug: + print(res) + if res.status != 200: + self.extract_error(res) + return None + return json.loads(res.data) + except BaseException, e: + if self.debug: + print("error during http access: " + repr(e)) + self.error = repr(e) return None - return res.json() def update_room (self, id, user_id, capacity=None, name=None, venue_id=None): - payload = {} - if id is None: + try: + payload = {} + if id is None: raise 'property id must be provided' - payload['id'] = id - if user_id is None: - raise 'property user_id must be provided' - payload['user_id'] = user_id - if capacity is not None: - payload['capacity'] = capacity - if id is not None: payload['id'] = id - if name is not None: - payload['name'] = name - if user_id is not None: + if user_id is None: + raise 'property user_id must be provided' payload['user_id'] = user_id - if venue_id is not None: - payload['venue_id'] = venue_id - uri = self.endpoint + "/room/update" - if self.debug: - print("POST " + uri) - res = self.session.post(uri, auth=(self.key, self.secret), json=payload) - if res.status_code != 200: - self.extract_error(res) + if capacity is not None: + payload['capacity'] = capacity + if id is not None: + payload['id'] = id + if name is not None: + payload['name'] = name + if user_id is not None: + payload['user_id'] = user_id + if venue_id is not None: + payload['venue_id'] = venue_id + uri = '%s/room/update' % self.endpoint + if self.debug: + print('POST %s' % uri) + hdrs = urllib3.util.make_headers( + basic_auth='%s:%s' % (self.key, self.secret), + ) + hdrs['Content-Type']= 'application/json' + res = self.http.request('POST', uri, headers=hdrs, body=json.dumps(payload)) + if self.debug: + print(res) + if res.status != 200: + self.extract_error(res) + return None + return True + except BaseException, e: + if self.debug: + print("error during http access: " + repr(e)) + self.error = repr(e) return None - return True def lookup_room (self, id): - payload = {} - if id is None: + try: + payload = {} + if id is None: raise 'property id must be provided' - payload['id'] = id - if id is not None: payload['id'] = id - uri = self.endpoint + "/room/lookup" - if self.debug: - print("GET " + uri) - res = self.session.get(uri, params=payload) - if res.status_code != 200: - self.extract_error(res) + if id is not None: + payload['id'] = id + uri = '%s/room/lookup' % self.endpoint + if self.debug: + print("GET " + uri) + res = self.http.request('GET', uri, body=json.dumps(payload)) + if self.debug: + print(res) + if res.status != 200: + self.extract_error(res) + return None + return json.loads(res.data) + except BaseException, e: + if self.debug: + print("error during http access: " + repr(e)) + self.error = repr(e) return None - return res.json() def delete_room (self, id, user_id): - payload = {} - if id is None: + try: + payload = {} + if id is None: raise 'property id must be provided' - payload['id'] = id - if user_id is None: - raise 'property user_id must be provided' - payload['user_id'] = user_id - if id is not None: payload['id'] = id - if user_id is not None: + if user_id is None: + raise 'property user_id must be provided' payload['user_id'] = user_id - uri = self.endpoint + "/room/delete" - if self.debug: - print("POST " + uri) - res = self.session.post(uri, auth=(self.key, self.secret), json=payload) - if res.status_code != 200: - self.extract_error(res) + if id is not None: + payload['id'] = id + if user_id is not None: + payload['user_id'] = user_id + uri = '%s/room/delete' % self.endpoint + if self.debug: + print('POST %s' % uri) + hdrs = urllib3.util.make_headers( + basic_auth='%s:%s' % (self.key, self.secret), + ) + hdrs['Content-Type']= 'application/json' + res = self.http.request('POST', uri, headers=hdrs, body=json.dumps(payload)) + if self.debug: + print(res) + if res.status != 200: + self.extract_error(res) + return None + return True + except BaseException, e: + if self.debug: + print("error during http access: " + repr(e)) + self.error = repr(e) return None - return True def list_room (self, venue_id, lang=None, limit=None): - payload = {} - if venue_id is None: + try: + payload = {} + if venue_id is None: raise 'property venue_id must be provided' - payload['venue_id'] = venue_id - if lang is not None: - payload['lang'] = lang - if limit is not None: - payload['limit'] = limit - if venue_id is not None: payload['venue_id'] = venue_id - uri = self.endpoint + "/room/list" - if self.debug: - print("GET " + uri) - res = self.session.get(uri, params=payload) - if res.status_code != 200: - self.extract_error(res) + if lang is not None: + payload['lang'] = lang + if limit is not None: + payload['limit'] = limit + if venue_id is not None: + payload['venue_id'] = venue_id + uri = '%s/room/list' % self.endpoint + if self.debug: + print("GET " + uri) + res = self.http.request('GET', uri, body=json.dumps(payload)) + if self.debug: + print(res) + if res.status != 200: + self.extract_error(res) + return None + return json.loads(res.data) + except BaseException, e: + if self.debug: + print("error during http access: " + repr(e)) + self.error = repr(e) return None - return res.json() def create_conference_series (self, slug, title, user_id, description=None): - payload = {} - if slug is None: + try: + payload = {} + if slug is None: raise 'property slug must be provided' - payload['slug'] = slug - if title is None: - raise 'property title must be provided' - payload['title'] = title - if user_id is None: - raise 'property user_id must be provided' - payload['user_id'] = user_id - if description is not None: - payload['description'] = description - if slug is not None: payload['slug'] = slug - if title is not None: + if title is None: + raise 'property title must be provided' payload['title'] = title - if user_id is not None: + if user_id is None: + raise 'property user_id must be provided' payload['user_id'] = user_id - uri = self.endpoint + "/conference_series/create" - if self.debug: - print("POST " + uri) - res = self.session.post(uri, auth=(self.key, self.secret), json=payload) - if res.status_code != 200: - self.extract_error(res) + if description is not None: + payload['description'] = description + if slug is not None: + payload['slug'] = slug + if title is not None: + payload['title'] = title + if user_id is not None: + payload['user_id'] = user_id + uri = '%s/conference_series/create' % self.endpoint + if self.debug: + print('POST %s' % uri) + hdrs = urllib3.util.make_headers( + basic_auth='%s:%s' % (self.key, self.secret), + ) + hdrs['Content-Type']= 'application/json' + res = self.http.request('POST', uri, headers=hdrs, body=json.dumps(payload)) + if self.debug: + print(res) + if res.status != 200: + self.extract_error(res) + return None + return json.loads(res.data) + except BaseException, e: + if self.debug: + print("error during http access: " + repr(e)) + self.error = repr(e) return None - return res.json() def list_conference_series (self, limit=None, since=None): - payload = {} - if limit is not None: - payload['limit'] = limit - if since is not None: - payload['since'] = since - uri = self.endpoint + "/conference_series/list" - if self.debug: - print("GET " + uri) - res = self.session.get(uri, params=payload) - if res.status_code != 200: - self.extract_error(res) + try: + payload = {} + if limit is not None: + payload['limit'] = limit + if since is not None: + payload['since'] = since + uri = '%s/conference_series/list' % self.endpoint + if self.debug: + print("GET " + uri) + res = self.http.request('GET', uri, body=json.dumps(payload)) + if self.debug: + print(res) + if res.status != 200: + self.extract_error(res) + return None + return json.loads(res.data) + except BaseException, e: + if self.debug: + print("error during http access: " + repr(e)) + self.error = repr(e) return None - return res.json() def add_conference_series_admin (self, admin_id, series_id, user_id): - payload = {} - if admin_id is None: + try: + payload = {} + if admin_id is None: raise 'property admin_id must be provided' - payload['admin_id'] = admin_id - if series_id is None: - raise 'property series_id must be provided' - payload['series_id'] = series_id - if user_id is None: - raise 'property user_id must be provided' - payload['user_id'] = user_id - if admin_id is not None: payload['admin_id'] = admin_id - if series_id is not None: + if series_id is None: + raise 'property series_id must be provided' payload['series_id'] = series_id - if user_id is not None: + if user_id is None: + raise 'property user_id must be provided' payload['user_id'] = user_id - uri = self.endpoint + "/conference_series/admin/add" - if self.debug: - print("POST " + uri) - res = self.session.post(uri, auth=(self.key, self.secret), json=payload) - if res.status_code != 200: - self.extract_error(res) + if admin_id is not None: + payload['admin_id'] = admin_id + if series_id is not None: + payload['series_id'] = series_id + if user_id is not None: + payload['user_id'] = user_id + uri = '%s/conference_series/admin/add' % self.endpoint + if self.debug: + print('POST %s' % uri) + hdrs = urllib3.util.make_headers( + basic_auth='%s:%s' % (self.key, self.secret), + ) + hdrs['Content-Type']= 'application/json' + res = self.http.request('POST', uri, headers=hdrs, body=json.dumps(payload)) + if self.debug: + print(res) + if res.status != 200: + self.extract_error(res) + return None + return True + except BaseException, e: + if self.debug: + print("error during http access: " + repr(e)) + self.error = repr(e) return None - return True def create_conference (self, series_id, slug, title, user_id, description=None, sub_title=None): - payload = {} - if series_id is None: + try: + payload = {} + if series_id is None: raise 'property series_id must be provided' - payload['series_id'] = series_id - if slug is None: - raise 'property slug must be provided' - payload['slug'] = slug - if title is None: - raise 'property title must be provided' - payload['title'] = title - if user_id is None: - raise 'property user_id must be provided' - payload['user_id'] = user_id - if description is not None: - payload['description'] = description - if series_id is not None: payload['series_id'] = series_id - if slug is not None: + if slug is None: + raise 'property slug must be provided' payload['slug'] = slug - if sub_title is not None: - payload['sub_title'] = sub_title - if title is not None: + if title is None: + raise 'property title must be provided' payload['title'] = title - if user_id is not None: + if user_id is None: + raise 'property user_id must be provided' payload['user_id'] = user_id - uri = self.endpoint + "/conference/create" - if self.debug: - print("POST " + uri) - res = self.session.post(uri, auth=(self.key, self.secret), json=payload) - if res.status_code != 200: - self.extract_error(res) + if description is not None: + payload['description'] = description + if series_id is not None: + payload['series_id'] = series_id + if slug is not None: + payload['slug'] = slug + if sub_title is not None: + payload['sub_title'] = sub_title + if title is not None: + payload['title'] = title + if user_id is not None: + payload['user_id'] = user_id + uri = '%s/conference/create' % self.endpoint + if self.debug: + print('POST %s' % uri) + hdrs = urllib3.util.make_headers( + basic_auth='%s:%s' % (self.key, self.secret), + ) + hdrs['Content-Type']= 'application/json' + res = self.http.request('POST', uri, headers=hdrs, body=json.dumps(payload)) + if self.debug: + print(res) + if res.status != 200: + self.extract_error(res) + return None + return json.loads(res.data) + except BaseException, e: + if self.debug: + print("error during http access: " + repr(e)) + self.error = repr(e) return None - return res.json() def add_conference_dates (self, conference_id, dates, user_id): - payload = {} - if conference_id is None: + try: + payload = {} + if conference_id is None: raise 'property conference_id must be provided' - payload['conference_id'] = conference_id - if dates is None: - raise 'property dates must be provided' - payload['dates'] = dates - if user_id is None: - raise 'property user_id must be provided' - payload['user_id'] = user_id - if conference_id is not None: payload['conference_id'] = conference_id - if dates is not None: + if dates is None: + raise 'property dates must be provided' payload['dates'] = dates - if user_id is not None: + if user_id is None: + raise 'property user_id must be provided' payload['user_id'] = user_id - uri = self.endpoint + "/conference/dates/add" - if self.debug: - print("POST " + uri) - res = self.session.post(uri, auth=(self.key, self.secret), json=payload) - if res.status_code != 200: - self.extract_error(res) + if conference_id is not None: + payload['conference_id'] = conference_id + if dates is not None: + payload['dates'] = dates + if user_id is not None: + payload['user_id'] = user_id + uri = '%s/conference/dates/add' % self.endpoint + if self.debug: + print('POST %s' % uri) + hdrs = urllib3.util.make_headers( + basic_auth='%s:%s' % (self.key, self.secret), + ) + hdrs['Content-Type']= 'application/json' + res = self.http.request('POST', uri, headers=hdrs, body=json.dumps(payload)) + if self.debug: + print(res) + if res.status != 200: + self.extract_error(res) + return None + return True + except BaseException, e: + if self.debug: + print("error during http access: " + repr(e)) + self.error = repr(e) return None - return True def delete_conference_dates (self, conference_id, dates, user_id): - payload = {} - if conference_id is None: + try: + payload = {} + if conference_id is None: raise 'property conference_id must be provided' - payload['conference_id'] = conference_id - if dates is None: - raise 'property dates must be provided' - payload['dates'] = dates - if user_id is None: - raise 'property user_id must be provided' - payload['user_id'] = user_id - if conference_id is not None: payload['conference_id'] = conference_id - if dates is not None: + if dates is None: + raise 'property dates must be provided' payload['dates'] = dates - if user_id is not None: + if user_id is None: + raise 'property user_id must be provided' payload['user_id'] = user_id - uri = self.endpoint + "/conference/dates/delete" - if self.debug: - print("POST " + uri) - res = self.session.post(uri, auth=(self.key, self.secret), json=payload) - if res.status_code != 200: - self.extract_error(res) + if conference_id is not None: + payload['conference_id'] = conference_id + if dates is not None: + payload['dates'] = dates + if user_id is not None: + payload['user_id'] = user_id + uri = '%s/conference/dates/delete' % self.endpoint + if self.debug: + print('POST %s' % uri) + hdrs = urllib3.util.make_headers( + basic_auth='%s:%s' % (self.key, self.secret), + ) + hdrs['Content-Type']= 'application/json' + res = self.http.request('POST', uri, headers=hdrs, body=json.dumps(payload)) + if self.debug: + print(res) + if res.status != 200: + self.extract_error(res) + return None + return True + except BaseException, e: + if self.debug: + print("error during http access: " + repr(e)) + self.error = repr(e) return None - return True def add_conference_admin (self, admin_id, conference_id, user_id): - payload = {} - if admin_id is None: + try: + payload = {} + if admin_id is None: raise 'property admin_id must be provided' - payload['admin_id'] = admin_id - if conference_id is None: - raise 'property conference_id must be provided' - payload['conference_id'] = conference_id - if user_id is None: - raise 'property user_id must be provided' - payload['user_id'] = user_id - if admin_id is not None: payload['admin_id'] = admin_id - if conference_id is not None: + if conference_id is None: + raise 'property conference_id must be provided' payload['conference_id'] = conference_id - if user_id is not None: + if user_id is None: + raise 'property user_id must be provided' payload['user_id'] = user_id - uri = self.endpoint + "/conference/admin/add" - if self.debug: - print("POST " + uri) - res = self.session.post(uri, auth=(self.key, self.secret), json=payload) - if res.status_code != 200: - self.extract_error(res) + if admin_id is not None: + payload['admin_id'] = admin_id + if conference_id is not None: + payload['conference_id'] = conference_id + if user_id is not None: + payload['user_id'] = user_id + uri = '%s/conference/admin/add' % self.endpoint + if self.debug: + print('POST %s' % uri) + hdrs = urllib3.util.make_headers( + basic_auth='%s:%s' % (self.key, self.secret), + ) + hdrs['Content-Type']= 'application/json' + res = self.http.request('POST', uri, headers=hdrs, body=json.dumps(payload)) + if self.debug: + print(res) + if res.status != 200: + self.extract_error(res) + return None + return True + except BaseException, e: + if self.debug: + print("error during http access: " + repr(e)) + self.error = repr(e) return None - return True def delete_conference_admin (self, admin_id, conference_id, user_id): - payload = {} - if admin_id is None: + try: + payload = {} + if admin_id is None: raise 'property admin_id must be provided' - payload['admin_id'] = admin_id - if conference_id is None: - raise 'property conference_id must be provided' - payload['conference_id'] = conference_id - if user_id is None: - raise 'property user_id must be provided' - payload['user_id'] = user_id - if admin_id is not None: payload['admin_id'] = admin_id - if conference_id is not None: + if conference_id is None: + raise 'property conference_id must be provided' payload['conference_id'] = conference_id - if user_id is not None: + if user_id is None: + raise 'property user_id must be provided' payload['user_id'] = user_id - uri = self.endpoint + "/conference/admin/delete" - if self.debug: - print("POST " + uri) - res = self.session.post(uri, auth=(self.key, self.secret), json=payload) - if res.status_code != 200: - self.extract_error(res) + if admin_id is not None: + payload['admin_id'] = admin_id + if conference_id is not None: + payload['conference_id'] = conference_id + if user_id is not None: + payload['user_id'] = user_id + uri = '%s/conference/admin/delete' % self.endpoint + if self.debug: + print('POST %s' % uri) + hdrs = urllib3.util.make_headers( + basic_auth='%s:%s' % (self.key, self.secret), + ) + hdrs['Content-Type']= 'application/json' + res = self.http.request('POST', uri, headers=hdrs, body=json.dumps(payload)) + if self.debug: + print(res) + if res.status != 200: + self.extract_error(res) + return None + return True + except BaseException, e: + if self.debug: + print("error during http access: " + repr(e)) + self.error = repr(e) return None - return True def add_conference_venue (self, conference_id, user_id, venue_id): - payload = {} - if conference_id is None: + try: + payload = {} + if conference_id is None: raise 'property conference_id must be provided' - payload['conference_id'] = conference_id - if user_id is None: - raise 'property user_id must be provided' - payload['user_id'] = user_id - if venue_id is None: - raise 'property venue_id must be provided' - payload['venue_id'] = venue_id - if conference_id is not None: payload['conference_id'] = conference_id - if user_id is not None: + if user_id is None: + raise 'property user_id must be provided' payload['user_id'] = user_id - if venue_id is not None: + if venue_id is None: + raise 'property venue_id must be provided' payload['venue_id'] = venue_id - uri = self.endpoint + "/conference/venue/add" - if self.debug: - print("POST " + uri) - res = self.session.post(uri, auth=(self.key, self.secret), json=payload) - if res.status_code != 200: - self.extract_error(res) + if conference_id is not None: + payload['conference_id'] = conference_id + if user_id is not None: + payload['user_id'] = user_id + if venue_id is not None: + payload['venue_id'] = venue_id + uri = '%s/conference/venue/add' % self.endpoint + if self.debug: + print('POST %s' % uri) + hdrs = urllib3.util.make_headers( + basic_auth='%s:%s' % (self.key, self.secret), + ) + hdrs['Content-Type']= 'application/json' + res = self.http.request('POST', uri, headers=hdrs, body=json.dumps(payload)) + if self.debug: + print(res) + if res.status != 200: + self.extract_error(res) + return None + return True + except BaseException, e: + if self.debug: + print("error during http access: " + repr(e)) + self.error = repr(e) return None - return True def delete_conference_venue (self, conference_id, user_id, venue_id): - payload = {} - if conference_id is None: + try: + payload = {} + if conference_id is None: raise 'property conference_id must be provided' - payload['conference_id'] = conference_id - if user_id is None: - raise 'property user_id must be provided' - payload['user_id'] = user_id - if venue_id is None: - raise 'property venue_id must be provided' - payload['venue_id'] = venue_id - if conference_id is not None: payload['conference_id'] = conference_id - if user_id is not None: + if user_id is None: + raise 'property user_id must be provided' payload['user_id'] = user_id - if venue_id is not None: + if venue_id is None: + raise 'property venue_id must be provided' payload['venue_id'] = venue_id - uri = self.endpoint + "/conference/venue/delete" - if self.debug: - print("POST " + uri) - res = self.session.post(uri, auth=(self.key, self.secret), json=payload) - if res.status_code != 200: - self.extract_error(res) + if conference_id is not None: + payload['conference_id'] = conference_id + if user_id is not None: + payload['user_id'] = user_id + if venue_id is not None: + payload['venue_id'] = venue_id + uri = '%s/conference/venue/delete' % self.endpoint + if self.debug: + print('POST %s' % uri) + hdrs = urllib3.util.make_headers( + basic_auth='%s:%s' % (self.key, self.secret), + ) + hdrs['Content-Type']= 'application/json' + res = self.http.request('POST', uri, headers=hdrs, body=json.dumps(payload)) + if self.debug: + print(res) + if res.status != 200: + self.extract_error(res) + return None + return True + except BaseException, e: + if self.debug: + print("error during http access: " + repr(e)) + self.error = repr(e) return None - return True def lookup_conference (self, id, lang=None): - payload = {} - if id is None: + try: + payload = {} + if id is None: raise 'property id must be provided' - payload['id'] = id - if id is not None: payload['id'] = id - if lang is not None: - payload['lang'] = lang - uri = self.endpoint + "/conference/lookup" - if self.debug: - print("GET " + uri) - res = self.session.get(uri, params=payload) - if res.status_code != 200: - self.extract_error(res) + if id is not None: + payload['id'] = id + if lang is not None: + payload['lang'] = lang + uri = '%s/conference/lookup' % self.endpoint + if self.debug: + print("GET " + uri) + res = self.http.request('GET', uri, body=json.dumps(payload)) + if self.debug: + print(res) + if res.status != 200: + self.extract_error(res) + return None + return json.loads(res.data) + except BaseException, e: + if self.debug: + print("error during http access: " + repr(e)) + self.error = repr(e) return None - return res.json() def lookup_conference_by_slug (self, slug, lang=None): - payload = {} - if slug is None: + try: + payload = {} + if slug is None: raise 'property slug must be provided' - payload['slug'] = slug - if lang is not None: - payload['lang'] = lang - if slug is not None: payload['slug'] = slug - uri = self.endpoint + "/conference/lookup_by_slug" - if self.debug: - print("GET " + uri) - res = self.session.get(uri, params=payload) - if res.status_code != 200: - self.extract_error(res) + if lang is not None: + payload['lang'] = lang + if slug is not None: + payload['slug'] = slug + uri = '%s/conference/lookup_by_slug' % self.endpoint + if self.debug: + print("GET " + uri) + res = self.http.request('GET', uri, body=json.dumps(payload)) + if self.debug: + print(res) + if res.status != 200: + self.extract_error(res) + return None + return json.loads(res.data) + except BaseException, e: + if self.debug: + print("error during http access: " + repr(e)) + self.error = repr(e) return None - return res.json() def list_conference (self, lang=None, limit=None, range_end=None, range_start=None, since=None, status=None): - payload = {} - if lang is not None: - payload['lang'] = lang - if limit is not None: - payload['limit'] = limit - if range_end is not None: - payload['range_end'] = range_end - if range_start is not None: - payload['range_start'] = range_start - if since is not None: - payload['since'] = since - if status is not None: - payload['status'] = status - uri = self.endpoint + "/conference/list" - if self.debug: - print("GET " + uri) - res = self.session.get(uri, params=payload) - if res.status_code != 200: - self.extract_error(res) + try: + payload = {} + if lang is not None: + payload['lang'] = lang + if limit is not None: + payload['limit'] = limit + if range_end is not None: + payload['range_end'] = range_end + if range_start is not None: + payload['range_start'] = range_start + if since is not None: + payload['since'] = since + if status is not None: + payload['status'] = status + uri = '%s/conference/list' % self.endpoint + if self.debug: + print("GET " + uri) + res = self.http.request('GET', uri, body=json.dumps(payload)) + if self.debug: + print(res) + if res.status != 200: + self.extract_error(res) + return None + return json.loads(res.data) + except BaseException, e: + if self.debug: + print("error during http access: " + repr(e)) + self.error = repr(e) return None - return res.json() def update_conference (self, id, user_id, description=None, slug=None, status=None, sub_title=None, title=None): - payload = {} - if id is None: + try: + payload = {} + if id is None: raise 'property id must be provided' - payload['id'] = id - if user_id is None: - raise 'property user_id must be provided' - payload['user_id'] = user_id - if description is not None: - payload['description'] = description - if id is not None: payload['id'] = id - if slug is not None: - payload['slug'] = slug - if status is not None: - payload['status'] = status - if sub_title is not None: - payload['sub_title'] = sub_title - if title is not None: - payload['title'] = title - if user_id is not None: + if user_id is None: + raise 'property user_id must be provided' payload['user_id'] = user_id - uri = self.endpoint + "/conference/update" - if self.debug: - print("POST " + uri) - res = self.session.post(uri, auth=(self.key, self.secret), json=payload) - if res.status_code != 200: - self.extract_error(res) + if description is not None: + payload['description'] = description + if id is not None: + payload['id'] = id + if slug is not None: + payload['slug'] = slug + if status is not None: + payload['status'] = status + if sub_title is not None: + payload['sub_title'] = sub_title + if title is not None: + payload['title'] = title + if user_id is not None: + payload['user_id'] = user_id + uri = '%s/conference/update' % self.endpoint + if self.debug: + print('POST %s' % uri) + hdrs = urllib3.util.make_headers( + basic_auth='%s:%s' % (self.key, self.secret), + ) + hdrs['Content-Type']= 'application/json' + res = self.http.request('POST', uri, headers=hdrs, body=json.dumps(payload)) + if self.debug: + print(res) + if res.status != 200: + self.extract_error(res) + return None + return True + except BaseException, e: + if self.debug: + print("error during http access: " + repr(e)) + self.error = repr(e) return None - return True def delete_conference_series (self, id, user_id): - payload = {} - if id is None: + try: + payload = {} + if id is None: raise 'property id must be provided' - payload['id'] = id - if user_id is None: - raise 'property user_id must be provided' - payload['user_id'] = user_id - if id is not None: payload['id'] = id - if user_id is not None: + if user_id is None: + raise 'property user_id must be provided' payload['user_id'] = user_id - uri = self.endpoint + "/conference_series/delete" - if self.debug: - print("POST " + uri) - res = self.session.post(uri, auth=(self.key, self.secret), json=payload) - if res.status_code != 200: - self.extract_error(res) + if id is not None: + payload['id'] = id + if user_id is not None: + payload['user_id'] = user_id + uri = '%s/conference_series/delete' % self.endpoint + if self.debug: + print('POST %s' % uri) + hdrs = urllib3.util.make_headers( + basic_auth='%s:%s' % (self.key, self.secret), + ) + hdrs['Content-Type']= 'application/json' + res = self.http.request('POST', uri, headers=hdrs, body=json.dumps(payload)) + if self.debug: + print(res) + if res.status != 200: + self.extract_error(res) + return None + return True + except BaseException, e: + if self.debug: + print("error during http access: " + repr(e)) + self.error = repr(e) return None - return True def delete_conference (self, id): - payload = {} - if id is None: + try: + payload = {} + if id is None: raise 'property id must be provided' - payload['id'] = id - if id is not None: payload['id'] = id - uri = self.endpoint + "/conference/delete" - if self.debug: - print("POST " + uri) - res = self.session.post(uri, auth=(self.key, self.secret), json=payload) - if res.status_code != 200: - self.extract_error(res) + if id is not None: + payload['id'] = id + uri = '%s/conference/delete' % self.endpoint + if self.debug: + print('POST %s' % uri) + hdrs = urllib3.util.make_headers( + basic_auth='%s:%s' % (self.key, self.secret), + ) + hdrs['Content-Type']= 'application/json' + res = self.http.request('POST', uri, headers=hdrs, body=json.dumps(payload)) + if self.debug: + print(res) + if res.status != 200: + self.extract_error(res) + return None + return True + except BaseException, e: + if self.debug: + print("error during http access: " + repr(e)) + self.error = repr(e) return None - return True def create_session (self, abstract, conference_id, duration, speaker_id, title, user_id, category=None, material_level=None, memo=None, photo_permission=None, slide_language=None, slide_subtitles=None, slide_url=None, spoken_language=None, tags=None, video_permission=None, video_url=None): - payload = {} - if abstract is None: + try: + payload = {} + if abstract is None: raise 'property abstract must be provided' - payload['abstract'] = abstract - if conference_id is None: - raise 'property conference_id must be provided' - payload['conference_id'] = conference_id - if duration is None: - raise 'property duration must be provided' - payload['duration'] = duration - if speaker_id is None: - raise 'property speaker_id must be provided' - payload['speaker_id'] = speaker_id - if title is None: - raise 'property title must be provided' - payload['title'] = title - if user_id is None: - raise 'property user_id must be provided' - payload['user_id'] = user_id - if abstract is not None: payload['abstract'] = abstract - if category is not None: - payload['category'] = category - if conference_id is not None: + if conference_id is None: + raise 'property conference_id must be provided' payload['conference_id'] = conference_id - if duration is not None: + if duration is None: + raise 'property duration must be provided' payload['duration'] = duration - if material_level is not None: - payload['material_level'] = material_level - if memo is not None: - payload['memo'] = memo - if photo_permission is not None: - payload['photo_permission'] = photo_permission - if slide_language is not None: - payload['slide_language'] = slide_language - if slide_subtitles is not None: - payload['slide_subtitles'] = slide_subtitles - if slide_url is not None: - payload['slide_url'] = slide_url - if speaker_id is not None: + if speaker_id is None: + raise 'property speaker_id must be provided' payload['speaker_id'] = speaker_id - if spoken_language is not None: - payload['spoken_language'] = spoken_language - if tags is not None: - payload['tags'] = tags - if title is not None: + if title is None: + raise 'property title must be provided' payload['title'] = title - if user_id is not None: + if user_id is None: + raise 'property user_id must be provided' payload['user_id'] = user_id - if video_permission is not None: - payload['video_permission'] = video_permission - if video_url is not None: - payload['video_url'] = video_url - uri = self.endpoint + "/session/create" - if self.debug: - print("POST " + uri) - res = self.session.post(uri, auth=(self.key, self.secret), json=payload) - if res.status_code != 200: - self.extract_error(res) + if abstract is not None: + payload['abstract'] = abstract + if category is not None: + payload['category'] = category + if conference_id is not None: + payload['conference_id'] = conference_id + if duration is not None: + payload['duration'] = duration + if material_level is not None: + payload['material_level'] = material_level + if memo is not None: + payload['memo'] = memo + if photo_permission is not None: + payload['photo_permission'] = photo_permission + if slide_language is not None: + payload['slide_language'] = slide_language + if slide_subtitles is not None: + payload['slide_subtitles'] = slide_subtitles + if slide_url is not None: + payload['slide_url'] = slide_url + if speaker_id is not None: + payload['speaker_id'] = speaker_id + if spoken_language is not None: + payload['spoken_language'] = spoken_language + if tags is not None: + payload['tags'] = tags + if title is not None: + payload['title'] = title + if user_id is not None: + payload['user_id'] = user_id + if video_permission is not None: + payload['video_permission'] = video_permission + if video_url is not None: + payload['video_url'] = video_url + uri = '%s/session/create' % self.endpoint + if self.debug: + print('POST %s' % uri) + hdrs = urllib3.util.make_headers( + basic_auth='%s:%s' % (self.key, self.secret), + ) + hdrs['Content-Type']= 'application/json' + res = self.http.request('POST', uri, headers=hdrs, body=json.dumps(payload)) + if self.debug: + print(res) + if res.status != 200: + self.extract_error(res) + return None + return json.loads(res.data) + except BaseException, e: + if self.debug: + print("error during http access: " + repr(e)) + self.error = repr(e) return None - return res.json() def lookup_session (self, id): - payload = {} - if id is None: + try: + payload = {} + if id is None: raise 'property id must be provided' - payload['id'] = id - if id is not None: payload['id'] = id - uri = self.endpoint + "/session/lookup" - if self.debug: - print("GET " + uri) - res = self.session.get(uri, params=payload) - if res.status_code != 200: - self.extract_error(res) + if id is not None: + payload['id'] = id + uri = '%s/session/lookup' % self.endpoint + if self.debug: + print("GET " + uri) + res = self.http.request('GET', uri, body=json.dumps(payload)) + if self.debug: + print(res) + if res.status != 200: + self.extract_error(res) + return None + return json.loads(res.data) + except BaseException, e: + if self.debug: + print("error during http access: " + repr(e)) + self.error = repr(e) return None - return res.json() def delete_session (self, id, user_id): - payload = {} - if id is None: + try: + payload = {} + if id is None: raise 'property id must be provided' - payload['id'] = id - if user_id is None: - raise 'property user_id must be provided' - payload['user_id'] = user_id - if id is not None: payload['id'] = id - if user_id is not None: + if user_id is None: + raise 'property user_id must be provided' payload['user_id'] = user_id - uri = self.endpoint + "/session/delete" - if self.debug: - print("POST " + uri) - res = self.session.post(uri, auth=(self.key, self.secret), json=payload) - if res.status_code != 200: - self.extract_error(res) + if id is not None: + payload['id'] = id + if user_id is not None: + payload['user_id'] = user_id + uri = '%s/session/delete' % self.endpoint + if self.debug: + print('POST %s' % uri) + hdrs = urllib3.util.make_headers( + basic_auth='%s:%s' % (self.key, self.secret), + ) + hdrs['Content-Type']= 'application/json' + res = self.http.request('POST', uri, headers=hdrs, body=json.dumps(payload)) + if self.debug: + print(res) + if res.status != 200: + self.extract_error(res) + return None + return True + except BaseException, e: + if self.debug: + print("error during http access: " + repr(e)) + self.error = repr(e) return None - return True def update_session (self, id, user_id, abstract=None, category=None, conference_id=None, confirmed=None, duration=None, has_interpretation=None, material_level=None, memo=None, photo_permission=None, slide_language=None, slide_subtitles=None, slide_url=None, sort_order=None, speaker_id=None, spoken_language=None, status=None, tags=None, title=None, video_permission=None, video_url=None): - payload = {} - if id is None: + try: + payload = {} + if id is None: raise 'property id must be provided' - payload['id'] = id - if user_id is None: - raise 'property user_id must be provided' - payload['user_id'] = user_id - if abstract is not None: - payload['abstract'] = abstract - if category is not None: - payload['category'] = category - if conference_id is not None: - payload['conference_id'] = conference_id - if confirmed is not None: - payload['confirmed'] = confirmed - if duration is not None: - payload['duration'] = duration - if has_interpretation is not None: - payload['has_interpretation'] = has_interpretation - if id is not None: payload['id'] = id - if material_level is not None: - payload['material_level'] = material_level - if memo is not None: - payload['memo'] = memo - if photo_permission is not None: - payload['photo_permission'] = photo_permission - if slide_language is not None: - payload['slide_language'] = slide_language - if slide_subtitles is not None: - payload['slide_subtitles'] = slide_subtitles - if slide_url is not None: - payload['slide_url'] = slide_url - if sort_order is not None: - payload['sort_order'] = sort_order - if speaker_id is not None: - payload['speaker_id'] = speaker_id - if spoken_language is not None: - payload['spoken_language'] = spoken_language - if status is not None: - payload['status'] = status - if tags is not None: - payload['tags'] = tags - if title is not None: - payload['title'] = title - if user_id is not None: + if user_id is None: + raise 'property user_id must be provided' payload['user_id'] = user_id - if video_permission is not None: - payload['video_permission'] = video_permission - if video_url is not None: - payload['video_url'] = video_url - uri = self.endpoint + "/session/update" - if self.debug: - print("POST " + uri) - res = self.session.post(uri, auth=(self.key, self.secret), json=payload) - if res.status_code != 200: - self.extract_error(res) + if abstract is not None: + payload['abstract'] = abstract + if category is not None: + payload['category'] = category + if conference_id is not None: + payload['conference_id'] = conference_id + if confirmed is not None: + payload['confirmed'] = confirmed + if duration is not None: + payload['duration'] = duration + if has_interpretation is not None: + payload['has_interpretation'] = has_interpretation + if id is not None: + payload['id'] = id + if material_level is not None: + payload['material_level'] = material_level + if memo is not None: + payload['memo'] = memo + if photo_permission is not None: + payload['photo_permission'] = photo_permission + if slide_language is not None: + payload['slide_language'] = slide_language + if slide_subtitles is not None: + payload['slide_subtitles'] = slide_subtitles + if slide_url is not None: + payload['slide_url'] = slide_url + if sort_order is not None: + payload['sort_order'] = sort_order + if speaker_id is not None: + payload['speaker_id'] = speaker_id + if spoken_language is not None: + payload['spoken_language'] = spoken_language + if status is not None: + payload['status'] = status + if tags is not None: + payload['tags'] = tags + if title is not None: + payload['title'] = title + if user_id is not None: + payload['user_id'] = user_id + if video_permission is not None: + payload['video_permission'] = video_permission + if video_url is not None: + payload['video_url'] = video_url + uri = '%s/session/update' % self.endpoint + if self.debug: + print('POST %s' % uri) + hdrs = urllib3.util.make_headers( + basic_auth='%s:%s' % (self.key, self.secret), + ) + hdrs['Content-Type']= 'application/json' + res = self.http.request('POST', uri, headers=hdrs, body=json.dumps(payload)) + if self.debug: + print(res) + if res.status != 200: + self.extract_error(res) + return None + return True + except BaseException, e: + if self.debug: + print("error during http access: " + repr(e)) + self.error = repr(e) return None - return True def list_session_by_conference (self, conference_id, date=None): - payload = {} - if conference_id is None: + try: + payload = {} + if conference_id is None: raise 'property conference_id must be provided' - payload['conference_id'] = conference_id - if conference_id is not None: payload['conference_id'] = conference_id - if date is not None: - payload['date'] = date - uri = self.endpoint + "/schedule/list" - if self.debug: - print("GET " + uri) - res = self.session.get(uri, params=payload) - if res.status_code != 200: - self.extract_error(res) + if conference_id is not None: + payload['conference_id'] = conference_id + if date is not None: + payload['date'] = date + uri = '%s/schedule/list' % self.endpoint + if self.debug: + print("GET " + uri) + res = self.http.request('GET', uri, body=json.dumps(payload)) + if self.debug: + print(res) + if res.status != 200: + self.extract_error(res) + return None + return json.loads(res.data) + except BaseException, e: + if self.debug: + print("error during http access: " + repr(e)) + self.error = repr(e) return None - return res.json() def create_question (self, body, session_id, user_id): - payload = {} - if body is None: + try: + payload = {} + if body is None: raise 'property body must be provided' - payload['body'] = body - if session_id is None: - raise 'property session_id must be provided' - payload['session_id'] = session_id - if user_id is None: - raise 'property user_id must be provided' - payload['user_id'] = user_id - if body is not None: payload['body'] = body - if session_id is not None: + if session_id is None: + raise 'property session_id must be provided' payload['session_id'] = session_id - if user_id is not None: + if user_id is None: + raise 'property user_id must be provided' payload['user_id'] = user_id - uri = self.endpoint + "/question/create" - if self.debug: - print("GET " + uri) - res = self.session.get(uri, params=payload) - if res.status_code != 200: - self.extract_error(res) + if body is not None: + payload['body'] = body + if session_id is not None: + payload['session_id'] = session_id + if user_id is not None: + payload['user_id'] = user_id + uri = '%s/question/create' % self.endpoint + if self.debug: + print("GET " + uri) + res = self.http.request('GET', uri, body=json.dumps(payload)) + if self.debug: + print(res) + if res.status != 200: + self.extract_error(res) + return None + return json.loads(res.data) + except BaseException, e: + if self.debug: + print("error during http access: " + repr(e)) + self.error = repr(e) return None - return res.json() def delete_question (self, id): - payload = {} - if id is None: + try: + payload = {} + if id is None: raise 'property id must be provided' - payload['id'] = id - if id is not None: payload['id'] = id - uri = self.endpoint + "/question/delete" - if self.debug: - print("POST " + uri) - res = self.session.post(uri, auth=(self.key, self.secret), json=payload) - if res.status_code != 200: - self.extract_error(res) + if id is not None: + payload['id'] = id + uri = '%s/question/delete' % self.endpoint + if self.debug: + print('POST %s' % uri) + hdrs = urllib3.util.make_headers( + basic_auth='%s:%s' % (self.key, self.secret), + ) + hdrs['Content-Type']= 'application/json' + res = self.http.request('POST', uri, headers=hdrs, body=json.dumps(payload)) + if self.debug: + print(res) + if res.status != 200: + self.extract_error(res) + return None + return True + except BaseException, e: + if self.debug: + print("error during http access: " + repr(e)) + self.error = repr(e) return None - return True def list_question (self, session_id, limit=None, since=None): - payload = {} - if session_id is None: + try: + payload = {} + if session_id is None: raise 'property session_id must be provided' - payload['session_id'] = session_id - if limit is not None: - payload['limit'] = limit - if session_id is not None: payload['session_id'] = session_id - if since is not None: - payload['since'] = since - uri = self.endpoint + "/question/list" - if self.debug: - print("GET " + uri) - res = self.session.get(uri, params=payload) - if res.status_code != 200: - self.extract_error(res) + if limit is not None: + payload['limit'] = limit + if session_id is not None: + payload['session_id'] = session_id + if since is not None: + payload['since'] = since + uri = '%s/question/list' % self.endpoint + if self.debug: + print("GET " + uri) + res = self.http.request('GET', uri, body=json.dumps(payload)) + if self.debug: + print(res) + if res.status != 200: + self.extract_error(res) + return None + return json.loads(res.data) + except BaseException, e: + if self.debug: + print("error during http access: " + repr(e)) + self.error = repr(e) return None - return res.json() def create_session_survey_response (self, material_quality, overall_rating, session_id, speaker_knowledge, speaker_presentation, user_id, user_prior_knowledge, comment_good=None, comment_improvement=None): - payload = {} - if material_quality is None: + try: + payload = {} + if material_quality is None: raise 'property material_quality must be provided' - payload['material_quality'] = material_quality - if overall_rating is None: - raise 'property overall_rating must be provided' - payload['overall_rating'] = overall_rating - if session_id is None: - raise 'property session_id must be provided' - payload['session_id'] = session_id - if speaker_knowledge is None: - raise 'property speaker_knowledge must be provided' - payload['speaker_knowledge'] = speaker_knowledge - if speaker_presentation is None: - raise 'property speaker_presentation must be provided' - payload['speaker_presentation'] = speaker_presentation - if user_id is None: - raise 'property user_id must be provided' - payload['user_id'] = user_id - if user_prior_knowledge is None: - raise 'property user_prior_knowledge must be provided' - payload['user_prior_knowledge'] = user_prior_knowledge - if comment_good is not None: - payload['comment_good'] = comment_good - if comment_improvement is not None: - payload['comment_improvement'] = comment_improvement - if material_quality is not None: payload['material_quality'] = material_quality - if overall_rating is not None: + if overall_rating is None: + raise 'property overall_rating must be provided' payload['overall_rating'] = overall_rating - if session_id is not None: + if session_id is None: + raise 'property session_id must be provided' payload['session_id'] = session_id - if speaker_knowledge is not None: + if speaker_knowledge is None: + raise 'property speaker_knowledge must be provided' payload['speaker_knowledge'] = speaker_knowledge - if speaker_presentation is not None: + if speaker_presentation is None: + raise 'property speaker_presentation must be provided' payload['speaker_presentation'] = speaker_presentation - if user_id is not None: + if user_id is None: + raise 'property user_id must be provided' payload['user_id'] = user_id - if user_prior_knowledge is not None: + if user_prior_knowledge is None: + raise 'property user_prior_knowledge must be provided' payload['user_prior_knowledge'] = user_prior_knowledge - uri = self.endpoint + "/survey_session_response/create" - if self.debug: - print("GET " + uri) - res = self.session.get(uri, params=payload) - if res.status_code != 200: - self.extract_error(res) + if comment_good is not None: + payload['comment_good'] = comment_good + if comment_improvement is not None: + payload['comment_improvement'] = comment_improvement + if material_quality is not None: + payload['material_quality'] = material_quality + if overall_rating is not None: + payload['overall_rating'] = overall_rating + if session_id is not None: + payload['session_id'] = session_id + if speaker_knowledge is not None: + payload['speaker_knowledge'] = speaker_knowledge + if speaker_presentation is not None: + payload['speaker_presentation'] = speaker_presentation + if user_id is not None: + payload['user_id'] = user_id + if user_prior_knowledge is not None: + payload['user_prior_knowledge'] = user_prior_knowledge + uri = '%s/survey_session_response/create' % self.endpoint + if self.debug: + print("GET " + uri) + res = self.http.request('GET', uri, body=json.dumps(payload)) + if self.debug: + print(res) + if res.status != 200: + self.extract_error(res) + return None + return True + except BaseException, e: + if self.debug: + print("error during http access: " + repr(e)) + self.error = repr(e) return None - return True def add_featured_speaker (self, conference_id, description, display_name, avatar_url=None, speaker_id=None, user_id=None): - payload = {} - if conference_id is None: + try: + payload = {} + if conference_id is None: raise 'property conference_id must be provided' - payload['conference_id'] = conference_id - if description is None: - raise 'property description must be provided' - payload['description'] = description - if display_name is None: - raise 'property display_name must be provided' - payload['display_name'] = display_name - if avatar_url is not None: - payload['avatar_url'] = avatar_url - if conference_id is not None: payload['conference_id'] = conference_id - if description is not None: + if description is None: + raise 'property description must be provided' payload['description'] = description - if display_name is not None: + if display_name is None: + raise 'property display_name must be provided' payload['display_name'] = display_name - if speaker_id is not None: - payload['speaker_id'] = speaker_id - if user_id is not None: - payload['user_id'] = user_id - uri = self.endpoint + "/featured_speaker/add" - if self.debug: - print("POST " + uri) - res = self.session.post(uri, auth=(self.key, self.secret), json=payload) - if res.status_code != 200: - self.extract_error(res) + if avatar_url is not None: + payload['avatar_url'] = avatar_url + if conference_id is not None: + payload['conference_id'] = conference_id + if description is not None: + payload['description'] = description + if display_name is not None: + payload['display_name'] = display_name + if speaker_id is not None: + payload['speaker_id'] = speaker_id + if user_id is not None: + payload['user_id'] = user_id + uri = '%s/featured_speaker/add' % self.endpoint + if self.debug: + print('POST %s' % uri) + hdrs = urllib3.util.make_headers( + basic_auth='%s:%s' % (self.key, self.secret), + ) + hdrs['Content-Type']= 'application/json' + res = self.http.request('POST', uri, headers=hdrs, body=json.dumps(payload)) + if self.debug: + print(res) + if res.status != 200: + self.extract_error(res) + return None + return json.loads(res.data) + except BaseException, e: + if self.debug: + print("error during http access: " + repr(e)) + self.error = repr(e) return None - return res.json() def lookup_featured_speaker (self, id, lang=None): - payload = {} - if id is None: + try: + payload = {} + if id is None: raise 'property id must be provided' - payload['id'] = id - if id is not None: payload['id'] = id - if lang is not None: - payload['lang'] = lang - uri = self.endpoint + "/featured_speaker/lookup" - if self.debug: - print("GET " + uri) - res = self.session.get(uri, params=payload) - if res.status_code != 200: - self.extract_error(res) + if id is not None: + payload['id'] = id + if lang is not None: + payload['lang'] = lang + uri = '%s/featured_speaker/lookup' % self.endpoint + if self.debug: + print("GET " + uri) + res = self.http.request('GET', uri, body=json.dumps(payload)) + if self.debug: + print(res) + if res.status != 200: + self.extract_error(res) + return None + return json.loads(res.data) + except BaseException, e: + if self.debug: + print("error during http access: " + repr(e)) + self.error = repr(e) return None - return res.json() def list_featured_speakers (self, conference_id=None, lang=None, limit=None, since=None): - payload = {} - if conference_id is not None: - payload['conference_id'] = conference_id - if lang is not None: - payload['lang'] = lang - if limit is not None: - payload['limit'] = limit - if since is not None: - payload['since'] = since - uri = self.endpoint + "/featured_speaker/list" - if self.debug: - print("GET " + uri) - res = self.session.get(uri, params=payload) - if res.status_code != 200: - self.extract_error(res) + try: + payload = {} + if conference_id is not None: + payload['conference_id'] = conference_id + if lang is not None: + payload['lang'] = lang + if limit is not None: + payload['limit'] = limit + if since is not None: + payload['since'] = since + uri = '%s/featured_speaker/list' % self.endpoint + if self.debug: + print("GET " + uri) + res = self.http.request('GET', uri, body=json.dumps(payload)) + if self.debug: + print(res) + if res.status != 200: + self.extract_error(res) + return None + return json.loads(res.data) + except BaseException, e: + if self.debug: + print("error during http access: " + repr(e)) + self.error = repr(e) return None - return res.json() def update_featured_speaker (self, id, user_id, avatar_url=None, description=None, display_name=None, speaker_id=None): - payload = {} - if id is None: + try: + payload = {} + if id is None: raise 'property id must be provided' - payload['id'] = id - if user_id is None: - raise 'property user_id must be provided' - payload['user_id'] = user_id - if avatar_url is not None: - payload['avatar_url'] = avatar_url - if description is not None: - payload['description'] = description - if display_name is not None: - payload['display_name'] = display_name - if id is not None: payload['id'] = id - if speaker_id is not None: - payload['speaker_id'] = speaker_id - if user_id is not None: + if user_id is None: + raise 'property user_id must be provided' payload['user_id'] = user_id - uri = self.endpoint + "/featured_speaker/update" - if self.debug: - print("POST " + uri) - res = self.session.post(uri, auth=(self.key, self.secret), json=payload) - if res.status_code != 200: - self.extract_error(res) + if avatar_url is not None: + payload['avatar_url'] = avatar_url + if description is not None: + payload['description'] = description + if display_name is not None: + payload['display_name'] = display_name + if id is not None: + payload['id'] = id + if speaker_id is not None: + payload['speaker_id'] = speaker_id + if user_id is not None: + payload['user_id'] = user_id + uri = '%s/featured_speaker/update' % self.endpoint + if self.debug: + print('POST %s' % uri) + hdrs = urllib3.util.make_headers( + basic_auth='%s:%s' % (self.key, self.secret), + ) + hdrs['Content-Type']= 'application/json' + res = self.http.request('POST', uri, headers=hdrs, body=json.dumps(payload)) + if self.debug: + print(res) + if res.status != 200: + self.extract_error(res) + return None + return True + except BaseException, e: + if self.debug: + print("error during http access: " + repr(e)) + self.error = repr(e) return None - return True def delete_featured_speaker (self, id, user_id): - payload = {} - if id is None: + try: + payload = {} + if id is None: raise 'property id must be provided' - payload['id'] = id - if user_id is None: - raise 'property user_id must be provided' - payload['user_id'] = user_id - if id is not None: payload['id'] = id - if user_id is not None: + if user_id is None: + raise 'property user_id must be provided' payload['user_id'] = user_id - uri = self.endpoint + "/featured_speaker/delete" - if self.debug: - print("POST " + uri) - res = self.session.post(uri, auth=(self.key, self.secret), json=payload) - if res.status_code != 200: - self.extract_error(res) + if id is not None: + payload['id'] = id + if user_id is not None: + payload['user_id'] = user_id + uri = '%s/featured_speaker/delete' % self.endpoint + if self.debug: + print('POST %s' % uri) + hdrs = urllib3.util.make_headers( + basic_auth='%s:%s' % (self.key, self.secret), + ) + hdrs['Content-Type']= 'application/json' + res = self.http.request('POST', uri, headers=hdrs, body=json.dumps(payload)) + if self.debug: + print(res) + if res.status != 200: + self.extract_error(res) + return None + return True + except BaseException, e: + if self.debug: + print("error during http access: " + repr(e)) + self.error = repr(e) return None - return True - def add_sponsor (self, conference_id, group_name, logo_url1, name, url, user_id, logo_url2=None, logo_url3=None, sort_order=None): - payload = {} - if conference_id is None: + def add_sponsor (self, conference_id, group_name, name, url, user_id, sort_order=None): + try: + payload = {} + if conference_id is None: raise 'property conference_id must be provided' - payload['conference_id'] = conference_id - if group_name is None: - raise 'property group_name must be provided' - payload['group_name'] = group_name - if logo_url1 is None: - raise 'property logo_url1 must be provided' - payload['logo_url1'] = logo_url1 - if name is None: - raise 'property name must be provided' - payload['name'] = name - if url is None: - raise 'property url must be provided' - payload['url'] = url - if user_id is None: - raise 'property user_id must be provided' - payload['user_id'] = user_id - if conference_id is not None: payload['conference_id'] = conference_id - if group_name is not None: + if group_name is None: + raise 'property group_name must be provided' payload['group_name'] = group_name - if logo_url1 is not None: - payload['logo_url1'] = logo_url1 - if logo_url2 is not None: - payload['logo_url2'] = logo_url2 - if logo_url3 is not None: - payload['logo_url3'] = logo_url3 - if name is not None: + if name is None: + raise 'property name must be provided' payload['name'] = name - if sort_order is not None: - payload['sort_order'] = sort_order - if url is not None: + if url is None: + raise 'property url must be provided' payload['url'] = url - if user_id is not None: + if user_id is None: + raise 'property user_id must be provided' payload['user_id'] = user_id - uri = self.endpoint + "/sponsor/add" - if self.debug: - print("POST " + uri) - res = self.session.post(uri, auth=(self.key, self.secret), json=payload) - if res.status_code != 200: - self.extract_error(res) + if conference_id is not None: + payload['conference_id'] = conference_id + if group_name is not None: + payload['group_name'] = group_name + if name is not None: + payload['name'] = name + if sort_order is not None: + payload['sort_order'] = sort_order + if url is not None: + payload['url'] = url + if user_id is not None: + payload['user_id'] = user_id + uri = '%s/sponsor/add' % self.endpoint + if self.debug: + print('POST %s' % uri) + hdrs = urllib3.util.make_headers( + basic_auth='%s:%s' % (self.key, self.secret), + ) + hdrs['Content-Type']= 'application/json' + res = self.http.request('POST', uri, headers=hdrs, body=json.dumps(payload)) + if self.debug: + print(res) + if res.status != 200: + self.extract_error(res) + return None + return json.loads(res.data) + except BaseException, e: + if self.debug: + print("error during http access: " + repr(e)) + self.error = repr(e) return None - return res.json() def lookup_sponsor (self, id, lang=None): - payload = {} - if id is None: + try: + payload = {} + if id is None: raise 'property id must be provided' - payload['id'] = id - if id is not None: payload['id'] = id - if lang is not None: - payload['lang'] = lang - uri = self.endpoint + "/sponsor/lookup" - if self.debug: - print("GET " + uri) - res = self.session.get(uri, params=payload) - if res.status_code != 200: - self.extract_error(res) + if id is not None: + payload['id'] = id + if lang is not None: + payload['lang'] = lang + uri = '%s/sponsor/lookup' % self.endpoint + if self.debug: + print("GET " + uri) + res = self.http.request('GET', uri, body=json.dumps(payload)) + if self.debug: + print(res) + if res.status != 200: + self.extract_error(res) + return None + return json.loads(res.data) + except BaseException, e: + if self.debug: + print("error during http access: " + repr(e)) + self.error = repr(e) return None - return res.json() def list_sponsors (self, conference_id=None, lang=None, limit=None, since=None): - payload = {} - if conference_id is not None: - payload['conference_id'] = conference_id - if lang is not None: - payload['lang'] = lang - if limit is not None: - payload['limit'] = limit - if since is not None: - payload['since'] = since - uri = self.endpoint + "/sponsor/list" - if self.debug: - print("GET " + uri) - res = self.session.get(uri, params=payload) - if res.status_code != 200: - self.extract_error(res) + try: + payload = {} + if conference_id is not None: + payload['conference_id'] = conference_id + if lang is not None: + payload['lang'] = lang + if limit is not None: + payload['limit'] = limit + if since is not None: + payload['since'] = since + uri = '%s/sponsor/list' % self.endpoint + if self.debug: + print("GET " + uri) + res = self.http.request('GET', uri, body=json.dumps(payload)) + if self.debug: + print(res) + if res.status != 200: + self.extract_error(res) + return None + return json.loads(res.data) + except BaseException, e: + if self.debug: + print("error during http access: " + repr(e)) + self.error = repr(e) return None - return res.json() - def update_sponsor (self, id, user_id, group_name=None, logo_url1=None, logo_url2=None, logo_url3=None, name=None, sort_order=None, url=None): - payload = {} - if id is None: + def update_sponsor (self, id, user_id, group_name=None, name=None, sort_order=None, url=None): + try: + payload = {} + if id is None: raise 'property id must be provided' - payload['id'] = id - if user_id is None: - raise 'property user_id must be provided' - payload['user_id'] = user_id - if group_name is not None: - payload['group_name'] = group_name - if id is not None: payload['id'] = id - if logo_url1 is not None: - payload['logo_url1'] = logo_url1 - if logo_url2 is not None: - payload['logo_url2'] = logo_url2 - if logo_url3 is not None: - payload['logo_url3'] = logo_url3 - if name is not None: - payload['name'] = name - if sort_order is not None: - payload['sort_order'] = sort_order - if url is not None: - payload['url'] = url - if user_id is not None: + if user_id is None: + raise 'property user_id must be provided' payload['user_id'] = user_id - uri = self.endpoint + "/sponsor/update" - if self.debug: - print("POST " + uri) - res = self.session.post(uri, auth=(self.key, self.secret), json=payload) - if res.status_code != 200: - self.extract_error(res) + if group_name is not None: + payload['group_name'] = group_name + if id is not None: + payload['id'] = id + if name is not None: + payload['name'] = name + if sort_order is not None: + payload['sort_order'] = sort_order + if url is not None: + payload['url'] = url + if user_id is not None: + payload['user_id'] = user_id + uri = '%s/sponsor/update' % self.endpoint + if self.debug: + print('POST %s' % uri) + hdrs = urllib3.util.make_headers( + basic_auth='%s:%s' % (self.key, self.secret), + ) + hdrs['Content-Type']= 'application/json' + res = self.http.request('POST', uri, headers=hdrs, body=json.dumps(payload)) + if self.debug: + print(res) + if res.status != 200: + self.extract_error(res) + return None + return True + except BaseException, e: + if self.debug: + print("error during http access: " + repr(e)) + self.error = repr(e) return None - return True def delete_sponsor (self, id, user_id): - payload = {} - if id is None: + try: + payload = {} + if id is None: raise 'property id must be provided' - payload['id'] = id - if user_id is None: - raise 'property user_id must be provided' - payload['user_id'] = user_id - if id is not None: payload['id'] = id - if user_id is not None: + if user_id is None: + raise 'property user_id must be provided' payload['user_id'] = user_id - uri = self.endpoint + "/sponsor/delete" - if self.debug: - print("POST " + uri) - res = self.session.post(uri, auth=(self.key, self.secret), json=payload) - if res.status_code != 200: - self.extract_error(res) + if id is not None: + payload['id'] = id + if user_id is not None: + payload['user_id'] = user_id + uri = '%s/sponsor/delete' % self.endpoint + if self.debug: + print('POST %s' % uri) + hdrs = urllib3.util.make_headers( + basic_auth='%s:%s' % (self.key, self.secret), + ) + hdrs['Content-Type']= 'application/json' + res = self.http.request('POST', uri, headers=hdrs, body=json.dumps(payload)) + if self.debug: + print(res) + if res.status != 200: + self.extract_error(res) + return None + return True + except BaseException, e: + if self.debug: + print("error during http access: " + repr(e)) + self.error = repr(e) return None - return True diff --git a/requirements.txt b/requirements.txt index 0c91723..e3e128e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,5 +4,5 @@ feedparser jinja2 py-gfm redis -requests +urllib3 wsgi-request-logger \ No newline at end of file diff --git a/vendor.py b/vendor.py new file mode 100644 index 0000000..4609019 --- /dev/null +++ b/vendor.py @@ -0,0 +1,71 @@ +# +# Copyright 2014 Jon Wayne Parrott, [proppy], Michael R. Bernstein +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# Notes: +# - Imported from https://github.com/jonparrott/Darth-Vendor/. +# - Added license header. +# - Renamed `darth.vendor` to `vendor.add` to match upcoming SDK interface. +# - Renamed `position` param to `index` to match upcoming SDK interface. +# - Removed funny arworks docstring. + +import site +import os.path +import sys + + +def add(folder, index=1): + """ + Adds the given folder to the python path. Supports namespaced packages. + By default, packages in the given folder take precedence over site-packages + and any previous path manipulations. + + Args: + folder: Path to the folder containing packages, relative to ``os.getcwd()`` + position: Where in ``sys.path`` to insert the vendor packages. By default + this is set to 1. It is inadvisable to set it to 0 as it will override + any modules in the current working directory. + """ + + # Check if the path contains a virtualenv. + site_dir = os.path.join(folder, 'lib', 'python' + sys.version[:3], 'site-packages') + if os.path.exists(site_dir): + folder = site_dir + # Otherwise it's just a normal path, make it absolute. + else: + folder = os.path.join(os.path.dirname(__file__), folder) + + # Use site.addsitedir() because it appropriately reads .pth + # files for namespaced packages. Unfortunately, there's not an + # option to choose where addsitedir() puts its paths in sys.path + # so we have to do a little bit of magic to make it play along. + + # We're going to grab the current sys.path and split it up into + # the first entry and then the rest. Essentially turning + # ['.', '/site-packages/x', 'site-packages/y'] + # into + # ['.'] and ['/site-packages/x', 'site-packages/y'] + # The reason for this is we want '.' to remain at the top of the + # list but we want our vendor files to override everything else. + sys.path, remainder = sys.path[:1], sys.path[1:] + + # Now we call addsitedir which will append our vendor directories + # to sys.path (which was truncated by the last step.) + site.addsitedir(folder) + + # Finally, we'll add the paths we removed back. + # The final product is something like this: + # ['.', '/vendor-folder', /site-packages/x', 'site-packages/y'] + sys.path.extend(remainder) \ No newline at end of file