Completed
Push — master ( d2e951...b1f2c8 )
by Haridarshan
02:18
created
src/HelperFactory.php 3 patches
Doc Comments   +4 added lines patch added patch discarded remove patch
@@ -96,6 +96,10 @@
 block discarded – undo
96 96
      * @param object $object
97 97
      * @return void
98 98
      */
99
+
100
+    /**
101
+     * @param ClientException $e
102
+     */
99 103
     private static function throwException($object, $e)
100 104
     {
101 105
         $exception = array();
Please login to merge, or discard this patch.
Unused Use Statements   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -2,13 +2,13 @@
 block discarded – undo
2 2
 namespace Haridarshan\Instagram;
3 3
 
4 4
 use GuzzleHttp\Client;
5
+use GuzzleHttp\Exception\ClientException;
5 6
 use GuzzleHttp\Psr7\Response;
6 7
 use GuzzleHttp\Psr7\Stream;
7
-use GuzzleHttp\Exception\ClientException;
8
-use Haridarshan\Instagram\InstagramResponse;
9 8
 use Haridarshan\Instagram\Exceptions\InstagramException;
10
-use Haridarshan\Instagram\Exceptions\InstagramServerException;
11 9
 use Haridarshan\Instagram\Exceptions\InstagramOAuthException;
10
+use Haridarshan\Instagram\Exceptions\InstagramServerException;
11
+use Haridarshan\Instagram\InstagramResponse;
12 12
 
13 13
 class HelperFactory
14 14
 {
Please login to merge, or discard this patch.
Indentation   +77 added lines, -77 removed lines patch added patch discarded remove patch
@@ -12,33 +12,33 @@  discard block
 block discarded – undo
12 12
 
13 13
 class HelperFactory
14 14
 {
15
-    /** @var Response $response */
16
-    protected static $response;
15
+	/** @var Response $response */
16
+	protected static $response;
17 17
     
18
-    /** @var Stream $stream */
19
-    protected static $stream;
18
+	/** @var Stream $stream */
19
+	protected static $stream;
20 20
     
21
-    /** @var object $content */
22
-    protected static $content;
21
+	/** @var object $content */
22
+	protected static $content;
23 23
     
24
-    private function __construct()
25
-    {
26
-        // a factory constructor should never be invoked
27
-    }
24
+	private function __construct()
25
+	{
26
+		// a factory constructor should never be invoked
27
+	}
28 28
     
29
-    /*
29
+	/*
30 30
      * Factory Client method to create \GuzzleHttp\Client object
31 31
      * @param string $uri
32 32
      * @return Client
33 33
      */
34
-    public static function client($uri)
35
-    {
36
-        return new Client([
37
-            'base_uri' => $uri
38
-        ]);
39
-    }
34
+	public static function client($uri)
35
+	{
36
+		return new Client([
37
+			'base_uri' => $uri
38
+		]);
39
+	}
40 40
     
41
-    /*
41
+	/*
42 42
      *
43 43
      * @param Client $client
44 44
      * @param string $endpoint
@@ -48,78 +48,78 @@  discard block
 block discarded – undo
48 48
      * @throws InstagramOAuthException
49 49
      * @throws InstagramException
50 50
      */
51
-    public static function request(Client $client, $endpoint, $options, $method = 'GET')
52
-    {
53
-        try {
54
-            return $client->request($method, $endpoint, [
55
-                'headers' => ['Accept' => 'application/json'],
56
-                'body' => static::createBody($options, $method)
57
-            ]);
58
-        } catch (ClientException $e) {
59
-            static::throwException(static::extractOriginalExceptionMessage($e), $e);
60
-        }
61
-    }
51
+	public static function request(Client $client, $endpoint, $options, $method = 'GET')
52
+	{
53
+		try {
54
+			return $client->request($method, $endpoint, [
55
+				'headers' => ['Accept' => 'application/json'],
56
+				'body' => static::createBody($options, $method)
57
+			]);
58
+		} catch (ClientException $e) {
59
+			static::throwException(static::extractOriginalExceptionMessage($e), $e);
60
+		}
61
+	}
62 62
     
63
-    /*
63
+	/*
64 64
      * Create body for Guzzle client request
65 65
      * @param array|null|string $options
66 66
      * @param string $method GET|POST
67 67
      * @return string|mixed
68 68
      */
69
-    private static function createBody($options, $method)
70
-    {
71
-        return ('GET' !== $method) ? is_array($options) ? http_build_query($options) : ltrim($options, '&') : null;
72
-    }
69
+	private static function createBody($options, $method)
70
+	{
71
+		return ('GET' !== $method) ? is_array($options) ? http_build_query($options) : ltrim($options, '&') : null;
72
+	}
73 73
     
74
-    /*
74
+	/*
75 75
      * Method to extract all exceptions for Guzzle ClientException
76 76
      * @param ClientException $e
77 77
      * @return
78 78
      */
79
-    private static function extractOriginalExceptionMessage(ClientException $e)
80
-    {
81
-        self::$response = $e->getResponse();
82
-        self::$stream = self::$response->getBody();
83
-        self::$content = self::$stream->getContents();
84
-        if (empty(self::$content)) {
85
-            throw new InstagramServerException(
86
-                $e->getMessage(),
87
-                $e->getCode(),
88
-                $e
89
-            );
90
-        } else {
91
-            return json_decode(self::$content);
92
-        }
93
-    }
79
+	private static function extractOriginalExceptionMessage(ClientException $e)
80
+	{
81
+		self::$response = $e->getResponse();
82
+		self::$stream = self::$response->getBody();
83
+		self::$content = self::$stream->getContents();
84
+		if (empty(self::$content)) {
85
+			throw new InstagramServerException(
86
+				$e->getMessage(),
87
+				$e->getCode(),
88
+				$e
89
+			);
90
+		} else {
91
+			return json_decode(self::$content);
92
+		}
93
+	}
94 94
     
95
-    /*
95
+	/*
96 96
      * @param object $object
97 97
      * @return void
98 98
      */
99
-    private static function throwException($object, $e)
100
-    {
101
-        $exception = array();
102
-        if (isset($object->meta)) {
103
-            $exception['error_type'] = $object->meta->error_type;
104
-            $exception['error_message'] = $object->meta->error_message;
105
-            $exception['error_code'] = $object->meta->code;
106
-        } else {
107
-            $exception['error_type'] = $object->error_type;
108
-            $exception['error_message'] = $object->error_message;
109
-            $exception['error_code'] = $object->code;
110
-        }
111
-        if (stripos($exception['error_type'], "oauth") !== false) {
112
-            throw new InstagramOAuthException(
113
-                json_encode(array("Type" => $exception['error_type'], "Message" => $exception['error_message'])),
114
-                $exception['error_code'],
115
-                $e
116
-            );
117
-        } else {
118
-            throw new InstagramException(
119
-                json_encode(array("Type" => $exception['error_type'], "Message" => $exception['error_message'])),
120
-                $exception['error_code'],
121
-                $e
122
-            );
123
-        }
124
-    }
99
+	private static function throwException($object, $e)
100
+	{
101
+		$exception = array();
102
+		if (isset($object->meta)) {
103
+			$exception['error_type'] = $object->meta->error_type;
104
+			$exception['error_message'] = $object->meta->error_message;
105
+			$exception['error_code'] = $object->meta->code;
106
+		} else {
107
+			$exception['error_type'] = $object->error_type;
108
+			$exception['error_message'] = $object->error_message;
109
+			$exception['error_code'] = $object->code;
110
+		}
111
+		if (stripos($exception['error_type'], "oauth") !== false) {
112
+			throw new InstagramOAuthException(
113
+				json_encode(array("Type" => $exception['error_type'], "Message" => $exception['error_message'])),
114
+				$exception['error_code'],
115
+				$e
116
+			);
117
+		} else {
118
+			throw new InstagramException(
119
+				json_encode(array("Type" => $exception['error_type'], "Message" => $exception['error_message'])),
120
+				$exception['error_code'],
121
+				$e
122
+			);
123
+		}
124
+	}
125 125
 }
Please login to merge, or discard this patch.
src/Instagram.php 2 patches
Unused Use Statements   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -15,11 +15,9 @@
 block discarded – undo
15 15
 namespace Haridarshan\Instagram;
16 16
 
17 17
 use Haridarshan\Instagram\Constants;
18
-use Haridarshan\Instagram\InstagramOAuth;
19
-use Haridarshan\Instagram\HelperFactory;
20 18
 use Haridarshan\Instagram\Exceptions\InstagramException;
21
-use Haridarshan\Instagram\Exceptions\InstagramOAuthException;
22
-use Haridarshan\Instagram\Exceptions\InstagramThrottleException;
19
+use Haridarshan\Instagram\HelperFactory;
20
+use Haridarshan\Instagram\InstagramOAuth;
23 21
 
24 22
 class Instagram
25 23
 {
Please login to merge, or discard this patch.
Indentation   +121 added lines, -121 removed lines patch added patch discarded remove patch
@@ -23,200 +23,200 @@
 block discarded – undo
23 23
 
24 24
 class Instagram
25 25
 {
26
-    /** @var string */
27
-    private $clientId;
26
+	/** @var string */
27
+	private $clientId;
28 28
 	
29
-    /** @var string */
30
-    private $clientSecret;
29
+	/** @var string */
30
+	private $clientSecret;
31 31
 	
32
-    /** @var string */
33
-    private $callbackUrl;
32
+	/** @var string */
33
+	private $callbackUrl;
34 34
     
35
-    /** @var array<string> */
36
-    private $defaultScopes = array("basic", "public_content", "follower_list", "comments", "relationships", "likes");
35
+	/** @var array<string> */
36
+	private $defaultScopes = array("basic", "public_content", "follower_list", "comments", "relationships", "likes");
37 37
 	
38
-    /** @var array<string> */
39
-    private $scopes = array();
38
+	/** @var array<string> */
39
+	private $scopes = array();
40 40
 	
41
-    /*
41
+	/*
42 42
     * Random string indicating the state to prevent spoofing
43 43
     * @var string
44 44
     */
45
-    private $state;
45
+	private $state;
46 46
 		
47
-    /** @var \GuzzleHttp\Client $client */
48
-    protected $client;
47
+	/** @var \GuzzleHttp\Client $client */
48
+	protected $client;
49 49
 	
50
-    /** @var object $oauthResponse */
51
-    private $oauthResponse;
50
+	/** @var object $oauthResponse */
51
+	private $oauthResponse;
52 52
 	
53
-    /*
53
+	/*
54 54
      * Default Constructor
55 55
      * Instagram Configuration Data
56 56
      * @param array|object|string $config
57 57
      */
58
-    public function __construct($config)
59
-    {
60
-        if (is_array($config)) {
61
-            $this->setClientId($config['ClientId']);
62
-            $this->setClientSecret($config['ClientSecret']);
63
-            $this->setCallbackUrl($config['Callback']);
64
-            $this->state = isset($config['State']) ? $config['State'] : substr(md5(rand()), 0, 7);
65
-        } else {
66
-            throw new InstagramException('Invalid Instagram Configuration data', 400);
67
-        }
68
-        $this->client = HelperFactory::client(Constants::API_HOST);
69
-    }
70
-	
71
-    /*
58
+	public function __construct($config)
59
+	{
60
+		if (is_array($config)) {
61
+			$this->setClientId($config['ClientId']);
62
+			$this->setClientSecret($config['ClientSecret']);
63
+			$this->setCallbackUrl($config['Callback']);
64
+			$this->state = isset($config['State']) ? $config['State'] : substr(md5(rand()), 0, 7);
65
+		} else {
66
+			throw new InstagramException('Invalid Instagram Configuration data', 400);
67
+		}
68
+		$this->client = HelperFactory::client(Constants::API_HOST);
69
+	}
70
+	
71
+	/*
72 72
      * Make URLs for user browser navigation
73 73
      * @param string $path
74 74
      * @param array  $parameters
75 75
      * @return string
76 76
      */
77
-    public function getLoginUrl(array $parameters)
78
-    {
79
-        if (!isset($parameters['scope'])) {
80
-            throw new InstagramException("Missing or Invalid Scope permission used", 400);
81
-        }
82
-        if (count(array_diff($parameters['scope'], $this->defaultScopes)) === 0) {
83
-            $this->scopes = $parameters['scope'];
84
-        } else {
85
-            throw new InstagramException("Missing or Invalid Scope permission used", 400);
86
-        }
87
-        $query = 'client_id='.$this->getClientId().'&redirect_uri='.urlencode($this->getCallbackUrl()).'&response_type=code&state='.$this->state;
88
-        $query .= isset($this->scopes) ? '&scope='.urlencode(str_replace(",", " ", implode(",", $parameters['scope']))) : '';
89
-        return sprintf('%s%s?%s', Constants::API_HOST, Constants::API_AUTH, $query);
90
-    }
91
-	
92
-    /*
77
+	public function getLoginUrl(array $parameters)
78
+	{
79
+		if (!isset($parameters['scope'])) {
80
+			throw new InstagramException("Missing or Invalid Scope permission used", 400);
81
+		}
82
+		if (count(array_diff($parameters['scope'], $this->defaultScopes)) === 0) {
83
+			$this->scopes = $parameters['scope'];
84
+		} else {
85
+			throw new InstagramException("Missing or Invalid Scope permission used", 400);
86
+		}
87
+		$query = 'client_id='.$this->getClientId().'&redirect_uri='.urlencode($this->getCallbackUrl()).'&response_type=code&state='.$this->state;
88
+		$query .= isset($this->scopes) ? '&scope='.urlencode(str_replace(",", " ", implode(",", $parameters['scope']))) : '';
89
+		return sprintf('%s%s?%s', Constants::API_HOST, Constants::API_AUTH, $query);
90
+	}
91
+	
92
+	/*
93 93
      * Get the Oauth Access Token of a user from callback code
94 94
      *
95 95
      * @param string $path - OAuth Access Token Path
96 96
      * @param string $code - Oauth2 Code returned with callback url after successfull login
97 97
      * @param boolean $token - true will return only access token
98 98
      */
99
-    public function oauth($code, $token = false)
100
-    {
101
-        $options = array(
102
-            "grant_type" => "authorization_code",
103
-            "client_id" => $this->getClientId(),
104
-            "client_secret" => $this->getClientSecret(),
105
-            "redirect_uri" => $this->getCallbackUrl(),
106
-            "code" => $code,
107
-            "state" => $this->state
108
-        );
99
+	public function oauth($code, $token = false)
100
+	{
101
+		$options = array(
102
+			"grant_type" => "authorization_code",
103
+			"client_id" => $this->getClientId(),
104
+			"client_secret" => $this->getClientSecret(),
105
+			"redirect_uri" => $this->getCallbackUrl(),
106
+			"code" => $code,
107
+			"state" => $this->state
108
+		);
109 109
 		$this->oauthResponse = new InstagramOAuth(
110 110
 			json_decode((HelperFactory::request($this->client, Constants::API_TOKEN, $options, 'POST'))->getBody()->getContents())
111 111
 		);
112
-        return $this->oauthResponse;
113
-    }
112
+		return $this->oauthResponse;
113
+	}
114 114
    
115
-    /*
115
+	/*
116 116
      * Set Client Id
117 117
      * @param string $clientId
118 118
      * @return void
119 119
      */
120
-    public function setClientId($clientId)
121
-    {
122
-        $this->clientId = $clientId;
123
-    }
120
+	public function setClientId($clientId)
121
+	{
122
+		$this->clientId = $clientId;
123
+	}
124 124
 	
125
-    /*
125
+	/*
126 126
      * Get Client Id
127 127
      * @return string
128 128
      */
129
-    public function getClientId()
130
-    {
131
-        return $this->clientId;
132
-    }
129
+	public function getClientId()
130
+	{
131
+		return $this->clientId;
132
+	}
133 133
 	
134
-    /*
134
+	/*
135 135
      * Set Client Secret
136 136
      * @param string $secret
137 137
      * @return void
138 138
      */
139
-    public function setClientSecret($secret)
140
-    {
141
-        $this->clientSecret = $secret;
142
-    }
139
+	public function setClientSecret($secret)
140
+	{
141
+		$this->clientSecret = $secret;
142
+	}
143 143
 	
144
-    /*
144
+	/*
145 145
      * Getter: Client Id
146 146
      * @return string
147 147
      */
148
-    public function getClientSecret()
149
-    {
150
-        return $this->clientSecret;
151
-    }
148
+	public function getClientSecret()
149
+	{
150
+		return $this->clientSecret;
151
+	}
152 152
 	
153
-    /*
153
+	/*
154 154
      * Setter: Callback Url
155 155
      * @param string $url
156 156
      * @return void
157 157
      */
158
-    public function setCallbackUrl($url)
159
-    {
160
-        $this->callbackUrl = $url;
161
-    }
158
+	public function setCallbackUrl($url)
159
+	{
160
+		$this->callbackUrl = $url;
161
+	}
162 162
 	
163
-    /*
163
+	/*
164 164
      * Getter: Callback Url
165 165
      * @return string
166 166
      */
167
-    public function getCallbackUrl()
168
-    {
169
-        return $this->callbackUrl;
170
-    }
167
+	public function getCallbackUrl()
168
+	{
169
+		return $this->callbackUrl;
170
+	}
171 171
 	
172
-    /*
172
+	/*
173 173
      * Get InstagramOAuth
174 174
      * @return InstagramOAuth
175 175
      */
176
-    public function getOAuth()
177
-    {
178
-        if ($this->oauthResponse instanceof InstagramOAuth) {
179
-            return $this->oauthResponse;
180
-        } else {
181
-            $this->oauthResponse = new InstagramOAuth(json_decode(json_encode(["access_token" => null])));
182
-            return $this->oauthResponse;
183
-        }
184
-    }
185
-    /*
176
+	public function getOAuth()
177
+	{
178
+		if ($this->oauthResponse instanceof InstagramOAuth) {
179
+			return $this->oauthResponse;
180
+		} else {
181
+			$this->oauthResponse = new InstagramOAuth(json_decode(json_encode(["access_token" => null])));
182
+			return $this->oauthResponse;
183
+		}
184
+	}
185
+	/*
186 186
      * @return Client
187 187
      */
188
-    public function getHttpClient()
189
-    {
190
-        return $this->client;
191
-    }
188
+	public function getHttpClient()
189
+	{
190
+		return $this->client;
191
+	}
192 192
 	
193
-    /*
193
+	/*
194 194
      * Setter: User Access Token
195 195
      * @param string $token
196 196
      * @return void
197 197
      */
198
-    public function setAccessToken($token)
199
-    {
200
-        if (!$this->oauthResponse instanceof InstagramOAuth) {
201
-            $this->oauthResponse = new InstagramOAuth(json_decode(json_encode(["access_token" => $token])));
202
-        }
203
-    }
198
+	public function setAccessToken($token)
199
+	{
200
+		if (!$this->oauthResponse instanceof InstagramOAuth) {
201
+			$this->oauthResponse = new InstagramOAuth(json_decode(json_encode(["access_token" => $token])));
202
+		}
203
+	}
204 204
 
205
-    /*
205
+	/*
206 206
      * Get a string containing the version of the library.
207 207
      * @return string
208 208
      */
209
-    public function getLibraryVersion()
210
-    {
211
-        return Constants::VERSION;
212
-    }
209
+	public function getLibraryVersion()
210
+	{
211
+		return Constants::VERSION;
212
+	}
213 213
 	
214
-    /*
214
+	/*
215 215
      * Get state value
216 216
      * @return string|mixed
217 217
      */
218
-    public function getState()
219
-    {
220
-        return $this->state;
221
-    }
218
+	public function getState()
219
+	{
220
+		return $this->state;
221
+	}
222 222
 }
Please login to merge, or discard this patch.
src/InstagramRequest.php 2 patches
Unused Use Statements   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -1,11 +1,10 @@
 block discarded – undo
1 1
 <?php
2 2
 namespace Haridarshan\Instagram;
3 3
 
4
-use Haridarshan\Instagram\HelperFactory;
5 4
 use Haridarshan\Instagram\Constants;
5
+use Haridarshan\Instagram\HelperFactory;
6 6
 use Haridarshan\Instagram\Instagram;
7 7
 use Haridarshan\Instagram\InstagramResponse;
8
-use Haridarshan\Instagram\Exceptions\InstagramResponseException;
9 8
 
10 9
 class InstagramRequest
11 10
 {
Please login to merge, or discard this patch.
Indentation   +70 added lines, -70 removed lines patch added patch discarded remove patch
@@ -9,30 +9,30 @@  discard block
 block discarded – undo
9 9
 
10 10
 class InstagramRequest
11 11
 {
12
-    /** @var string $path */
13
-    private $path;
12
+	/** @var string $path */
13
+	private $path;
14 14
     
15
-    /** @var array $params */
16
-    private $params;
15
+	/** @var array $params */
16
+	private $params;
17 17
     
18
-    /** @var string $method */
19
-    private $method;
18
+	/** @var string $method */
19
+	private $method;
20 20
 
21
-    /*
21
+	/*
22 22
     * Remaining Rate Limit
23 23
     * Sandbox = 500
24 24
     * Live = 5000
25 25
     * @var array $x_rate_limit_remaining
26 26
     */
27
-    private $xRateLimitRemaining = 500;
27
+	private $xRateLimitRemaining = 500;
28 28
     
29
-    /** @var InstagramResponse $response */
30
-    protected $response;
29
+	/** @var InstagramResponse $response */
30
+	protected $response;
31 31
     
32
-    /** @var Instagram $instagram */
33
-    protected $instagram;
32
+	/** @var Instagram $instagram */
33
+	protected $instagram;
34 34
     
35
-    /*
35
+	/*
36 36
      * Create the request and execute it to get the response
37 37
      * @param Instagram $instagram
38 38
      * @param string $path
@@ -41,68 +41,68 @@  discard block
 block discarded – undo
41 41
      *
42 42
      * @return InstagramResponse
43 43
      */
44
-    public function __construct(Instagram $instagram, $path, array $params = array(), $method = 'GET')
45
-    {
46
-        $this->instagram = $instagram;
47
-        $this->path = $path;
48
-        $this->params = $params;
49
-        $this->method = $method;
50
-    }
44
+	public function __construct(Instagram $instagram, $path, array $params = array(), $method = 'GET')
45
+	{
46
+		$this->instagram = $instagram;
47
+		$this->path = $path;
48
+		$this->params = $params;
49
+		$this->method = $method;
50
+	}
51 51
     
52
-    /*
52
+	/*
53 53
      * Execute the Instagram Request
54 54
      * @param void
55 55
      * @return InstagramResponse
56 56
      */
57
-    protected function execute()
58
-    {
59
-        $this->isRateLimitReached();
60
-        $this->isAccessTokenPresent();
61
-        $oauth = $this->instagram->getOAuth();
62
-        if (!$oauth->isAccessTokenSet()) {
63
-            $oauth->setAccessToken($this->params['access_token']);
64
-        }
65
-        $authentication_method = '?access_token='.$this->params['access_token'];
66
-        $endpoint = Constants::API_VERSION.$this->path.(('GET' === $this->method) ? '?'.http_build_query($this->params) : $authentication_method);
67
-        $endpoint .= (strstr($endpoint, '?') ? '&' : '?').'sig='.static::generateSignature($this->instagram->getClientSecret(), $this->path, $this->params);
57
+	protected function execute()
58
+	{
59
+		$this->isRateLimitReached();
60
+		$this->isAccessTokenPresent();
61
+		$oauth = $this->instagram->getOAuth();
62
+		if (!$oauth->isAccessTokenSet()) {
63
+			$oauth->setAccessToken($this->params['access_token']);
64
+		}
65
+		$authentication_method = '?access_token='.$this->params['access_token'];
66
+		$endpoint = Constants::API_VERSION.$this->path.(('GET' === $this->method) ? '?'.http_build_query($this->params) : $authentication_method);
67
+		$endpoint .= (strstr($endpoint, '?') ? '&' : '?').'sig='.static::generateSignature($this->instagram->getClientSecret(), $this->path, $this->params);
68 68
         
69
-        $this->response = new InstagramResponse(HelperFactory::request($this->instagram->getHttpClient(), $endpoint, $this->params, $this->method));
70
-        $this->xRateLimitRemaining = $this->response->getHeader('X-Ratelimit-Remaining');
71
-    }
69
+		$this->response = new InstagramResponse(HelperFactory::request($this->instagram->getHttpClient(), $endpoint, $this->params, $this->method));
70
+		$this->xRateLimitRemaining = $this->response->getHeader('X-Ratelimit-Remaining');
71
+	}
72 72
     
73
-    /*
73
+	/*
74 74
      * Check Access Token is present. If not throw InstagramRequestException
75 75
      * @throws InstagramRequestException
76 76
      */
77
-    protected function isAccessTokenPresent()
78
-    {
79
-        if (!isset($this->params['access_token'])) {
80
-            throw new InstagramRequestException("{$this->path} - api requires an authenticated users access token.", 400);
81
-        }
82
-    }
77
+	protected function isAccessTokenPresent()
78
+	{
79
+		if (!isset($this->params['access_token'])) {
80
+			throw new InstagramRequestException("{$this->path} - api requires an authenticated users access token.", 400);
81
+		}
82
+	}
83 83
     
84
-    /*
84
+	/*
85 85
      * Get Response
86 86
      * @return InstagramResponse
87 87
      */
88
-    public function getResponse()
89
-    {
90
-        $this->execute();
91
-        return $this->response;
92
-    }
88
+	public function getResponse()
89
+	{
90
+		$this->execute();
91
+		return $this->response;
92
+	}
93 93
     
94
-    /*
94
+	/*
95 95
      * Check whether api rate limit is reached or not
96 96
      * @throws InstagramThrottleException
97 97
      */
98
-    private function isRateLimitReached()
99
-    {
100
-        if (!$this->getRateLimit()) {
101
-            throw new InstagramThrottleException("400 Bad Request : You have reached Instagram API Rate Limit", 400);
102
-        }
103
-    }
98
+	private function isRateLimitReached()
99
+	{
100
+		if (!$this->getRateLimit()) {
101
+			throw new InstagramThrottleException("400 Bad Request : You have reached Instagram API Rate Limit", 400);
102
+		}
103
+	}
104 104
     
105
-    /*
105
+	/*
106 106
      * Secure API Request by using endpoint, paramters and API secret
107 107
      * copy from Instagram API Documentation: https://www.instagram.com/developer/secure-api-requests/
108 108
      *
@@ -112,21 +112,21 @@  discard block
 block discarded – undo
112 112
      *
113 113
      * @return string (Signature)
114 114
      */
115
-    public static function generateSignature($secret, $endpoint, $params)
116
-    {
117
-        $signature = $endpoint;
118
-        ksort($params);
119
-        foreach ($params as $key => $value) {
120
-            $signature .= "|$key=$value";
121
-        }
122
-        return hash_hmac('sha256', $signature, $secret, false);
123
-    }
115
+	public static function generateSignature($secret, $endpoint, $params)
116
+	{
117
+		$signature = $endpoint;
118
+		ksort($params);
119
+		foreach ($params as $key => $value) {
120
+			$signature .= "|$key=$value";
121
+		}
122
+		return hash_hmac('sha256', $signature, $secret, false);
123
+	}
124 124
     
125
-    /*
125
+	/*
126 126
      * @return int
127 127
      */
128
-    public function getRateLimit()
129
-    {
130
-        return $this->xRateLimitRemaining;
131
-    }
128
+	public function getRateLimit()
129
+	{
130
+		return $this->xRateLimitRemaining;
131
+	}
132 132
 }
Please login to merge, or discard this patch.
src/Exceptions/InstagramException.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -3,13 +3,13 @@
 block discarded – undo
3 3
 
4 4
 class InstagramException extends \Exception
5 5
 {
6
-    /*
6
+	/*
7 7
     * Get Exception type
8 8
     * @return string | nul;
9 9
     */
10
-    public function getType()
11
-    {
12
-        $message = json_decode($this->message);
13
-        return isset($message->Type) ? $message->Type : null;
14
-    }
10
+	public function getType()
11
+	{
12
+		$message = json_decode($this->message);
13
+		return isset($message->Type) ? $message->Type : null;
14
+	}
15 15
 }
Please login to merge, or discard this patch.
src/InstagramOAuth.php 1 patch
Indentation   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -5,61 +5,61 @@
 block discarded – undo
5 5
 
6 6
 class InstagramOAuth
7 7
 {
8
-    /** @var string $accessToken */
9
-    private $accessToken;
8
+	/** @var string $accessToken */
9
+	private $accessToken;
10 10
     
11
-    /** @var object $user */
12
-    private $user;
11
+	/** @var object $user */
12
+	private $user;
13 13
     
14
-    /*
14
+	/*
15 15
      * @param object $oauth
16 16
      * @return this
17 17
      * @throws InstagramOAuthException
18 18
      */
19
-    public function __construct($oauth)
20
-    {
21
-        if (!empty($oauth)) {
22
-            $this->accessToken = $oauth->access_token;
23
-            $this->user = isset($oauth->user) ? $oauth->user : null;
24
-        } else {
25
-            throw new InstagramOAuthException("Bad Request 400 empty Response", 400);
26
-        }
27
-    }
19
+	public function __construct($oauth)
20
+	{
21
+		if (!empty($oauth)) {
22
+			$this->accessToken = $oauth->access_token;
23
+			$this->user = isset($oauth->user) ? $oauth->user : null;
24
+		} else {
25
+			throw new InstagramOAuthException("Bad Request 400 empty Response", 400);
26
+		}
27
+	}
28 28
     
29
-    /*
29
+	/*
30 30
      * Get Access Token
31 31
      * @return string
32 32
      */
33
-    public function getAccessToken()
34
-    {
35
-        return $this->accessToken;
36
-    }
33
+	public function getAccessToken()
34
+	{
35
+		return $this->accessToken;
36
+	}
37 37
     
38
-    /*
38
+	/*
39 39
      * Set Access Token
40 40
      * @param string $token
41 41
      * @return void
42 42
      */
43
-    public function setAccessToken($token)
44
-    {
45
-        $this->accessToken = $token;
46
-    }
43
+	public function setAccessToken($token)
44
+	{
45
+		$this->accessToken = $token;
46
+	}
47 47
     
48
-    /*
48
+	/*
49 49
      * If AccessToken is set return true else false
50 50
      * @return bool
51 51
      */
52
-    public function isAccessTokenSet()
53
-    {
54
-        return isset($this->accessToken) ? true : false;
55
-    }
52
+	public function isAccessTokenSet()
53
+	{
54
+		return isset($this->accessToken) ? true : false;
55
+	}
56 56
     
57
-    /*
57
+	/*
58 58
      * Get User Info
59 59
      * @return object
60 60
      */
61
-    public function getUserInfo()
62
-    {
63
-        return $this->user;
64
-    }
61
+	public function getUserInfo()
62
+	{
63
+		return $this->user;
64
+	}
65 65
 }
Please login to merge, or discard this patch.
src/Constants.php 1 patch
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -3,18 +3,18 @@
 block discarded – undo
3 3
 
4 4
 class Constants
5 5
 {
6
-    /** Library Version */
7
-    const VERSION = '2.0';
6
+	/** Library Version */
7
+	const VERSION = '2.0';
8 8
     
9
-    /** API End Point */
10
-    const API_VERSION = 'v1';
9
+	/** API End Point */
10
+	const API_VERSION = 'v1';
11 11
     
12
-    /** API End Point */
13
-    const API_HOST = 'https://api.instagram.com/';
12
+	/** API End Point */
13
+	const API_HOST = 'https://api.instagram.com/';
14 14
     
15
-    /** OAuth2.0 Authorize API End Point */
16
-    const API_AUTH = 'oauth/authorize';
15
+	/** OAuth2.0 Authorize API End Point */
16
+	const API_AUTH = 'oauth/authorize';
17 17
     
18
-    /** OAuth Access Token API End Point */
19
-    const API_TOKEN = 'oauth/access_token';
18
+	/** OAuth Access Token API End Point */
19
+	const API_TOKEN = 'oauth/access_token';
20 20
 }
Please login to merge, or discard this patch.
src/InstagramResponse.php 1 patch
Indentation   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -8,14 +8,14 @@  discard block
 block discarded – undo
8 8
 
9 9
 class InstagramResponse
10 10
 {	
11
-    /** @var int $status_code */
12
-    private $statusCode;
11
+	/** @var int $status_code */
12
+	private $statusCode;
13 13
 	
14
-    /** @var string $protocol */
15
-    private $protocol = '1.1';
14
+	/** @var string $protocol */
15
+	private $protocol = '1.1';
16 16
 	
17
-    /** @var array $headers */
18
-    private $headers = [];
17
+	/** @var array $headers */
18
+	private $headers = [];
19 19
 	
20 20
 	/** @var bool */
21 21
 	private $isPagination = false;
@@ -32,36 +32,36 @@  discard block
 block discarded – undo
32 32
 	/** @var object */
33 33
 	private $data;
34 34
 	
35
-    /** @var object $body */
36
-    private $body;
35
+	/** @var object $body */
36
+	private $body;
37 37
 	
38 38
 	/*
39 39
 	 * @param Response $response
40 40
 	 * @return this
41 41
 	 * @throws InstagramResponseException
42 42
 	 */
43
-    public function __construct(Response $response)
44
-    {
45
-        if ($response instanceof Response) {
46
-            $this->setParams($response);
47
-        } else {
48
-            throw new InstagramResponseException('Bad Request: Response is not valid instance of GuzzleHttp\Psr7\Response', 404);
49
-        }
50
-    }
43
+	public function __construct(Response $response)
44
+	{
45
+		if ($response instanceof Response) {
46
+			$this->setParams($response);
47
+		} else {
48
+			throw new InstagramResponseException('Bad Request: Response is not valid instance of GuzzleHttp\Psr7\Response', 404);
49
+		}
50
+	}
51 51
     
52 52
 	/* 
53 53
 	 * Set Values to the class members
54 54
 	 * @param Response $response
55 55
 	 * @return void
56 56
 	 */
57
-    private function setParams($response)
58
-    {
59
-        $this->protocol = $response->getProtocolVersion();
60
-        $this->statusCode = (int) $response->getStatusCode();
61
-        $this->headers = $response->getHeaders();
62
-        $this->body = json_decode($response->getBody()->getContents());
57
+	private function setParams($response)
58
+	{
59
+		$this->protocol = $response->getProtocolVersion();
60
+		$this->statusCode = (int) $response->getStatusCode();
61
+		$this->headers = $response->getHeaders();
62
+		$this->body = json_decode($response->getBody()->getContents());
63 63
 		$this->extractBodyParts();
64
-    }
64
+	}
65 65
 	
66 66
 	private function extractBodyParts()
67 67
 	{
@@ -82,38 +82,38 @@  discard block
 block discarded – undo
82 82
 	 * Get response
83 83
 	 * @return object|string 
84 84
 	 */
85
-    public function getBody()
86
-    {
87
-        return $this->body;
88
-    }
85
+	public function getBody()
86
+	{
87
+		return $this->body;
88
+	}
89 89
     
90 90
 	/*
91 91
 	 * Get Status Code
92 92
 	 * @return int
93 93
 	 */
94
-    public function getStatusCode()
95
-    {
96
-        return $this->statusCode;
97
-    }
94
+	public function getStatusCode()
95
+	{
96
+		return $this->statusCode;
97
+	}
98 98
     
99 99
 	/*
100 100
 	 * Get specific header
101 101
 	 * @param string $header
102 102
 	 * @retrun string 
103 103
 	 */
104
-    public function getHeader($header)
105
-    {
106
-        return isset($this->headers[$header]) ? $this->headers[$header] : [];
107
-    }
104
+	public function getHeader($header)
105
+	{
106
+		return isset($this->headers[$header]) ? $this->headers[$header] : [];
107
+	}
108 108
 	
109 109
 	/*
110 110
 	 * Get all headers
111 111
 	 * @retrun array 
112 112
 	 */
113
-    public function getHeaders()
114
-    {
115
-        return $this->headers;
116
-    }
113
+	public function getHeaders()
114
+	{
115
+		return $this->headers;
116
+	}
117 117
 	
118 118
 	/*
119 119
 	 * Get data from body
Please login to merge, or discard this patch.