Skip to content

Commit 31939fc

Browse files
feat(hackathon): Finalize Foursquare Controller
1 parent 876f2ce commit 31939fc

File tree

5 files changed

+133
-4
lines changed

5 files changed

+133
-4
lines changed

app/Http/Controllers/FoursquareController.php

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

55
use Illuminate\Http\Request;
66

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

1011
class FoursquareController extends Controller
1112
{
12-
//
13+
/**
14+
* Instance of Foursquare API
15+
* @var object
16+
*/
17+
protected $foursquare;
18+
19+
/**
20+
* Initialize the Controller with necessary arguments
21+
*/
22+
public function __construct()
23+
{
24+
$this->foursquare = new FoursquareApi(env('FOURSQUARE_CLIENT_ID'), env('FOURSQUARE_CLIENT_SECRET'));
25+
}
26+
27+
/**
28+
* Search For Venues
29+
* @return array
30+
*/
31+
private function getVenues()
32+
{
33+
// Searching for venues nearby e.g Lagos, Nigeria
34+
$endpoint = 'venues/search';
35+
36+
// Prepare parameters
37+
$params = ['near' => 'Lagos, Nigeria'];
38+
39+
// Perform a request to a public resource
40+
$response = json_decode($this->foursquare->GetPublic($endpoint,$params),true);
41+
42+
return $response['response']['venues'];
43+
}
44+
45+
/**
46+
* Return all data to the Foursquare API dashboard
47+
* @return mixed
48+
*/
49+
public function getPage()
50+
{
51+
$venues = $this->getVenues();
52+
53+
return view('api.foursquare')->withVenues($venues);
54+
}
55+
1356
}

app/Http/routes.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,12 @@
139139
'middleware' => ['auth']
140140
]);
141141

142+
Route::get('/api/foursquare', [
143+
'uses' => 'FoursquareController@getPage',
144+
'as' => 'api.foursquare',
145+
'middleware' => ['auth']
146+
]);
147+
142148
Route::post('/slack/message', [
143149
'uses' => 'SlackController@sendMessageToTeam',
144150
'as' => 'slack.message',

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
"vluzrmos/slack-api": "^0.4.6",
2222
"vinkla/facebook": "^2.0",
2323
"linkedinapi/linkedin": "^1.1",
24-
"socialiteproviders/foursquare": "^1.1"
24+
"socialiteproviders/foursquare": "^1.1",
25+
"hownowstephen/php-foursquare": "1.2.*"
2526
},
2627
"require-dev": {
2728
"fzaninotto/faker": "~1.4",

composer.lock

Lines changed: 29 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
@extends('layouts.master')
2+
3+
@section('content')
4+
<div class="main-container">
5+
@include('layouts.partials.alerts')
6+
7+
<div class="page-header">
8+
<h3><i style="color: #335397" class="fa fa-foursquare-square"></i> Foursquare API</h3>
9+
</div>
10+
11+
<div class="btn-group btn-group-justified">
12+
<a href="https://developers.facebook.com/docs/graph-api/quickstart/" target="_blank" class="btn btn-primary">
13+
<i class="fa fa-check-square-o"></i> Quickstart
14+
</a>
15+
<a href="https://developers.facebook.com/tools/explorer" target="_blank" class="btn btn-primary">
16+
<i class="fa fa-facebook"></i> Graph API Explorer
17+
</a>
18+
<a href="https://developers.facebook.com/docs/graph-api/reference/" target="_blank" class="btn btn-primary">
19+
<i class="fa fa-code-fork"></i> API Reference
20+
</a>
21+
</div>
22+
23+
<h3><i class="fa fa-user"></i> List Of Venues Near Lagos, Nigeria (You can specify your location)</h3>
24+
25+
@if ($venues)
26+
<table class="table table-striped table-bordered">
27+
<thead>
28+
<tr>
29+
<th>No</th>
30+
<th>Name</th>
31+
<th>Geopoints</th>
32+
</tr>
33+
</thead>
34+
<tbody>
35+
36+
<?php $kar = 1; ?>
37+
@foreach ($venues as $venue)
38+
<tr>
39+
<td>{{ $kar }}</td>
40+
<td>{{ $venue['name'] }}</td>
41+
<td>{{ $venue['location']['lat'] . ',' . $venue['location']['lng'] }}</td>
42+
</tr>
43+
<?php $kar++ ?>
44+
@endforeach
45+
</tbody>
46+
</table>
47+
@endif
48+
49+
50+
<br>
51+
</div>
52+
@stop

0 commit comments

Comments
 (0)