Completed
Push — master ( 64f1fd...d8491f )
by Haridarshan
02:22
created
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/InstagramRequest.php 1 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/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.
src/HelperFactory.php 1 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
      * @param Client $client
43 43
      * @param string $endpoint
44 44
      * @param array|string $options
@@ -47,79 +47,79 @@  discard block
 block discarded – undo
47 47
      * @throws InstagramOAuthException
48 48
      * @throws InstagramException
49 49
      */
50
-    public static function request(Client $client, $endpoint, $options, $method = 'GET')
51
-    {
52
-        try {
53
-            return $client->request($method, $endpoint, [
54
-                'headers' => ['Accept' => 'application/json'],
55
-                'body' => static::createBody($options, $method)
56
-            ]);
57
-        } catch (ClientException $e) {
58
-            static::throwException(static::extractOriginalExceptionMessage($e), $e);
59
-        }
60
-    }
50
+	public static function request(Client $client, $endpoint, $options, $method = 'GET')
51
+	{
52
+		try {
53
+			return $client->request($method, $endpoint, [
54
+				'headers' => ['Accept' => 'application/json'],
55
+				'body' => static::createBody($options, $method)
56
+			]);
57
+		} catch (ClientException $e) {
58
+			static::throwException(static::extractOriginalExceptionMessage($e), $e);
59
+		}
60
+	}
61 61
     
62
-    /*
62
+	/*
63 63
      * Create body for Guzzle client request
64 64
      * @param array|null|string $options
65 65
      * @param string $method GET|POST
66 66
      * @return string|mixed
67 67
      */
68
-    protected static function createBody($options, $method)
69
-    {
70
-        return ('GET' !== $method) ? is_array($options) ? http_build_query($options) : ltrim($options, '&') : null;
71
-    }
68
+	protected static function createBody($options, $method)
69
+	{
70
+		return ('GET' !== $method) ? is_array($options) ? http_build_query($options) : ltrim($options, '&') : null;
71
+	}
72 72
     
73
-    /*
73
+	/*
74 74
      * Method to extract all exceptions for Guzzle ClientException
75 75
      * @param ClientException $e
76 76
      * @return
77 77
      */
78
-    protected static function extractOriginalExceptionMessage(ClientException $e)
79
-    {
80
-        self::$response = $e->getResponse();
81
-        self::$stream = self::$response->getBody();
82
-        self::$content = self::$stream->getContents();
83
-        if (empty(self::$content)) {
84
-            throw new InstagramServerException(
85
-                $e->getMessage(),
86
-                $e->getCode(),
87
-                $e
88
-            );
89
-        } else {
90
-            return json_decode(self::$content);
91
-        }
92
-    }
78
+	protected static function extractOriginalExceptionMessage(ClientException $e)
79
+	{
80
+		self::$response = $e->getResponse();
81
+		self::$stream = self::$response->getBody();
82
+		self::$content = self::$stream->getContents();
83
+		if (empty(self::$content)) {
84
+			throw new InstagramServerException(
85
+				$e->getMessage(),
86
+				$e->getCode(),
87
+				$e
88
+			);
89
+		} else {
90
+			return json_decode(self::$content);
91
+		}
92
+	}
93 93
     
94
-    /*
94
+	/*
95 95
      * @param object $object
96 96
 	 * @param ClientException $e
97 97
      * @return void
98 98
      */
99
-    protected 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
+	protected 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 1 patch
Indentation   +121 added lines, -121 removed lines patch added patch discarded remove patch
@@ -21,199 +21,199 @@
 block discarded – undo
21 21
 
22 22
 class Instagram
23 23
 {
24
-    /** @var string */
25
-    private $clientId;
24
+	/** @var string */
25
+	private $clientId;
26 26
 	
27
-    /** @var string */
28
-    private $clientSecret;
27
+	/** @var string */
28
+	private $clientSecret;
29 29
 	
30
-    /** @var string */
31
-    private $callbackUrl;
30
+	/** @var string */
31
+	private $callbackUrl;
32 32
     
33
-    /** @var array<string> */
34
-    private $defaultScopes = array("basic", "public_content", "follower_list", "comments", "relationships", "likes");
33
+	/** @var array<string> */
34
+	private $defaultScopes = array("basic", "public_content", "follower_list", "comments", "relationships", "likes");
35 35
 	
36
-    /** @var array<string> */
37
-    private $scopes = array();
36
+	/** @var array<string> */
37
+	private $scopes = array();
38 38
 	
39
-    /*
39
+	/*
40 40
     * Random string indicating the state to prevent spoofing
41 41
     * @var string
42 42
     */
43
-    private $state;
43
+	private $state;
44 44
 		
45
-    /** @var \GuzzleHttp\Client $client */
46
-    protected $client;
45
+	/** @var \GuzzleHttp\Client $client */
46
+	protected $client;
47 47
 	
48
-    /** @var object $oauthResponse */
49
-    private $oauthResponse;
48
+	/** @var object $oauthResponse */
49
+	private $oauthResponse;
50 50
 	
51
-    /*
51
+	/*
52 52
      * Default Constructor
53 53
      * Instagram Configuration Data
54 54
      * @param array|object|string $config
55 55
      */
56
-    public function __construct($config)
57
-    {
58
-        if (is_array($config)) {
59
-            $this->setClientId($config['ClientId']);
60
-            $this->setClientSecret($config['ClientSecret']);
61
-            $this->setCallbackUrl($config['Callback']);
62
-            $this->state = isset($config['State']) ? $config['State'] : substr(md5(rand()), 0, 7);
63
-        } else {
64
-            throw new InstagramException('Invalid Instagram Configuration data', 400);
65
-        }
66
-        $this->client = HelperFactory::client(Constants::API_HOST);
67
-    }
68
-	
69
-    /*
56
+	public function __construct($config)
57
+	{
58
+		if (is_array($config)) {
59
+			$this->setClientId($config['ClientId']);
60
+			$this->setClientSecret($config['ClientSecret']);
61
+			$this->setCallbackUrl($config['Callback']);
62
+			$this->state = isset($config['State']) ? $config['State'] : substr(md5(rand()), 0, 7);
63
+		} else {
64
+			throw new InstagramException('Invalid Instagram Configuration data', 400);
65
+		}
66
+		$this->client = HelperFactory::client(Constants::API_HOST);
67
+	}
68
+	
69
+	/*
70 70
      * Make URLs for user browser navigation
71 71
      * @param string $path
72 72
      * @param array  $parameters
73 73
      * @return string
74 74
      */
75
-    public function getLoginUrl(array $parameters)
76
-    {
77
-        if (!isset($parameters['scope'])) {
78
-            throw new InstagramException("Missing or Invalid Scope permission used", 400);
79
-        }
80
-        if (count(array_diff($parameters['scope'], $this->defaultScopes)) === 0) {
81
-            $this->scopes = $parameters['scope'];
82
-        } else {
83
-            throw new InstagramException("Missing or Invalid Scope permission used", 400);
84
-        }
85
-        $query = 'client_id='.$this->getClientId().'&redirect_uri='.urlencode($this->getCallbackUrl()).'&response_type=code&state='.$this->state;
86
-        $query .= isset($this->scopes) ? '&scope='.urlencode(str_replace(",", " ", implode(",", $parameters['scope']))) : '';
87
-        return sprintf('%s%s?%s', Constants::API_HOST, Constants::API_AUTH, $query);
88
-    }
89
-	
90
-    /*
75
+	public function getLoginUrl(array $parameters)
76
+	{
77
+		if (!isset($parameters['scope'])) {
78
+			throw new InstagramException("Missing or Invalid Scope permission used", 400);
79
+		}
80
+		if (count(array_diff($parameters['scope'], $this->defaultScopes)) === 0) {
81
+			$this->scopes = $parameters['scope'];
82
+		} else {
83
+			throw new InstagramException("Missing or Invalid Scope permission used", 400);
84
+		}
85
+		$query = 'client_id='.$this->getClientId().'&redirect_uri='.urlencode($this->getCallbackUrl()).'&response_type=code&state='.$this->state;
86
+		$query .= isset($this->scopes) ? '&scope='.urlencode(str_replace(",", " ", implode(",", $parameters['scope']))) : '';
87
+		return sprintf('%s%s?%s', Constants::API_HOST, Constants::API_AUTH, $query);
88
+	}
89
+	
90
+	/*
91 91
      * Get the Oauth Access Token of a user from callback code
92 92
      * @param string $code - Oauth2 Code returned with callback url after successfull login
93 93
      * @return InstagramOAuth
94 94
      */
95
-    public function oauth($code)
96
-    {
97
-        $options = array(
98
-            "grant_type" => "authorization_code",
99
-            "client_id" => $this->getClientId(),
100
-            "client_secret" => $this->getClientSecret(),
101
-            "redirect_uri" => $this->getCallbackUrl(),
102
-            "code" => $code,
103
-            "state" => $this->state
104
-        );
95
+	public function oauth($code)
96
+	{
97
+		$options = array(
98
+			"grant_type" => "authorization_code",
99
+			"client_id" => $this->getClientId(),
100
+			"client_secret" => $this->getClientSecret(),
101
+			"redirect_uri" => $this->getCallbackUrl(),
102
+			"code" => $code,
103
+			"state" => $this->state
104
+		);
105 105
 		$response = HelperFactory::request($this->client, Constants::API_TOKEN, $options, 'POST');
106 106
 		$this->oauthResponse = new InstagramOAuth(
107 107
 			json_decode($response->getBody()->getContents())
108 108
 		);
109
-        return $this->oauthResponse;
110
-    }
109
+		return $this->oauthResponse;
110
+	}
111 111
    
112
-    /*
112
+	/*
113 113
      * Set Client Id
114 114
      * @param string $clientId
115 115
      * @return void
116 116
      */
117
-    public function setClientId($clientId)
118
-    {
119
-        $this->clientId = $clientId;
120
-    }
117
+	public function setClientId($clientId)
118
+	{
119
+		$this->clientId = $clientId;
120
+	}
121 121
 	
122
-    /*
122
+	/*
123 123
      * Get Client Id
124 124
      * @return string
125 125
      */
126
-    public function getClientId()
127
-    {
128
-        return $this->clientId;
129
-    }
126
+	public function getClientId()
127
+	{
128
+		return $this->clientId;
129
+	}
130 130
 	
131
-    /*
131
+	/*
132 132
      * Set Client Secret
133 133
      * @param string $secret
134 134
      * @return void
135 135
      */
136
-    public function setClientSecret($secret)
137
-    {
138
-        $this->clientSecret = $secret;
139
-    }
136
+	public function setClientSecret($secret)
137
+	{
138
+		$this->clientSecret = $secret;
139
+	}
140 140
 	
141
-    /*
141
+	/*
142 142
      * Getter: Client Id
143 143
      * @return string
144 144
      */
145
-    public function getClientSecret()
146
-    {
147
-        return $this->clientSecret;
148
-    }
145
+	public function getClientSecret()
146
+	{
147
+		return $this->clientSecret;
148
+	}
149 149
 	
150
-    /*
150
+	/*
151 151
      * Setter: Callback Url
152 152
      * @param string $url
153 153
      * @return void
154 154
      */
155
-    public function setCallbackUrl($url)
156
-    {
157
-        $this->callbackUrl = $url;
158
-    }
155
+	public function setCallbackUrl($url)
156
+	{
157
+		$this->callbackUrl = $url;
158
+	}
159 159
 	
160
-    /*
160
+	/*
161 161
      * Getter: Callback Url
162 162
      * @return string
163 163
      */
164
-    public function getCallbackUrl()
165
-    {
166
-        return $this->callbackUrl;
167
-    }
164
+	public function getCallbackUrl()
165
+	{
166
+		return $this->callbackUrl;
167
+	}
168 168
 	
169
-    /*
169
+	/*
170 170
      * Get InstagramOAuth
171 171
      * @return InstagramOAuth
172 172
      */
173
-    public function getOAuth()
174
-    {
175
-        if ($this->oauthResponse instanceof InstagramOAuth) {
176
-            return $this->oauthResponse;
177
-        } else {
178
-            $this->oauthResponse = new InstagramOAuth(json_decode(json_encode(["access_token" => null])));
179
-            return $this->oauthResponse;
180
-        }
181
-    }
182
-    /*
173
+	public function getOAuth()
174
+	{
175
+		if ($this->oauthResponse instanceof InstagramOAuth) {
176
+			return $this->oauthResponse;
177
+		} else {
178
+			$this->oauthResponse = new InstagramOAuth(json_decode(json_encode(["access_token" => null])));
179
+			return $this->oauthResponse;
180
+		}
181
+	}
182
+	/*
183 183
      * @return Client
184 184
      */
185
-    public function getHttpClient()
186
-    {
187
-        return $this->client;
188
-    }
185
+	public function getHttpClient()
186
+	{
187
+		return $this->client;
188
+	}
189 189
 	
190
-    /*
190
+	/*
191 191
      * Setter: User Access Token
192 192
      * @param string $token
193 193
      * @return void
194 194
      */
195
-    public function setAccessToken($token)
196
-    {
197
-        if (!$this->oauthResponse instanceof InstagramOAuth) {
198
-            $this->oauthResponse = new InstagramOAuth(json_decode(json_encode(["access_token" => $token])));
199
-        }
200
-    }
195
+	public function setAccessToken($token)
196
+	{
197
+		if (!$this->oauthResponse instanceof InstagramOAuth) {
198
+			$this->oauthResponse = new InstagramOAuth(json_decode(json_encode(["access_token" => $token])));
199
+		}
200
+	}
201 201
 
202
-    /*
202
+	/*
203 203
      * Get a string containing the version of the library.
204 204
      * @return string
205 205
      */
206
-    public function getLibraryVersion()
207
-    {
208
-        return Constants::VERSION;
209
-    }
206
+	public function getLibraryVersion()
207
+	{
208
+		return Constants::VERSION;
209
+	}
210 210
 	
211
-    /*
211
+	/*
212 212
      * Get state value
213 213
      * @return string|mixed
214 214
      */
215
-    public function getState()
216
-    {
217
-        return $this->state;
218
-    }
215
+	public function getState()
216
+	{
217
+		return $this->state;
218
+	}
219 219
 }
Please login to merge, or discard this patch.