3

I have a news provider who sends me non-RSS XML feeds through HTTP requests that then need to be parsed to be used on my site. However, my first request to the external server always has to be an authentication request which expires after 24 hrs. The authentication ID gets sent back to me as an XML tag attribute in the source code of an otherwise empty document. I then have to include this ID with every news request I send back to the news server.

Is there any way to automate this entire process through a series of Drupal 6 modules, or is it just best to write the code directly in the template files and schedule a daily task to request the authentication ID?

1 Answer 1

1

You could write a module where you implement hook_cron() to get the authentication ID and then store in the drupal DB (e.g. as variable via variable_set()). After that you can use it inside your templates without any worry. But you have to trigger your cron.php once a day via a sytem cron-job or the poormanscron module. For PHP xml-parsing take a look at SimpleXML.

EDIT: Module creation:

For this job it would be a simple module. Take a look at the module-dev-guide. First you create a YOURMODULE.info file. After that you put your code inside a YOURMODULE.module file. Than implement that hook_cron() like that:

function YOURMODULE_cron() {
     update_news_service_id();
}

function update_news_service_id() {
    // add your code here
}

One more comment: If you try to solve it this way you must consider calling update_news_service_id() from the template (or ..._preprocess()) if you run into an expired service id-error.

1
  • OK thanks... is it difficult writing my own hook_cron module? I really don't have any experience writing modules as I'm much more of a themer than a developer. Thank you for your help!
    – Jane
    May 14, 2011 at 17:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.