Skip to content

Instantly share code, notes, and snippets.

@brianseitel
Created June 11, 2015 01:49
Show Gist options
  • Save brianseitel/bb2b0630ec63590ac187 to your computer and use it in GitHub Desktop.
Save brianseitel/bb2b0630ec63590ac187 to your computer and use it in GitHub Desktop.
Lob API wrapper
<?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