Fab1en / rocket-chat-rest-client

Rocket Chat REST API client in PHP
49 stars 38 forks source link

Return object response data after login #10

Open albanafmeti opened 7 years ago

albanafmeti commented 7 years ago

Why returning true when somebody may need more information for example authToken ? The returned object is different from false so I think it will be fine returning the object $response->body->data.

Fab1en commented 7 years ago

Thanks for collaborating @albanafmeti ! I chose to encapsulate a maximum of the login logic inside the API objects, so that it's straightforward to use it. Concerning the Auth Token, I save it when the login method is called with $save_auth=true :

if( $save_auth) {
    // save auth token for future requests
    $tmp = Request::init()
        ->addHeader('X-Auth-Token', $response->body->data->authToken)
        ->addHeader('X-User-Id', $response->body->data->userId);
    Request::ini( $tmp );
}

Doing this will ship the auth token automatically with following requests, so you don't have to worry about it.

If you need the auth token outside the login method, you can get it from the Request :

$token = Request::init()->headers["X-Auth-Token"];
albanafmeti commented 7 years ago

Check this out https://github.com/albanafmeti/rocket-chat