Skip to content

Commit

Permalink
Merge pull request #4 from gpassarelli/master
Browse files Browse the repository at this point in the history
Update version of Intercom PHP Client #3
  • Loading branch information
darkin1 authored Aug 7, 2016
2 parents f3f31cc + 25bc52b commit de15cb0
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 14 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"email": "dciesielski87@gmail.com"
}],
"require": {
"php": ">=5.4.0",
"intercom/intercom-php": "1.5.0"
"php": ">= 5.6",
"intercom/intercom-php" : "^3.0"
},
"autoload": {
"psr-4": {
Expand Down
6 changes: 6 additions & 0 deletions config/intercom.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php

return [
'app_id' => env('INTERCOM_APP_ID'),
'api_key' => env('INTERCOM_APP_KEY'),
];
3 changes: 1 addition & 2 deletions src/Intercom.php → src/Facades/Intercom.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php

namespace Darkin1\Intercom;
namespace Darkin1\Intercom\Facades;

use Illuminate\Support\Facades\Facade;

Expand Down
7 changes: 3 additions & 4 deletions src/IntercomApi.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<?php

namespace Darkin1\Intercom;

use Intercom\IntercomBasicAuthClient;
use Intercom\IntercomClient;

/**
* Class IntercomApi
Expand All @@ -18,7 +17,7 @@ class IntercomApi
/**
* @param $intercom
*/
public function __construct(IntercomBasicAuthClient $intercom)
public function __construct($intercom)
{
$this->intercom = $intercom;
}
Expand All @@ -32,7 +31,7 @@ public function __construct(IntercomBasicAuthClient $intercom)
*/
public function __call($method, array $args)
{
return call_user_func_array([$this->intercom, $method], $args);
return $this->intercom->{$method};
}

}
46 changes: 40 additions & 6 deletions src/IntercomServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,58 @@

use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Config;
use Intercom\IntercomBasicAuthClient;
use Intercom\IntercomClient;

class IntercomServiceProvider extends ServiceProvider
{
/**
* Indicates if loading of the provider is deferred.
*
* @var bool
*/
protected $defer = true;

/**
* Bootstrap the application events.
*
* @return void
*/
public function boot()
{
// Allow users to publish config to override the defaults.
$this->publishes([
__DIR__.'/../config/intercom.php' => config_path('intercom.php'),
], 'darkin1/intercom');
}
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
$this->app->bind('intercom', function () {
$intercom = IntercomBasicAuthClient::factory([
'app_id' => Config::get('intercom.app_id'),
'api_key' => Config::get('intercom.api_key'),
]);
// Use the provided config as default.
$this->mergeConfigFrom(
__DIR__.'/../config/intercom.php', 'intercom'
);

$this->app->singleton('intercom', function ($app) {
$appID = $app['config']->get('intercom.app_id');
$apiKey = $app['config']->get('intercom.api_key');

$intercom = new IntercomClient($appID, $apiKey);

return new IntercomApi($intercom);
});
}

/**
* Get the services provided by the provider.
*
* @return array
*/
public function provides()
{
return array('intercom');
}
}

0 comments on commit de15cb0

Please sign in to comment.