Skip to content

Commit 4f2aa4c

Browse files
feat(hackathon): Add Lob API functionality
1 parent 3016974 commit 4f2aa4c

File tree

4 files changed

+123
-8
lines changed

4 files changed

+123
-8
lines changed

app/Http/Controllers/LobController.php

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,53 @@
44

55
use Illuminate\Http\Request;
66

7+
use Lob\Lob;
78
use App\Http\Requests;
89
use App\Http\Controllers\Controller;
910

1011
class LobController extends Controller
1112
{
13+
/**
14+
* LOB API KEY
15+
* @var string
16+
*/
17+
protected $apikey;
18+
19+
/**
20+
* Instance of Lob
21+
* @var object
22+
*/
23+
protected $lob;
24+
25+
/**
26+
* Initialize Lob
27+
*/
28+
public function __construct()
29+
{
30+
$this->apikey = env('LOB_API_KEY');
31+
$this->lob = new Lob($this->apikey);
32+
}
33+
34+
/**
35+
* Get all delivery routes for this zip code
36+
* @param string $zipcdode
37+
* @return array
38+
*/
39+
private function getRoutes($zipcode)
40+
{
41+
$results = $this->lob->routes()->all(['zip_codes' => $zipcode]);
42+
43+
return $results[0]['routes'];
44+
}
45+
1246
/**
1347
* Return all data to the Lob API dashboard
1448
* @return mixed
1549
*/
1650
public function getPage()
1751
{
18-
return view('api.lob');
52+
$routes = $this->getRoutes('10007');
53+
54+
return view('api.lob')->withRoutes($routes);
1955
}
2056
}

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
"metalmatze/lastfm-api-wrapper": "dev-master",
1717
"aloha/twilio": "^2.0",
1818
"fabpot/goutte": "^3.1",
19-
"mjerwin/clockwork-sms": "^0.9.1"
19+
"mjerwin/clockwork-sms": "^0.9.1",
20+
"lob/lob-php": "^1.6"
2021
},
2122
"require-dev": {
2223
"fzaninotto/faker": "~1.4",

composer.lock

Lines changed: 60 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

resources/views/api/lob.blade.php

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
</div>
1010

1111
<div class="btn-group btn-group-justified">
12-
<a href="https://lob.com/docs" class="btn btn-primary">
12+
<a href="https://lob.com/docs" target="_blank" class="btn btn-primary">
1313
<i class="fa fa-check-square-o"></i> API Documentation
1414
</a>
15-
<a href="https://github.com/lob/lob-node" target="_blank" class="btn btn-primary">
16-
<i class="fa fa-code"></i> Lob Node Docs
15+
<a href="https://github.com/lob/lob-php" target="_blank" class="btn btn-primary">
16+
<i class="fa fa-code"></i> Lob PHP Docs
1717
</a>
1818
<a href="https://dashboard.lob.com/register" target="_blank" class="btn btn-primary">
1919
<i class="fa fa-gear"></i> Create API Account
@@ -22,7 +22,27 @@
2222

2323
<h3>Delivery routes in 10007</h3>
2424

25-
<table class="table table-striped table-bordered"><thead><tr><th>Route</th><th># of Residential Addresses</th><th># of Business Addresses</th></tr></thead><tbody><tr><td>B099</td><td>0</td><td>0</td></tr><tr><td>C000</td><td>0</td><td>0</td></tr><tr><td>C001</td><td>455</td><td>38</td></tr><tr><td>C003</td><td>13</td><td>12</td></tr><tr><td>C004</td><td>152</td><td>47</td></tr><tr><td>C005</td><td>0</td><td>34</td></tr><tr><td>C006</td><td>0</td><td>138</td></tr><tr><td>C008</td><td>254</td><td>93</td></tr><tr><td>C009</td><td>454</td><td>48</td></tr><tr><td>C012</td><td>239</td><td>46</td></tr><tr><td>C013</td><td>441</td><td>40</td></tr><tr><td>C014</td><td>0</td><td>23</td></tr><tr><td>C017</td><td>0</td><td>51</td></tr><tr><td>C018</td><td>0</td><td>157</td></tr><tr><td>C019</td><td>356</td><td>54</td></tr><tr><td>C020</td><td>1</td><td>122</td></tr><tr><td>C021</td><td>6</td><td>76</td></tr><tr><td>C022</td><td>400</td><td>62</td></tr><tr><td>C023</td><td>43</td><td>85</td></tr><tr><td>C098</td><td>440</td><td>29</td></tr><tr><td>C099</td><td>18</td><td>97</td></tr></tbody></table>
25+
@if ($routes)
26+
<table class="table table-striped table-bordered">
27+
<thead>
28+
<tr>
29+
<th>Route</th>
30+
<th># of Residential Addresses</th>
31+
<th># of Business Addresses</th>
32+
</tr>
33+
</thead>
34+
<tbody>
35+
36+
@foreach ($routes as $route)
37+
<tr>
38+
<td>{{ $route['route'] }}</td>
39+
<td>{{ $route['residential'] }}</td>
40+
<td>{{ $route['business'] }}</td>
41+
</tr>
42+
@endforeach
43+
</tbody>
44+
</table>
45+
@endif
2646
<br>
2747
</div>
2848
@stop

0 commit comments

Comments
 (0)