Skip to content

Commit

Permalink
extend GET requests to send parameters in URL
Browse files Browse the repository at this point in the history
  • Loading branch information
Pixelairport committed Oct 15, 2020
1 parent 4f77f81 commit c913a0a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
30 changes: 29 additions & 1 deletion src/ImmoScout/Traits/Oauth1Trait.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,11 @@ public function setResponseType($type){
public function request($method, $endpoint, $parameter=[])
{
// Do the request
$res = $this->client->request($method, $this->api_base_uri . $endpoint, $parameter);
if(strtolower($method)=='get'){
$res = $this->client->request($method, $this->api_base_uri . $endpoint . $this->parameterArrayToUrlString($parameter));
}else{
$res = $this->client->request($method, $this->api_base_uri . $endpoint, $parameter);
}

// Default return
if($this->responseType=='xml'){
Expand All @@ -106,6 +110,30 @@ public function request($method, $endpoint, $parameter=[])
return $res;
}

/**
* Transform parameter array to string.
* The string could be used in GET requests to
* extend the url.
*
* @param $parameter
* @return string
*/
protected function parameterArrayToUrlString($parameter)
{
if(is_array($parameter) && count($parameter)>0)
{
$urlParameter = '?';

foreach($parameter as $key=>$value){
$urlParameter .= $key.'='.$value.'&';
}

return substr($urlParameter, 0, -1);
}

return '';
}

/**
* Transform response to xml (array).
*
Expand Down
5 changes: 3 additions & 2 deletions src/ImmoScout/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ public function __construct($key, $secret, $access_token = null, $token_secret =
/**
* Get all real estate offers from a user.
*
* @param array
* @return mixed
*/
public function findOffers()
public function findOffers($parameter=[])
{
return $this->request('GET', '/offer/v1.0/user/me/realestate');
return $this->request('GET', '/offer/v1.0/user/me/realestate', $parameter);
}
}

0 comments on commit c913a0a

Please sign in to comment.