Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get Individual Raw Link by passing service tag #90

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,13 @@ Share::page('http://jorenvanhocht.be', 'Your share text can be placed here')->re
#### Linkedin

``` php
Share::page('http://jorenvanhocht.be', 'Share title')->linkedin('Extra linkedin summary can be passed here')
Share::page('http://jorenvanhocht.be', 'Share title')->linkedin('Extra linkedin summary can be passed here');
```

#### Whatsapp

``` php
Share::page('http://jorenvanhocht.be')->whatsapp()
Share::page('http://jorenvanhocht.be')->whatsapp();
```

#### Telegram
Expand Down Expand Up @@ -155,6 +155,12 @@ Share::page('http://jorenvanhocht.be', 'Share title')
->getRawLinks();
```

Or you can simply pass the service tag as the parameter inside ```getRawLinks()```

```php
Share::page('http://jorenvanhocht.be', 'Share title')->getRawLinks('facebook');
```

Outputs:

```html
Expand Down Expand Up @@ -183,6 +189,25 @@ Outputs:
]
```

**Getting specific raw link**

You can get the raw link of a specific service by passing the service tag inside ```getRawLinks()```

```php
$shareLinks = Share::page('http://jorenvanhocht.be', 'Share title')
->facebook()
->twitter()
->linkedin('Extra linkedin summary can be passed here')
->whatsapp();
$linkedIn = $shareLinks->getRawLinks('linkedin');
```

Outputs:

```
http://www.linkedin.com/shareArticle?mini=true&url=http://jorenvanhocht.be&title=Share+title&summary=Extra+linkedin+summary+can+be+passed+here
```

### Optional parameters

#### Add extra classes, id's or titles to the social buttons
Expand Down
15 changes: 11 additions & 4 deletions src/Share.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,15 +222,22 @@ public function pinterest()

/**
* Get the raw generated links.
*
* Supply social media name for specific raw tag.
* @param string $socialMedia
* @return string|array
*/
public function getRawLinks()
public function getRawLinks($socialMedia = null)
{
if(count($this->generatedUrls) === 1) {
if(!is_null($socialMedia)) {
if(is_array($socialMedia) && count($socialMedia) > 1) {
$socialMedia = Arr::first($socialMedia);
}
$this->$socialMedia();
return Arr::get($this->generatedUrls, $socialMedia);
}
if(is_array($this->generatedUrls) && count($this->generatedUrls) === 1) {
return Arr::first($this->generatedUrls);
}

return $this->generatedUrls;
}

Expand Down
85 changes: 85 additions & 0 deletions tests/IndividualRawLinkTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php

namespace Jorenvh\Share\Test;

use Jorenvh\Share\ShareFacade;

class IndividualRawLinkTest extends TestCase
{
/**
* @test
*/
public function it_can_generate_a_facebook_raw_link()
{
$result = ShareFacade::page('https://codeswitch.be')->getRawLinks('facebook');
$expected = 'https://www.facebook.com/sharer/sharer.php?u=https://codeswitch.be';

$this->assertEquals($expected, (string)$result);
}

/**
* @test
*/
public function it_can_generate_a_linkedin_raw_link()
{
$result = ShareFacade::page('https://codeswitch.be','Title')->getRawLinks('linkedin');
$expected = 'https://www.linkedin.com/sharing/share-offsite?mini=true&url=https://codeswitch.be&title=Title&summary=';

$this->assertEquals($expected, (string)$result);
}

/**
* @test
*/
public function it_can_generate_a_pinterest_raw_link()
{
$result = ShareFacade::page('https://codeswitch.be')->getRawLinks('pinterest');
$expected = 'https://pinterest.com/pin/create/button/?url=https://codeswitch.be';

$this->assertEquals($expected, (string)$result);
}

/**
* @test
*/
public function it_can_generate_a_reddit_raw_link()
{
$result = ShareFacade::page('https://codeswitch.be')->getRawLinks('reddit');
$expected = 'https://www.reddit.com/submit?title=Default+share+text&url=https://codeswitch.be';

$this->assertEquals($expected, (string)$result);
}

/**
* @test
*/
public function it_can_generate_a_telegram_raw_link()
{
$result = ShareFacade::page('https://codeswitch.be')->getRawLinks('telegram');
$expected = 'https://telegram.me/share/url?url=https://codeswitch.be&text=Default+share+text';

$this->assertEquals($expected, (string)$result);
}

/**
* @test
*/
public function it_can_generate_a_twitter_raw_link()
{
$result = ShareFacade::page('https://codeswitch.be')->getRawLinks('twitter');
$expected = 'https://twitter.com/intent/tweet?text=Default+share+text&url=https://codeswitch.be';

$this->assertEquals($expected, (string)$result);
}

/**
* @test
*/
public function it_can_generate_a_whatsapp_raw_link()
{
$result = ShareFacade::page('https://codeswitch.be')->getRawLinks('whatsapp');
$expected = 'https://wa.me/?text=https://codeswitch.be';

$this->assertEquals($expected, (string)$result);
}
}
2 changes: 1 addition & 1 deletion tests/LinkedInShareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Jorenvh\Share\ShareFacade;

class LinkedinShareTest extends TestCase
class LinkedInShareTest extends TestCase
{
/**
* @test
Expand Down