Heal Your Church WebSite


Teaching, rebuking, correcting & training in righteous web design.

Cleaning-up the BibleGateway SOAP example

On the page entitled ‘How to display the Verse of the Day on your Web site,’ the good folks at the BibleGateway describe how to leverage the NuSOAP toolkit to consume the verse of the day SOAP-based web service using PHP. Unfortunately, their demo code is a bit buggy and when fixed, doesn’t render a result really helpful to a casual developer. This post ‘cleans-up’ this cruft to help you better incorporate the BibleGateway’ verse of the day on your church’s website.

Speaking Pure Geek

I know, I know, for some of you I might as well be speaking ancient Greek … or geek depending on your perspective. But I also need to throw a bone to some of the die-hard HYCW cult members who’ve been craving for a coding sample, not really having offered one for about a year now.

So bear with me as I describe how to use the PHP NuSOAP library to incorporate the Bible Gateway’s verse of the day onto your church web site.

Prep Work:

Assuming you have ‘shell’ access (via Putty), execute the following steps:

  1. mkdir nusoap
  2. cd nusoap
  3. wget http:///sourceforge/nusoap/nusoap-0.7.2.zip
  4. unzip nusoap-0.7.2.zip
  5. cd samples
  6. pwd (this last command is optional – can cut-n-paste the path if you want)

Edit Work:

Leaving your shell session/window open, now open your browser and go to the BibleGateway ‘how-to’ page and copy their sample under ‘2) Add the Verse of the Day code to your website‘ into your computer’s clipboard.

Now back to your shell session, create a .php file to run the SOAP client, e.g.:

  1. nano bg-votd.php

Once pasted, implement the following changes

  1. modify line# 15 so it reads:
    require_once('../lib/nusoap.php');
  2. fix the bug between lines 23 & 25 from:
    'options'=>array('include-copyright'=>'both')
    )
    );
  3. to:
    'options'=>array('include-copyright'=>'both')
    );
  4. modify line 34 so it reads:
    print header('Content-Type: text/plain');
    var_dump($results);

Plug-n-pray!

Okay, now you should be ready to run your sample … for example, here’s my result set:
http://healyourchurchwebsite.com/nusoap/samples/bg-votd.php

Once you get that to work, you may want too add requests strings to support different versions, other API arguments and/or infuse related services.

Then all that is left is rendering the array members in HTML – hopefully using stunningly stellar semantic HTML.

If you do, let us know. In the meantime, enjoy the my cleaned-up code sample below:

<?php
/**
* Display Bible Gateway Verse of the Day.
* original: http://www.biblegateway.com/usage/votd/docs/
* implements: http://sourceforge.net/projects/nusoap/
* modified/updated:
*		Dean Peters
*		11-Jul-2007
*		modified library path in original on line #15
*		fixed bug in original on line #24
*		modified output in original on line #34
*		additional documentation:
*		http://healyourchurchwebsite.com
*			/2007/07/11/cleaning-up_the_bibleGateway_sOAP_example
*/

/* display SOAP errors */
function showErrors( $soapclient, $results ) {
echo 'Request: <xmp>'.$soapclient->request.'</xmp>';
echo 'Response: <xmp>'.$soapclient->response.'</xmp>';
echo 'Debug log: <pre>'.$soapclient->debug_str.'</pre>';
echo $results['faultstring'];
}

/* load NuSOAP library */
/* dp 11jul07 : path updated to reflect nusoap distribution defaults */
require_once('../lib/nusoap.php');

/* create new soap client */
$soapclient = new soapclient('http://www.biblegateway.com/usage/votd/');

/* set parameter values */
/* dp 11jul07 : removed buggy extra parenthesis */
$parameters= array('preferences'=>array('version_id'=>'31',
'utc_offset'=>'-5'),
'options'=>array('include-copyright'=>'both')
);

/* call service and get verse of the day */
$results = $soapclient->call('doGetVotd',$parameters);

/* display verse of the day */
/* dp 11jul07 : modified output on good load  */
if($err = $soapclient->getError()){
showErrors($soapclient, $results);
} else {
print header('Content-Type: text/plain');
var_dump($results);
}
?>

Or for those who’ve read this article to the bitter-end, you can skip steps 6-11 and just wget the text-file version here.

3 Comments

  1. Interesting post. I recently built a Joomla component based on the BibleGateway VOTD. If I remember right there were a number of errors on their example pages including fundamental errors like the SOAP API was different in their tutorial vs the full documentation. I emailed them with the changes and it looks like they implemented some, but as you found, not all of the changes. Oh well. Thanks for your post

  2. I fixed the little errors on my own, but wouldn’t have had a clue about the output line without your help. Thx!

    I get output from my PHP file that looks, well, a little raw. I put a snippet below.

    Do I need XML etc., and if so, how? (When I click on your result set, it just loads your regular blog page)

    array(2) {
    ["details"]=>
    array(4) {
    ["verseurl"]=>
    string(74) “http://www.biblegateway.com/passage/?version=9&search=Luke 1:46-47, 49″
    ["audiourl"]=>
    .
    .
    .
    string(182) ““And Mary said,
    }
    }

  3. Pingback: Zipsites Official Blog - Create Your Own Mashup