Skip to content

Commit 60959d9

Browse files
feat(hackathon): Add Tumblr API functionality
1 parent 3ae4840 commit 60959d9

File tree

7 files changed

+259
-13
lines changed

7 files changed

+259
-13
lines changed
+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
3+
namespace App\Http\Controllers;
4+
5+
use Illuminate\Http\Request;
6+
7+
use Tumblr;
8+
use App\Http\Requests;
9+
use App\Http\Controllers\Controller;
10+
11+
class TumblrController extends Controller
12+
{
13+
/**
14+
* Instance of Tumblr API
15+
* @var object
16+
*/
17+
protected $tumblr;
18+
19+
/**
20+
* Initialize the Controller with necessary arguments
21+
*/
22+
public function __construct()
23+
{
24+
$this->tumblr = new Tumblr();
25+
26+
// Set API key.
27+
$this->tumblr->setApiKey(env('TUMBLR_API_KEY'));
28+
}
29+
30+
/**
31+
* Get Basic Information about the blog
32+
* @return array
33+
*/
34+
private function getBlogInfo($tumblrBlogUrl)
35+
{
36+
$info = $this->tumblr->blogInfo($tumblrBlogUrl);
37+
38+
return (array)$info;
39+
}
40+
41+
/**
42+
* Get Posts from the Tumblr blog
43+
* @return array
44+
*/
45+
private function getPosts($tumblrBlogUrl)
46+
{
47+
$info = $this->tumblr->posts($tumblrBlogUrl);
48+
49+
return (array)$info->response->posts;
50+
}
51+
52+
/**
53+
* Return all data to the Tumblr API dashboard
54+
* @return mixed
55+
*/
56+
public function getPage()
57+
{
58+
$posts = $this->getPosts('taylorswift.tumblr.com');
59+
60+
return view('api.tumblr')->withPosts($posts);
61+
}
62+
}

app/Http/routes.php

+13
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,19 @@
145145
'middleware' => ['auth']
146146
]);
147147

148+
Route::get('/api/instagram', [
149+
'uses' => 'InstagramController@getPage',
150+
'as' => 'api.instagram',
151+
'middleware' => ['auth']
152+
]);
153+
154+
Route::get('/api/tumblr', [
155+
'uses' => 'TumblrController@getPage',
156+
'as' => 'api.tumblr',
157+
'middleware' => ['auth']
158+
]);
159+
160+
148161
Route::post('/slack/message', [
149162
'uses' => 'SlackController@sendMessageToTeam',
150163
'as' => 'slack.message',

composer.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
"vinkla/facebook": "^2.0",
2323
"linkedinapi/linkedin": "^1.1",
2424
"socialiteproviders/foursquare": "^1.1",
25-
"hownowstephen/php-foursquare": "1.2.*"
25+
"hownowstephen/php-foursquare": "1.2.*",
26+
"jaapz/tumblr": "dev-master"
2627
},
2728
"require-dev": {
2829
"fzaninotto/faker": "~1.4",

composer.lock

+90-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/instagram.php

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
/*
4+
* This file is part of Laravel Instagram.
5+
*
6+
* (c) Vincent Klaiber <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
return [
13+
14+
/*
15+
|--------------------------------------------------------------------------
16+
| Default Connection Name
17+
|--------------------------------------------------------------------------
18+
|
19+
| Here you may specify which of the connections below you wish to use as
20+
| your default connection for all work. Of course, you may use many
21+
| connections at once using the manager class.
22+
|
23+
*/
24+
25+
'default' => 'main',
26+
27+
/*
28+
|--------------------------------------------------------------------------
29+
| Instagram Connections
30+
|--------------------------------------------------------------------------
31+
|
32+
| Here are each of the connections setup for your application. Example
33+
| configuration has been included, but you may add as many connections as
34+
| you would like.
35+
|
36+
*/
37+
38+
'connections' => [
39+
40+
'main' => [
41+
'client_id' => env('INSTAGRAM_CLIENT_ID'),
42+
'client_secret' => env('INSTAGRAM_CLIENT_SECRET'),
43+
'callback_url' => env('INSTAGRAM_CALLBACK_URL'),
44+
],
45+
46+
'alternative' => [
47+
'client_id' => 'your-client-id',
48+
'client_secret' => null,
49+
'callback_url' => null,
50+
],
51+
52+
],
53+
54+
];

resources/views/api/tumblr.blade.php

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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 class="fa fa-tumblr-square"></i> Tumblr API</h3>
9+
</div>
10+
11+
<div class="btn-group btn-group-justified">
12+
<a href="https://github.com/jaapz/Tumblr" target="_blank" class="btn btn-primary">
13+
<i class="fa fa-check-square-o"></i> PHP Tumblr API
14+
</a>
15+
<a href="https://www.tumblr.com/docs/en/api/v2" target="_blank" class="btn btn-primary">
16+
<i class="fa fa-code-fork"></i> API Reference
17+
</a>
18+
</div>
19+
20+
<h3><i class="fa fa-user"></i> Posts on Taylor Swift Tumblr</h3>
21+
22+
@if ($posts)
23+
<ul class="media-list">
24+
@foreach($posts as $post)
25+
<li class="media">
26+
<div class="media-body">
27+
<strong class="media-heading"><a href="{{ $post->post_url }}">{{ $post->slug }}</strong>
28+
<span class="text-muted"> {{ $post->caption }}</span>
29+
<span class="text-muted"> {{ $post->date }}</span>
30+
<p>{{ $post->summary }}</p>
31+
</div>
32+
</li>
33+
@endforeach
34+
</ul>
35+
@endif
36+
<br>
37+
</div>
38+
@stop

resources/views/apidashboard.blade.php

-9
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,6 @@
4343
</div>
4444
</a>
4545
</div>
46-
<div class="col-sm-4">
47-
<a href="/api/instagram" style="color: #fff">
48-
<div style="background-color: #947563" class="panel panel-default">
49-
<div class="panel-body">
50-
<img src="http://i.imgur.com/aRc6LUJ.png" height="40"> Instagram
51-
</div>
52-
</div>
53-
</a>
54-
</div>
5546
<div class="col-sm-4">
5647
<a href="/api/lastfm" style="color: #fff">
5748
<div style="background-color: #d21309" class="panel panel-default">

0 commit comments

Comments
 (0)