Skip to content
This repository
Browse code

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
... ... @@ -1 +1,3 @@
1   -/config.xml
  1 +/config.xml
  2 +tmp
  3 +.DS_Store
26 cache/cache.php
... ... @@ -0,0 +1,26 @@
  1 +<?php
  2 +
  3 +namespace Instaphp\Cache
  4 +{
  5 + use Instaphp;
  6 + require_once('icache.php');
  7 +
  8 + abstract class Cache implements iCache
  9 + {
  10 + private static $_instance;
  11 +
  12 + private function __construct($engine)
  13 + {
  14 +
  15 + }
  16 +
  17 + public static function Instance($engine = "File")
  18 + {
  19 + if (null == static::$_instance) {
  20 + $method = new \ReflectionMethod("Instaphp\\Cache\\{$engine}", "Instance");
  21 + static::$_instance = $method->invoke(null, null);
  22 + }
  23 + return static::$_instance;
  24 + }
  25 + }
  26 +}
4 cache/file.php
@@ -8,13 +8,13 @@
8 8 {
9 9 use Instaphp;
10 10 use Instaphp\Config;
11   - require_once('icache.php');
  11 + require_once('cache.php');
12 12 /**
13 13 * Description of file
14 14 *
15 15 * @author randy
16 16 */
17   - class File implements iCache
  17 + class File extends Cache
18 18 {
19 19 private static $_instance;
20 20 private $_config;
11 config.php
@@ -126,6 +126,17 @@ public function CacheSetting($name, $key)
126 126
127 127 }
128 128
  129 + public function GetSection($section = null, \SimpleXMLElement $parent = null)
  130 + {
  131 + if (empty($section))
  132 + return null;
  133 +
  134 + if (null !== $parent)
  135 + return $parent->xpath($section);
  136 +
  137 + return $this->xpath($section);
  138 + }
  139 +
129 140 }
130 141
131 142 }
6 config.sample.xml
@@ -12,5 +12,11 @@
12 12 <Instaphp>
13 13 <RedirectUri></RedirectUri>
14 14 <CACertBundlePath></CACertBundlePath>
  15 + <Cache Engine="File" Enabled="true">
  16 + <Settings>
  17 + <Setting Path="tmp/cache"/>
  18 + <Setting TTL="+2 Minutes"/>
  19 + </Settings>
  20 + </Cache>
15 21 </Instaphp>
16 22 </Config>
11 request.php
@@ -83,17 +83,20 @@ public function __construct($url = null, $params = array())
83 83 $this->parameters = $params;
84 84 $this->url = $url;
85 85
86   - $cacheConfig = Config::Instance()->xpath("//Cache");
  86 +/*
  87 + $cacheConfig = Config::Instance()->GetSection("Instaphp/Cache");
87 88 if (!empty($cacheConfig) && count($cacheConfig) > 0) {
88 89 $cacheConfig = $cacheConfig[0];
89 90 if ($cacheConfig["Enabled"]) {
90 91 $engine = (string)$cacheConfig["Engine"];
91   - $method = new \ReflectionMethod("Instaphp\\Cache\\".$engine, 'Instance');
92   - $this->_cache = $method->invoke(null, null);
93   -// $this->_cache = Cache\File::Instance();
  92 + $this->_cache = Cache\Cache::Instance($engine);
  93 + // $method = new \ReflectionMethod("Instaphp\\Cache\\".$engine, 'Instance');
  94 + // $this->_cache = $method->invoke(null, null);
  95 + // $this->_cache = Cache\File::Instance();
94 96 }
95 97
96 98 }
  99 +*/
97 100 }
98 101
99 102
10 response.php
@@ -132,7 +132,7 @@ public static function Create(Request $request, Response $response)
132 132 $error = new Error;
133 133 $error->type = 'cURLResponseError';
134 134 $error->code = $response->info['http_code'];
135   - $error->url = $request->url;
  135 + $error->url = $response->info['url'];
136 136 switch ($error->code)
137 137 {
138 138 case 505:
@@ -179,7 +179,7 @@ public static function Create(Request $request, Response $response)
179 179 }
180 180
181 181 if (isset($obj->{'error_message'})) {
182   - $response->error = new Error($obj->{'error_type'}, $obj->{'code'}, $obj->{'error_message'}, $request->url);
  182 + $response->error = new Error($obj->{'error_type'}, $obj->{'code'}, $obj->{'error_message'}, $response->info['url']);
183 183 }
184 184
185 185 if (isset($obj->{'access_token'})) {
@@ -191,7 +191,9 @@ public static function Create(Request $request, Response $response)
191 191 $response->meta = $obj->{'meta'};
192 192
193 193 if (isset($obj->{'meta'}) && $obj->{'meta'}->code !== 200) {
194   - $response->error = new Error($response->meta->error_type, $response->meta->code, $response->meta->error_message, $request->url);
  194 + $response->error = new Error($response->meta->error_type, $response->meta->code, $response->meta->error_message, $response->info['url']);
  195 + $query = '';
  196 +
195 197 }
196 198
197 199 if (isset($obj->{'data'}))
@@ -256,7 +258,7 @@ class Error
256 258 * @access public
257 259 **/
258 260 public $url = null;
259   -
  261 +
260 262 /**
261 263 * The constructor constructs
262 264 * @param string $type The error type
2  webrequest.php
@@ -180,7 +180,7 @@ public function Create($url, $method = 'GET', $parameters = array())
180 180 $options = $this->_options;
181 181
182 182 foreach ($parameters as $k => $v)
183   - $query .= ((strlen ($query) == 0) ? '':'&') . sprintf('%s=%s', $k, $v);
  183 + $query .= ((strlen ($query) == 0) ? "":"&") . sprintf('%s=%s', $k, urlencode($v));
184 184
185 185 switch (strtolower($method))
186 186 {

0 comments on commit 4bf90e1

Please sign in to comment.
Something went wrong with that request. Please try again.