cc-4105: clean up url construction in api client

This commit is contained in:
Rudi Grinberg 2012-07-13 16:32:17 -04:00 committed by Martin Konecny
parent 0fd6c4adbf
commit 44d91f7798
4 changed files with 15 additions and 8 deletions

View File

@ -550,9 +550,12 @@ class ApiController extends Zend_Controller_Action
//The key does not have any meaning as of yet but it could potentially correspond
//to some unique id.
$responses = array();
Logging::log("inside reloadMetadataGroupAction");
return;
foreach ($request->getRequest()->getParams() as $action => $raw_json) {
$info_json = json_decode($raw_json, $assoc=true);
array_push($responses, $this->dispatchMetaDataAction($info_json, $info_json['mode']));
Logging::log( $info_json );
}
// TODO : do something with $responses here instead of doing nothing
}

View File

@ -6,7 +6,6 @@
# You will probably want to create a script on your server side to automatically
# schedule a playlist one minute from the current time.
###############################################################################
import sys
import time
import urllib
@ -312,33 +311,36 @@ class AirTimeApiClient():
return response
def construct_url(self,config_action_key):
"""Constructs the base url for every request"""
# TODO : Make other methods in this class use this this method.
url = "http://%s:%s/%s/%s" % (self.config["base_url"], str(self.config["base_port"]), self.config["api_base"], self.config[config_action_key])
url = url.replace("%%api_key%%", self.config["api_key"])
return url
def setup_media_monitor(self):
logger = self.logger
response = None
try:
url = "http://%s:%s/%s/%s" % (self.config["base_url"], str(self.config["base_port"]), self.config["api_base"], self.config["media_setup_url"])
url = url.replace("%%api_key%%", self.config["api_key"])
url = self.construct_url("media_setup_url")
response = self.get_response_from_server(url)
response = json.loads(response)
logger.info("Connected to Airtime Server. Json Media Storage Dir: %s", response)
except Exception, e:
response = None
logger.error("Exception: %s", e)
return response
def update_media_metadata(self, md, mode, is_record=False):
logger = self.logger
response = None
try:
url = "http://%s:%s/%s/%s" % (self.config["base_url"], str(self.config["base_port"]), self.config["api_base"], self.config["update_media_url"])
url = url.replace("%%api_key%%", self.config["api_key"])
url = self.construct_url("update_media_url")
url = url.replace("%%mode%%", mode)
md = convert_dict_value_to_utf8(md)
data = urllib.urlencode(md)
req = urllib2.Request(url, data)

View File

@ -20,6 +20,7 @@ class LazyProperty(object):
setattr(obj,self.func_name,value)
return value
class IncludeOnly(object):
"""
A little decorator to help listeners only be called on extensions they support

View File

@ -20,6 +20,7 @@ channels = {
org = Organizer(channel=channels['org'],target_path=channels['watch'].path)
watch = WatchSyncer(channel=channels['watch'])
problem_files = ProblemFileHandler(channel=channels['badfile'])
# do the bootstrapping before any listening is going one
#conn = Connection('localhost', 'more', 'shit', 'here')
#db = DBDumper(conn).dump_block()