| @@ -88,9 +88,9 @@ | ||
| 88 | 88 | * @return string |
| 89 | 89 | */ |
| 90 | 90 | public function get_auth_url() { |
| 91 | 91 | $auth_url = add_query_arg( |
| 92 | - [ | |
| 92 | + array( | |
| 93 | 93 | 'client_id' => $this->client_id, |
| 94 | 94 | 'scope' => urlencode_deep( $this->auth_scope ), |
| 95 | 95 | 'redirect_uri' => $this->redirect_uri, |
| 96 | 96 | 'response_type' => 'code', |
| @@ -95,9 +95,9 @@ | ||
| 95 | 95 | 'redirect_uri' => $this->redirect_uri, |
| 96 | 96 | 'response_type' => 'code', |
| 97 | 97 | 'access_type' => 'offline', |
| 98 | 98 | |
| 99 | - ], self::TIMETICS_AUTH_URL | |
| 99 | + ), self::TIMETICS_AUTH_URL | |
| 100 | 100 | ); |
| 101 | 101 | |
| 102 | 102 | return $auth_url; |
| 103 | 103 | } |
| @@ -106,13 +106,13 @@ | ||
| 106 | 106 | * Set google authentication configuration |
| 107 | 107 | * |
| 108 | 108 | * @return void |
| 109 | 109 | */ |
| 110 | - public function set_auth_config( $args = [] ) { | |
| 111 | - $defaults = [ | |
| 110 | + public function set_auth_config( $args = array() ) { | |
| 111 | + $defaults = array( | |
| 112 | 112 | 'client_id' => '', |
| 113 | 113 | 'client_secrete' => '', |
| 114 | - ]; | |
| 114 | + ); | |
| 115 | 115 | |
| 116 | 116 | $args = wp_parse_args( $args, $defaults ); |
| 117 | 117 | |
| 118 | 118 | $this->client_id = $args['client_id']; |
| @@ -150,25 +150,27 @@ | ||
| 150 | 150 | if ( strlen( $code ) === 0 ) { |
| 151 | 151 | throw new InvalidArgumentException( 'Invalid code' ); |
| 152 | 152 | } |
| 153 | 153 | |
| 154 | - $args = [ | |
| 154 | + $args = array( | |
| 155 | 155 | 'client_id' => $this->client_id, |
| 156 | 156 | 'client_secret' => $this->client_secrete, |
| 157 | 157 | 'code' => $code, |
| 158 | 158 | 'redirect_uri' => $this->redirect_uri, |
| 159 | 159 | 'grant_type' => 'authorization_code', |
| 160 | - ]; | |
| 160 | + ); | |
| 161 | 161 | |
| 162 | - $response = wp_remote_post( self::TIMETICS_TOKEN_URI, [ 'body' => $args ] ); | |
| 162 | + $response = wp_remote_post( self::TIMETICS_TOKEN_URI, array( 'body' => $args ) ); | |
| 163 | 163 | |
| 164 | - if ( ! is_wp_error( $response ) ) { | |
| 165 | - $data = json_decode( wp_remote_retrieve_body( $response ), true ); | |
| 164 | + $status_code = wp_remote_retrieve_response_code( $response ); | |
| 166 | 165 | |
| 167 | - return $data; | |
| 166 | + if ( 200 != $status_code ) { | |
| 167 | + return false; | |
| 168 | 168 | } |
| 169 | 169 | |
| 170 | - return $response; | |
| 170 | + $data = json_decode( wp_remote_retrieve_body( $response ), true ); | |
| 171 | + | |
| 172 | + return $data; | |
| 171 | 173 | } |
| 172 | 174 | |
| 173 | 175 | /** |
| 174 | 176 | * Fetch access token by using refresh token |
| @@ -175,25 +177,27 @@ | ||
| 175 | 177 | * |
| 176 | 178 | * @return void |
| 177 | 179 | */ |
| 178 | 180 | public function fetch_access_token_with_refresh_token( $refresh_token ) { |
| 179 | - $args = [ | |
| 181 | + $args = array( | |
| 180 | 182 | 'client_id' => $this->client_id, |
| 181 | 183 | 'client_secret' => $this->client_secrete, |
| 182 | 184 | 'refresh_token' => $refresh_token, |
| 183 | 185 | 'redirect_uri' => $this->redirect_uri, |
| 184 | 186 | 'grant_type' => 'refresh_token', |
| 185 | - ]; | |
| 187 | + ); | |
| 186 | 188 | |
| 187 | - $response = wp_remote_post( self::TIMETICS_TOKEN_URI, [ 'body' => $args ] ); | |
| 189 | + $response = wp_remote_post( self::TIMETICS_TOKEN_URI, array( 'body' => $args ) ); | |
| 188 | 190 | |
| 189 | - if ( ! is_wp_error( $response ) ) { | |
| 190 | - $data = json_decode( wp_remote_retrieve_body( $response ), true ); | |
| 191 | + $status_code = wp_remote_retrieve_response_code( $response ); | |
| 191 | 192 | |
| 192 | - return $data; | |
| 193 | + if ( 200 != $status_code ) { | |
| 194 | + return false; | |
| 193 | 195 | } |
| 194 | 196 | |
| 195 | - return $response; | |
| 197 | + $data = json_decode( wp_remote_retrieve_body( $response ), true ); | |
| 198 | + | |
| 199 | + return $data; | |
| 196 | 200 | } |
| 197 | 201 | |
| 198 | 202 | /** |
| 199 | 203 | * Revoke authorization |
| @@ -203,18 +207,18 @@ | ||
| 203 | 207 | * @return bool |
| 204 | 208 | */ |
| 205 | 209 | public function revoke( $token ) { |
| 206 | 210 | $response = wp_remote_post( |
| 207 | - self::TIMETICS_REVOKE_URI, [ | |
| 208 | - 'headers' => [ | |
| 211 | + self::TIMETICS_REVOKE_URI, array( | |
| 212 | + 'headers' => array( | |
| 209 | 213 | 'content-type' => 'application/x-www-form-urlencoded', |
| 210 | - ], | |
| 214 | + ), | |
| 211 | 215 | 'body' => build_query( |
| 212 | - [ | |
| 216 | + array( | |
| 213 | 217 | 'token' => $token, |
| 214 | - ] | |
| 218 | + ) | |
| 215 | 219 | ), |
| 216 | - ] | |
| 220 | + ) | |
| 217 | 221 | ); |
| 218 | 222 | |
| 219 | 223 | $status_code = wp_remote_retrieve_response_code( $response ); |
| 220 | 224 | |