-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathgetPets.php
61 lines (51 loc) · 1.63 KB
/
getPets.php
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
<?php
// getPets.php
// A bit like getPet.php, except it can deal with multiple pets.
// Instead of just printing the pets, it turns each one into an instance
// of the new custom object type 'Pet' and adds them to the $pets array
include_once 'getHousehold.php';
include_once 'pet_class.php';
$ch = curl_init($endpoint."/api/household/$household/pet");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Authorization: Bearer $token"));
$result = json_decode(curl_exec($ch),true) or die("Curl Failed\n");
//print "creating array\n";
$pets = array();
if($result['data']) {
foreach ($result['data'] as $currentpet) {
// Create a new instance of type 'pet' and populate with returned data
//print "Found a new pet... creating object\n";
$pet = new Pet();
$pet->pet_name = $currentpet['name'];
$pet->pet_id = $currentpet['id'];
if(isset($currentpet['comments'])) {
$pet->pet_description = $currentpet['comments'];
}
if(isset($currentpet['date_of_birth'])) {
$pet->pet_dob = substr($currentpet['date_of_birth'],0,10);
}
if(isset($currentpet['weight'])) {
$pet->pet_weight = $currentpet['weight']." KG";
}
if($currentpet['gender']=="0") {
$pet->pet_gender = "Female";
} else {
$pet->pet_gender = "Male";
}
if($currentpet['species_id']=="2") {
$pet->pet_species = "Dog";
} else {
$pet->pet_species = "Cat";
}
// Add to array of pets
$pets[] = $pet;
}
foreach($pets as $currentpet) {
print_if_needed($currentpet->pet_id . ": " . $currentpet->pet_name . "\n",$suppression);
}
// How many pet objects?
//print count($pets);
} else {
die("No Pets!\n");
}
?>