-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathclass.wspakkeshop.php
175 lines (159 loc) · 5.26 KB
/
class.wspakkeshop.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
<?php
/**
* This class will enable access to the GLS Pakkeshop webservcie.
* The service descriptio is located at http://www.gls.dk/webservices_v2/wsPakkeshop.asmx
* Methods available in this class matches technical documentation v.1.0.0.2 from GLS.
*
* Requirements:
* PHP 5 with
* --enable-libxml
* --enable-soap
*
* @author Dan Storm
* @created 15/01/2012
* @info http://catalystcode.net
* @version 1.0
*/
class wsPakkeshop
{
private $client, $encoding, $country;
public $error;
/**
* This is the constructor method.
* This starts the SoapClient to GLS wsPakkeshop SOAP service.
*
* @access public
* @params string The country you want to search in, defaults to DK (valid values is compliant with ISO 3166-2)
* @params string The encoding you wish to use - default is ISO-8859-1.
*/
public function __construct($country = 'DK', $encoding = 'ISO-8859-1')
{
$this->country = $country;
$this->client = new SoapClient("http://www.gls.dk/webservices_v3/wsShopFinder.asmx?WSDL", array('trace' => 1, 'encoding' => $encoding));
}
/**
* This method returns an array of objects with all
* registrered parcel shops.
*
* @access public
* @return mixed An array of objects or boolean false if service call failed.
*/
public function GetAllParcelShops()
{
try
{
$shops = $this->client->GetAllParcelShops(array( 'countryIso3166A2' => $this->country ));
return $shops->GetAllParcelShopsResult->PakkeshopData;
}
catch(Exception $e)
{
$this->error = __METHOD__.': '.$e->getMessage();
return false;
}
}
/**
*
* This method returns an array of objects with parcel shops
* near the exact address specfied. The street name and number
* needs to be provided for this to work.
* The service call will fail is address doesn't exist.
*
* @acess public
* @param string Exact street address with streetnumber
* @param int The zipcode for the provided address
* @param int The amount of parcel shops returned - default is 5.
* @return mixed An array of objects or boolean false if service call failed.
*/
public function GetParcelShopDropPoint( $street, $zipcode, $amount = 5)
{
try
{
$shops = $this->client->GetParcelShopDropPoint(array('street' => $street, 'zipcode' => $zipcode, 'countryIso3166A2' => $this->country, 'Amount' => $amount));
return $shops->GetNearstParcelShopsResult->parcelshops->PakkeshopData;
}
catch(Exception $e)
{
$this->error = __METHOD__.': '.$e->getMessage();
return false;
}
}
/**
* This method returns an object for the specific parcel shop from it's
* parcel shop number.
*
* @access public
* @param int The number of the parcel shop.
* @return mixed An object of the parcel shop or boolean false if service call failed.
*/
public function GetOneParcelShop( $ParcelShopNumber )
{
try
{
$shop = $this->client->GetOneParcelShop(array('ParcelShopNumber' => $ParcelShopNumber));
return $shop->GetOneParcelShopResult;
}
catch(Exception $e)
{
$this->error = __METHOD__.': '.$e->getMessage();
return false;
}
}
/**
* This method returns an array of objects with parcel shops
* near in the specified zipcode.
*
* @access public
* @param int The zipcode to find parcel shops in.
* @return mixed An array of objects or boolean false if service call failed.
*/
public function GetParcelShopsInZipcode( $zipcode )
{
try
{
$shops = $this->client->GetParcelShopsInZipcode(array('zipcode' => $zipcode, 'countryIso3166A2' => $this->country));
if(isset($shops->GetParcelShopsInZipcodeResult->PakkeshopData))
{
if(!is_array($shops->GetParcelShopsInZipcodeResult->PakkeshopData))
return array($shops->GetParcelShopsInZipcodeResult->PakkeshopData);
else
return $shops->GetParcelShopsInZipcodeResult->PakkeshopData;
}
else
return array();
}
catch(Exception $e)
{
$this->error = __METHOD__.': '.$e->getMessage();
return false;
}
}
/**
* This method returns an array of objects with parcel shops
* near the exact address specfied OR the zipcode provided.
* If the streetname and number cannot be found in the provided zipcode
* the search for nearest parcel shops is expanded and limited to parcel
* shops in the provided zipcode.
*
* @access public
* @param string Exact street address with streetnumber
* @param int The zipcode for the provided address
* @param int The amount of parcel shops returned - default is 5.
* @return mixed An array of objects or boolean false if service call failed.
*/
public function SearchNearestParcelShops( $street, $zipcode, $amount = 5)
{
try
{
$shops = $this->client->SearchNearestParcelShops(array('street' => $street, 'zipcode' => $zipcode, 'countryIso3166A2' => $this->country, 'Amount' => $amount));
if(!is_array($shops->SearchNearestParcelShopsResult->parcelshops->PakkeshopData))
return array($shops->SearchNearestParcelShopsResult->parcelshops->PakkeshopData);
return $shops->SearchNearestParcelShopsResult->parcelshops->PakkeshopData;
}
catch(Exception $e)
{
$this->error = __METHOD__.': '.$e->getMessage();
return false;
}
}
}
?>