diff --git a/docs/class-LINE.LINEBot.Constant.Meta.html b/docs/class-LINE.LINEBot.Constant.Meta.html index a88efae5..d348acb2 100644 --- a/docs/class-LINE.LINEBot.Constant.Meta.html +++ b/docs/class-LINE.LINEBot.Constant.Meta.html @@ -125,7 +125,7 @@

Meta

# - '3.4.0' + '3.5.0'
diff --git a/docs/class-LINE.LINEBot.HTTPClient.CurlHTTPClient.html b/docs/class-LINE.LINEBot.HTTPClient.CurlHTTPClient.html index 35be1016..545e2ccb 100644 --- a/docs/class-LINE.LINEBot.HTTPClient.CurlHTTPClient.html +++ b/docs/class-LINE.LINEBot.HTTPClient.CurlHTTPClient.html @@ -166,7 +166,7 @@

CurlHTTPClient

# - get( string $url , array $data = array ( ), array $headers = array ( ) ) + get( string $url , array $data = array ( ), array $headers = array ( ) )
Sends GET request to LINE Messaging API. @@ -206,7 +206,7 @@

Implementation of

# - post( string $url , array $data , array $headers = NULL ) + post( string $url , array $data , array $headers = NULL )
Sends POST request to LINE Messaging API. @@ -246,7 +246,7 @@

Implementation of

# - delete( string $url ) + delete( string $url )
Sends DELETE request to LINE Messaging API. diff --git a/docs/source-class-LINE.LINEBot.Constant.Meta.html b/docs/source-class-LINE.LINEBot.Constant.Meta.html index 462b94dd..7855c766 100644 --- a/docs/source-class-LINE.LINEBot.Constant.Meta.html +++ b/docs/source-class-LINE.LINEBot.Constant.Meta.html @@ -79,7 +79,7 @@ class Meta { - const VERSION = '3.4.0'; + const VERSION = '3.5.0'; }
diff --git a/docs/source-class-LINE.LINEBot.Event.MessageEvent.LocationMessage.html b/docs/source-class-LINE.LINEBot.Event.MessageEvent.LocationMessage.html index 8c1616dd..56705afb 100644 --- a/docs/source-class-LINE.LINEBot.Event.MessageEvent.LocationMessage.html +++ b/docs/source-class-LINE.LINEBot.Event.MessageEvent.LocationMessage.html @@ -99,21 +99,21 @@ /** * Returns title of the location message. * - * @return string + * @return string|null */ public function getTitle() { - return $this->message['title']; + return array_key_exists('title', $this->message) ? $this->message['title'] : null; } /** * Returns address of the location message. * - * @return string + * @return string|null */ public function getAddress() { - return $this->message['address']; + return array_key_exists('address', $this->message) ? $this->message['address'] : null; } /** diff --git a/docs/source-class-LINE.LINEBot.HTTPClient.CurlHTTPClient.html b/docs/source-class-LINE.LINEBot.HTTPClient.CurlHTTPClient.html index 36c68006..bb4d1027 100644 --- a/docs/source-class-LINE.LINEBot.HTTPClient.CurlHTTPClient.html +++ b/docs/source-class-LINE.LINEBot.HTTPClient.CurlHTTPClient.html @@ -56,7 +56,7 @@
-
  1:   2:   3:   4:   5:   6:   7:   8:   9:  10:  11:  12:  13:  14:  15:  16:  17:  18:  19:  20:  21:  22:  23:  24:  25:  26:  27:  28:  29:  30:  31:  32:  33:  34:  35:  36:  37:  38:  39:  40:  41:  42:  43:  44:  45:  46:  47:  48:  49:  50:  51:  52:  53:  54:  55:  56:  57:  58:  59:  60:  61:  62:  63:  64:  65:  66:  67:  68:  69:  70:  71:  72:  73:  74:  75:  76:  77:  78:  79:  80:  81:  82:  83:  84:  85:  86:  87:  88:  89:  90:  91:  92:  93:  94:  95:  96:  97:  98:  99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 
+
  1:   2:   3:   4:   5:   6:   7:   8:   9:  10:  11:  12:  13:  14:  15:  16:  17:  18:  19:  20:  21:  22:  23:  24:  25:  26:  27:  28:  29:  30:  31:  32:  33:  34:  35:  36:  37:  38:  39:  40:  41:  42:  43:  44:  45:  46:  47:  48:  49:  50:  51:  52:  53:  54:  55:  56:  57:  58:  59:  60:  61:  62:  63:  64:  65:  66:  67:  68:  69:  70:  71:  72:  73:  74:  75:  76:  77:  78:  79:  80:  81:  82:  83:  84:  85:  86:  87:  88:  89:  90:  91:  92:  93:  94:  95:  96:  97:  98:  99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 
<?php
 
 /**
@@ -122,119 +122,122 @@
      */
     public function get($url, array $data = [], array $headers = [])
     {
-        return $this->sendRequest('GET', $url, $headers, $data);
-    }
-
-    /**
-     * Sends POST request to LINE Messaging API.
-     *
-     * @param string $url Request URL.
-     * @param array $data Request body or resource path.
-     * @param array|null $headers Request headers.
-     * @return Response Response of API request.
-     * @throws CurlExecutionException
-     */
-    public function post($url, array $data, array $headers = null)
-    {
-        $headers = is_null($headers) ? ['Content-Type: application/json; charset=utf-8'] : $headers;
-        return $this->sendRequest('POST', $url, $headers, $data);
-    }
-
-    /**
-     * Sends DELETE request to LINE Messaging API.
-     *
-     * @param string $url Request URL.
-     * @return Response Response of API request.
-     * @throws CurlExecutionException
-     */
-    public function delete($url)
-    {
-        return $this->sendRequest('DELETE', $url, [], []);
-    }
-
-    /**
-     * @param string $method
-     * @param array $headers
-     * @param string|null $reqBody
-     * @return array cUrl options
-     */
-    private function getOptions($method, $headers, $reqBody)
-    {
-        $options = [
-            CURLOPT_CUSTOMREQUEST => $method,
-            CURLOPT_HTTPHEADER => $headers,
-            CURLOPT_RETURNTRANSFER => true,
-            CURLOPT_BINARYTRANSFER => true,
-            CURLOPT_HEADER => true,
-        ];
-        if ($method === 'POST') {
-            if (is_null($reqBody)) {
-                // Rel: https://github.com/line/line-bot-sdk-php/issues/35
-                $options[CURLOPT_HTTPHEADER][] = 'Content-Length: 0';
-            } else {
-                if (isset($reqBody['__file']) && isset($reqBody['__type'])) {
-                    $options[CURLOPT_PUT] = true;
-                    $options[CURLOPT_INFILE] = fopen($reqBody['__file'], 'r');
-                    $options[CURLOPT_INFILESIZE] = filesize($reqBody['__file']);
-                } elseif (!empty($reqBody)) {
-                    $options[CURLOPT_POST] = true;
-                    $options[CURLOPT_POSTFIELDS] = json_encode($reqBody);
-                } else {
+        if ($data) {
+            $url .= '?' . http_build_query($data);
+        }
+        return $this->sendRequest('GET', $url, $headers);
+    }
+
+    /**
+     * Sends POST request to LINE Messaging API.
+     *
+     * @param string $url Request URL.
+     * @param array $data Request body or resource path.
+     * @param array|null $headers Request headers.
+     * @return Response Response of API request.
+     * @throws CurlExecutionException
+     */
+    public function post($url, array $data, array $headers = null)
+    {
+        $headers = is_null($headers) ? ['Content-Type: application/json; charset=utf-8'] : $headers;
+        return $this->sendRequest('POST', $url, $headers, $data);
+    }
+
+    /**
+     * Sends DELETE request to LINE Messaging API.
+     *
+     * @param string $url Request URL.
+     * @return Response Response of API request.
+     * @throws CurlExecutionException
+     */
+    public function delete($url)
+    {
+        return $this->sendRequest('DELETE', $url, [], []);
+    }
+
+    /**
+     * @param string $method
+     * @param array $headers
+     * @param string|null $reqBody
+     * @return array cUrl options
+     */
+    private function getOptions($method, $headers, $reqBody)
+    {
+        $options = [
+            CURLOPT_CUSTOMREQUEST => $method,
+            CURLOPT_HTTPHEADER => $headers,
+            CURLOPT_RETURNTRANSFER => true,
+            CURLOPT_BINARYTRANSFER => true,
+            CURLOPT_HEADER => true,
+        ];
+        if ($method === 'POST') {
+            if (is_null($reqBody)) {
+                // Rel: https://github.com/line/line-bot-sdk-php/issues/35
+                $options[CURLOPT_HTTPHEADER][] = 'Content-Length: 0';
+            } else {
+                if (isset($reqBody['__file']) && isset($reqBody['__type'])) {
+                    $options[CURLOPT_PUT] = true;
+                    $options[CURLOPT_INFILE] = fopen($reqBody['__file'], 'r');
+                    $options[CURLOPT_INFILESIZE] = filesize($reqBody['__file']);
+                } elseif (!empty($reqBody)) {
                     $options[CURLOPT_POST] = true;
-                    $options[CURLOPT_POSTFIELDS] = $reqBody;
-                }
-            }
-        }
-        return $options;
-    }
-
-    /**
-     * @param string $method
-     * @param string $url
-     * @param array $additionalHeader
-     * @param string|null $reqBody
-     * @return Response
-     * @throws CurlExecutionException
-     */
-    private function sendRequest($method, $url, array $additionalHeader, $reqBody = null)
-    {
-        $curl = new Curl($url);
-
-        $headers = array_merge($this->authHeaders, $this->userAgentHeader, $additionalHeader);
-
-        $options = $this->getOptions($method, $headers, $reqBody);
-        $curl->setoptArray($options);
+                    $options[CURLOPT_POSTFIELDS] = json_encode($reqBody);
+                } else {
+                    $options[CURLOPT_POST] = true;
+                    $options[CURLOPT_POSTFIELDS] = $reqBody;
+                }
+            }
+        }
+        return $options;
+    }
+
+    /**
+     * @param string $method
+     * @param string $url
+     * @param array $additionalHeader
+     * @param string|null $reqBody
+     * @return Response
+     * @throws CurlExecutionException
+     */
+    private function sendRequest($method, $url, array $additionalHeader, $reqBody = null)
+    {
+        $curl = new Curl($url);
+
+        $headers = array_merge($this->authHeaders, $this->userAgentHeader, $additionalHeader);
 
-        $result = $curl->exec();
-
-        if ($curl->errno()) {
-            throw new CurlExecutionException($curl->error());
-        }
-
-        $info = $curl->getinfo();
-        $httpStatus = $info['http_code'];
+        $options = $this->getOptions($method, $headers, $reqBody);
+        $curl->setoptArray($options);
+
+        $result = $curl->exec();
+
+        if ($curl->errno()) {
+            throw new CurlExecutionException($curl->error());
+        }
 
-        $responseHeaderSize = $info['header_size'];
-
-        $responseHeaderStr = substr($result, 0, $responseHeaderSize);
-        $responseHeaders = [];
-        foreach (explode("\r\n", $responseHeaderStr) as $responseHeader) {
-            $kv = explode(':', $responseHeader, 2);
-            if (count($kv) === 2) {
-                $responseHeaders[$kv[0]] = trim($kv[1]);
-            }
-        }
-
-        $body = substr($result, $responseHeaderSize);
-
-        if (isset($options[CURLOPT_INFILE])) {
-            fclose($options[CURLOPT_INFILE]);
-        }
-
-        return new Response($httpStatus, $body, $responseHeaders);
-    }
-}
-
+ $info = $curl->getinfo(); + $httpStatus = $info['http_code']; + + $responseHeaderSize = $info['header_size']; + + $responseHeaderStr = substr($result, 0, $responseHeaderSize); + $responseHeaders = []; + foreach (explode("\r\n", $responseHeaderStr) as $responseHeader) { + $kv = explode(':', $responseHeader, 2); + if (count($kv) === 2) { + $responseHeaders[$kv[0]] = trim($kv[1]); + } + } + + $body = substr($result, $responseHeaderSize); + + if (isset($options[CURLOPT_INFILE])) { + fclose($options[CURLOPT_INFILE]); + } + + return new Response($httpStatus, $body, $responseHeaders); + } +} +