Completed
Push — master ( 251a35...5d6710 )
by Haridarshan
02:16
created
src/InstagramOAuth.php 1 patch
Indentation   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -5,60 +5,60 @@
 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 \stdClass $oauth
16 16
      * @throws InstagramOAuthException
17 17
      */
18
-    public function __construct(\stdClass $oauth)
19
-    {
20
-        if (!empty($oauth)) {
21
-            $this->accessToken = $oauth->access_token;
22
-            $this->user = isset($oauth->user) ? $oauth->user : null;
23
-        } else {
24
-            throw new InstagramOAuthException("Bad Request 400 empty Response", 400);
25
-        }
26
-    }
18
+	public function __construct(\stdClass $oauth)
19
+	{
20
+		if (!empty($oauth)) {
21
+			$this->accessToken = $oauth->access_token;
22
+			$this->user = isset($oauth->user) ? $oauth->user : null;
23
+		} else {
24
+			throw new InstagramOAuthException("Bad Request 400 empty Response", 400);
25
+		}
26
+	}
27 27
     
28
-    /*
28
+	/*
29 29
      * Get Access Token
30 30
      * @return string
31 31
      */
32
-    public function getAccessToken()
33
-    {
34
-        return $this->accessToken;
35
-    }
32
+	public function getAccessToken()
33
+	{
34
+		return $this->accessToken;
35
+	}
36 36
     
37
-    /*
37
+	/*
38 38
      * Set Access Token
39 39
      * @param string $token
40 40
      * @return void
41 41
      */
42
-    public function setAccessToken($token)
43
-    {
44
-        $this->accessToken = $token;
45
-    }
42
+	public function setAccessToken($token)
43
+	{
44
+		$this->accessToken = $token;
45
+	}
46 46
     
47
-    /*
47
+	/*
48 48
      * If AccessToken is set return true else false
49 49
      * @return bool
50 50
      */
51
-    public function isAccessTokenSet()
52
-    {
53
-        return isset($this->accessToken) ? true : false;
54
-    }
51
+	public function isAccessTokenSet()
52
+	{
53
+		return isset($this->accessToken) ? true : false;
54
+	}
55 55
     
56
-    /*
56
+	/*
57 57
      * Get User Info
58 58
      * @return object
59 59
      */
60
-    public function getUserInfo()
61
-    {
62
-        return $this->user;
63
-    }
60
+	public function getUserInfo()
61
+	{
62
+		return $this->user;
63
+	}
64 64
 }
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
@@ -6,14 +6,14 @@  discard block
 block discarded – undo
6 6
 
7 7
 class InstagramResponse
8 8
 {	
9
-    /** @var int $status_code */
10
-    private $statusCode;
9
+	/** @var int $status_code */
10
+	private $statusCode;
11 11
 	
12
-    /** @var string $protocol */
13
-    private $protocol = '1.1';
12
+	/** @var string $protocol */
13
+	private $protocol = '1.1';
14 14
 	
15
-    /** @var array $headers */
16
-    private $headers = [];
15
+	/** @var array $headers */
16
+	private $headers = [];
17 17
 	
18 18
 	/** @var bool */
19 19
 	private $isPagination = false;
@@ -30,35 +30,35 @@  discard block
 block discarded – undo
30 30
 	/** @var object */
31 31
 	private $data;
32 32
 	
33
-    /** @var object $body */
34
-    private $body;
33
+	/** @var object $body */
34
+	private $body;
35 35
 	
36 36
 	/*
37 37
 	 * @param Response $response
38 38
 	 * @throws InstagramResponseException
39 39
 	 */
40
-    public function __construct(Response $response)
41
-    {
42
-        if ($response instanceof Response) {
43
-            $this->setParams($response);
44
-        } else {
45
-            throw new InstagramResponseException('Bad Request: Response is not valid instance of GuzzleHttp\Psr7\Response', 404);
46
-        }
47
-    }
40
+	public function __construct(Response $response)
41
+	{
42
+		if ($response instanceof Response) {
43
+			$this->setParams($response);
44
+		} else {
45
+			throw new InstagramResponseException('Bad Request: Response is not valid instance of GuzzleHttp\Psr7\Response', 404);
46
+		}
47
+	}
48 48
     
49 49
 	/* 
50 50
 	 * Set Values to the class members
51 51
 	 * @param Response $response
52 52
 	 * @return void
53 53
 	 */
54
-    private function setParams(Response $response)
55
-    {
56
-        $this->protocol = $response->getProtocolVersion();
57
-        $this->statusCode = (int) $response->getStatusCode();
58
-        $this->headers = $response->getHeaders();
59
-        $this->body = json_decode($response->getBody()->getContents());
54
+	private function setParams(Response $response)
55
+	{
56
+		$this->protocol = $response->getProtocolVersion();
57
+		$this->statusCode = (int) $response->getStatusCode();
58
+		$this->headers = $response->getHeaders();
59
+		$this->body = json_decode($response->getBody()->getContents());
60 60
 		$this->extractBodyParts();
61
-    }
61
+	}
62 62
 	
63 63
 	private function extractBodyParts()
64 64
 	{
@@ -79,38 +79,38 @@  discard block
 block discarded – undo
79 79
 	 * Get response
80 80
 	 * @return object|string 
81 81
 	 */
82
-    public function getBody()
83
-    {
84
-        return $this->body;
85
-    }
82
+	public function getBody()
83
+	{
84
+		return $this->body;
85
+	}
86 86
     
87 87
 	/*
88 88
 	 * Get Status Code
89 89
 	 * @return int
90 90
 	 */
91
-    public function getStatusCode()
92
-    {
93
-        return $this->statusCode;
94
-    }
91
+	public function getStatusCode()
92
+	{
93
+		return $this->statusCode;
94
+	}
95 95
     
96 96
 	/*
97 97
 	 * Get specific header
98 98
 	 * @param string $header
99 99
 	 * @retrun string 
100 100
 	 */
101
-    public function getHeader($header)
102
-    {
103
-        return isset($this->headers[$header]) ? $this->headers[$header] : [];
104
-    }
101
+	public function getHeader($header)
102
+	{
103
+		return isset($this->headers[$header]) ? $this->headers[$header] : [];
104
+	}
105 105
 	
106 106
 	/*
107 107
 	 * Get all headers
108 108
 	 * @retrun array 
109 109
 	 */
110
-    public function getHeaders()
111
-    {
112
-        return $this->headers;
113
-    }
110
+	public function getHeaders()
111
+	{
112
+		return $this->headers;
113
+	}
114 114
 	
115 115
 	/*
116 116
 	 * 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
@@ -11,33 +11,33 @@  discard block
 block discarded – undo
11 11
 
12 12
 class HelperFactory
13 13
 {
14
-    /** @var Response $response */
15
-    protected static $response;
14
+	/** @var Response $response */
15
+	protected static $response;
16 16
     
17
-    /** @var Stream $stream */
18
-    protected static $stream;
17
+	/** @var Stream $stream */
18
+	protected static $stream;
19 19
     
20
-    /** @var object $content */
21
-    protected static $content;
20
+	/** @var object $content */
21
+	protected static $content;
22 22
     
23
-    private function __construct()
24
-    {
25
-        // a factory constructor should never be invoked
26
-    }
23
+	private function __construct()
24
+	{
25
+		// a factory constructor should never be invoked
26
+	}
27 27
     
28
-    /*
28
+	/*
29 29
      * Factory Client method to create \GuzzleHttp\Client object
30 30
      * @param string $uri
31 31
      * @return Client
32 32
      */
33
-    public static function client($uri)
34
-    {
35
-        return new Client([
36
-            'base_uri' => $uri
37
-        ]);
38
-    }
33
+	public static function client($uri)
34
+	{
35
+		return new Client([
36
+			'base_uri' => $uri
37
+		]);
38
+	}
39 39
     
40
-    /*
40
+	/*
41 41
      * @param Client $client
42 42
      * @param string $endpoint
43 43
      * @param array|string $options
@@ -46,79 +46,79 @@  discard block
 block discarded – undo
46 46
      * @throws InstagramOAuthException
47 47
      * @throws InstagramException
48 48
      */
49
-    public static function request(Client $client, $endpoint, $options, $method = 'GET')
50
-    {
51
-        try {
52
-            return $client->request($method, $endpoint, [
53
-                'headers' => ['Accept' => 'application/json'],
54
-                'body' => static::createBody($options, $method)
55
-            ]);
56
-        } catch (ClientException $e) {
57
-            static::throwException(static::extractOriginalExceptionMessage($e), $e);
58
-        }
59
-    }
49
+	public static function request(Client $client, $endpoint, $options, $method = 'GET')
50
+	{
51
+		try {
52
+			return $client->request($method, $endpoint, [
53
+				'headers' => ['Accept' => 'application/json'],
54
+				'body' => static::createBody($options, $method)
55
+			]);
56
+		} catch (ClientException $e) {
57
+			static::throwException(static::extractOriginalExceptionMessage($e), $e);
58
+		}
59
+	}
60 60
     
61
-    /*
61
+	/*
62 62
      * Create body for Guzzle client request
63 63
      * @param array|null|string $options
64 64
      * @param string $method GET|POST
65 65
      * @return string|mixed
66 66
      */
67
-    protected static function createBody($options, $method)
68
-    {
69
-        return ('GET' !== $method) ? is_array($options) ? http_build_query($options) : ltrim($options, '&') : null;
70
-    }
67
+	protected static function createBody($options, $method)
68
+	{
69
+		return ('GET' !== $method) ? is_array($options) ? http_build_query($options) : ltrim($options, '&') : null;
70
+	}
71 71
     
72
-    /*
72
+	/*
73 73
      * Method to extract all exceptions for Guzzle ClientException
74 74
      * @param ClientException $e
75 75
      * @return
76 76
      */
77
-    protected static function extractOriginalExceptionMessage(ClientException $e)
78
-    {
79
-        self::$response = $e->getResponse();
80
-        self::$stream = self::$response->getBody();
81
-        self::$content = self::$stream->getContents();
82
-        if (empty(self::$content)) {
83
-            throw new InstagramServerException(
84
-                $e->getMessage(),
85
-                $e->getCode(),
86
-                $e
87
-            );
88
-        } else {
89
-            return json_decode(self::$content);
90
-        }
91
-    }
77
+	protected static function extractOriginalExceptionMessage(ClientException $e)
78
+	{
79
+		self::$response = $e->getResponse();
80
+		self::$stream = self::$response->getBody();
81
+		self::$content = self::$stream->getContents();
82
+		if (empty(self::$content)) {
83
+			throw new InstagramServerException(
84
+				$e->getMessage(),
85
+				$e->getCode(),
86
+				$e
87
+			);
88
+		} else {
89
+			return json_decode(self::$content);
90
+		}
91
+	}
92 92
     
93
-    /*
93
+	/*
94 94
      * @param \stdClass $object
95 95
 	 * @param ClientException $e
96 96
      * @return void
97 97
      */
98
-    protected static function throwException(\stdClass $object, ClientException $e)
99
-    {
100
-        $exception = array();
101
-        if (isset($object->meta)) {
102
-            $exception['error_type'] = $object->meta->error_type;
103
-            $exception['error_message'] = $object->meta->error_message;
104
-            $exception['error_code'] = $object->meta->code;
105
-        } else {
106
-            $exception['error_type'] = $object->error_type;
107
-            $exception['error_message'] = $object->error_message;
108
-            $exception['error_code'] = $object->code;
109
-        }
110
-        if (stripos($exception['error_type'], "oauth") !== false) {
111
-            throw new InstagramOAuthException(
112
-                json_encode(array("Type" => $exception['error_type'], "Message" => $exception['error_message'])),
113
-                $exception['error_code'],
114
-                $e
115
-            );
116
-        } else {
117
-            throw new InstagramException(
118
-                json_encode(array("Type" => $exception['error_type'], "Message" => $exception['error_message'])),
119
-                $exception['error_code'],
120
-                $e
121
-            );
122
-        }
123
-    }
98
+	protected static function throwException(\stdClass $object, ClientException $e)
99
+	{
100
+		$exception = array();
101
+		if (isset($object->meta)) {
102
+			$exception['error_type'] = $object->meta->error_type;
103
+			$exception['error_message'] = $object->meta->error_message;
104
+			$exception['error_code'] = $object->meta->code;
105
+		} else {
106
+			$exception['error_type'] = $object->error_type;
107
+			$exception['error_message'] = $object->error_message;
108
+			$exception['error_code'] = $object->code;
109
+		}
110
+		if (stripos($exception['error_type'], "oauth") !== false) {
111
+			throw new InstagramOAuthException(
112
+				json_encode(array("Type" => $exception['error_type'], "Message" => $exception['error_message'])),
113
+				$exception['error_code'],
114
+				$e
115
+			);
116
+		} else {
117
+			throw new InstagramException(
118
+				json_encode(array("Type" => $exception['error_type'], "Message" => $exception['error_message'])),
119
+				$exception['error_code'],
120
+				$e
121
+			);
122
+		}
123
+	}
124 124
 }
Please login to merge, or discard this patch.