#!/usr/bin/php -Cq 1 2 3 You have an invitation from Joe {msgid} Click here to review your invitation. '; echo "Sending a message via POST.. "; $ret = curlRest('/messages/1/outbox', $postData, 'application/atom+xml', 'POST'); if (! empty($ret)) { echo "FAILURE:\n[$ret]\n"; die(); } else { echo "OK\n"; } */ // ************** Set App Data using XML post payload ********************** // $postData = ' pokes 1 last_poke 2008-02-13T18:30:02Z '; echo "Setting pokes and last_poke app data using XML.. "; $ret = curlRest('/appdata/1/@self/1', $postData, 'application/xml'); if (! empty($ret)) { echo "FAILURE:\n[$ret]\n"; die(); } else { echo "OK\n"; // verify data was written correctly echo "Verifying XML set app data.. "; $ret = curlRest('/appdata/1/@self/1?fields=pokes,last_poke', '', 'application/json', 'GET'); $retDecoded = json_decode($ret, true); if ($ret == $retDecoded) { die("Invalid json string in return: $ret\n"); } if (isset($retDecoded['entry']) && isset($retDecoded['entry'][1]) && isset($retDecoded['entry'][1]['last_poke']) && isset($retDecoded['entry'][1]['pokes']) && $retDecoded['entry'][1]['last_poke'] == '2008-02-13T18:30:02Z' && $retDecoded['entry'][1]['pokes'] == '1') { echo "OK\n"; } else { echo "FAILURE, unexpected return value: $ret\n"; die(); } } // ************** Set App Data using ATOM post payload ********************** // $postData = ' 2 2003-12-14T18:30:02Z <updated>2003-12-14T18:30:02Z</updated> <author><url>urn:guid:example.org:34KJDCSKJN2HHF0DW20394</url></author> <id>urn:guid:example.org:34KJDCSKJN2HHF0DW20394</id> </entry>'; echo "Setting pokes and last_poke app data using Atom.. "; $ret = curlRest('/appdata/1/@self/1', $postData, 'application/atom+xml'); if (! empty($ret)) { echo "FAILURE:\n$ret\n\n"; die(); } else { echo "OK\n"; // verify data was written correctly echo "Verifying Atom set app data.. "; $ret = curlRest('/appdata/1/@self/1?fields=pokes,last_poke', '', 'application/json', 'GET'); $retDecoded = json_decode($ret, true); if ($ret == $retDecoded) { die("Invalid json string in return: $ret\n"); } if (isset($retDecoded['entry']) && isset($retDecoded['entry'][1]) && isset($retDecoded['entry'][1]['last_poke']) && isset($retDecoded['entry'][1]['pokes']) && $retDecoded['entry'][1]['last_poke'] == '2003-12-14T18:30:02Z' && $retDecoded['entry'][1]['pokes'] == '2') { echo "OK\n"; } else { echo "FAILURE, unexpected return value: $ret\n"; die(); } } // ************** Set App Data using JSON post payload ********************** // $postData = '{ "pokes" : 4, "last_poke" : "2008-06-13T18:30:02Z" }'; echo "Setting pokes and last_poke app data using JSON.. "; $ret = curlRest('/appdata/1/@self/1', $postData, 'application/json'); if (! empty($ret)) { echo "FAILURE:\n$ret\n\n"; die(); } else { echo "OK\n"; // verify data was written correctly echo "Verifying Atom set app data.. "; $ret = curlRest('/appdata/1/@self/1?fields=pokes,last_poke', '', 'application/json', 'GET'); $retDecoded = json_decode($ret, true); if ($ret == $retDecoded) { die("Invalid json string in return: $ret\n"); } if (isset($retDecoded['entry']) && isset($retDecoded['entry'][1]) && isset($retDecoded['entry'][1]['last_poke']) && isset($retDecoded['entry'][1]['pokes']) && $retDecoded['entry'][1]['last_poke'] == '2008-06-13T18:30:02Z' && $retDecoded['entry'][1]['pokes'] == '4') { echo "OK\n"; } else { echo "FAILURE, unexpected return value: $ret\n"; die(); } } // ************** Delete app data ********************** // echo "Deleting app data.. "; $ret = curlRest('/appdata/1/@self/1?fields=pokes,last_poke', '', 'application/json', 'DELETE'); if (! empty($ret)) { echo "FAILURE:\n$ret\n"; die(); } else { echo "OK\n"; } // ************** Create Activity using JSON post payload ********************** // echo "Creating activity using JSON.. "; $randomTitle = "[" . rand(0, 2048) . "] test activity"; $postData = '{ "id" : "http://example.org/activities/example.org:87ead8dead6beef/self/af3778", "title" : "' . $randomTitle . '", "updated" : "2008-02-20T23:35:37.266Z", "body" : "Some details for some activity", "bodyId" : "383777272", "url" : "http://api.example.org/activity/feeds/.../af3778", "userId" : "example.org:34KJDCSKJN2HHF0DW20394" }'; $ret = curlRest('/activities/1/@self', $postData, 'application/json'); if (! empty($ret)) { echo "FAILURE:\n$ret"; die(); } else { echo "OK\n"; // verify data was written correctly echo "Verifying JSON created activity.. "; $ret = curlRest('/activities/1/@self?count=20', '', 'application/json', 'GET'); $retDecoded = json_decode($ret, true); if ($ret == $retDecoded) { die("Invalid json string in return: $ret\n"); } $found = false; // see if we can find our just created activity if (isset($retDecoded['entry'])) { foreach ($retDecoded['entry'] as $entry) { if ($entry['title'] == $randomTitle) { $found = true; $activityId = $entry['id']; break; } } echo "OK\n"; } if (! $found) { echo "FAILURE, couldn't find activity, or unexpected return value: $ret\n"; die(); } else { echo "Deleting created activity.."; $ret = curlRest("/activities/1/@self/@app/$activityId", '', 'application/json', 'DELETE'); if (! empty($ret)) { die("FAILED\n"); } else { echo "OK\n"; } } } // ************** Create Activity using XML post payload ********************** // echo "Creating activity using XML.. "; $randomTitle = "[" . rand(0, 2048) . "] test activity"; $postData = '<activity xmlns="http://ns.opensocial.org/2008/opensocial"> <id>http://example.org/activities/example.org:87ead8dead6beef/self/af3778</id> <title>' . $randomTitle . ' 2008-02-20T23:35:37.266Z Some details for some activity 383777272 http://api.example.org/activity/feeds/.../af3778 example.org:34KJDCSKJN2HHF0DW20394 '; $ret = curlRest('/activities/1/@self', $postData, 'application/xml'); if (! empty($ret)) { echo "FAILURE:\n$ret"; die(); } else { echo "OK\n"; // verify data was written correctly echo "Verifying XML created activity.. "; $ret = curlRest('/activities/1/@self?count=4', '', 'application/json', 'GET'); $retDecoded = json_decode($ret, true); if ($ret == $retDecoded) { die("Invalid json string in return: $ret\n"); } $found = false; // see if we can find our just created activity if (isset($retDecoded['entry'])) { foreach ($retDecoded['entry'] as $entry) { if ($entry['title'] == $randomTitle) { $found = true; $activityId = $entry['id']; break; } } echo "OK\n"; } if (! $found) { echo "FAILURE, couldn't find activity, or unexpected return value: $ret\n"; die(); } else { echo "Deleting created activity.."; $ret = curlRest("/activities/1/@self/@app/$activityId", '', 'application/json', 'DELETE'); if (! empty($ret)) { die("FAILED\n"); } else { echo "OK\n"; } } } // ************** Create Activity using Atom post payload ********************** // echo "Creating activity using Atom.. "; $randomTitle = "[" . rand(0, 2048) . "] test activity"; $postData = ' http://example.org/activities/example.org:87ead8dead6beef/self/af3778 ' . $randomTitle . ' Some details for some activity 2008-02-20T23:35:37.266Z urn:guid:example.org:34KJDCSKJN2HHF0DW20394 383777272 '; $ret = curlRest('/activities/1/@self', $postData, 'application/atom+xml'); if (! empty($ret)) { echo "FAILURE:\n$ret"; die(); } else { echo "OK\n"; // verify data was written correctly echo "Verifying Atom created activity.. "; $ret = curlRest('/activities/1/@self?count=4', '', 'application/json', 'GET'); $retDecoded = json_decode($ret, true); if ($ret == $retDecoded) { die("Invalid json string in return: $ret\n"); } $found = false; // see if we can find our just created activity if (isset($retDecoded['entry'])) { foreach ($retDecoded['entry'] as $entry) { if ($entry['title'] == $randomTitle) { $found = true; $activityId = $entry['id']; break; } } echo "OK\n"; } if (! $found) { echo "FAILURE, couldn't find activity, or unexpected return value: $ret\n"; die(); } else { echo "Deleting created activity.."; $ret = curlRest("/activities/1/@self/@app/$activityId", '', 'application/json', 'DELETE'); if (! empty($ret)) { die("FAILED: $ret\n"); } else { echo "OK\n"; } } }