Permalink
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...
1 parent 4539cef commit 4bf90e1c5c732bb4c1b31b9e9ac65506805e8a0e randy committed Aug 15, 2011
Showing with 62 additions and 12 deletions.
  1. +3 −1 .gitignore
  2. +26 −0 cache/cache.php
  3. +2 −2 cache/file.php
  4. +11 −0 config.php
  5. +6 −0 config.sample.xml
  6. +7 −4 request.php
  7. +6 −4 response.php
  8. +1 −1 webrequest.php
View
4 .gitignore
@@ -1 +1,3 @@
-/config.xml
+/config.xml
+tmp
+.DS_Store
View
26 cache/cache.php
@@ -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;
+ }
+ }
+}
View
4 cache/file.php
@@ -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;
View
11 config.php
@@ -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);
+ }
+
}
}
View
6 config.sample.xml
@@ -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>
View
11 request.php
@@ -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();
}
}
+*/
}
View
10 response.php
@@ -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
View
2 webrequest.php
@@ -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))
{

0 comments on commit 4bf90e1

Please sign in to comment.