Example #1
0
 /**
  * @param Apist $resource
  *
  * @throws ParseException
  * @throws \InvalidArgumentException
  */
 public function load(Apist $resource)
 {
     $data = Yaml::parse($this->file);
     if (isset($data['baseUrl'])) {
         $resource->setBaseUrl($data['baseUrl']);
         unset($data['baseUrl']);
     }
     $this->blueprintParser->parse($data);
 }
Example #2
0
 /**
  * @param $blueprint
  * @return array
  */
 protected function parseBlueprint($blueprint)
 {
     $callback = function (&$value) {
         if (is_string($value)) {
             $value = str_replace(':current', '*', $value);
         }
         if ($value[0] === ':') {
             # structure
             $structure = $this->getStructure($value);
             $value = $this->parseBlueprint($structure);
             return;
         }
         if (strpos($value, '|') === false) {
             return;
         }
         $parts = preg_split('/\\s?\\|\\s?/', $value);
         $selector = array_shift($parts);
         $value = Apist::filter($selector);
         foreach ($parts as $part) {
             $this->addCallbackToFilter($value, $part);
         }
     };
     if (!is_array($blueprint)) {
         $callback($blueprint);
     } else {
         array_walk_recursive($blueprint, $callback);
     }
     return $blueprint;
 }
Example #3
0
 /**
  * @param \GuzzleHttp\ClientInterface $httpClient
  * @param string $baseUrl
  * @param null $file
  *
  * @throws \Symfony\Component\Yaml\Exception\ParseException
  * @throws \InvalidArgumentException
  */
 public function __construct(ClientInterface $httpClient, $baseUrl = '', $file = null)
 {
     if ($file !== null) {
         $this->loadFromYml($file);
     }
     parent::__construct($httpClient, $baseUrl);
 }
Example #4
0
 /**
  * @param array $options
  */
 function __construct($file = null, $options = [])
 {
     if (!is_null($file)) {
         $this->loadFromYml($file);
     }
     parent::__construct($options);
 }
Example #5
0
 public function ImageUrl($url)
 {
     // http://radikal.ru/F/s39.radikal.ru/i086/0909/e7/c510615b8119.jpg.html
     //  redirect -> http://f-picture.net/fp/80c5ae08a4564d288671f1f060ba8786
     $data = $this->get($url, ['image_url' => Apist::filter('div.f-content div img')->attr('src')]);
     return $data['image_url'];
 }
Example #6
0
 /**
  * Make http request
  *
  * @param array $arguments
  */
 protected function makeRequest($arguments = [])
 {
     $defaults = $this->getDefaultOptions();
     $arguments = array_merge($defaults, $arguments);
     $client = $this->resource->getGuzzle();
     $request = $client->createRequest($this->getMethod(), $this->url, $arguments);
     $response = $client->send($request);
     $this->setResponse($response);
     $this->setContent((string) $response->getBody());
 }
Example #7
0
 /**
  * Get the full description of the job
  *
  * @param int $id
  *
  * @return array
  */
 public function getItem($id)
 {
     return $this->get('/jobs/' . $id, ['requirements' => Apist::filter('.requirements')->html(), 'bonuses' => Apist::filter('.bonuses')->html(), 'skills' => Apist::filter('.tags .tag')->each(Apist::filter('*')->text()->trim()), 'instructions' => Apist::filter('.instructions .text')->html()]);
 }
Example #8
0
 public function non_array_blueprint()
 {
     return $this->get('/', Apist::filter('.page_head .title'));
 }