cc-4105: clean up url construction in api client
This commit is contained in:
parent
0fd6c4adbf
commit
44d91f7798
|
@ -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
|
//The key does not have any meaning as of yet but it could potentially correspond
|
||||||
//to some unique id.
|
//to some unique id.
|
||||||
$responses = array();
|
$responses = array();
|
||||||
|
Logging::log("inside reloadMetadataGroupAction");
|
||||||
|
return;
|
||||||
foreach ($request->getRequest()->getParams() as $action => $raw_json) {
|
foreach ($request->getRequest()->getParams() as $action => $raw_json) {
|
||||||
$info_json = json_decode($raw_json, $assoc=true);
|
$info_json = json_decode($raw_json, $assoc=true);
|
||||||
array_push($responses, $this->dispatchMetaDataAction($info_json, $info_json['mode']));
|
array_push($responses, $this->dispatchMetaDataAction($info_json, $info_json['mode']));
|
||||||
|
Logging::log( $info_json );
|
||||||
}
|
}
|
||||||
// TODO : do something with $responses here instead of doing nothing
|
// TODO : do something with $responses here instead of doing nothing
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
# You will probably want to create a script on your server side to automatically
|
# You will probably want to create a script on your server side to automatically
|
||||||
# schedule a playlist one minute from the current time.
|
# schedule a playlist one minute from the current time.
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
import urllib
|
import urllib
|
||||||
|
@ -312,33 +311,36 @@ class AirTimeApiClient():
|
||||||
|
|
||||||
return response
|
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):
|
def setup_media_monitor(self):
|
||||||
logger = self.logger
|
logger = self.logger
|
||||||
|
|
||||||
response = None
|
response = None
|
||||||
try:
|
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 = self.construct_url("media_setup_url")
|
||||||
url = url.replace("%%api_key%%", self.config["api_key"])
|
|
||||||
|
|
||||||
response = self.get_response_from_server(url)
|
response = self.get_response_from_server(url)
|
||||||
response = json.loads(response)
|
response = json.loads(response)
|
||||||
logger.info("Connected to Airtime Server. Json Media Storage Dir: %s", response)
|
logger.info("Connected to Airtime Server. Json Media Storage Dir: %s", response)
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
response = None
|
response = None
|
||||||
logger.error("Exception: %s", e)
|
logger.error("Exception: %s", e)
|
||||||
|
|
||||||
return response
|
return response
|
||||||
|
|
||||||
def update_media_metadata(self, md, mode, is_record=False):
|
def update_media_metadata(self, md, mode, is_record=False):
|
||||||
logger = self.logger
|
logger = self.logger
|
||||||
response = None
|
response = None
|
||||||
try:
|
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 = self.construct_url("update_media_url")
|
||||||
url = url.replace("%%api_key%%", self.config["api_key"])
|
|
||||||
url = url.replace("%%mode%%", mode)
|
url = url.replace("%%mode%%", mode)
|
||||||
|
|
||||||
md = convert_dict_value_to_utf8(md)
|
md = convert_dict_value_to_utf8(md)
|
||||||
|
|
||||||
|
|
||||||
data = urllib.urlencode(md)
|
data = urllib.urlencode(md)
|
||||||
req = urllib2.Request(url, data)
|
req = urllib2.Request(url, data)
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,7 @@ class LazyProperty(object):
|
||||||
setattr(obj,self.func_name,value)
|
setattr(obj,self.func_name,value)
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
|
||||||
class IncludeOnly(object):
|
class IncludeOnly(object):
|
||||||
"""
|
"""
|
||||||
A little decorator to help listeners only be called on extensions they support
|
A little decorator to help listeners only be called on extensions they support
|
||||||
|
|
|
@ -20,6 +20,7 @@ channels = {
|
||||||
org = Organizer(channel=channels['org'],target_path=channels['watch'].path)
|
org = Organizer(channel=channels['org'],target_path=channels['watch'].path)
|
||||||
watch = WatchSyncer(channel=channels['watch'])
|
watch = WatchSyncer(channel=channels['watch'])
|
||||||
problem_files = ProblemFileHandler(channel=channels['badfile'])
|
problem_files = ProblemFileHandler(channel=channels['badfile'])
|
||||||
|
|
||||||
# do the bootstrapping before any listening is going one
|
# do the bootstrapping before any listening is going one
|
||||||
#conn = Connection('localhost', 'more', 'shit', 'here')
|
#conn = Connection('localhost', 'more', 'shit', 'here')
|
||||||
#db = DBDumper(conn).dump_block()
|
#db = DBDumper(conn).dump_block()
|
||||||
|
|
Loading…
Reference in New Issue