From 662d62a7df1247515572bf517e14b795714e0824 Mon Sep 17 00:00:00 2001 From: Afterster Date: Sat, 28 Dec 2013 16:29:50 +0100 Subject: [PATCH 1/2] Add first Requests HTTP client implementation --- lib/EchoNest/HttpClient/Requests.php | 75 ++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 lib/EchoNest/HttpClient/Requests.php diff --git a/lib/EchoNest/HttpClient/Requests.php b/lib/EchoNest/HttpClient/Requests.php new file mode 100644 index 0000000..a62eaee --- /dev/null +++ b/lib/EchoNest/HttpClient/Requests.php @@ -0,0 +1,75 @@ + + * @license MIT License + */ +class EchoNest_HttpClient_Requests extends EchoNest_HttpClient +{ + /** + * Send a request to the server, receive a response + * + * @param string $apiPath Request API path + * @param array $parameters Parameters + * @param string $httpMethod HTTP method to use + * + * @return string HTTP response + */ + protected function doRequest($url, array $parameters = array(), $httpMethod = 'GET', array $options = array()) + { + if($this->options['api_key']) + { + $parameters = array_merge(array( + 'format' => $this->options['format'], + 'api_key' => $this->options['api_key'] + ), $parameters); + } + + $headers = array(); + $headers['User-Agent'] = $this->options['user_agent']; + + if ('GET' === $httpMethod && !empty($parameters)) { + $queryString = utf8_encode($this->buildQuery($parameters)); + $url .= '?' . $queryString; + + $this->debug('send ' . $httpMethod . ' request: ' . $url); + $request = Requests::get($url, $headers); + } + else { + $this->debug('send ' . $httpMethod . ' request: ' . $url); + $request = Requests::post($url, $headers, $parameters); + } + + return $request->body; + } + + protected function buildQuery($parameters) + { + $append = ''; + foreach ($parameters as $key => $value) + { + // multiple parameter passed + if (is_array($value)) { + foreach ($value as $val) { + $append.=sprintf('&%s=%s', $key, $val); + } + unset($parameters[$key]); + } + elseif (is_bool($value)) { + $parameters[$key] = $value ? 'true' : 'false'; + } + } + + return http_build_query($parameters, '', '&') . $append; + } + + protected function debug($message) + { + if($this->options['debug']) + { + print $message."\n"; + } + } +} From 7eb810d86923a73e51a34713d70ff7b9805e7b09 Mon Sep 17 00:00:00 2001 From: Randy Barlow Date: Sat, 21 Jan 2017 13:15:37 -0500 Subject: [PATCH 2/2] Drop execute permissions on the php files. --- lib/EchoNest/Api.php | 0 lib/EchoNest/Api/Artist.php | 0 lib/EchoNest/Api/Catalog.php | 0 lib/EchoNest/Api/Playlist.php | 0 lib/EchoNest/Api/Song.php | 0 lib/EchoNest/Api/Track.php | 0 lib/EchoNest/Client.php | 0 lib/EchoNest/HttpClient/Curl.php | 0 lib/EchoNest/HttpClient/Exception.php | 0 9 files changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 lib/EchoNest/Api.php mode change 100755 => 100644 lib/EchoNest/Api/Artist.php mode change 100755 => 100644 lib/EchoNest/Api/Catalog.php mode change 100755 => 100644 lib/EchoNest/Api/Playlist.php mode change 100755 => 100644 lib/EchoNest/Api/Song.php mode change 100755 => 100644 lib/EchoNest/Api/Track.php mode change 100755 => 100644 lib/EchoNest/Client.php mode change 100755 => 100644 lib/EchoNest/HttpClient/Curl.php mode change 100755 => 100644 lib/EchoNest/HttpClient/Exception.php diff --git a/lib/EchoNest/Api.php b/lib/EchoNest/Api.php old mode 100755 new mode 100644 diff --git a/lib/EchoNest/Api/Artist.php b/lib/EchoNest/Api/Artist.php old mode 100755 new mode 100644 diff --git a/lib/EchoNest/Api/Catalog.php b/lib/EchoNest/Api/Catalog.php old mode 100755 new mode 100644 diff --git a/lib/EchoNest/Api/Playlist.php b/lib/EchoNest/Api/Playlist.php old mode 100755 new mode 100644 diff --git a/lib/EchoNest/Api/Song.php b/lib/EchoNest/Api/Song.php old mode 100755 new mode 100644 diff --git a/lib/EchoNest/Api/Track.php b/lib/EchoNest/Api/Track.php old mode 100755 new mode 100644 diff --git a/lib/EchoNest/Client.php b/lib/EchoNest/Client.php old mode 100755 new mode 100644 diff --git a/lib/EchoNest/HttpClient/Curl.php b/lib/EchoNest/HttpClient/Curl.php old mode 100755 new mode 100644 diff --git a/lib/EchoNest/HttpClient/Exception.php b/lib/EchoNest/HttpClient/Exception.php old mode 100755 new mode 100644