Passed
Push — master ( fc00fd...bc29a4 )
by Davide
50s
created
src/DavidePastore/Ipinfo/Host.php 1 patch
Indentation   +98 added lines, -98 removed lines patch added patch discarded remove patch
@@ -9,113 +9,113 @@
 block discarded – undo
9 9
  */
10 10
 class Host
11 11
 {
12
-    /**
13
-     * Contains all the properties of the host.
14
-     *
15
-     * @var array
16
-     */
17
-    protected $properties;
12
+	/**
13
+	 * Contains all the properties of the host.
14
+	 *
15
+	 * @var array
16
+	 */
17
+	protected $properties;
18 18
 
19
-    /**
20
-     * Create an Host object with all the properties.
21
-     *
22
-     * @param array $properties
23
-     */
24
-    public function __construct($properties = array())
25
-    {
26
-        //Merge default values
27
-        $this->properties = array_merge(array(
28
-                Ipinfo::CITY => '',
29
-                Ipinfo::COUNTRY => '',
30
-                Ipinfo::HOSTNAME => '',
31
-                Ipinfo::IP => '',
32
-                Ipinfo::LOC => '',
33
-                Ipinfo::ORG => '',
34
-                Ipinfo::PHONE => '',
35
-                Ipinfo::POSTAL => '',
36
-                Ipinfo::REGION => '',
37
-        ), $properties);
38
-    }
19
+	/**
20
+	 * Create an Host object with all the properties.
21
+	 *
22
+	 * @param array $properties
23
+	 */
24
+	public function __construct($properties = array())
25
+	{
26
+		//Merge default values
27
+		$this->properties = array_merge(array(
28
+				Ipinfo::CITY => '',
29
+				Ipinfo::COUNTRY => '',
30
+				Ipinfo::HOSTNAME => '',
31
+				Ipinfo::IP => '',
32
+				Ipinfo::LOC => '',
33
+				Ipinfo::ORG => '',
34
+				Ipinfo::PHONE => '',
35
+				Ipinfo::POSTAL => '',
36
+				Ipinfo::REGION => '',
37
+		), $properties);
38
+	}
39 39
 
40
-    /**
41
-     * Get the city value.
42
-     */
43
-    public function getCity()
44
-    {
45
-        return $this->properties[Ipinfo::CITY];
46
-    }
40
+	/**
41
+	 * Get the city value.
42
+	 */
43
+	public function getCity()
44
+	{
45
+		return $this->properties[Ipinfo::CITY];
46
+	}
47 47
 
48
-    /**
49
-     * Get the country value.
50
-     */
51
-    public function getCountry()
52
-    {
53
-        return $this->properties[Ipinfo::COUNTRY];
54
-    }
48
+	/**
49
+	 * Get the country value.
50
+	 */
51
+	public function getCountry()
52
+	{
53
+		return $this->properties[Ipinfo::COUNTRY];
54
+	}
55 55
 
56
-    /**
57
-     * Get the hostname value.
58
-     */
59
-    public function getHostname()
60
-    {
61
-        return $this->properties[Ipinfo::HOSTNAME];
62
-    }
56
+	/**
57
+	 * Get the hostname value.
58
+	 */
59
+	public function getHostname()
60
+	{
61
+		return $this->properties[Ipinfo::HOSTNAME];
62
+	}
63 63
 
64
-    /**
65
-     * Get the ip value.
66
-     */
67
-    public function getIp()
68
-    {
69
-        return $this->properties[Ipinfo::IP];
70
-    }
64
+	/**
65
+	 * Get the ip value.
66
+	 */
67
+	public function getIp()
68
+	{
69
+		return $this->properties[Ipinfo::IP];
70
+	}
71 71
 
72
-    /**
73
-     * Get the loc value.
74
-     */
75
-    public function getLoc()
76
-    {
77
-        return $this->properties[Ipinfo::LOC];
78
-    }
72
+	/**
73
+	 * Get the loc value.
74
+	 */
75
+	public function getLoc()
76
+	{
77
+		return $this->properties[Ipinfo::LOC];
78
+	}
79 79
 
80
-    /**
81
-     * Get the org value.
82
-     */
83
-    public function getOrg()
84
-    {
85
-        return $this->properties[Ipinfo::ORG];
86
-    }
80
+	/**
81
+	 * Get the org value.
82
+	 */
83
+	public function getOrg()
84
+	{
85
+		return $this->properties[Ipinfo::ORG];
86
+	}
87 87
 
88
-    /**
89
-     * Get the phone value.
90
-     */
91
-    public function getPhone()
92
-    {
93
-        return $this->properties[Ipinfo::PHONE];
94
-    }
88
+	/**
89
+	 * Get the phone value.
90
+	 */
91
+	public function getPhone()
92
+	{
93
+		return $this->properties[Ipinfo::PHONE];
94
+	}
95 95
 
96
-    /**
97
-     * Get the postal value.
98
-     */
99
-    public function getPostal()
100
-    {
101
-        return $this->properties[Ipinfo::POSTAL];
102
-    }
96
+	/**
97
+	 * Get the postal value.
98
+	 */
99
+	public function getPostal()
100
+	{
101
+		return $this->properties[Ipinfo::POSTAL];
102
+	}
103 103
 
104
-    /**
105
-     * Get the region value.
106
-     */
107
-    public function getRegion()
108
-    {
109
-        return $this->properties[Ipinfo::REGION];
110
-    }
104
+	/**
105
+	 * Get the region value.
106
+	 */
107
+	public function getRegion()
108
+	{
109
+		return $this->properties[Ipinfo::REGION];
110
+	}
111 111
 
112
-    /**
113
-     * Get all the properties.
114
-     *
115
-     * @return array An associative array with all the properties.
116
-     */
117
-    public function getProperties()
118
-    {
119
-        return $this->properties;
120
-    }
112
+	/**
113
+	 * Get all the properties.
114
+	 *
115
+	 * @return array An associative array with all the properties.
116
+	 */
117
+	public function getProperties()
118
+	{
119
+		return $this->properties;
120
+	}
121 121
 }
Please login to merge, or discard this patch.
src/DavidePastore/Ipinfo/Exception/IpInfoException.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -6,11 +6,11 @@
 block discarded – undo
6 6
  */
7 7
 class IpInfoException extends \Exception
8 8
 {
9
-    private $fullMessage;
9
+	private $fullMessage;
10 10
 
11
-    public function __construct($error, $fullMessage)
12
-    {
13
-        parent::__construct($error);
14
-        $this->fullMessage = $fullMessage;
15
-    }
11
+	public function __construct($error, $fullMessage)
12
+	{
13
+		parent::__construct($error);
14
+		$this->fullMessage = $fullMessage;
15
+	}
16 16
 }
Please login to merge, or discard this patch.
src/DavidePastore/Ipinfo/Ipinfo.php 2 patches
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
      */
121 121
     public function getYourOwnIpDetails()
122 122
     {
123
-        $response = $this->makeCurlRequest($this::BASE_URL.'json');
123
+        $response = $this->makeCurlRequest($this::BASE_URL . 'json');
124 124
         $response = $this->jsonDecodeResponse($response);
125 125
 
126 126
         return new Host($response);
@@ -135,7 +135,7 @@  discard block
 block discarded – undo
135 135
      */
136 136
     public function getFullIpDetails($ipAddress)
137 137
     {
138
-        $response = $this->makeCurlRequest($this::BASE_URL.$ipAddress);
138
+        $response = $this->makeCurlRequest($this::BASE_URL . $ipAddress);
139 139
         $response = $this->jsonDecodeResponse($response);
140 140
 
141 141
         return new Host($response);
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
      */
154 154
     public function getSpecificField($ipAddress, $field)
155 155
     {
156
-        $response = $this->makeCurlRequest($this::BASE_URL.$ipAddress.'/'.$field);
156
+        $response = $this->makeCurlRequest($this::BASE_URL . $ipAddress . '/' . $field);
157 157
         $response = $this->checkGeo($field, $response);
158 158
 
159 159
         return $response;
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
      */
171 171
     public function getYourOwnIpSpecificField($field)
172 172
     {
173
-        $response = $this->makeCurlRequest($this::BASE_URL.$field);
173
+        $response = $this->makeCurlRequest($this::BASE_URL . $field);
174 174
         $response = $this->checkGeo($field, $response);
175 175
 
176 176
         return $response;
@@ -224,11 +224,11 @@  discard block
 block discarded – undo
224 224
         $curl = curl_init();
225 225
 
226 226
         if (!empty($this->settings['token'])) {
227
-            $address .= '?token='.$this->settings['token'];
227
+            $address .= '?token=' . $this->settings['token'];
228 228
         }
229 229
 
230 230
         if ($this->settings['debug']) {
231
-            echo 'Request address: '.$address."\n";
231
+            echo 'Request address: ' . $address . "\n";
232 232
         }
233 233
 
234 234
         curl_setopt_array($curl, array(
@@ -240,7 +240,7 @@  discard block
 block discarded – undo
240 240
 
241 241
         if ($response === false && $this->settings['debug']) {
242 242
             $error = curl_error($curl);
243
-            echo "The error is".$error;
243
+            echo "The error is" . $error;
244 244
         }
245 245
 
246 246
         curl_close($curl);
Please login to merge, or discard this patch.
Indentation   +274 added lines, -274 removed lines patch added patch discarded remove patch
@@ -12,278 +12,278 @@
 block discarded – undo
12 12
  */
13 13
 class Ipinfo
14 14
 {
15
-    /**
16
-     * The base url of the ipinfo service.
17
-     *
18
-     * @var string
19
-     */
20
-    const BASE_URL = 'https://ipinfo.io/';
21
-
22
-    /**
23
-     * The ip string.
24
-     *
25
-     * @var string
26
-     */
27
-    const IP = 'ip';
28
-
29
-    /**
30
-     * The hostname string.
31
-     *
32
-     * @var string
33
-     */
34
-    const HOSTNAME = 'hostname';
35
-
36
-    /**
37
-     * The loc string.
38
-     *
39
-     * @var string
40
-     */
41
-    const LOC = 'loc';
42
-
43
-    /**
44
-     * The org string.
45
-     *
46
-     * @var string
47
-     */
48
-    const ORG = 'org';
49
-
50
-    /**
51
-     * The city string.
52
-     *
53
-     * @var string
54
-     */
55
-    const CITY = 'city';
56
-
57
-    /**
58
-     * The region string.
59
-     *
60
-     * @var string
61
-     */
62
-    const REGION = 'region';
63
-
64
-    /**
65
-     * The country string.
66
-     *
67
-     * @var string
68
-     */
69
-    const COUNTRY = 'country';
70
-
71
-    /**
72
-     * The phone string.
73
-     *
74
-     * @var string
75
-     */
76
-    const PHONE = 'phone';
77
-
78
-    /**
79
-     * The geo string.
80
-     *
81
-     * @var string
82
-     */
83
-    const GEO = 'geo';
84
-
85
-    /**
86
-     * The postal string.
87
-     *
88
-     * @var string
89
-     */
90
-    const POSTAL = 'postal';
91
-
92
-    /**
93
-     * All the settings.
94
-     *
95
-     * @var array
96
-     */
97
-    protected $settings;
98
-
99
-    /**
100
-     * Create an Ipinfo instance.
101
-     *
102
-     * @param array $settings An array with all the settings.
103
-     *                        Supported keys are:
104
-     *                        - token: string the developer token;
105
-     *                        - debug: boolean active or not the debug.
106
-     */
107
-    public function __construct($settings = array())
108
-    {
109
-        //Merge user settings
110
-        $this->settings = array_merge(array(
111
-                'token' => '',
112
-                'connectionTimeout' => 0,
113
-                'timeout' => 0,
114
-                'debug' => false,
115
-        ), $settings);
116
-    }
117
-
118
-    /**
119
-     * Get all the info about your own ip address.
120
-     *
121
-     * @return \DavidePastore\Ipinfo\Host The Host object with all the info.
122
-     */
123
-    public function getYourOwnIpDetails()
124
-    {
125
-        $response = $this->makeCurlRequest($this::BASE_URL.'json');
126
-        $response = $this->jsonDecodeResponse($response);
127
-
128
-        return new Host($response);
129
-    }
130
-
131
-    /**
132
-     * Get all the info about an ip address.
133
-     *
134
-     * @param string $ipAddress The ip address.
135
-     *
136
-     * @return \DavidePastore\Ipinfo\Host The Host object with all the info.
137
-     */
138
-    public function getFullIpDetails($ipAddress)
139
-    {
140
-        $response = $this->makeCurlRequest($this::BASE_URL.$ipAddress);
141
-        $response = $this->jsonDecodeResponse($response);
142
-
143
-        return new Host($response);
144
-    }
145
-
146
-    /**
147
-     * Get a specific field value.
148
-     *
149
-     * @param string $ipAddress The ip address.
150
-     * @param string $field     The field.
151
-     *
152
-     * @return string|\DavidePastore\Ipinfo\Host The value of the given field for the given ip.
153
-     *                                           This could returns an Host object if you call it with for the field
154
-     *                                           \DavidePastore\Ipinfo\Ipinfo::GEO.
155
-     */
156
-    public function getSpecificField($ipAddress, $field)
157
-    {
158
-        $response = $this->makeCurlRequest($this::BASE_URL.$ipAddress.'/'.$field);
159
-        $response = $this->checkGeo($field, $response);
160
-
161
-        return $response;
162
-    }
163
-
164
-    /**
165
-     * Get a specific field value of your own ip address.
166
-     *
167
-     * @param string $field The field.
168
-     *
169
-     * @return string|\DavidePastore\Ipinfo\Host The value of the given field for your own ip.
170
-     *                                           This could returns an Host object if you call it with for the field
171
-     *                                           \DavidePastore\Ipinfo\Ipinfo::GEO.
172
-     */
173
-    public function getYourOwnIpSpecificField($field)
174
-    {
175
-        $response = $this->makeCurlRequest($this::BASE_URL.$field);
176
-        $response = $this->checkGeo($field, $response);
177
-
178
-        return $response;
179
-    }
180
-
181
-    /**
182
-     * Use the /geo call to get just the geolocation information, which will often be
183
-     * faster than getting the full response.
184
-     *
185
-     * @param string $ipAddress The ip address.
186
-     *
187
-     * @return \DavidePastore\Ipinfo\Host
188
-     */
189
-    public function getIpGeoDetails($ipAddress)
190
-    {
191
-        return $this->getSpecificField($ipAddress, $this::GEO);
192
-    }
193
-
194
-    /**
195
-     * Check if the response is GEO and set the parameters accordingly.
196
-     *
197
-     * @param string $field    The field value.
198
-     * @param string $response The response from the server.
199
-     *
200
-     * @return Ambigous <\DavidePastore\Ipinfo\Host, string> Returns an Host object if the request is
201
-     *                  of the GEO type, a string otherwise. If the field value is different from the GEO type, it will
202
-     *                  delete the last character ('\n').
203
-     */
204
-    private function checkGeo($field, $response)
205
-    {
206
-        if ($field == $this::GEO) {
207
-            $response = $this->jsonDecodeResponse($response);
208
-            $response = new Host($response);
209
-        } else {
210
-            $this->checkErrors($response);
211
-            $response = substr($response, 0, -1);
212
-        }
213
-
214
-        return $response;
215
-    }
216
-
217
-    /**
218
-     * Make a curl request.
219
-     *
220
-     * @param string $address The address of the request.
221
-     *
222
-     * @return string Returns the response from the request.
223
-     */
224
-    private function makeCurlRequest($address)
225
-    {
226
-        $curl = curl_init();
227
-
228
-        if (!empty($this->settings['token'])) {
229
-            $address .= '?token='.$this->settings['token'];
230
-        }
231
-
232
-        if ($this->settings['debug']) {
233
-            echo 'Request address: '.$address."\n";
234
-        }
235
-
236
-        curl_setopt_array($curl, array(
237
-            CURLOPT_RETURNTRANSFER => 1,
238
-            CURLOPT_URL => $address,
239
-            CURLOPT_CONNECTTIMEOUT => $this->settings['connectionTimeout'],
240
-            CURLOPT_TIMEOUT => $this->settings['timeout'],
241
-            CURLOPT_CAINFO => __DIR__ . "/cacert.pem"
242
-        ));
243
-
244
-        $response = curl_exec($curl);
245
-
246
-        if ($response === false && $this->settings['debug']) {
247
-            $error = curl_error($curl);
248
-            echo "The error is".$error;
249
-        }
250
-
251
-        curl_close($curl);
252
-
253
-        return $response;
254
-    }
255
-
256
-    /**
257
-     * Returns the json decoded associative array.
258
-     * @param  string $response Response from the http call.
259
-     * @return array           Returns the associative array with the response.
260
-     * @throws RateLimitExceedException    If you exceed the rate limit.
261
-     * @throws InvalidTokenException If the used token is invalid.
262
-     */
263
-    private function jsonDecodeResponse($response)
264
-    {
265
-        if ($response) {
266
-            // Check if the response contains an error message
267
-            $this->checkErrors($response);
268
-            $response = json_decode($response, true);
269
-        } else {
270
-            $response = array();
271
-        }
272
-        return $response;
273
-    }
274
-
275
-    /**
276
-     * Check if the given response has some kind of errors.
277
-     * @param string $response The response to check.
278
-     * @throws RateLimitExceedException    If you exceed the rate limit.
279
-     * @throws InvalidTokenException If the used token is invalid.
280
-     */
281
-    private function checkErrors($response)
282
-    {
283
-        if (strpos($response, 'Rate limit exceeded.') !== false) {
284
-            throw new RateLimitExceedException("You exceed the rate limit.", $response);
285
-        } elseif (strpos($response, 'Unknown token.') !== false) {
286
-            throw new InvalidTokenException("The used token is invalid.", $response);
287
-        }
288
-    }
15
+	/**
16
+	 * The base url of the ipinfo service.
17
+	 *
18
+	 * @var string
19
+	 */
20
+	const BASE_URL = 'https://ipinfo.io/';
21
+
22
+	/**
23
+	 * The ip string.
24
+	 *
25
+	 * @var string
26
+	 */
27
+	const IP = 'ip';
28
+
29
+	/**
30
+	 * The hostname string.
31
+	 *
32
+	 * @var string
33
+	 */
34
+	const HOSTNAME = 'hostname';
35
+
36
+	/**
37
+	 * The loc string.
38
+	 *
39
+	 * @var string
40
+	 */
41
+	const LOC = 'loc';
42
+
43
+	/**
44
+	 * The org string.
45
+	 *
46
+	 * @var string
47
+	 */
48
+	const ORG = 'org';
49
+
50
+	/**
51
+	 * The city string.
52
+	 *
53
+	 * @var string
54
+	 */
55
+	const CITY = 'city';
56
+
57
+	/**
58
+	 * The region string.
59
+	 *
60
+	 * @var string
61
+	 */
62
+	const REGION = 'region';
63
+
64
+	/**
65
+	 * The country string.
66
+	 *
67
+	 * @var string
68
+	 */
69
+	const COUNTRY = 'country';
70
+
71
+	/**
72
+	 * The phone string.
73
+	 *
74
+	 * @var string
75
+	 */
76
+	const PHONE = 'phone';
77
+
78
+	/**
79
+	 * The geo string.
80
+	 *
81
+	 * @var string
82
+	 */
83
+	const GEO = 'geo';
84
+
85
+	/**
86
+	 * The postal string.
87
+	 *
88
+	 * @var string
89
+	 */
90
+	const POSTAL = 'postal';
91
+
92
+	/**
93
+	 * All the settings.
94
+	 *
95
+	 * @var array
96
+	 */
97
+	protected $settings;
98
+
99
+	/**
100
+	 * Create an Ipinfo instance.
101
+	 *
102
+	 * @param array $settings An array with all the settings.
103
+	 *                        Supported keys are:
104
+	 *                        - token: string the developer token;
105
+	 *                        - debug: boolean active or not the debug.
106
+	 */
107
+	public function __construct($settings = array())
108
+	{
109
+		//Merge user settings
110
+		$this->settings = array_merge(array(
111
+				'token' => '',
112
+				'connectionTimeout' => 0,
113
+				'timeout' => 0,
114
+				'debug' => false,
115
+		), $settings);
116
+	}
117
+
118
+	/**
119
+	 * Get all the info about your own ip address.
120
+	 *
121
+	 * @return \DavidePastore\Ipinfo\Host The Host object with all the info.
122
+	 */
123
+	public function getYourOwnIpDetails()
124
+	{
125
+		$response = $this->makeCurlRequest($this::BASE_URL.'json');
126
+		$response = $this->jsonDecodeResponse($response);
127
+
128
+		return new Host($response);
129
+	}
130
+
131
+	/**
132
+	 * Get all the info about an ip address.
133
+	 *
134
+	 * @param string $ipAddress The ip address.
135
+	 *
136
+	 * @return \DavidePastore\Ipinfo\Host The Host object with all the info.
137
+	 */
138
+	public function getFullIpDetails($ipAddress)
139
+	{
140
+		$response = $this->makeCurlRequest($this::BASE_URL.$ipAddress);
141
+		$response = $this->jsonDecodeResponse($response);
142
+
143
+		return new Host($response);
144
+	}
145
+
146
+	/**
147
+	 * Get a specific field value.
148
+	 *
149
+	 * @param string $ipAddress The ip address.
150
+	 * @param string $field     The field.
151
+	 *
152
+	 * @return string|\DavidePastore\Ipinfo\Host The value of the given field for the given ip.
153
+	 *                                           This could returns an Host object if you call it with for the field
154
+	 *                                           \DavidePastore\Ipinfo\Ipinfo::GEO.
155
+	 */
156
+	public function getSpecificField($ipAddress, $field)
157
+	{
158
+		$response = $this->makeCurlRequest($this::BASE_URL.$ipAddress.'/'.$field);
159
+		$response = $this->checkGeo($field, $response);
160
+
161
+		return $response;
162
+	}
163
+
164
+	/**
165
+	 * Get a specific field value of your own ip address.
166
+	 *
167
+	 * @param string $field The field.
168
+	 *
169
+	 * @return string|\DavidePastore\Ipinfo\Host The value of the given field for your own ip.
170
+	 *                                           This could returns an Host object if you call it with for the field
171
+	 *                                           \DavidePastore\Ipinfo\Ipinfo::GEO.
172
+	 */
173
+	public function getYourOwnIpSpecificField($field)
174
+	{
175
+		$response = $this->makeCurlRequest($this::BASE_URL.$field);
176
+		$response = $this->checkGeo($field, $response);
177
+
178
+		return $response;
179
+	}
180
+
181
+	/**
182
+	 * Use the /geo call to get just the geolocation information, which will often be
183
+	 * faster than getting the full response.
184
+	 *
185
+	 * @param string $ipAddress The ip address.
186
+	 *
187
+	 * @return \DavidePastore\Ipinfo\Host
188
+	 */
189
+	public function getIpGeoDetails($ipAddress)
190
+	{
191
+		return $this->getSpecificField($ipAddress, $this::GEO);
192
+	}
193
+
194
+	/**
195
+	 * Check if the response is GEO and set the parameters accordingly.
196
+	 *
197
+	 * @param string $field    The field value.
198
+	 * @param string $response The response from the server.
199
+	 *
200
+	 * @return Ambigous <\DavidePastore\Ipinfo\Host, string> Returns an Host object if the request is
201
+	 *                  of the GEO type, a string otherwise. If the field value is different from the GEO type, it will
202
+	 *                  delete the last character ('\n').
203
+	 */
204
+	private function checkGeo($field, $response)
205
+	{
206
+		if ($field == $this::GEO) {
207
+			$response = $this->jsonDecodeResponse($response);
208
+			$response = new Host($response);
209
+		} else {
210
+			$this->checkErrors($response);
211
+			$response = substr($response, 0, -1);
212
+		}
213
+
214
+		return $response;
215
+	}
216
+
217
+	/**
218
+	 * Make a curl request.
219
+	 *
220
+	 * @param string $address The address of the request.
221
+	 *
222
+	 * @return string Returns the response from the request.
223
+	 */
224
+	private function makeCurlRequest($address)
225
+	{
226
+		$curl = curl_init();
227
+
228
+		if (!empty($this->settings['token'])) {
229
+			$address .= '?token='.$this->settings['token'];
230
+		}
231
+
232
+		if ($this->settings['debug']) {
233
+			echo 'Request address: '.$address."\n";
234
+		}
235
+
236
+		curl_setopt_array($curl, array(
237
+			CURLOPT_RETURNTRANSFER => 1,
238
+			CURLOPT_URL => $address,
239
+			CURLOPT_CONNECTTIMEOUT => $this->settings['connectionTimeout'],
240
+			CURLOPT_TIMEOUT => $this->settings['timeout'],
241
+			CURLOPT_CAINFO => __DIR__ . "/cacert.pem"
242
+		));
243
+
244
+		$response = curl_exec($curl);
245
+
246
+		if ($response === false && $this->settings['debug']) {
247
+			$error = curl_error($curl);
248
+			echo "The error is".$error;
249
+		}
250
+
251
+		curl_close($curl);
252
+
253
+		return $response;
254
+	}
255
+
256
+	/**
257
+	 * Returns the json decoded associative array.
258
+	 * @param  string $response Response from the http call.
259
+	 * @return array           Returns the associative array with the response.
260
+	 * @throws RateLimitExceedException    If you exceed the rate limit.
261
+	 * @throws InvalidTokenException If the used token is invalid.
262
+	 */
263
+	private function jsonDecodeResponse($response)
264
+	{
265
+		if ($response) {
266
+			// Check if the response contains an error message
267
+			$this->checkErrors($response);
268
+			$response = json_decode($response, true);
269
+		} else {
270
+			$response = array();
271
+		}
272
+		return $response;
273
+	}
274
+
275
+	/**
276
+	 * Check if the given response has some kind of errors.
277
+	 * @param string $response The response to check.
278
+	 * @throws RateLimitExceedException    If you exceed the rate limit.
279
+	 * @throws InvalidTokenException If the used token is invalid.
280
+	 */
281
+	private function checkErrors($response)
282
+	{
283
+		if (strpos($response, 'Rate limit exceeded.') !== false) {
284
+			throw new RateLimitExceedException("You exceed the rate limit.", $response);
285
+		} elseif (strpos($response, 'Unknown token.') !== false) {
286
+			throw new InvalidTokenException("The used token is invalid.", $response);
287
+		}
288
+	}
289 289
 }
Please login to merge, or discard this patch.