public function Process($parameters)
 {
     // set the URL parameters
     $content = '';
     $count = count($parameters['param']);
     foreach ($parameters['param'] as $paramName => $param) {
         $content .= $paramName . '=' . rawurlencode($param);
         if (--$count > 0) {
             $content .= '&';
         }
     }
     $request = new \Buzz\Message\Request('GET', '/1/' . $parameters['endpoint'] . '?' . $content . '&key=' . $this->getEmbedlyApiKey(), 'http://api.embed.ly');
     $response = new \Buzz\Message\Response();
     $client = new \Buzz\Client\FileGetContents();
     $client->send($request, $response);
     $json = $response->getContent();
     $decoder = new JsonDecode(true);
     $result = $decoder->decode($json, 'json');
     if ($response->getStatusCode() == '200') {
         $parameters['response'] = $result;
     } else {
         $msg = 'Something went wrong';
         if (isset($result['error_message'])) {
             $msg = $result['error_message'];
         }
         throw new \Exception($msg);
     }
     return $parameters;
 }
Exemple #2
0
 /**
  * Displays Syrup components with their recent version
  *
  * @return JsonResponse
  */
 public function indexAction()
 {
     $rootPath = str_replace('web/../', '', ROOT_PATH);
     $filepath = $rootPath . '/../../composer/installed.json';
     if (!file_exists($filepath)) {
         $filepath = $rootPath . '/vendor/composer/installed.json';
     }
     $installedJson = file_get_contents($filepath);
     $jsonDecoder = new JsonDecode(true);
     $installedArr = $jsonDecoder->decode($installedJson, JsonEncoder::FORMAT);
     $syrupComponents = array();
     foreach ($installedArr as $package) {
         $nameArr = explode("/", $package['name']);
         if ($nameArr[0] == 'syrup' || $nameArr[0] == 'keboola') {
             $syrupComponents[$package['name']] = $package['version'];
         }
     }
     return new JsonResponse(array("host" => gethostname(), "components" => $syrupComponents, "documentation" => "http://documentation.keboola.com/syrup"));
 }
 public function Process($parameters)
 {
     // set the URL parameters
     $content = '';
     $count = count($parameters['param']);
     foreach ($parameters['param'] as $paramName => $param) {
         $content .= $paramName . '=' . rawurlencode($param);
         if (--$count > 0) {
             $content .= '&';
         }
     }
     $request = new \Buzz\Message\Request('GET', '/1/oembed?' . $content, 'http://api.embed.ly');
     $response = new \Buzz\Message\Response();
     $client = new \Buzz\Client\FileGetContents();
     $client->send($request, $response);
     if ($response->getStatusCode() == '200') {
         $json = $response->getContent();
         $decoder = new JsonDecode(true);
         $parameters['response'] = $decoder->decode($json, 'json');
     } else {
         throw new Exception('Something went wrong');
     }
     return $parameters;
 }
 /**
  * @Route("/api-add-news", name="add-news")
  * @Security("has_role('ROLE_ADMIN')")
  */
 public function addNewsAction(Request $request)
 {
     $em = $this->getDoctrine()->getManager();
     $news = new News();
     $news->setTitle($request->get('title'));
     $news->setBody($request->get('body'));
     $news->setHaveImage(false);
     $newsCategories = $news->getCategories();
     $decoder = new JsonDecode();
     $categories = $decoder->decode($request->get('categories'), JsonEncoder::FORMAT);
     foreach ($categories as $categoryData) {
         $category = $em->find('AppBundle\\Entity\\Category', $categoryData->id);
         $newsCategories->add($category);
     }
     if ($img = $request->files->get('image')) {
         $news->setHaveImage(true);
     }
     $em->persist($news);
     $em->flush();
     if ($img) {
         $img->move('bundles/app/image/', 'news-' . $news->getId() . '.jpg');
     }
     return new JsonResponse(array('success' => true, 'message' => 'news has been added'));
 }
 /**
  * @requires function json_last_error_msg
  * @dataProvider decodeProviderException
  * @expectedException Symfony\Component\Serializer\Exception\UnexpectedValueException
  */
 public function testDecodeWithException($value)
 {
     $this->decode->decode($value, JsonEncoder::FORMAT);
 }
 /**
  * @param string $data
  * @return mixed
  */
 protected function decode($data)
 {
     return $this->jsonDecoder->decode($data, 'json');
 }
Exemple #7
0
 /**
  * Get credentials
  *
  * @return array
  */
 public function getCredentials()
 {
     $decode = new JsonDecode();
     $credentials = $decode->decode($this->credentials, JsonEncoder::FORMAT);
     if (!$credentials) {
         $credentials = array();
     }
     return $credentials;
 }
 public function settingsCredentialAction(Request $request)
 {
     $em = $this->getDoctrine()->getManager();
     $member = $this->get('security.context')->getToken()->getUser();
     $chat = $member->getChat();
     if (!$member->hasCredential(Entity\ChatMember::CREDENTIALS_SETTINGS)) {
         throw new AccessDeniedHttpException($this->get('translator')->trans('Вы не можете управлять настройками чата'));
     }
     if ($request->getMethod() == Request::METHOD_POST) {
         $decoder = new JsonDecode();
         $data = $decoder->decode($request->getContent(), JsonEncoder::FORMAT);
         $entity = $em->getRepository('ChatCommonBundle:ChatMember')->findOneBy(array('id' => $data->memberId, 'chat' => $chat));
         if ($entity) {
             if (!in_array($data->credential, $entity->getAllCredentials())) {
                 throw new AccessDeniedHttpException($this->get('translator')->trans('Нет таких полномочий'));
             }
             $credentials = $entity->getCredentials();
             if ($entity->hasCredential($data->credential)) {
                 $entity->removeCredential($data->credential);
             } else {
                 $entity->addCredential($data->credential);
             }
         }
         $em->persist($entity);
         $em->flush();
     }
     return new \Symfony\Component\HttpFoundation\Response();
 }
Exemple #9
0
 /**
  * @expectedException \Symfony\Component\Serializer\Exception\UnexpectedValueException
  */
 public function testDecodeWithInvalidData()
 {
     $result = $this->decoder->decode('kaboom!', 'json');
 }
 private static function fetchArrayStructureFromFile($sFilePath, $bFirstLevel = TRUE)
 {
     // todo: import handling for yaml
     if (!file_exists($sFilePath)) {
         throw new \InvalidArgumentException(sprintf("The config file '%s' does not exist", $sFilePath));
     }
     if (is_dir($sFilePath)) {
         $aConfig = array();
         if (!$bFirstLevel) {
             return $aConfig;
         }
         $aFiles = @scandir($sFilePath, SCANDIR_SORT_NONE);
         if (is_array($aFiles)) {
             foreach ($aFiles as $sFile) {
                 if (in_array($sFile, array('.', '..'))) {
                     continue;
                 }
                 $aConfig = array_merge($aConfig, self::fetchArrayStructureFromFile($sFilePath . DIRECTORY_SEPARATOR . $sFile, FALSE));
             }
         }
     } elseif (preg_match('/\\.ya?ml$/i', $sFilePath)) {
         $aConfig = Yaml::parse(file_get_contents($sFilePath));
     } elseif (preg_match('/\\.json$/i', $sFilePath)) {
         $oJsonDecoder = new JsonDecode();
         $aConfig = $oJsonDecoder->decode(file_get_contents($sFilePath), JsonEncoder::FORMAT, array('json_decode_associative' => TRUE));
     } elseif (preg_match('/\\.ini$/i', $sFilePath)) {
         $aConfig = parse_ini_file($sFilePath, TRUE);
         $aConfig = $aConfig === FALSE ? array() : $aConfig;
     } elseif (preg_match('/\\.php$/i', $sFilePath)) {
         $aConfig = (require $sFilePath);
         $aConfig = $aConfig === 1 ? array() : $aConfig;
     } else {
         throw new \InvalidArgumentException(sprintf("The file '%s' is not supported", $sFilePath));
     }
     return $aConfig;
 }