-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexample.php
More file actions
62 lines (45 loc) · 1.33 KB
/
example.php
File metadata and controls
62 lines (45 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
use Alegra\Api;
use Alegra\Contact;
use GuzzleHttp\Exception\ClientException;
use GuzzleHttp\Exception\ServerException;
use GuzzleHttp\Exception\ConnectException;
use GuzzleHttp\Exception\RequestException;
require './vendor/autoload.php';
Api::auth('Your user', 'Your api token');
try {
// Save using create method
$contact = Contact::create(['name' => 'Your contact name']); // Create the contact
// Save using instance
$contact = new Contact;
$contact->name = 'My second contact';
$contact->save(); // Update the contact
// Update an existing contact
$contact = Contact::get(1); // where 1 is the id of resource.
$contact->identification = '900.123.123-8';
$contact->email = 'email@server.com';
$contact->save();
// Get all contacts
$contacts = Contact::all();
$contacts->each(function ($contact) {
print_r($contact);
});
// Get a delete
$contact = Contact::get(1);
$contact->delete();
// Delete without get
$contact = new Contact(1);
$contact->delete();
// Delete using static interface
Contact::delete(1);
} catch (ClientException $e) { // 4.x
// code
} catch (ServerException $e) { // 5.x
// code
} catch (ConnectException $e) {
// code
} catch (RequestException $e) {
// code
} catch (Exception $e) {
// code
}