1+ <?php
2+ /**
3+ * Created by Olimar Ferraz
4+ 5+ * Date: 05/06/2018 - 14:17
6+ */
7+
8+ namespace Modules \OpenId \Services ;
9+
10+ class Api
11+ {
12+ /**
13+ * @var \GuzzleHttp\Client
14+ */
15+ private static $ client ;
16+ /**
17+ * @var string
18+ */
19+ private static $ version ;
20+ /**
21+ * @var bool
22+ */
23+ private static $ initialized = FALSE ;
24+
25+ /**
26+ * Class constructor
27+ */
28+ private static function initialize ()
29+ {
30+ if (self ::$ initialized ) return ;
31+
32+ self ::$ client = \OpenId::getClient ();
33+ self ::$ version = config ('openid.api-version ' );
34+ self ::$ initialized = TRUE ;
35+ }
36+
37+ /**
38+ * @return array
39+ */
40+ public static function getSystems ()
41+ {
42+ return self ::getResponse ('system ' );
43+ }
44+
45+ /**
46+ * @return array
47+ */
48+ public static function getSystemRoles ()
49+ {
50+ return self ::getResponse ('system/roles ' );
51+ }
52+
53+ /**
54+ * @return array
55+ */
56+ public static function getUser ()
57+ {
58+ return self ::getResponse ('user ' );
59+ }
60+
61+ /**
62+ * @return array
63+ */
64+ public static function getUserSystems ()
65+ {
66+ return self ::getResponse ('user/systems ' );
67+ }
68+
69+ /**
70+ * @return array
71+ */
72+ public static function getUserPermissions ()
73+ {
74+ return self ::getResponse ('user/permissions ' );
75+ }
76+
77+ /**
78+ *
79+ */
80+ public static function createUserPermission ()
81+ {
82+ //
83+ }
84+
85+ /**
86+ * @return array
87+ */
88+ public static function getStates ()
89+ {
90+ return self ::getResponse ('address/states ' );
91+ }
92+
93+ /**
94+ * @param string $state
95+ *
96+ * @return array
97+ */
98+ public static function getCities (string $ state )
99+ {
100+ return self ::getResponse ('address/cities/ ' . $ state );
101+ }
102+
103+ /**
104+ * @return array
105+ */
106+ public static function isAddressFilled ()
107+ {
108+ return self ::getResponse ('address/filled ' );
109+ }
110+
111+ /**
112+ * @param string $uri
113+ *
114+ * @return array
115+ */
116+ private static function getResponse (string $ uri ): array
117+ {
118+ self ::initialize ();
119+
120+ $ response = self ::$ client ->get ('api/ ' . self ::$ version . '/ ' . $ uri );
121+
122+ return json_decode ($ response ->getBody (), TRUE );
123+ }
124+ }
0 commit comments