Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixing some issues around Errors and the Instagram API url used which…

… produced the error. Encoding the query params since it was producing 400 responses from the API in some cases
  • Loading branch information...
commit 4bf90e1c5c732bb4c1b31b9e9ac65506805e8a0e 1 parent 4539cef
randy authored
4 .gitignore
View
@@ -1 +1,3 @@
-/config.xml
+/config.xml
+tmp
+.DS_Store
26 cache/cache.php
View
@@ -0,0 +1,26 @@
+<?php
+
+namespace Instaphp\Cache
+{
+ use Instaphp;
+ require_once('icache.php');
+
+ abstract class Cache implements iCache
+ {
+ private static $_instance;
+
+ private function __construct($engine)
+ {
+
+ }
+
+ public static function Instance($engine = "File")
+ {
+ if (null == static::$_instance) {
+ $method = new \ReflectionMethod("Instaphp\\Cache\\{$engine}", "Instance");
+ static::$_instance = $method->invoke(null, null);
+ }
+ return static::$_instance;
+ }
+ }
+}
4 cache/file.php
View
@@ -8,13 +8,13 @@
{
use Instaphp;
use Instaphp\Config;
- require_once('icache.php');
+ require_once('cache.php');
/**
* Description of file
*
* @author randy
*/
- class File implements iCache
+ class File extends Cache
{
private static $_instance;
private $_config;
11 config.php
View
@@ -126,6 +126,17 @@ public function CacheSetting($name, $key)
}
+ public function GetSection($section = null, \SimpleXMLElement $parent = null)
+ {
+ if (empty($section))
+ return null;
+
+ if (null !== $parent)
+ return $parent->xpath($section);
+
+ return $this->xpath($section);
+ }
+
}
}
6 config.sample.xml
View
@@ -12,5 +12,11 @@
<Instaphp>
<RedirectUri></RedirectUri>
<CACertBundlePath></CACertBundlePath>
+ <Cache Engine="File" Enabled="true">
+ <Settings>
+ <Setting Path="tmp/cache"/>
+ <Setting TTL="+2 Minutes"/>
+ </Settings>
+ </Cache>
</Instaphp>
</Config>
11 request.php
View
@@ -83,17 +83,20 @@ public function __construct($url = null, $params = array())
$this->parameters = $params;
$this->url = $url;
- $cacheConfig = Config::Instance()->xpath("//Cache");
+/*
+ $cacheConfig = Config::Instance()->GetSection("Instaphp/Cache");
if (!empty($cacheConfig) && count($cacheConfig) > 0) {
$cacheConfig = $cacheConfig[0];
if ($cacheConfig["Enabled"]) {
$engine = (string)$cacheConfig["Engine"];
- $method = new \ReflectionMethod("Instaphp\\Cache\\".$engine, 'Instance');
- $this->_cache = $method->invoke(null, null);
-// $this->_cache = Cache\File::Instance();
+ $this->_cache = Cache\Cache::Instance($engine);
+ // $method = new \ReflectionMethod("Instaphp\\Cache\\".$engine, 'Instance');
+ // $this->_cache = $method->invoke(null, null);
+ // $this->_cache = Cache\File::Instance();
}
}
+*/
}
10 response.php
View
@@ -132,7 +132,7 @@ public static function Create(Request $request, Response $response)
$error = new Error;
$error->type = 'cURLResponseError';
$error->code = $response->info['http_code'];
- $error->url = $request->url;
+ $error->url = $response->info['url'];
switch ($error->code)
{
case 505:
@@ -179,7 +179,7 @@ public static function Create(Request $request, Response $response)
}
if (isset($obj->{'error_message'})) {
- $response->error = new Error($obj->{'error_type'}, $obj->{'code'}, $obj->{'error_message'}, $request->url);
+ $response->error = new Error($obj->{'error_type'}, $obj->{'code'}, $obj->{'error_message'}, $response->info['url']);
}
if (isset($obj->{'access_token'})) {
@@ -191,7 +191,9 @@ public static function Create(Request $request, Response $response)
$response->meta = $obj->{'meta'};
if (isset($obj->{'meta'}) && $obj->{'meta'}->code !== 200) {
- $response->error = new Error($response->meta->error_type, $response->meta->code, $response->meta->error_message, $request->url);
+ $response->error = new Error($response->meta->error_type, $response->meta->code, $response->meta->error_message, $response->info['url']);
+ $query = '';
+
}
if (isset($obj->{'data'}))
@@ -256,7 +258,7 @@ class Error
* @access public
**/
public $url = null;
-
+
/**
* The constructor constructs
* @param string $type The error type
2  webrequest.php
View
@@ -180,7 +180,7 @@ public function Create($url, $method = 'GET', $parameters = array())
$options = $this->_options;
foreach ($parameters as $k => $v)
- $query .= ((strlen ($query) == 0) ? '':'&') . sprintf('%s=%s', $k, $v);
+ $query .= ((strlen ($query) == 0) ? "":"&") . sprintf('%s=%s', $k, urlencode($v));
switch (strtolower($method))
{
Please sign in to comment.
Something went wrong with that request. Please try again.