This repository has been archived by the owner on Dec 22, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.php
74 lines (61 loc) · 1.77 KB
/
index.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
<?php
# Location data provided by: elevenbasetwo.com
# includes
include 'Network/Curl/Curl.php';
use Phalcon\Mvc\Micro as Micro;
use Network\Curl\Curl as Curl;
# init
$app = new Micro;
$curl = new Curl;
# class
class ZipCode {
public function all($zipcode){
global $curl;
$r = $curl->get('http://zip.elevenbasetwo.com/v2/US/'.$zipcode);
$d = (object) json_decode($r['data'], true);
print $d->city;
print $d->state;
print $d->country;
}
public function city($zipcode){
global $curl;
$r = $curl->get('http://zip.elevenbasetwo.com/v2/US/'.$zipcode);
$d = (object) json_decode($r['data'], true);
print $d->city;
}
public function state($zipcode){
global $curl;
$r = $curl->get('http://zip.elevenbasetwo.com/v2/US/'.$zipcode);
$d = (object) json_decode($r['data'], true);
print $d->state;
}
public function country($zipcode){
global $curl;
$r = $curl->get('http://zip.elevenbasetwo.com/v2/US/'.$zipcode);
$d = (object) json_decode($r['data'], true);
print $d->country;
}
}
# routes
$app->get('/', function(){
echo "<strong>Invalid API Call...</strong><br /><br />Available: <br />/all/{zipcode}<br />/city/{zipcode}<br />/state/{zipcode}<br />/country/{zipcode}";
});
$app->get('/all/{zip}', function($zip){
ZipCode::all($zip);
});
$app->get('/city/{zip}', function($zip){
ZipCode::city($zip);
});
$app->get('/state/{zip}', function($zip){
ZipCode::state($zip);
});
$app->get('/country/{zip}', function($zip){
ZipCode::country($zip);
});
# error pages
$app->notFound(function() use ($app) {
$app->response->setStatusCode(404, 'Not Found')->sendHeaders();
echo '404';
});
# run app
$app->handle();