convert input to an EasyPost object

@param mixed  $response
@param string $apiKey
@param string $parent
@param string $name
@return array
960115
public static function convertToEasyPostObject($response, $apiKey, $parent = null, $name = null)
    {
        $types = array(
            'Address'           => '\EasyPost\Address',
            'Batch'             => '\EasyPost\Batch',
            'CarrierAccount'    => '\EasyPost\CarrierAccount',
            'Container'         => '\EasyPost\Container',
            'CustomsInfo'       => '\EasyPost\CustomsInfo',
            'CustomsItem'       => '\EasyPost\CustomsItem',
            'Event'             => '\EasyPost\Event',
            'Fee'               => '\EasyPost\Fee',
            'Item'              => '\EasyPost\Item',
            'Order'             => '\EasyPost\Order',
            'Parcel'            => '\EasyPost\Parcel',
            'Pickup'            => '\EasyPost\Pickup',
            'PostageLabel'      => '\EasyPost\PostageLabel',
            'Rate'              => '\EasyPost\Rate',
            'Refund'            => '\EasyPost\Refund',
            'ScanForm'          => '\EasyPost\ScanForm',
            'Shipment'          => '\EasyPost\Shipment',
            'Tracker'           => '\EasyPost\Tracker',
            'User'              => '\EasyPost\User',
            'Insurance'         => '\EasyPost\Insurance',
            'Report'            => '\EasyPost\Report',
            'ShipmentReport'    => '\EasyPost\Report',
            'PaymentLogReport'  => '\EasyPost\Report',
            'TrackerReport'     => '\EasyPost\Report',
            'Webhook'           => '\EasyPost\Webhook'
        );

        $prefixes = array(
            'adr'       => '\EasyPost\Address',
            'batch'     => '\EasyPost\Batch',
            'ca'        => '\EasyPost\CarrierAccount',
            'container' => '\EasyPost\Container',
            'cstinfo'   => '\EasyPost\CustomsInfo',
            'cstitem'   => '\EasyPost\CustomsItem',
            'evt'       => '\EasyPost\Event',
            'fee'       => '\EasyPost\Fee',
            'item'      => '\EasyPost\Item',
            'order'     => '\EasyPost\Order',
            'prcl'      => '\EasyPost\Parcel',
            'pickup'    => '\EasyPost\Pickup',
            'pl'        => '\EasyPost\PostageLabel',
            'rate'      => '\EasyPost\Rate',
            'rfnd'      => '\EasyPost\Refund',
            'sf'        => '\EasyPost\ScanForm',
            'shp'       => '\EasyPost\Shipment',
            'trk'       => '\EasyPost\Tracker',
            'user'      => '\EasyPost\User',
            'ins'       => '\EasyPost\Insurance',
            'shprep'    => '\EasyPost\Report',
            'plrep'     => '\EasyPost\Report',
            'trkrep'    => '\EasyPost\Report',
            'hook'      => '\EasyPost\Webhook'
        );

        if (self::isList($response)) {
            $mapped = array();
            foreach ($response as $object => $v) {
                if (is_string($object) && isset($types[$object])) {
                    $v['object'] = $object;
                }
                array_push($mapped, self::convertToEasyPostObject($v, $apiKey, $parent, $name));
            }

            return $mapped;
        } else if (is_array($response)) {
            if (isset($response['object']) && is_string($response['object']) && isset($types[$response['object']])) {
                $class = $types[$response['object']];
            } else if (isset($response['id']) && isset($prefixes[substr($response['id'], 0, strpos($response['id'], "_"))])) {
                $class = $prefixes[substr($response['id'], 0, strpos($response['id'], "_"))];
            } else {
                $class = '\EasyPost\EasyPostObject';
            }

            return EasyPostObject::constructFrom($response, $class, $apiKey, $parent, $name);
        } else {

            return $response;
        }
    }
56019
private function postProcessing(JsonResponse $response) {
		$apiUrl = $this->getServiceContainer()->getPreferenceLoader()->getSystemPreferences()->getApiUrl();
		$response->setContent(str_replace('%apiurl%', $apiUrl, $response->getContent()));
		return $response;
	}
346983
public static function buildHttpQuery($data, ?string $parent = null): array
    {
        $result = [];

        if (is_object($data)) {
            $data = get_object_vars($data);
        }

        foreach ($data as $key => $value) {
            if ($parent) {
                $new_key = sprintf('%s[%s]', $parent, $key);
            } else {
                $new_key = $key;
            }

            if (!$value instanceof CURLFile && (is_array($value) || is_object($value))) {
                $result = array_merge($result, self::buildHttpQuery($value, $new_key));
            } else {
                $result[$new_key] = $value;
            }
        }

        return $result;
    }
648733
protected function wrapResponse(Request $request, JsonResponse $response)
    {
        switch ($request->query->get(self::PARAMETER_WRAPPER)) {
            case self::WRAPPER_POST_MESSAGE:
                $response->setContent(
                    sprintf(
                        $this->getPostMessageTemplate(),
                        $response->getContent(),
                        $this->getCallbackFromRequest($request),
                        $this->getPostMessageOrigin()
                    )
                )->headers->set('Content-Type', 'text/html');
                break;
            default:
                $response->setCallback(
                    $request->query->get(self::PARAMETER_CALLBACK)
                );
                break;
        }
    }
1090873
public function transform(ApiRequest $request, ApiResponse $response, array $context = []): ApiResponse
	{
		if (isset($context['exception'])) {
			// Convert exception to json
			$content = Json::encode($this->extractException($request, $response, $context));
			if ($context['exception'] instanceof ClientErrorException || $context['exception'] instanceof ServerErrorException) {
				$response = $response->withStatus($context['exception']->getCode());
			} else {
				$response = $response->withStatus(500);
			}
		} else {
			// Convert data to array to json
			$content = Json::encode($this->extractData($request, $response, $context));
		}

		$response->getBody()->write($content);

		// Setup content type
		return $response
			->withHeader('Content-Type', 'application/json');
	}
1159568
protected function getRule(string $name, string $key, array $parent_names = []): array
    {
        if (isset($this->rules[$key])) {
            return $this->rules[$key];
        }
        if ($this->total_rules === 1 || !$parent_names) {
            return $this->rules['*']; // Done here.
        }
        foreach (array_map('strtolower', $parent_names) as $_parent_key) {
            if (isset($this->rules[$_parent_key])) {
                return $this->rules[$_parent_key];
            }
        } // unset($_parent_key); // Housekeeping.

        return $this->rules['*'];
    }
417900
def json_post(methodname, rtype, key):
    """"""
    return compose(
        reusable,
        map_return(registry(rtype), itemgetter(key)),
        basic_interaction,
        map_yield(partial(_json_as_post, methodname)),
        oneyield,
    )
1229813
protected function parseResponse($name, $response)
    {
        if ($response instanceof static) {
            return $response;
        }

        #echo "> $name : ".substr(print_r($response, TRUE),0,100)."\n";

        // change return values where it is too difficult to minim in standalone mode
        switch ($name) {
            case 'type':
                $response = self::$typeMap[$response];
                break;

            // Handle scripting errors
            case 'eval':
            case 'evalsha':
            case 'script':
                $error = $this->redis->getLastError();
                $this->redis->clearLastError();
                if ($error && \strpos($error, 'NOSCRIPT') === 0) {
                    $response = null;
                } elseif ($error) {
                    throw new RedisException($error);
                }
                break;
            case 'exists':
                // smooth over phpredis-v4 vs earlier difference to match documented credis return results
                $response = (int) $response;
                break;
            default:
                $error = $this->redis->getLastError();
                $this->redis->clearLastError();
                if ($error) {
                    throw new RedisException($error);
                }
                break;
        }

        return $response;
    }
1210603
protected function simplifyResponse(array $response)
    {
        // Simplify response by removing main key (which should be the only
        // remaining one).
        if (!empty($this->mainResponseKey) && isset($response[$this->mainResponseKey])) {
            $response = $response[$this->mainResponseKey];

            if ($this->isList) {
                // Remove further indirection, i.e. get value of "singular",
                // which will be the first (and only) key.
                $response = reset($response);
                // If there was only 1 list result, it wasn't put in an array.
                if (!is_array(reset($response))) {
                    $response = array($response);
                }
            }
        }
        return $response;
    }
283104
private function prepareApiResponse(
        ResponseContextAbstract $responseContext,
        string $apiClassMethod
    ): ApiResponseInterface {
        $prepareApiResponse = sprintf("prepare%sResponse", ucfirst($apiClassMethod));

        $this->assertMethodExists($prepareApiResponse);

        $apiResponse = $this->{$prepareApiResponse}($responseContext);

        return $apiResponse;
    }
898194
public function apiAction() {
        /**
         * Prepare the server. Zend_Json_Server cannot work with batched requests natively,
         * so that's taken care of customly here. Therefore, autoEmitResponse is set to false
         * so the server doesn't print the response directly.
         */
        $server = new Zend_Json_Server();
        $server->setClass('Garp_Content_Manager_Proxy');
        $server->setAutoEmitResponse(false);

        if ($this->getRequest()->isPost()) {
            $post = $this->_getJsonRpcRequest();
            $batch = false;
            $responses = array();
            $requests = Zend_Json::decode($post, Zend_Json::TYPE_ARRAY);
            /**
             * Check if this was a batch request. In that case the array is a plain array of
             * arrays. If not, there will be a 'jsonrpc' key in the root of the array.
             */
            $batch = !array_key_exists('jsonrpc', $requests);
            if (!$batch) {
                $requests = array($requests);
            }
            foreach ($requests as $i => $request) {
                $request = $this->_reformJsonRpcRequest($request);
                $requestJson = Zend_Json::encode($request);
                $requestObj = new Zend_Json_Server_Request();
                $requestObj->loadJson($requestJson);
                $server->setRequest($requestObj);
                /**
                 * Note; response gets returned by reference, resulting in a $responses array
                 * containing all the same items.
                 * That's why clone is used here.
                 */
                $response = clone $server->handle();
                $responses[] = $response;
            }
            $response = $batch ? '[' . implode(',', $responses) . ']' : $responses[0];
        } else {
            $response = $server->getServiceMap();
        }
        $this->_helper->layout->setLayout('json');
        //  filter out escaped slashes, because they're annoying and not necessary.
        $response = str_replace('\/', '/', $response);
        $this->view->response = $response;
    }
56442
public static function post(string $name)
    {
        return (isset($_POST[$name]) && $_POST[$name] != '') ? $_POST[$name] : '';
    }
589296
public static function getHeader(ResponseInterface $response, $name)
    {
        $headers = $response->getHeader($name);

        return array_shift($headers);
    }
532391
private function _handleRecursive($response, $resourceName)
    {
        $result = null;
        if (isset($response['id'])) {
            $result = $this->_convertResponseToModel($response, $resourceName);
        } else if (!is_null($response)) {
            $paymentArray = array();
            foreach ($response as $paymentData) {
                array_push($paymentArray, $this->_convertResponseToModel($paymentData, $resourceName));
            }
            $result = $paymentArray;
        }
        return $result;
    }
1121033
function apiResponded(apiResponse) {
      // Convert XML to JS object
      var parser = new xml2js.Parser({explicitArray:false});
      parser.parseString(apiResponse, function (err, result) {
        // If the method processes the response, give it back
        // Otherwise call the original callback

        if(typeof a.processor !== 'undefined')
          a.processor(result.response, a.callback);
        else
          a.callback(result.response);
      });


    }
689391
public static function convertToPingppObject($resp, $apiKey)
    {
        $types = array(
            'charge' => 'Pingpp_Charge',
            'list' => 'Pingpp_List',
            'refund' => 'Pingpp_Refund'
        );
        if (self::isList($resp)) {
            $mapped = array();
            foreach ($resp as $i)
                array_push($mapped, self::convertToPingppObject($i, $apiKey));
            return $mapped;
        } else if (is_object($resp)) {
            if (isset($resp->object) 
                && is_string($resp->object)
                && isset($types[$resp->object])) {
                    $class = $types[$resp->object];
                } else {
                    $class = 'Pingpp_Object';
                }
            return Pingpp_Object::scopedConstructFrom($class, $resp, $apiKey);
        } else {
            return $resp;
        }
    }
1154796
public function post($name, $spaceId = null, $threadId = null, $guestSpaceId = null): array
    {
        $options = ['json' => ['name' => $name]];
        if ($spaceId !== null) {
            $options['json']['space'] = $spaceId;
            $options['json']['thread'] = $threadId;
        }

        /** @var JsonStream $stream */
        $stream = $this->client
            ->post(KintoneApi::generateUrl('preview/app.json', $guestSpaceId), $options)
            ->getBody();

        return $stream->jsonSerialize();
    }