Skip to content

Commit

Permalink
Added docs for listening to events.
Browse files Browse the repository at this point in the history
  • Loading branch information
typerandom committed Jun 20, 2014
1 parent 38e1d51 commit e942706
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,20 @@ Since the version has been explicitly specified using options, the call will be
Since the version has been explicitly specified, the call will be made against version `3`.

$api->v3->user->login(array("login" => "test", "password" => "test"));

## Events

This library emits the following events:

* **success** Emitted when a call succeeds.
* **error** Emitted when a call results in an error.
* **unauthorized** Emitted when a call results in an authentication error. Emitted before emitting the *error* event.

### Listening to events

$api->on('success', function($sender, $call_context, $result){
echo(sprintf("Call to %s.%s resulted in %s", $call_context->service, $call_context->method, json_encode($result)));
});

## Error handling

Expand Down Expand Up @@ -235,6 +249,21 @@ Setting `throw_errors` to `false` is more of a way to tell the client to be sile
}
}

### Intercepting errors with events

#### All errors

$api->on('error', function($sender, $call_context, $error){
echo(sprintf("Call to %s.%s resulted in error %s (%s)", $call_context->service, $call_context->method, $error->message, $error->error_code)));
});

#### Only unauthorized events

$api->on('unauthorized', function($sender, $call_context, $error){
header("Location: /login.php");
die();
});

## Solving issues

### See what is being sent to/from UserApp
Expand Down Expand Up @@ -285,6 +314,7 @@ Is exactly the same as:

* PHP >= 5.3.2
* [cURL](http://php.net/manual/en/book.curl.php)
* [sabre/event](https://github.com/fruux/sabre-event)

## License

Expand Down

0 comments on commit e942706

Please sign in to comment.