Instaphp/Response.php
public static function Create(Request $request, Response $response)
    {
        $obj = json_decode($response->json);

		//-- for embeded calls, just return the embeded object
		if (isset($obj->{'provider_url'}) && !empty($obj->{'provider_url'})) {
			$response->embed = $obj;
			return $response;
		}
			
        if (empty($obj)) {
			$error = new Error;
			$error->type = 'cURLResponseError';
			$error->code = $response->info['http_code'];
			$error->url = $response->info['url'];
			switch ($error->code)
			{
				case 505:
					$error->message = 'HTTP version not supported? Weird.';
					break;
				case 504:
					$error->message = 'Gateway timeout. Sorry.';
					break;
				case 503:
					$error->message = 'The API is currently unavailable';
					break;
				case 502:
					$error->message = 'Baaaaaaaaad gateway!';
					break;
				case 501:
					$error->message = 'Sorry, not implemented... YET.';
					break;
				case 500:
					$error->message = 'Whoops! API just barfed on your new shoes.';
					break;
				case 405:
					$error->message = 'Method not allowed.';
					break;
				case 404:
					$error->message = 'Received a 404 from the API';
					break;
				case 403:
					$error->message = 'The API says you are forbidden';
					break;
				case 402:
					$error->message = 'The API claims you own them money.';
					break;
				case 401:
					$error->message = 'The API says you are unauthorized.';
					break;
				case 400:
					$error->message = 'POBR... Plain Old Bad Request.';
					break;
				default:
					$error->message = 'Unknown error ocurred making this request';
					break;
			}
			$response->error = $error;
        }

        if (isset($obj->{'error_message'})) {
            $response->error = new Error($obj->{'error_type'}, $obj->{'code'}, $obj->{'error_message'}, $response->info['url']);
        }

        if (isset($obj->{'access_token'})) {
            $response->auth->access_token = $obj->{'access_token'};
            $response->auth->user = $obj->{'user'};
        }

        if (isset($obj->{'meta'}))
            $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, $response->info['url']);
            $query = '';
            
        }

        if (isset($obj->{'data'}))
            $response->data = $obj->{'data'};

        if (isset($obj->{'pagination'}))
            $response->pagination = $obj->{'pagination'};

        return $response;
    }
public static function Create(Request $request, Response $response)
    {
        $obj = json_decode($response->json);

		//-- for embeded calls, just return the embeded object
		if (isset($obj->{'provider_url'}) && !empty($obj->{'provider_url'})) {
			$response->embed = $obj;
			return $response;
		}
			
        if (empty($obj)) {
			$error = new Error;
			$error->type = 'cURLResponseError';
			$error->code = $response->info['http_code'];
			$error->url = $response->info['url'];
			switch ($error->code)
			{
				case 505:
					$error->message = 'HTTP version not supported? Weird.';
					break;
				case 504:
					$error->message = 'Gateway timeout. Sorry.';
					break;
				case 503:
					$error->message = 'The API is currently unavailable';
					break;
				case 502:
					$error->message = 'Baaaaaaaaad gateway!';
					break;
				case 501:
					$error->message = 'Sorry, not implemented... YET.';
					break;
				case 500:
					$error->message = 'Whoops! API just barfed on your new shoes.';
					break;
				case 405:
					$error->message = 'Method not allowed.';
					break;
				case 404:
					$error->message = 'Received a 404 from the API';
					break;
				case 403:
					$error->message = 'The API says you are forbidden';
					break;
				case 402:
					$error->message = 'The API claims you own them money.';
					break;
				case 401:
					$error->message = 'The API says you are unauthorized.';
					break;
				case 400:
					$error->message = 'POBR... Plain Old Bad Request.';
					break;
				default:
					$error->message = 'Unknown error ocurred making this request';
					break;
			}
			$response->error = $error;
        }

        if (isset($obj->{'error_message'})) {
            $response->error = new Error($obj->{'error_type'}, $obj->{'code'}, $obj->{'error_message'}, $response->info['url']);
        }

        if (isset($obj->{'access_token'})) {
            $response->auth->access_token = $obj->{'access_token'};
            $response->auth->user = $obj->{'user'};
        }

        if (isset($obj->{'meta'}))
            $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, $response->info['url']);
            $query = '';
            
        }

        if (isset($obj->{'data'}))
            $response->data = $obj->{'data'};

        if (isset($obj->{'pagination'}))
            $response->pagination = $obj->{'pagination'};

        return $response;
    }
A convenience method to parse the response text and build a Response object
@access public
@static
@param string $responseText The response from the API call
@param string $url The url used to generate the Response object
@return Response