/** * Register bindings in the container. * * @return void */ public function register() { $this->app->singleton(Basecamp::class, function ($app) { Config::set(['applicationName' => getenv('BASECAMP_APPLICATION_NAME'), 'applicationContact' => getenv('BASECAMP_APPLICATION_CONTACT'), 'authenticationType' => getenv('BASECAMP_AUTHENTICATION_TYPE'), 'clientId' => getenv('BASECAMP_CLIENT_ID'), 'clientSecret' => getenv('BASECAMP_CLIENT_SECRET'), 'redirectUri' => getenv('BASECAMP_REDIRECT_URI'), 'username' => getenv('BASECAMP_USERNAME'), 'password' => getenv('BASECAMP_PASSWORD'), 'accountId' => getenv('BASECAMP_ACCOUNT_ID')]); return new Basecamp(); }); }
public function testCanGetUserAccountId() { $user = User::getInstance(); \Zawntech\BasecampAPI\Config::set(['authenticationType' => 'OAuth']); // var_dump($user->getAccountId()); \Zawntech\BasecampAPI\Config::set(['authenticationType' => 'BasicHttp']); // var_dump($user->getAccountId()); }
public static function append($string) { if (!self::$enabled) { return; } $date = date('Y-m-d h:i:s A'); $auth = Config::getInstance()->authenticationType; file_put_contents(self::getPath(), "[{$date}] [{$auth}] {$string} \n", FILE_APPEND); }
public function testCanSetConfigurationOptions() { $originalConfig = Config::toArray(); // Set values by passing an array. Config::set(['applicationName' => 'a', 'applicationContact' => 'b', 'clientId' => 'c', 'clientSecret' => 'd', 'redirectUri' => 'e', 'username' => 'f', 'password' => 'g']); $this->assertEquals('a', $this->config->applicationName); $this->assertEquals('b', $this->config->applicationContact); $this->assertEquals('c', $this->config->clientId); $this->assertEquals('d', $this->config->clientSecret); $this->assertEquals('e', $this->config->redirectUri); $this->assertEquals('f', $this->config->username); $this->assertEquals('g', $this->config->password); // Restore config. Config::set($originalConfig); }
/** * @return string Absolute path to file. * @throws \Exception */ public function getPath() { // Default cache storage path (in library root). $defaultCachePath = __DIR__ . '/../../cache/'; // Is a cache path specified in the configuration? $configCachePath = Config::getInstance()->cachePath; if (!empty($configCachePath)) { // Verify that the directory actually exists. if (!is_dir($configCachePath)) { throw new \Exception('Invalid cache path specified in configuration!'); } // Return the custom path return $configCachePath . $this->getId(); } // Return the default cache path. return $defaultCachePath . $this->getId(); }
/** * @param null $authType 'BasicHttp' or 'OAuth' * @throws \Exception */ public function __construct($authType = null) { // Inject user instance $this->user = User::getInstance(); if (!empty(Config::getInstance()->oauthToken)) { $this->injectOAuthToken(Config::getInstance()->oauthToken); } // If no $authType was passed to the constructor, return. if (null == $authType) { // Is an module type specified in the configuration? if (null != $this->getAuthType()) { // Set the authentication type from configuration. $this->setAuthenticationType($this->getAuthType()); } return; } // Set the authentication type as passed to constructor. $this->setAuthenticationType($authType); }
/** * Return a user's Basecamp Account ID. * @return bool|string * @throws \Exception */ public function getAccountId() { // If module type if basic http, return the account ID specified in the configuration. if (Config::getInstance()->authenticationType == AuthType::BASIC_HTTP) { // If using Basic Http, a specified account ID is required in the configuration. if (empty(Config::getInstance()->accountId)) { throw new \Exception('No account ID set in configuration!'); } // Return the account ID from configuration. return Config::getInstance()->accountId; } if (Config::getInstance()->authenticationType == AuthType::OAUTH) { $auth = new Authorization(); $auth->load(); foreach ($auth->accounts as $account) { if ($account->product == "bcx") { return $account->id; } } } return false; }
<?php /** * Basecamp API PHPUnit Tests Bootstrapper */ // Load composer autoloader. require_once __DIR__ . '/../vendor/autoload.php'; // Load the local configuration file. $config = (include __DIR__ . '/config.php'); // Set the configuration. \Zawntech\BasecampAPI\Config::set($config); // Load oauth token from file. $json = file_get_contents(__DIR__ . '/basecamp-oauth-redirect/data.json'); $json = json_decode($json); \Zawntech\BasecampAPI\Auth\Authorizer::injectOAuthToken($json); require_once __DIR__ . '/TestCase.php';
/** * Initialize the Basecamp class. */ public function __construct() { $this->auth = new Authorizer(); $this->api = new API(); $this->config = Config::getInstance(); }
public function setUp() { // Set configuration object. $this->config = \Zawntech\BasecampAPI\Config::getInstance(); }
public function __construct() { // Load configuration. $this->config = Config::getInstance(); }
public function __construct($baseUrl, $args = [], $method = 'GET') { // Get configuration. $config = Config::getInstance(); // Validate configuration $config->validateConfiguration(); // Assign constructor arguments to object $this->baseUrl = $baseUrl; $this->args = $args; $this->method = $method; // Create cache object. $this->cache = new RequestCache($this); /* if ( false !== $this->cache->get() ) { $this->response = $this->cache->get()->response; $this->fromCache = true; return; } */ // Initialize the curl instance. $this->curl = curl_init(); // If this is a GET request, prepare the argument string, if supplied. if ($method == 'GET') { if (!empty($args)) { // Does the base url end in a ? character? if (false === strpos($baseUrl, '?')) { // Append the ? character $baseUrl .= '?'; } // Append the query arguments string. $baseUrl .= http_build_query($args); } } // Authorize. curl_setopt($this->curl, CURLOPT_HTTPHEADER, $this->getCurlHeaders()); // Set the application identity as part of the request. $userAgent = "{$config->applicationName} ({$config->applicationContact})"; curl_setopt($this->curl, CURLOPT_USERAGENT, $userAgent); // Set the URL option for the curl instance. curl_setopt($this->curl, CURLOPT_URL, $baseUrl); // Return transfer curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, true); // Get the headers curl_setopt($this->curl, CURLOPT_HEADER, true); curl_setopt($this->curl, CURLINFO_HEADER_OUT, true); // Verify SSL connections? if (!$this->verifySSL) { curl_setopt($this->curl, CURLOPT_SSL_VERIFYPEER, false); } // If this is a post request, assign the arguments. if (strtoupper($method) == 'POST') { curl_setopt($this->curl, CURLOPT_POST, true); curl_setopt($this->curl, CURLOPT_HTTPHEADER, $this->getCurlHeaders()); curl_setopt($this->curl, CURLOPT_POSTFIELDS, json_encode($this->args)); } // Put request? if (strtoupper($method) == 'PUT') { curl_setopt($this->curl, CURLOPT_CUSTOMREQUEST, 'PUT'); curl_setopt($this->curl, CURLOPT_HTTPHEADER, $this->getCurlHeaders()); curl_setopt($this->curl, CURLOPT_POSTFIELDS, json_encode($this->args)); } }