src/Controllers/HailController.php
public function fetchOneSync(HTTPRequest $request)
    {
        if (!Security::getCurrentUser()) {
            return $this->makeJsonReponse(401, [
                'message' => 'Unauthorized.'
            ])->setStatusDescription('Unauthorized.');
        }

        $params = $request->params();

        if (empty($params['Class']) || empty($params['HailID'])) {
            return $this->makeJsonReponse(400, [
                'message' => 'Invalid request.'
            ]);
        }
        $class_name = str_replace("-", "\\", $params['Class']);
        if (!class_exists($class_name)) {
            return $this->makeJsonReponse(400, [
                'message' => 'Invalid request.'
            ]);
        }
        $object = DataObject::get($class_name)->filter(['HailID' => $params['HailID']])->first();
        if (!$object) {
            return $this->makeJsonReponse(404, [
                'message' => 'Object does not exist.'
            ]);
        }

        //Refresh from Hail API
        $object->refresh();

        return $this->makeJsonReponse(200, [
            'message' => 'Success'
        ]);
    }
public function fetchOneSync(HTTPRequest $request)
    {
        if (!Security::getCurrentUser()) {
            return $this->makeJsonReponse(401, [
                'message' => 'Unauthorized.'
            ])->setStatusDescription('Unauthorized.');
        }

        $params = $request->params();

        if (empty($params['Class']) || empty($params['HailID'])) {
            return $this->makeJsonReponse(400, [
                'message' => 'Invalid request.'
            ]);
        }
        $class_name = str_replace("-", "\\", $params['Class']);
        if (!class_exists($class_name)) {
            return $this->makeJsonReponse(400, [
                'message' => 'Invalid request.'
            ]);
        }
        $object = DataObject::get($class_name)->filter(['HailID' => $params['HailID']])->first();
        if (!$object) {
            return $this->makeJsonReponse(404, [
                'message' => 'Object does not exist.'
            ]);
        }

        //Refresh from Hail API
        $object->refresh();

        return $this->makeJsonReponse(200, [
            'message' => 'Success'
        ]);
    }
public function fetchOneSync ( HTTPRequest $ request ) { if ( ! Security :: getCurrentUser ( ) ) { return $ this -> makeJsonReponse ( 401 , [ 'message' => 'Unauthorized.' ] ) -> setStatusDescription ( 'Unauthorized.' ) ; } $ params = $ request -> params ( ) ; if ( empty ( $ params [ 'Class' ] ) || empty ( $ params [ 'HailID' ] ) ) { return $ this -> makeJsonReponse ( 400 , [ 'message' => 'Invalid request.' ] ) ; } $ class_name = str_replace ( "-" , "\\" , $ params [ 'Class' ] ) ; if ( ! class_exists ( $ class_name ) ) { return $ this -> makeJsonReponse ( 400 , [ 'message' => 'Invalid request.' ] ) ; } $ object = DataObject :: get ( $ class_name ) -> filter ( [ 'HailID' => $ params [ 'HailID' ] ] ) -> first ( ) ; if ( ! $ object ) { return $ this -> makeJsonReponse ( 404 , [ 'message' => 'Object does not exist.' ] ) ; } //Refresh from Hail API
 $ object -> refresh ( ) ; return $ this -> makeJsonReponse ( 200 , [ 'message' => 'Success' ] ) ; }
Fetch one specific Hail object synchronously and update its database record

The object to fetch is specified in the URL
e.g.: /hail/fetchOne/[CLASS]/[HAILID]
Example: /hail/fetchOne/Firebrand-Hail-Models-Article/l1KjRUP will fetch and update the article with HailID=l1KjRUP

@param HTTPRequest $request Current request

@return HTTPResponse JSON response
@throws
Fetch one specific Hail object synchronously and update its database record