Skip to content

Commit

Permalink
add tags array to facebook post object to highlight specific words
Browse files Browse the repository at this point in the history
  • Loading branch information
Marvin Oßwald committed Jul 19, 2016
1 parent ea0df1f commit 990cf4b
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 10 deletions.
3 changes: 3 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Expand Down
4 changes: 2 additions & 2 deletions src/Drivers/Facebook/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Driver implements DriverInterface
/**
* @var string
*/
public $default_graph_version = 'v2.6';
public $default_graph_version = 'v2.7';
/**
* @var string
*/
Expand All @@ -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');
Expand Down
7 changes: 6 additions & 1 deletion src/Drivers/Facebook/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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
Expand Down
21 changes: 14 additions & 7 deletions tests/FacebookTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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"]);

}
}

0 comments on commit 990cf4b

Please sign in to comment.