cc-4105: added a method in API client corresponding to chunked requests.\nAlso add prepared corresponding apicontroller method

This commit is contained in:
Rudi Grinberg 2012-07-13 17:57:18 -04:00
parent 47893865cc
commit 8340079b95
3 changed files with 33 additions and 16 deletions

View File

@ -32,6 +32,7 @@ class ApiController extends Zend_Controller_Action
->addActionContext('update-source-status', 'json')
->addActionContext('get-bootstrap-info', 'json')
->addActionContext('get-files-without-replay-gain', 'json')
->addActionContext('reload-metadata-group', 'json')
->initContext();
}
@ -576,14 +577,16 @@ 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) {
foreach ($request->getParams() as $k => $raw_json) {
$info_json = json_decode($raw_json, $assoc=true);
array_push($responses, $this->dispatchMetaDataAction($info_json, $info_json['mode']));
$mode = $info_json['mode'];
unset($info_json['mode']);
// TODO : uncomment the following line to actually do something
// array_push($responses, $this->dispatchMetaDataAction($info_json, $info_json['mode']));
// Like wise, remove the following line when done
Logging::log( $info_json );
}
// TODO : do something with $responses here instead of doing nothing
die(json_encode( array('successes' => 19, 'fails' => 123) ));
}
public function reloadMetadataAction() {

View File

@ -64,6 +64,10 @@ show_schedule_url = 'recorded-shows/format/json/api_key/%%api_key%%'
# URL to upload the recorded show's file to Airtime
upload_file_url = 'upload-file/format/json/api_key/%%api_key%%'
# URL to commit multiple updates from media monitor at the same time
reload_metadata_group = 'reload-metadata-group/format/json/api_key/%%api_key%%'
#number of retries to upload file if connection problem
upload_retries = 3

View File

@ -340,7 +340,6 @@ class AirTimeApiClient():
md = convert_dict_value_to_utf8(md)
data = urllib.urlencode(md)
req = urllib2.Request(url, data)
@ -364,23 +363,34 @@ class AirTimeApiClient():
return response
def send_media_monitor_requests(self, md_list, mode, is_record=False):
def send_media_monitor_requests(self, action_list, 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 = url.replace("%%mode%%", mode)
md_list = convert_dict_value_to_utf8(md_list)
url = self.construct_url('reload_metadata_group')
# We are assuming that action_list is a list of dictionaries such
# that every dictionary represents the metadata of a file along
# with a special mode key that is the action to be executed by the
# controller.
valid_actions = []
# We could get a list of valid_actions in a much shorter way using
# filter but here we prefer a little more verbosity to help
# debugging
for action in action_list:
if not 'mode' in action:
self.logger.debug("Warning: Sending a request element without a 'mode'")
self.logger.debug("Here is the the request: '%s'" % str(action) )
else: valid_actions.append(action)
md_list = { i : json.dumps(convert_dict_value_to_utf8(md)) for i,md in enumerate(valid_actions) }
data = urllib.urlencode(md_list)
req = urllib2.Request(url, data)
response = self.get_response_from_server(req)
logger.info("update media %s, filepath: %s, mode: %s", response, md_list['MDATA_KEY_FILEPATH'], mode)
# We no longer have a single mode for every http request.
#logger.info("update media %s, filepath: %s, mode: %s", response, md_list['MDATA_KEY_FILEPATH'], mode)
response = json.loads(response)
# TODO : this request returns a more detailed response of what
# happened through a json array. Hence we should handle errors
# differently
if("error" not in response and is_record):
url = "http://%s:%s/%s/%s" % (self.config["base_url"], str(self.config["base_port"]), self.config["api_base"], self.config["upload_recorded"])
url = url.replace("%%fileid%%", str(response[u'id']))