Created
June 11, 2015 01:49
-
-
Save brianseitel/bb2b0630ec63590ac187 to your computer and use it in GitHub Desktop.
Lob API wrapper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Guzzle\Http\Client; | |
use Guzzle\Http\EntityBody; | |
use Guzzle\Http\Message\Request; | |
use Guzzle\Http\Message\Response; | |
class Lob { | |
private $base_url = 'https://api.lob.com/v1/'; | |
public function request($action, $endpoint, $params = []) { | |
$client = new Client($this->base_url); | |
if (!method_exists($client, $action)) { | |
throw new Exception("Action must be a valid Guzzle action, such as `get`, `post`, `delete`, etc."); | |
} | |
$request = $client->{$action}($endpoint, [], $params); | |
$request->setAuth(Config::get('lob.api_key'), null); | |
$results = $request->send()->getBody(true); | |
return json_decode($results, 1) ?: $results; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment