-
Notifications
You must be signed in to change notification settings - Fork 30
Eseye Simple Tutorial
This page will walk through a simple example of using Eseye to retrieve character information. It is assumed that you have composer installed and ready to use as this is the recommended way of getting Eseye.
The first thing we need is to install Eseye itself. Do this by following the following installation guide: Installation
Before we get to actually writing code, we need to get a Client ID, Secret key and a refresh token to use in the library. Do that by following this guide: Getting A Refresh Token
With all of the requirements met, lets start a simple example. We will begin by quickly talking about the basic steps/components we need. Those are:
You need handy:
- Your Client ID and Secret Key from the developers site.
- A refresh token.
We will use these by:
- Including the composer autoloader.
- Instantiating a new
EsiAuthentication
object with your Client ID, Secret Key and refresh token. - Instantiating a new
Eseye
object with the previously createdEsiAuthentication
object as argument. - Make some calls :D
So lets start. As mentioned in the previous section, we need to have the autoloader included and the Client ID, Secret Key and refresh token ready. Lets do that.
<?php
include 'vendor/autoload.php';
$client_id = 'client_id_string';
$secret_key = 'secret_key_string';
$refresh_token = 'refresh_token_string';
Next, we instantiate a new EsiAuthentication
instance with our values:
$authentication = new \Seat\Eseye\Containers\EsiAuthentication([
'client_id' => $client_id,
'secret' => $secret_key,
'refresh_token' => $refresh_token,
]);
Great. We instantiate a new Eseye
instance with the authentication information as argument:
$esi = new \Seat\Eseye\Eseye($authentication);
This leaves us with an ESI instance in the $esi
variable ready to make calls with! Lets make a call now to get some character information. For reference, the call itself is described on the EVE Swagger Interface here. Translating that into something Eseye will understand will look as follows:
$character_info = $esi->invoke('get', '/characters/{character_id}/', [
'character_id' => 1477919642,
]);
Lets take a closer look at the invoke()
method to understand it better.
Calls are made to the ESI service using the invoke()
method on an Eseye
object. The invoke()
method accepts 3 arguments as described below (or this line of code):
string $method, string $uri, array $uri_data = []
This can also be seen as:
$esi->invoke($method, $uri, $uri_data)`;
First we provide the $method
(eg: GET
, POST
, PUT
, DELETE
), next the $uri
as described on the EVE Swagger Interface, and finally the $uri_data
to place in URI values as an array. In the case of the URI /characters/{character_id}/
, the second array is simply ['character_id' => 1477919642]
so that the character_id
in the URI is replaced with 1477919642. If the endpoint does not require values in the URI, then the third argument can just be left out.
NOTE: It is also possible to set query string and body values using ->setQueryString()
and ->setBody()
respectively.
So to summarise; the definition according to ESI is using the GET
method on the /characters/{character_id}/
URI. Considering what we just learnt about the invoke()
method, it is then safe to assume that this will translate to:
$esi->invoke('get', '/characters/{character_id}/', ['character_id' => 1477919642]);
When the call is made, the variable $character_info
in our example will contain the response that we can use to extract data. The response itself is a PHP object, where you can extract values just as if you were working with class properties.
For example; to get the name from the data that is now in $character_info
, we would simply get it by using:
$name = $character_info->name;
With all of that said, a full example as described above would therefore be:
<?php
// Eseye - Simple Tutorial
include 'vendor/autoload.php';
$client_id = 'client_id_string';
$secret_key = 'secret_key_string';
$refresh_token = 'refresh_token_string';
$authentication = new \Seat\Eseye\Containers\EsiAuthentication([
'client_id' => $client_id,
'secret' => $secret_key,
'refresh_token' => $refresh_token,
]);
$esi = new \Seat\Eseye\Eseye($authentication);
$character_info = $esi->invoke('get', '/characters/{character_id}/', [
'character_id' => 1477919642,
]);
echo $character_info->name;