From 990cf4b0d0d43289b203d217fb71f6372e37ae9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marvin=20O=C3=9Fwald?= Date: Tue, 19 Jul 2016 11:38:00 +0200 Subject: [PATCH] add tags array to facebook post object to highlight specific words --- Readme.md | 3 +++ src/Drivers/Facebook/Driver.php | 4 ++-- src/Drivers/Facebook/Post.php | 7 ++++++- tests/FacebookTest.php | 21 ++++++++++++++------- 4 files changed, 25 insertions(+), 10 deletions(-) diff --git a/Readme.md b/Readme.md index c0650c6..eafe4ff 100644 --- a/Readme.md +++ b/Readme.md @@ -3,6 +3,9 @@ [![Build Status](https://travis-ci.org/marvinosswald/laravel-socialmedia.svg?branch=master)](https://travis-ci.org/marvinosswald/laravel-socialmedia) [![MIT License](https://img.shields.io/packagist/l/marvinosswald/laravel-socialmedia.svg?style=flat-square)](https://packagist.org/packages/marvinosswald/laravel-socialmedia) +The first step will be to implement a post function for each Driver and on this way a matching delete function for testing reasons. + + ## Install ``` diff --git a/src/Drivers/Facebook/Driver.php b/src/Drivers/Facebook/Driver.php index 0fc1b1e..e9e13f1 100644 --- a/src/Drivers/Facebook/Driver.php +++ b/src/Drivers/Facebook/Driver.php @@ -21,7 +21,7 @@ class Driver implements DriverInterface /** * @var string */ - public $default_graph_version = 'v2.6'; + public $default_graph_version = 'v2.7'; /** * @var string */ @@ -38,7 +38,7 @@ class Driver implements DriverInterface * @param string $default_graph_version * @param bool $default_access_token */ - public function __construct($app_id = false, $app_secret = false, $default_graph_version = 'v2.6', $default_access_token = false) + public function __construct($app_id = false, $app_secret = false, $default_graph_version = 'v2.7', $default_access_token = false) { $this->app_id = $app_id ?: env('FACEBOOK_APP_ID'); $this->app_secret = $app_secret ?: env('FACEBOOK_APP_SECRET'); diff --git a/src/Drivers/Facebook/Post.php b/src/Drivers/Facebook/Post.php index c4e3772..d8d2612 100644 --- a/src/Drivers/Facebook/Post.php +++ b/src/Drivers/Facebook/Post.php @@ -60,7 +60,7 @@ class Post implements PostInterface{ public $place = ''; /** - * Comma-separated list of user IDs of people tagged in this post. You cannot specify this field without also specifying a place. + * Array of Tags to be highlighted * * @var array */ @@ -100,6 +100,11 @@ public function __construct($fb,$params= []) } } } + if (!empty($this->tags)){ + foreach ($this->tags as $tag){ + $this->message = str_replace($tag,'#'.$tag,$this->message); + } + } } /** * @param $driver diff --git a/tests/FacebookTest.php b/tests/FacebookTest.php index f47c2f0..9b2d8dd 100644 --- a/tests/FacebookTest.php +++ b/tests/FacebookTest.php @@ -28,19 +28,26 @@ protected function getEnvironmentSetUp($app) $dotenv->load(); } } - + public function testFacebookPost() { - $message = 'Test Message'; - $post = Socialmedia::post([ - 'message' => $message - ],['facebook']); + $params = [ + 'message' => 'Message in a bottle', + 'link' => 'http://google.com', + 'picture' => 'http://placehold.it/200/400', + 'name' => 'The one who must not be named', + 'caption' => 'What an caption', + 'description' => 'Description', + 'place' => '', + 'tags' => ['bottle'], + 'targeting' => ['locales' => 5] + ]; + $post = Socialmedia::post($params,['facebook']); // Create a client with a base URI $client = new GuzzleHttp\Client(['base_uri' => 'https://graph.facebook.com/v2.6/']); $res = json_decode($client->request('GET', $post['facebook']->id."?access_token=".env('FACEBOOK_ACCESS_TOKEN'))->getBody()); - $this->assertEquals($message,$res->message); + $this->assertEquals('Message in a #bottle',$res->message); Socialmedia::delete($res->id,["facebook"]); - } } \ No newline at end of file