Skip to content

Commit

Permalink
Refactored curl methods to follow CRUD
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonkellydk committed May 17, 2017
1 parent 102ed88 commit 21a022e
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# AccuRanker for Laravel 5.1
# AccuRanker for Laravel 5+

**THIS PACKAGE IS UNDER DEVELOPMENT**

Expand Down
28 changes: 28 additions & 0 deletions src/SpotOnLive/AccuRanker/Services/AccuRankerService.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,18 @@ public function createKeywordForDomain($domainId, $keyword, $searchType, $search
return $this->convertResponseToKeyword($response);
}

/**
* @param $domainId
* @param $id
* @return null
*/
public function deleteKeywordsForDomain($domainId, $id)
{
$response = $this->delete('domains/' . $domainId . '/keywords/' . $id . '/');

return null;
}

/**
* Call the CURL get service
*
Expand Down Expand Up @@ -169,6 +181,22 @@ public function post($url, $body)
return $this->parse($result);
}

/**
* Call the CURL delete service
*
* @param $url
* @return array
*/
public function delete($url)
{
$result = $this->curlService->delete(
$this->getUrl() . $url,
$this->getToken()
);

return $this->parse($result);
}

/**
* Parse result
*
Expand Down
18 changes: 18 additions & 0 deletions src/SpotOnLive/AccuRanker/Services/AccuRankerServiceInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,22 @@ public function listKeywordsForDomain($id);
* @return array
*/
public function listKeywordHistory($keywordId);

/**
* @param $domainId
* @param $keyword
* @param $searchType
* @param $searchEngine
* @param array $optional
* @return mixed
*/
public function createKeywordForDomain($domainId, $keyword, $searchType, $searchEngine, $optional = []);

/**
* @param $domainId
* @param $id
* @return mixed
*/
public function deleteKeywordsForDomain($domainId, $id);

}
31 changes: 27 additions & 4 deletions src/SpotOnLive/AccuRanker/Services/CurlService.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use SpotOnLive\AccuRanker\Options\ApiOptions;


class CurlService implements CurlServiceInterface
{
/** @var ApiOptions */
Expand All @@ -30,7 +31,7 @@ public function get($url, $token, $params = [])

curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_TIMEOUT, $this->config->get('curl_timeout'));
curl_setopt($curl,CURLOPT_TIMEOUT, $this->config->get('curl_timeout'));
curl_setopt($curl, CURLOPT_HTTPHEADER, ['Authorization:' . $token]);

$result = curl_exec($curl);
Expand All @@ -52,9 +53,31 @@ public function post($url, $token, $body = [])
$curl = curl_init();

curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $body);
curl_setopt($curl, CURLOPT_TIMEOUT, $this->config->get('curl_timeout'));
curl_setopt($curl,CURLOPT_POST, 1);
curl_setopt($curl,CURLOPT_POSTFIELDS,$body);
curl_setopt($curl,CURLOPT_TIMEOUT, $this->config->get('curl_timeout'));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, ['Authorization:' . $token]);

$result = curl_exec($curl);

curl_close($curl);

return $result;
}


/**
* @param $url
* @param $token
* @return mixed
*/
public function delete($url, $token)
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE");
curl_setopt($curl,CURLOPT_TIMEOUT, $this->config->get('curl_timeout'));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, ['Authorization:' . $token]);

Expand Down
7 changes: 7 additions & 0 deletions src/SpotOnLive/AccuRanker/Services/CurlServiceInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,11 @@ public function get($url, $token);
* @return string
*/
public function post($url, $token, $body);

/**
* @param $url
* @param $token
* @return mixed
*/
public function delete($url, $token);
}

0 comments on commit 21a022e

Please sign in to comment.