gladiopeace / opensocial-php-client

Automatically exported from code.google.com/p/opensocial-php-client
Apache License 2.0
0 stars 0 forks source link

Constructing the osapi object is difficult #31

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
The code in _examples_common shows how ugly making an instance of osapi can
be, particularly for the three legged oauth case:

    $storage = new osapiFileStorage('/tmp/osapi/');
    $provider = new osapiXrdsProvider('http://www.partuza.nl/', $storage);
    $auth = osapiOAuth3Legged::performOAuthLogin($key, $secret, $storage,
$provider, $localUserId);
    $osapi = new osapi($provider, $auth);

Particularly, it feeds wrong to have to create a storage, pass the storage
to the provider's constructor, create an auth with both the storage and
provider, and then pass the auth and the provider to the osapi constructor.
 A much simpler approach would be to have:

    $osapi = new osapi();
    $osapi->setStorage(new osapiFileStorage('/tmp/osapi/'));
    $osapi->setProvider(new osapiXrdsProvider('http://www.partuza.nl'));
    $osapi->setAuth(osapiOAuth3Legged::performOAuthLogin($key, $secret,
$localUserId));

Storage/Provider/Auth objects should have setOsapi methods to allow them to
get back to the containing osapi parent object.  This way if the auth
object needs storage, it can call $this->getOsapi()->getStorage();

There should be static convenience methods for obtaining an osapi object
with sensible defaults:
osapiOrkutProvider::getOsapi($key, $secret);  

Original issue reported on code.google.com by api.kurrik%google.com@gtempaccount.com on 25 Mar 2009 at 10:39