Skip to content

Commit 990cf4b

Browse files
author
Marvin Oßwald
committed
add tags array to facebook post object to highlight specific words
1 parent ea0df1f commit 990cf4b

File tree

4 files changed

+25
-10
lines changed

4 files changed

+25
-10
lines changed

Readme.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
[![Build Status](https://travis-ci.org/marvinosswald/laravel-socialmedia.svg?branch=master)](https://travis-ci.org/marvinosswald/laravel-socialmedia)
44
[![MIT License](https://img.shields.io/packagist/l/marvinosswald/laravel-socialmedia.svg?style=flat-square)](https://packagist.org/packages/marvinosswald/laravel-socialmedia)
55

6+
The first step will be to implement a post function for each Driver and on this way a matching delete function for testing reasons.
7+
8+
69
## Install
710
```
811

src/Drivers/Facebook/Driver.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class Driver implements DriverInterface
2121
/**
2222
* @var string
2323
*/
24-
public $default_graph_version = 'v2.6';
24+
public $default_graph_version = 'v2.7';
2525
/**
2626
* @var string
2727
*/
@@ -38,7 +38,7 @@ class Driver implements DriverInterface
3838
* @param string $default_graph_version
3939
* @param bool $default_access_token
4040
*/
41-
public function __construct($app_id = false, $app_secret = false, $default_graph_version = 'v2.6', $default_access_token = false)
41+
public function __construct($app_id = false, $app_secret = false, $default_graph_version = 'v2.7', $default_access_token = false)
4242
{
4343
$this->app_id = $app_id ?: env('FACEBOOK_APP_ID');
4444
$this->app_secret = $app_secret ?: env('FACEBOOK_APP_SECRET');

src/Drivers/Facebook/Post.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class Post implements PostInterface{
6060
public $place = '';
6161

6262
/**
63-
* Comma-separated list of user IDs of people tagged in this post. You cannot specify this field without also specifying a place.
63+
* Array of Tags to be highlighted
6464
*
6565
* @var array
6666
*/
@@ -100,6 +100,11 @@ public function __construct($fb,$params= [])
100100
}
101101
}
102102
}
103+
if (!empty($this->tags)){
104+
foreach ($this->tags as $tag){
105+
$this->message = str_replace($tag,'#'.$tag,$this->message);
106+
}
107+
}
103108
}
104109
/**
105110
* @param $driver

tests/FacebookTest.php

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,26 @@ protected function getEnvironmentSetUp($app)
2828
$dotenv->load();
2929
}
3030
}
31-
31+
3232
public function testFacebookPost()
3333
{
34-
$message = 'Test Message';
35-
$post = Socialmedia::post([
36-
'message' => $message
37-
],['facebook']);
34+
$params = [
35+
'message' => 'Message in a bottle',
36+
'link' => 'http://google.com',
37+
'picture' => 'http://placehold.it/200/400',
38+
'name' => 'The one who must not be named',
39+
'caption' => 'What an caption',
40+
'description' => 'Description',
41+
'place' => '',
42+
'tags' => ['bottle'],
43+
'targeting' => ['locales' => 5]
44+
];
45+
$post = Socialmedia::post($params,['facebook']);
3846
// Create a client with a base URI
3947
$client = new GuzzleHttp\Client(['base_uri' => 'https://graph.facebook.com/v2.6/']);
4048
$res = json_decode($client->request('GET', $post['facebook']->id."?access_token=".env('FACEBOOK_ACCESS_TOKEN'))->getBody());
4149

42-
$this->assertEquals($message,$res->message);
50+
$this->assertEquals('Message in a #bottle',$res->message);
4351
Socialmedia::delete($res->id,["facebook"]);
44-
4552
}
4653
}

0 commit comments

Comments
 (0)