Handy helper PHP class

20 views
Skip to first unread message

Mark Christian

unread,
Jan 11, 2009, 4:58:12 PM1/11/09
to PBwiki API Hackers
Howdy, folks;
I've been looking for a side project to occupy my non-PBwiki hours,
but of course my thoughts drifted to PBwiki-related things.

To help make working with the PBwiki API a bit easier, I've put
together a really simple wrapper class in PHP. As long as your server
has the CURL extension installed, you should be able to use this. It
includes a simple demo web page to show how it works.

Now, keep in mind, this is a personal project, not endorsed or
supported by PBwiki. You can use it for whatever you want to —
suggestions and improvements are welcome. Good luck!

— Mark

demo.png
pbwikiapi.zip

GotInc

unread,
Feb 7, 2009, 12:12:24 PM2/7/09
to PBwiki API Hackers
Mark--

Thanks for sharing a very useful approach. This API provides excellent
possibilities.

Before reading PBwiki API Hackers group, using the API Documentation
as my guide, yielded the following code concept snippet below.

Used the curl class curl.php found here: http://github.com/shuber/curl/tree/master
which is a curl wrapper mentioned on php.net. http://www.php.net/manual/en/ref.curl.php
Download the class (changed from .php to .inc), read the docs, must
have curl installed.

// Produces contents of body of FrontPage in html which could be
embedded in an application.
<code>
<?php
require_once 'curl.inc';
$curl = new Curl;
$url = "https://wikiname.pbwiki.com/api_v2/";
$vars = array(
"op" => "GetPage",
"page" => "FrontPage",
"_type" => "html",
"read_key" => "apikey";
);
$response = $curl->post($url, $vars);
// print_r($response->headers);
echo $response;
?>
</code>

// replace wikiname with your wiki name
// replace apikey with your pbwiki api read key
// you can replace FrontPage with any other valid page name
// uncomment the print_r... line to see headers

Try different "op" values in the array like GetBundle and GetOps
(remove the "page" key and value when doing this), and try changeing
"_type" to "text" or "jsontext" or "xml" till you get the results you
desire. From here you can quickly change and see how you are
interacting with the API. Your $vars array would look like this to
GetBundle.

<code> // array for GetBundle
$vars = array(
"op" => "GetBundle",
"_type" => "text",
"read_key" => "apikey";
);
<code>

Keep in mind when you use text you get a string that looks like and
array when done this way. It allows you to quickly test out various
API calls and see the results in a human readable fashion. There's
code in Marks demo to take the jsontext and get an array. And
according to Sean Huber's curl.php docs, $curl->cookie_file =
'some_other_filename'; should allow an entry point for maintaining
sessions across requests.

--WW


On Jan 11, 4:58 pm, "Mark Christian" <mark.christ...@pbwiki.com>
wrote:
>  demo.png
> 160KViewDownload
>
>  pbwikiapi.zip
> 153KViewDownload

Mark Christian

unread,
Feb 9, 2009, 1:29:09 AM2/9/09
to 2wa...@gmail.com, PBwiki API Hackers
Excellent. If I had known about that Curl wrapper, I would've used it
rather than the homebrew one (which, fortunately, was just lying
around my hard drive). Let me know if you hack together anything.

Cheers;
— Mark
Reply all
Reply to author
Forward
0 new messages