Skip to content
This repository has been archived by the owner on Nov 8, 2023. It is now read-only.

Commit

Permalink
Merge pull request #22 from vinkla/elogram
Browse files Browse the repository at this point in the history
Switch to Elogram
  • Loading branch information
vinkla committed Mar 15, 2016
2 parents 96df2cb + ca492a8 commit bbd3da6
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 65 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG

## 4.0.0 (released 2016-03-14)

- Switch to `larabros/elogram`

## 3.2.2 (released 2016-01-30)

- Improved service provider
Expand Down
41 changes: 16 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
Laravel Instagram
=================

> **Note:** On the 17 Nov 2015 [Instagram](http://developers.instagram.com/post/133424514006/instagram-platform-update) made [changes to their API ](https://instagram.com/developer/changelog/). Apps created before Nov 17, 2015 wont be affected until Jun 2016. Apps created on or after Nov 17 2015 will require to use their updated API. Please note that this library doesn't yet support their new updates.
![instagram](https://cloud.githubusercontent.com/assets/499192/11020990/f0f31dea-8632-11e5-95b1-77e72c7ba271.png)

Laravel [Instagram](http://instagram.com/developer) is an [Instagram](http://instagram.com/developer) bridge for Laravel. [Instagram](http://instagram.com/developer) API package is made by [Christian Metz](https://github.com/cosenary/Instagram-PHP-API). The Laravel wrapper package is created and maintained by [Vincent Klaiber](https://github.com/vinkla).
Laravel [Instagram](http://instagram.com/developer) is an [Instagram](http://instagram.com/developer) bridge for Laravel and Lumen.

```php
// Fetching data.
$instagram->getUserFeed(30);
// Fetch user data.
$instagram->users()->get(30);

// Get popular media.
$instagram->getPopularMedia();
// Get liked media.
$instagram->users()->getLikedMedia();

// Want to use the facade?
Instagram::searchMedia(48.1454418, 11.5686003);
Instagram::likes()->like(413);
```

[![Build Status](https://img.shields.io/travis/vinkla/instagram/master.svg?style=flat)](https://travis-ci.org/vinkla/instagram)
Expand Down Expand Up @@ -65,7 +63,7 @@ This option `connections` is where each of the connections are setup for your ap

#### InstagramManager

This is the class of most interest. It is bound to the ioc container as `instagram` and can be accessed using the `Facades\Instagram` facade. This class implements the ManagerInterface by extending AbstractManager. The interface and abstract class are both part of [Graham Campbell's](https://github.com/GrahamCampbell) [Laravel Manager](https://github.com/GrahamCampbell/Laravel-Manager) package, so you may want to go and checkout the docs for how to use the manager class over at that repository. Note that the connection class returned will always be an instance of `MetzWeb\Instagram\Instagram`.
This is the class of most interest. It is bound to the ioc container as `instagram` and can be accessed using the `Facades\Instagram` facade. This class implements the ManagerInterface by extending AbstractManager. The interface and abstract class are both part of [Graham Campbell's](https://github.com/GrahamCampbell) [Laravel Manager](https://github.com/GrahamCampbell/Laravel-Manager) package, so you may want to go and checkout the docs for how to use the manager class over at that repository. Note that the connection class returned will always be an instance of `Larabros\Elogram\Client`.

#### Facades\Instagram

Expand All @@ -82,33 +80,26 @@ Here you can see an example of just how simple this package is to use. Out of th
// You can alias this in config/app.php.
use Vinkla\Instagram\Facades\Instagram;

// Get code parameter.
$code = Request::get('code');

// Request the access token.
$data = Instagram::getOAuthToken($code);

// Set the access token with $data object.
Instagram::setAccessToken($data);

Instagram::users()->get(30);
// We're done here - how easy was that, it just works!
Instagram::getUserLikes();

Instagram::likes()->get(101);
// This example is simple, and there are far more methods available.
```

The Instagram manager will behave like it is a `MetzWeb\Instagram\Instagram`. If you want to call specific connections, you can do that with the connection method:
The Instagram manager will behave like it is a `Larabros\Elogram\Client`. If you want to call specific connections, you can do that with the connection method:

```php
use Vinkla\Instagram\Facades\Instagram;

// Writing this…
Instagram::connection('main')->getUserLikes();
Instagram::connection('main')->users()->get(30);

// …is identical to writing this
Instagram::getUserLikes();
Instagram::users()->get(30);

// and is also identical to writing this.
Instagram::connection()->getUserLikes();
Instagram::connection()->users()->get(30);

// This is because the main connection is configured to be the default.
Instagram::getDefaultConnection(); // This will return main.
Expand All @@ -133,15 +124,15 @@ class Foo

public function bar()
{
$this->instagram->getPopularMedia();
$this->instagram->users()->get(30);
}
}

App::make('Foo')->bar();
```

## Documentation
There are other classes in this package that are not documented here. This is because the package is a Laravel wrapper of [Christian Metz's](https://github.com/cosenary) [Instagram API package](https://github.com/cosenary/Instagram-PHP-API).
There are other classes in this package that are not documented here. This is because the package is a Laravel wrapper of [Larabros's](https://github.com/larabros) [Elogram package](https://github.com/larabros/elogram).

## License

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"illuminate/contracts": "5.1.* || 5.2.*",
"illuminate/support": "5.1.* || 5.2.*",
"graham-campbell/manager": "^2.3",
"cosenary/instagram": "^2.3"
"larabros/elogram": "^1.1"
},
"require-dev": {
"graham-campbell/testbench": "^3.1",
Expand All @@ -33,7 +33,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "3.2-dev"
"dev-master": "4.0-dev"
}
},
"minimum-stability": "dev",
Expand Down
12 changes: 6 additions & 6 deletions config/instagram.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@
'connections' => [

'main' => [
'client_id' => 'your-client-id',
'client_secret' => null,
'callback_url' => null,
'id' => 'your-client-id',
'secret' => 'your-client-secret',
'access_token' => null,
],

'alternative' => [
'client_id' => 'your-client-id',
'client_secret' => null,
'callback_url' => null,
'id' => 'your-client-id',
'secret' => 'your-client-secret',
'access_token' => null,
],

],
Expand Down
34 changes: 18 additions & 16 deletions src/InstagramFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
namespace Vinkla\Instagram;

use InvalidArgumentException;
use MetzWeb\Instagram\Instagram;
use Larabros\Elogram\Client;

/**
* This is the Instagram factory class.
Expand All @@ -26,7 +26,7 @@ class InstagramFactory
*
* @param array $config
*
* @return \MetzWeb\Instagram\Instagram
* @return \Larabros\Elogram\Client
*/
public function make(array $config)
{
Expand All @@ -46,30 +46,32 @@ public function make(array $config)
*/
protected function getConfig(array $config)
{
if (!array_key_exists('client_id', $config)) {
throw new InvalidArgumentException('Missing configuration key [client_id].');
$keys = ['id', 'secret'];

foreach ($keys as $key) {
if (!array_key_exists($key, $config)) {
throw new InvalidArgumentException("Missing configuration key [$key].");
}
}

return array_only($config, ['client_id', 'client_secret', 'callback_url']);
return array_only($config, ['id', 'secret', 'access_token', 'redirect_url', 'options']);
}

/**
* Get the pusher client.
* Get the Instagram client.
*
* @param string[] $auth
*
* @return \Pusher
* @return \Larabros\Elogram\Client
*/
protected function getClient(array $auth)
{
if ($auth['client_secret'] && $auth['callback_url']) {
return new Instagram([
'apiKey' => $auth['client_id'],
'apiSecret' => $auth['client_secret'],
'apiCallback' => $auth['callback_url'],
]);
}

return new Instagram($auth['client_id']);
return new Client(
array_get($auth, 'id'),
array_get($auth, 'secret'),
array_get($auth, 'access_token', null),
array_get($auth, 'redirect_url', ''),
array_get($auth, 'options', [])
);
}
}
2 changes: 1 addition & 1 deletion src/InstagramManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class InstagramManager extends AbstractManager
/**
* The factory instance.
*
* @var InstagramFactory
* @var \Vinkla\Instagram\InstagramFactory
*/
private $factory;

Expand Down
4 changes: 2 additions & 2 deletions src/InstagramServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
use Illuminate\Contracts\Container\Container;
use Illuminate\Foundation\Application as LaravelApplication;
use Illuminate\Support\ServiceProvider;
use Larabros\Elogram\Client;
use Laravel\Lumen\Application as LumenApplication;
use MetzWeb\Instagram\Instagram;

/**
* This is the Instagram service provider class.
Expand Down Expand Up @@ -108,7 +108,7 @@ protected function registerBindings()
return $manager->connection();
});

$this->app->alias('instagram.connection', Instagram::class);
$this->app->alias('instagram.connection', Client::class);
}

/**
Expand Down
26 changes: 18 additions & 8 deletions tests/InstagramFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Vinkla\Tests\Instagram;

use MetzWeb\Instagram\Instagram;
use Larabros\Elogram\Client;
use Vinkla\Instagram\InstagramFactory;

/**
Expand All @@ -26,24 +26,34 @@ public function testMakeStandard()
$factory = $this->getInstagramFactory();

$return = $factory->make([
'client_id' => 'your-client-id',
'client_secret' => null,
'callback_url' => null,
'id' => 'your-client-id',
'secret' => 'your-client-secret',
]);

$this->assertInstanceOf(Instagram::class, $return);
$this->assertInstanceOf(Client::class, $return);
}

/**
* @expectedException \InvalidArgumentException
*/
public function testMakeWithoutClientId()
public function testMakeWithoutId()
{
$factory = $this->getInstagramFactory();

$factory->make([
'client_secret' => null,
'callback_url' => null,
'secret' => 'your-client-secret',
]);
}

/**
* @expectedException \InvalidArgumentException
*/
public function testMakeWithoutSecret()
{
$factory = $this->getInstagramFactory();

$factory->make([
'id' => 'your-client-id',
]);
}

Expand Down
6 changes: 3 additions & 3 deletions tests/InstagramManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

use GrahamCampbell\TestBench\AbstractTestCase as AbstractTestBenchTestCase;
use Illuminate\Contracts\Config\Repository;
use MetzWeb\Instagram\Instagram;
use Larabros\Elogram\Client;
use Mockery;
use Vinkla\Instagram\InstagramFactory;
use Vinkla\Instagram\InstagramManager;
Expand All @@ -38,7 +38,7 @@ public function testCreateConnection()

$return = $manager->connection();

$this->assertInstanceOf(Instagram::class, $return);
$this->assertInstanceOf(Client::class, $return);

$this->assertArrayHasKey('instagram', $manager->getConnections());
}
Expand All @@ -56,7 +56,7 @@ protected function getManager(array $config)
$config['name'] = 'instagram';

$manager->getFactory()->shouldReceive('make')->once()
->with($config)->andReturn(Mockery::mock(Instagram::class));
->with($config)->andReturn(new Client('id', 'secret'));

return $manager;
}
Expand Down
4 changes: 2 additions & 2 deletions tests/ServiceProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
namespace Vinkla\Tests\Instagram;

use GrahamCampbell\TestBenchCore\ServiceProviderTrait;
use MetzWeb\Instagram\Instagram;
use Larabros\Elogram\Client;
use Vinkla\Instagram\InstagramFactory;
use Vinkla\Instagram\InstagramManager;

Expand All @@ -37,7 +37,7 @@ public function testInstagramManagerIsInjectable()

public function testBindings()
{
$this->assertIsInjectable(Instagram::class);
$this->assertIsInjectable(Client::class);

$original = $this->app['instagram.connection'];
$this->app['instagram']->reconnect();
Expand Down

0 comments on commit bbd3da6

Please sign in to comment.