Ejemplo n.º 1
0
 public function testGetEndpoint()
 {
     $request = new Request(Type::TYPE_DOMAIN_RANKS, ['key' => $this->key, 'domain' => $this->domain]);
     $this->assertEquals("http://api.semrush.com/", $request->getEndpoint());
     $request = new Request(Type::TYPE_ADVERTISER_RANK, ['key' => $this->key, 'domain' => $this->domain]);
     $this->assertEquals("http://api.semrush.com/analytics/da/v2/", $request->getEndpoint());
 }
Ejemplo n.º 2
0
 /**
  * Serialise the request
  *
  * @param Request $request
  * @return string
  */
 public function serialise(Request $request)
 {
     $parameters = $request->getUrlParameters();
     ksort($parameters);
     $string = "";
     array_walk($parameters, function ($value, $key) use(&$string) {
         if (is_array($value)) {
             $value = implode("", $value);
         }
         $string .= $key . $value;
     });
     return md5($string);
 }
Ejemplo n.º 3
0
 /**
  * Parse a result into an array.  Also requires
  * the request so we can work out which columns
  * we expected the API to return.
  *
  * @param Request $request
  * @param string $data
  * @throws ErroneousResponseException
  * @return string[]
  */
 public function parseResult(Request $request, $data)
 {
     try {
         $this->handleErrors($data);
     } catch (EmptyResponseException $e) {
         return [];
     }
     $rows = $this->splitStringIntoArray($data);
     $columns = $request->getExpectedResultColumns();
     $rows = $this->hackToFixNewlineInCell($rows);
     foreach ($rows as &$row) {
         $row = $this->parseRow($columns, $row);
     }
     return $rows;
 }
Ejemplo n.º 4
0
 /**
  * Get the URL of this request
  *
  * @return string
  */
 protected function getUrl()
 {
     $params = $this->getOptionsAsStrings();
     return $this->request->getEndpoint() . "?" . http_build_query($params);
 }