Completed
Push — master ( c6a286...b1bd72 )
by Sergey
07:08
created
src/Api/Endpoints/Organizations.php 1 patch
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -6,21 +6,21 @@
 block discarded – undo
6 6
 
7 7
 class Organizations extends Endpoint
8 8
 {
9
-    use CrudEndpoint;
9
+	use CrudEndpoint;
10 10
 
11
-    /**
12
-     * @var string
13
-     */
14
-    protected $endpoint = 'organizations';
11
+	/**
12
+	 * @var string
13
+	 */
14
+	protected $endpoint = 'organizations';
15 15
 
16
-    /**
17
-     * @param string $id
18
-     * @return array
19
-     */
20
-    public function getById($id)
21
-    {
22
-        $this->headers['organizationId'] = $id;
16
+	/**
17
+	 * @param string $id
18
+	 * @return array
19
+	 */
20
+	public function getById($id)
21
+	{
22
+		$this->headers['organizationId'] = $id;
23 23
 
24
-        return parent::getById($id);
25
-    }
24
+		return parent::getById($id);
25
+	}
26 26
 }
27 27
\ No newline at end of file
Please login to merge, or discard this patch.
src/Api/Endpoints/Traits/CrudEndpoint.php 1 patch
Indentation   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -5,49 +5,49 @@
 block discarded – undo
5 5
 trait CrudEndpoint
6 6
 {
7 7
 
8
-    /**
9
-     * @param array $attributes
10
-     * @return array
11
-     */
12
-    public function create(array $attributes)
13
-    {
14
-        return $this
15
-            ->getHttp()
16
-            ->post(
17
-                $this->makeRequestUrl(),
18
-                $attributes,
19
-                $this->getHeaders()
20
-            );
21
-    }
8
+	/**
9
+	 * @param array $attributes
10
+	 * @return array
11
+	 */
12
+	public function create(array $attributes)
13
+	{
14
+		return $this
15
+			->getHttp()
16
+			->post(
17
+				$this->makeRequestUrl(),
18
+				$attributes,
19
+				$this->getHeaders()
20
+			);
21
+	}
22 22
 
23
-    /**
24
-     * @param string $itemId
25
-     * @param array $attributes
26
-     * @return mixed
27
-     */
28
-    public function update($itemId, array $attributes)
29
-    {
30
-        return $this
31
-            ->getHttp()
32
-            ->put(
33
-                $this->makeRequestUrl($itemId),
34
-                $attributes,
35
-                $this->getHeaders()
36
-            );
37
-    }
23
+	/**
24
+	 * @param string $itemId
25
+	 * @param array $attributes
26
+	 * @return mixed
27
+	 */
28
+	public function update($itemId, array $attributes)
29
+	{
30
+		return $this
31
+			->getHttp()
32
+			->put(
33
+				$this->makeRequestUrl($itemId),
34
+				$attributes,
35
+				$this->getHeaders()
36
+			);
37
+	}
38 38
 
39
-    /**
40
-     * @param string $itemId
41
-     * @return mixed
42
-     */
43
-    public function delete($itemId)
44
-    {
45
-        return $this
46
-            ->getHttp()
47
-            ->delete(
48
-                $this->makeRequestUrl($itemId),
49
-                [],
50
-                $this->getHeaders()
51
-            );
52
-    }
39
+	/**
40
+	 * @param string $itemId
41
+	 * @return mixed
42
+	 */
43
+	public function delete($itemId)
44
+	{
45
+		return $this
46
+			->getHttp()
47
+			->delete(
48
+				$this->makeRequestUrl($itemId),
49
+				[],
50
+				$this->getHeaders()
51
+			);
52
+	}
53 53
 }
Please login to merge, or discard this patch.
src/Api/Endpoints/EndpointsContainer.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -45,7 +45,7 @@
 block discarded – undo
45 45
     }
46 46
 
47 47
     /**
48
-     * @param $endpoint
48
+     * @param string $endpoint
49 49
      * @throws WrongEndpoint
50 50
      */
51 51
     protected function addProvider($endpoint)
Please login to merge, or discard this patch.
Indentation   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -8,63 +8,63 @@
 block discarded – undo
8 8
 
9 9
 class EndpointsContainer
10 10
 {
11
-    const ENDPOINTS_NAMESPACE = 'seregazhuk\\Favro\\Api\\Endpoints\\';
11
+	const ENDPOINTS_NAMESPACE = 'seregazhuk\\Favro\\Api\\Endpoints\\';
12 12
 
13
-    /*
13
+	/*
14 14
     * @var HttpInterface
15 15
     */
16
-    protected $http;
16
+	protected $http;
17 17
 
18
-    /*
18
+	/*
19 19
      * @var array
20 20
      */
21
-    protected $endpoints = [];
21
+	protected $endpoints = [];
22 22
 
23
-    /**
24
-     * @param HttpClient $http
25
-     */
26
-    public function __construct(HttpClient $http)
27
-    {
28
-        $this->http = $http;
29
-    }
23
+	/**
24
+	 * @param HttpClient $http
25
+	 */
26
+	public function __construct(HttpClient $http)
27
+	{
28
+		$this->http = $http;
29
+	}
30 30
 
31
-    /**
32
-     * @param string $endpoint
33
-     * @return Endpoint
34
-     */
35
-    public function resolve($endpoint)
36
-    {
37
-        $endpoint = strtolower($endpoint);
31
+	/**
32
+	 * @param string $endpoint
33
+	 * @return Endpoint
34
+	 */
35
+	public function resolve($endpoint)
36
+	{
37
+		$endpoint = strtolower($endpoint);
38 38
 
39
-        // Check if an instance has already been initiated
40
-        if (!isset($this->endpoints[$endpoint])) {
41
-            $this->addProvider($endpoint);
42
-        }
39
+		// Check if an instance has already been initiated
40
+		if (!isset($this->endpoints[$endpoint])) {
41
+			$this->addProvider($endpoint);
42
+		}
43 43
 
44
-        return $this->endpoints[$endpoint];
45
-    }
44
+		return $this->endpoints[$endpoint];
45
+	}
46 46
 
47
-    /**
48
-     * @param $endpoint
49
-     * @throws WrongEndpoint
50
-     */
51
-    protected function addProvider($endpoint)
52
-    {
53
-        $className = self::ENDPOINTS_NAMESPACE . ucfirst($endpoint);
47
+	/**
48
+	 * @param $endpoint
49
+	 * @throws WrongEndpoint
50
+	 */
51
+	protected function addProvider($endpoint)
52
+	{
53
+		$className = self::ENDPOINTS_NAMESPACE . ucfirst($endpoint);
54 54
 
55
-        if (!class_exists($className)) {
56
-            throw new WrongEndpoint("Endpoint $className not found.");
57
-        }
55
+		if (!class_exists($className)) {
56
+			throw new WrongEndpoint("Endpoint $className not found.");
57
+		}
58 58
 
59
-        $this->endpoints[$endpoint] = $this->buildEndpoint($className);
60
-    }
59
+		$this->endpoints[$endpoint] = $this->buildEndpoint($className);
60
+	}
61 61
 
62
-    /**
63
-     * @param string $className
64
-     * @return Endpoint|object
65
-     */
66
-    protected function buildEndpoint($className)
67
-    {
68
-        return (new ReflectionClass($className))->newInstanceArgs([$this->http]);
69
-    }
62
+	/**
63
+	 * @param string $className
64
+	 * @return Endpoint|object
65
+	 */
66
+	protected function buildEndpoint($className)
67
+	{
68
+		return (new ReflectionClass($className))->newInstanceArgs([$this->http]);
69
+	}
70 70
 }
71 71
\ No newline at end of file
Please login to merge, or discard this patch.
src/Favro.php 1 patch
Indentation   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -8,36 +8,36 @@
 block discarded – undo
8 8
 
9 9
 class Favro
10 10
 {
11
-    /**
12
-     * @param string $login
13
-     * @param string $password
14
-     * @return Api
15
-     */
16
-    public static function create($login, $password)
17
-    {
18
-        $endpointsContainer = new EndpointsContainer(
19
-            self::getHttpInterfaceAdapter($login, $password)
20
-        );
21
-        return new Api($endpointsContainer);
22
-    }
11
+	/**
12
+	 * @param string $login
13
+	 * @param string $password
14
+	 * @return Api
15
+	 */
16
+	public static function create($login, $password)
17
+	{
18
+		$endpointsContainer = new EndpointsContainer(
19
+			self::getHttpInterfaceAdapter($login, $password)
20
+		);
21
+		return new Api($endpointsContainer);
22
+	}
23 23
 
24
-    /**
25
-     * @param string $login
26
-     * @param string $password
27
-     * @return GuzzleHttpClient
28
-     */
29
-    protected static function getHttpInterfaceAdapter($login, $password)
30
-    {
31
-        return new GuzzleHttpClient(
32
-            new Client(['auth' => [$login, $password]])
33
-        );
34
-    }
24
+	/**
25
+	 * @param string $login
26
+	 * @param string $password
27
+	 * @return GuzzleHttpClient
28
+	 */
29
+	protected static function getHttpInterfaceAdapter($login, $password)
30
+	{
31
+		return new GuzzleHttpClient(
32
+			new Client(['auth' => [$login, $password]])
33
+		);
34
+	}
35 35
 
36
-    private function __construct()
37
-    {
38
-    }
36
+	private function __construct()
37
+	{
38
+	}
39 39
 
40
-    private function __clone()
41
-    {
42
-    }
40
+	private function __clone()
41
+	{
42
+	}
43 43
 }
44 44
\ No newline at end of file
Please login to merge, or discard this patch.
src/Contracts/HttpClient.php 1 patch
Indentation   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -4,41 +4,41 @@
 block discarded – undo
4 4
 
5 5
 interface HttpInterface
6 6
 {
7
-    /**
8
-     * @param $uri
9
-     * @param array $params
10
-     * @param array $headers
11
-     * @return array
12
-     */
13
-    public function get($uri, $params = [], $headers = []);
7
+	/**
8
+	 * @param $uri
9
+	 * @param array $params
10
+	 * @param array $headers
11
+	 * @return array
12
+	 */
13
+	public function get($uri, $params = [], $headers = []);
14 14
 
15
-    /**
16
-     * @param string $uri
17
-     * @param array $body
18
-     * @param array $headers
19
-     * @return array
20
-     */
21
-    public function post($uri, $body = [], $headers = []);
15
+	/**
16
+	 * @param string $uri
17
+	 * @param array $body
18
+	 * @param array $headers
19
+	 * @return array
20
+	 */
21
+	public function post($uri, $body = [], $headers = []);
22 22
 
23
-    /**
24
-     * @param string $uri
25
-     * @param array $body
26
-     * @param array $headers
27
-     * @return mixed
28
-     */
29
-    public function put($uri, $body = [], $headers = []);
23
+	/**
24
+	 * @param string $uri
25
+	 * @param array $body
26
+	 * @param array $headers
27
+	 * @return mixed
28
+	 */
29
+	public function put($uri, $body = [], $headers = []);
30 30
 
31
-    /**
32
-     * @param string $uri
33
-     * @param array $body
34
-     * @param array $headers
35
-     * @return mixed
36
-     */
37
-    public function delete($uri, $body = [], $headers = []);
31
+	/**
32
+	 * @param string $uri
33
+	 * @param array $body
34
+	 * @param array $headers
35
+	 * @return mixed
36
+	 */
37
+	public function delete($uri, $body = [], $headers = []);
38 38
 
39
-    /**
40
-     * @param string $url
41
-     * @return $this
42
-     */
43
-    public function setBaseUrl($url);
39
+	/**
40
+	 * @param string $url
41
+	 * @return $this
42
+	 */
43
+	public function setBaseUrl($url);
44 44
 }
45 45
\ No newline at end of file
Please login to merge, or discard this patch.
src/GuzzleHttpClient.php 1 patch
Indentation   +110 added lines, -110 removed lines patch added patch discarded remove patch
@@ -8,115 +8,115 @@
 block discarded – undo
8 8
 
9 9
 class GuzzleHttpAdapter implements HttpInterface
10 10
 {
11
-    /**
12
-     * @var ClientInterface
13
-     */
14
-    protected $client;
15
-
16
-    /**
17
-     * @param ClientInterface $client
18
-     */
19
-    public function __construct(ClientInterface $client)
20
-    {
21
-        $this->client = $client;
22
-    }
23
-
24
-    /**
25
-     * @param string $uri
26
-     * @param array $params
27
-     * @param array $headers
28
-     * @return string
29
-     */
30
-    public function get($uri, $params = [], $headers = [])
31
-    {
32
-        if (!empty($params)) {
33
-            $uri .= '?' . http_build_query($params);
34
-        }
35
-
36
-        $response = $this
37
-            ->client
38
-            ->get($uri, ['headers' => $headers]);
39
-
40
-        return $this->parseResponse($response);
41
-    }
42
-
43
-    /**
44
-     * @param string $uri
45
-     * @param array $body
46
-     * @param array $headers
47
-     * @return string
48
-     */
49
-    public function post($uri, $body = [], $headers = [])
50
-    {
51
-        $response = $this
52
-            ->client
53
-            ->post(
54
-                $uri, [
55
-                    'headers'     => $headers,
56
-                    'form_params' => $body,
57
-                ]
58
-            );
59
-
60
-        return $this->parseResponse($response);
61
-    }
62
-
63
-    /**
64
-     * @param string $uri
65
-     * @param array $body
66
-     * @param array $headers
67
-     * @return mixed
68
-     */
69
-    public function put($uri, $body = [], $headers = [])
70
-    {
71
-        $response = $this
72
-            ->client
73
-            ->put(
74
-                $uri, [
75
-                    'headers'     => $headers,
76
-                    'form_params' => $body,
77
-                ]
78
-            );
79
-
80
-        return $this->parseResponse($response);
81
-    }
82
-
83
-    /**
84
-     * @param string $uri
85
-     * @param array $body
86
-     * @param array $headers
87
-     * @return mixed
88
-     */
89
-    public function delete($uri, $body = [], $headers = [])
90
-    {
91
-        $response = $this
92
-            ->client
93
-            ->delete($uri, [
94
-                'headers'     => $headers,
95
-                'form_params' => $body,
96
-            ]);
97
-
98
-        return $this->parseResponse($response);
99
-    }
100
-
101
-    /**
102
-     * @param string $url
103
-     * @return $this
104
-     */
105
-    public function setBaseUrl($url)
106
-    {
107
-        $this->client->setBaseUrl($url);
108
-        return $this;
109
-    }
110
-
111
-    /**
112
-     * @param ResponseInterface $response
113
-     * @return array|null
114
-     */
115
-    protected function parseResponse(ResponseInterface $response)
116
-    {
117
-        $responseContents = $response->getBody()->getContents();
118
-
119
-        return json_decode($responseContents, true);
120
-    }
11
+	/**
12
+	 * @var ClientInterface
13
+	 */
14
+	protected $client;
15
+
16
+	/**
17
+	 * @param ClientInterface $client
18
+	 */
19
+	public function __construct(ClientInterface $client)
20
+	{
21
+		$this->client = $client;
22
+	}
23
+
24
+	/**
25
+	 * @param string $uri
26
+	 * @param array $params
27
+	 * @param array $headers
28
+	 * @return string
29
+	 */
30
+	public function get($uri, $params = [], $headers = [])
31
+	{
32
+		if (!empty($params)) {
33
+			$uri .= '?' . http_build_query($params);
34
+		}
35
+
36
+		$response = $this
37
+			->client
38
+			->get($uri, ['headers' => $headers]);
39
+
40
+		return $this->parseResponse($response);
41
+	}
42
+
43
+	/**
44
+	 * @param string $uri
45
+	 * @param array $body
46
+	 * @param array $headers
47
+	 * @return string
48
+	 */
49
+	public function post($uri, $body = [], $headers = [])
50
+	{
51
+		$response = $this
52
+			->client
53
+			->post(
54
+				$uri, [
55
+					'headers'     => $headers,
56
+					'form_params' => $body,
57
+				]
58
+			);
59
+
60
+		return $this->parseResponse($response);
61
+	}
62
+
63
+	/**
64
+	 * @param string $uri
65
+	 * @param array $body
66
+	 * @param array $headers
67
+	 * @return mixed
68
+	 */
69
+	public function put($uri, $body = [], $headers = [])
70
+	{
71
+		$response = $this
72
+			->client
73
+			->put(
74
+				$uri, [
75
+					'headers'     => $headers,
76
+					'form_params' => $body,
77
+				]
78
+			);
79
+
80
+		return $this->parseResponse($response);
81
+	}
82
+
83
+	/**
84
+	 * @param string $uri
85
+	 * @param array $body
86
+	 * @param array $headers
87
+	 * @return mixed
88
+	 */
89
+	public function delete($uri, $body = [], $headers = [])
90
+	{
91
+		$response = $this
92
+			->client
93
+			->delete($uri, [
94
+				'headers'     => $headers,
95
+				'form_params' => $body,
96
+			]);
97
+
98
+		return $this->parseResponse($response);
99
+	}
100
+
101
+	/**
102
+	 * @param string $url
103
+	 * @return $this
104
+	 */
105
+	public function setBaseUrl($url)
106
+	{
107
+		$this->client->setBaseUrl($url);
108
+		return $this;
109
+	}
110
+
111
+	/**
112
+	 * @param ResponseInterface $response
113
+	 * @return array|null
114
+	 */
115
+	protected function parseResponse(ResponseInterface $response)
116
+	{
117
+		$responseContents = $response->getBody()->getContents();
118
+
119
+		return json_decode($responseContents, true);
120
+	}
121 121
 
122 122
 }
123 123
\ No newline at end of file
Please login to merge, or discard this patch.
src/Api/Api.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -64,7 +64,7 @@
 block discarded – undo
64 64
      */
65 65
     public function setOrganization($organizationName)
66 66
     {
67
-        if($organization = $this->getOrganizationByName($organizationName)) {
67
+        if ($organization = $this->getOrganizationByName($organizationName)) {
68 68
             $this->setOrganizationId($organization['organizationId']);
69 69
         }
70 70
 
Please login to merge, or discard this patch.
Indentation   +82 added lines, -82 removed lines patch added patch discarded remove patch
@@ -29,86 +29,86 @@
 block discarded – undo
29 29
  */
30 30
 class Api
31 31
 {
32
-    /**
33
-     * @var EndpointsContainer
34
-     */
35
-    protected $endpointsContainer;
36
-
37
-    /**
38
-     * @var string
39
-     */
40
-    protected $organizationId;
41
-
42
-    public function __construct(EndpointsContainer $endpointsContainer)
43
-    {
44
-        $this->endpointsContainer = $endpointsContainer;
45
-    }
46
-
47
-    /**
48
-     * Magic method to access different endpoints.
49
-     *
50
-     * @param string $endpoint
51
-     *
52
-     * @return Endpoint
53
-     */
54
-    public function __get($endpoint)
55
-    {
56
-        $endpoint = $this->endpointsContainer->resolve($endpoint);
57
-
58
-        if (method_exists($endpoint, 'setOrganizationId')) {
59
-            $endpoint->setOrganizationId($this->organizationId);
60
-        }
61
-
62
-        return $endpoint;
63
-    }
64
-
65
-    /**
66
-     * @param $organizationName
67
-     * @return $this
68
-     */
69
-    public function setOrganization($organizationName)
70
-    {
71
-        if($organization = $this->getOrganizationByName($organizationName)) {
72
-            $this->setOrganizationId($organization['organizationId']);
73
-        }
74
-
75
-        return $this;
76
-    }
77
-
78
-    /**
79
-     * @param int $organizationId
80
-     * @return $this
81
-     */
82
-    public function setOrganizationId($organizationId)
83
-    {
84
-        $this->organizationId = $organizationId;
85
-
86
-        return $this;
87
-    }
88
-
89
-
90
-    /**
91
-     * @return string
92
-     */
93
-    public function getOrganizationId()
94
-    {
95
-        return $this->organizationId;
96
-    }
97
-
98
-    /**
99
-     * @param $organization
100
-     * @return bool|array
101
-     */
102
-    protected function getOrganizationByName($organization)
103
-    {
104
-        $organizations = $this->organizations->getAll();
105
-
106
-        foreach ($organizations['entities'] as $entity) {
107
-            if ($entity['name'] == $organization) {
108
-                return $entity;
109
-            }
110
-        }
111
-
112
-        return false;
113
-    }
32
+	/**
33
+	 * @var EndpointsContainer
34
+	 */
35
+	protected $endpointsContainer;
36
+
37
+	/**
38
+	 * @var string
39
+	 */
40
+	protected $organizationId;
41
+
42
+	public function __construct(EndpointsContainer $endpointsContainer)
43
+	{
44
+		$this->endpointsContainer = $endpointsContainer;
45
+	}
46
+
47
+	/**
48
+	 * Magic method to access different endpoints.
49
+	 *
50
+	 * @param string $endpoint
51
+	 *
52
+	 * @return Endpoint
53
+	 */
54
+	public function __get($endpoint)
55
+	{
56
+		$endpoint = $this->endpointsContainer->resolve($endpoint);
57
+
58
+		if (method_exists($endpoint, 'setOrganizationId')) {
59
+			$endpoint->setOrganizationId($this->organizationId);
60
+		}
61
+
62
+		return $endpoint;
63
+	}
64
+
65
+	/**
66
+	 * @param $organizationName
67
+	 * @return $this
68
+	 */
69
+	public function setOrganization($organizationName)
70
+	{
71
+		if($organization = $this->getOrganizationByName($organizationName)) {
72
+			$this->setOrganizationId($organization['organizationId']);
73
+		}
74
+
75
+		return $this;
76
+	}
77
+
78
+	/**
79
+	 * @param int $organizationId
80
+	 * @return $this
81
+	 */
82
+	public function setOrganizationId($organizationId)
83
+	{
84
+		$this->organizationId = $organizationId;
85
+
86
+		return $this;
87
+	}
88
+
89
+
90
+	/**
91
+	 * @return string
92
+	 */
93
+	public function getOrganizationId()
94
+	{
95
+		return $this->organizationId;
96
+	}
97
+
98
+	/**
99
+	 * @param $organization
100
+	 * @return bool|array
101
+	 */
102
+	protected function getOrganizationByName($organization)
103
+	{
104
+		$organizations = $this->organizations->getAll();
105
+
106
+		foreach ($organizations['entities'] as $entity) {
107
+			if ($entity['name'] == $organization) {
108
+				return $entity;
109
+			}
110
+		}
111
+
112
+		return false;
113
+	}
114 114
 }
115 115
\ No newline at end of file
Please login to merge, or discard this patch.
src/Api/Endpoints/Endpoint.php 1 patch
Indentation   +108 added lines, -108 removed lines patch added patch discarded remove patch
@@ -6,112 +6,112 @@
 block discarded – undo
6 6
 
7 7
 class Endpoint
8 8
 {
9
-    /**
10
-     * @var array
11
-     */
12
-    protected $allowedMethods = [
13
-        'getById',
14
-        'getAll',
15
-        'create',
16
-        'update',
17
-        'delete',
18
-    ];
19
-
20
-    /**
21
-     * @var string
22
-     */
23
-    protected $endpoint;
24
-
25
-    /**
26
-     * @var array
27
-     */
28
-    protected $headers = [];
29
-
30
-    /**
31
-     * @var HttpClient
32
-     */
33
-    protected $http;
34
-
35
-    /**
36
-     * @var string
37
-     */
38
-    protected $organizationId;
39
-
40
-    /**
41
-     * @param HttpClient $http
42
-     */
43
-    public function __construct(HttpClient $http)
44
-    {
45
-        $this->http = $http;
46
-    }
47
-
48
-    /**
49
-     * @param string $verb
50
-     * @return string
51
-     */
52
-    public function makeRequestUrl($verb = '')
53
-    {
54
-        return "https://favro.com/api/v1/{$this->endpoint}/$verb";
55
-    }
56
-
57
-    /**
58
-     * @param string $method
59
-     * @return bool
60
-     */
61
-    public function isMethodAllowed($method)
62
-    {
63
-        return in_array($method, $this->allowedMethods);
64
-    }
65
-
66
-    /**
67
-     * @return HttpClient
68
-     */
69
-    public function getHttp()
70
-    {
71
-        return $this->http;
72
-    }
73
-
74
-    /**
75
-     * @param array $params
76
-     * @return array
77
-     */
78
-    public function getAll(array $params = [])
79
-    {
80
-        return $this->getHttp()->get(
81
-            $this->makeRequestUrl(), $params, $this->getHeaders()
82
-        );
83
-    }
84
-
85
-    /**
86
-     * @param string $id
87
-     * @return array
88
-     */
89
-    public function getById($id)
90
-    {
91
-        return $this->getHttp()->get(
92
-            $this->makeRequestUrl($id), [], $this->getHeaders()
93
-        );
94
-    }
95
-
96
-    /**
97
-     * @return array
98
-     */
99
-    protected function getHeaders()
100
-    {
101
-        return array_merge(
102
-            $this->headers,
103
-            ['organizationId' => $this->organizationId]
104
-        );
105
-    }
106
-
107
-    /**
108
-     * @param int $organizationId
109
-     * @return $this
110
-     */
111
-    public function setOrganizationId($organizationId)
112
-    {
113
-        $this->organizationId = $organizationId;
114
-
115
-        return $this;
116
-    }
9
+	/**
10
+	 * @var array
11
+	 */
12
+	protected $allowedMethods = [
13
+		'getById',
14
+		'getAll',
15
+		'create',
16
+		'update',
17
+		'delete',
18
+	];
19
+
20
+	/**
21
+	 * @var string
22
+	 */
23
+	protected $endpoint;
24
+
25
+	/**
26
+	 * @var array
27
+	 */
28
+	protected $headers = [];
29
+
30
+	/**
31
+	 * @var HttpClient
32
+	 */
33
+	protected $http;
34
+
35
+	/**
36
+	 * @var string
37
+	 */
38
+	protected $organizationId;
39
+
40
+	/**
41
+	 * @param HttpClient $http
42
+	 */
43
+	public function __construct(HttpClient $http)
44
+	{
45
+		$this->http = $http;
46
+	}
47
+
48
+	/**
49
+	 * @param string $verb
50
+	 * @return string
51
+	 */
52
+	public function makeRequestUrl($verb = '')
53
+	{
54
+		return "https://favro.com/api/v1/{$this->endpoint}/$verb";
55
+	}
56
+
57
+	/**
58
+	 * @param string $method
59
+	 * @return bool
60
+	 */
61
+	public function isMethodAllowed($method)
62
+	{
63
+		return in_array($method, $this->allowedMethods);
64
+	}
65
+
66
+	/**
67
+	 * @return HttpClient
68
+	 */
69
+	public function getHttp()
70
+	{
71
+		return $this->http;
72
+	}
73
+
74
+	/**
75
+	 * @param array $params
76
+	 * @return array
77
+	 */
78
+	public function getAll(array $params = [])
79
+	{
80
+		return $this->getHttp()->get(
81
+			$this->makeRequestUrl(), $params, $this->getHeaders()
82
+		);
83
+	}
84
+
85
+	/**
86
+	 * @param string $id
87
+	 * @return array
88
+	 */
89
+	public function getById($id)
90
+	{
91
+		return $this->getHttp()->get(
92
+			$this->makeRequestUrl($id), [], $this->getHeaders()
93
+		);
94
+	}
95
+
96
+	/**
97
+	 * @return array
98
+	 */
99
+	protected function getHeaders()
100
+	{
101
+		return array_merge(
102
+			$this->headers,
103
+			['organizationId' => $this->organizationId]
104
+		);
105
+	}
106
+
107
+	/**
108
+	 * @param int $organizationId
109
+	 * @return $this
110
+	 */
111
+	public function setOrganizationId($organizationId)
112
+	{
113
+		$this->organizationId = $organizationId;
114
+
115
+		return $this;
116
+	}
117 117
 }
118 118
\ No newline at end of file
Please login to merge, or discard this patch.
src/Api/Endpoints/Cards.php 1 patch
Indentation   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -7,35 +7,35 @@
 block discarded – undo
7 7
 class Cards extends Endpoint
8 8
 {
9 9
 
10
-    use CrudEndpoint;
10
+	use CrudEndpoint;
11 11
 
12
-    /**
13
-     * @var string
14
-     */
15
-    protected $endpoint = 'cards';
12
+	/**
13
+	 * @var string
14
+	 */
15
+	protected $endpoint = 'cards';
16 16
 
17
-    /**
18
-     * @param string $widgetCommonId
19
-     * @return mixed
20
-     */
21
-    public function getAll($widgetCommonId)
22
-    {
23
-        return parent::getAll(['widgetCommonId'=>$widgetCommonId]);
24
-    }
17
+	/**
18
+	 * @param string $widgetCommonId
19
+	 * @return mixed
20
+	 */
21
+	public function getAll($widgetCommonId)
22
+	{
23
+		return parent::getAll(['widgetCommonId'=>$widgetCommonId]);
24
+	}
25 25
 
26
-    /**
27
-     * @param string $cardId
28
-     * @param bool $everywhere
29
-     * @return mixed
30
-     */
31
-    public function delete($cardId, $everywhere)
32
-    {
33
-        return $this
34
-            ->getHttp()
35
-            ->delete(
36
-                $this->makeRequestUrl($cardId),
37
-                ['everywhere' => $everywhere],
38
-                $this->getHeaders()
39
-            );
40
-    }
26
+	/**
27
+	 * @param string $cardId
28
+	 * @param bool $everywhere
29
+	 * @return mixed
30
+	 */
31
+	public function delete($cardId, $everywhere)
32
+	{
33
+		return $this
34
+			->getHttp()
35
+			->delete(
36
+				$this->makeRequestUrl($cardId),
37
+				['everywhere' => $everywhere],
38
+				$this->getHeaders()
39
+			);
40
+	}
41 41
 }
42 42
\ No newline at end of file
Please login to merge, or discard this patch.