-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBeerService.class.php
89 lines (74 loc) · 1.96 KB
/
BeerService.class.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
/**
* Created by PhpStorm.
* User: randyjp
* Date: 4/16/15
* Time: 3:50 PM
*/
class BeerService {
const WSDL = "http://simon.ist.rit.edu:8080/beer/BeerService?wsdl";
private $client;
function __construct(){
$options = array(
"trace" =>1,
"exception"=>1
);
try {
$this->client = new SoapClient(BeerService::WSDL, $options);
}
catch(SoapFault $e){
echo "Error with Soap";
var_dump($e);
}
}
public function getMethods()
{
try {
$methods = $this->client->getMethods();
}
catch(SoapFault $e){
echo "Error with Soap";
var_dump($e);
}
return "Methods are: " . implode(",",$methods->return);
}
public function getPrice($beer_name){
$params = array("arg0" =>$beer_name);
try {
return "The price for " . $beer_name . " is: $" . $this->client->getPrice($params)->return;
}
catch(SoapFault $e){
echo "Error with Soap";
var_dump($e);
}
}
public function getBeers($toPrint =false){
try {
$beers = $this->client->getBeers();
}
catch(SoapFault $e){
echo "Error with Soap";
var_dump($e);
}
if($toPrint) return "Available beers: " . implode(",",$beers->return);
return implode(",",$beers->return);
}
public function getCheapest(){
try {
return "The cheapest beer is: " . $this->client->getCheapest()->return;
}
catch(SoapFault $e){
echo "Error with Soap";
var_dump($e);
}
}
public function getCostliest(){
try {
return "The costliest beer is: " . $this->client->getCostliest()->return;
}
catch(SoapFault $e){
echo "Error with Soap";
var_dump($e);
}
}
}