@@ -12,31 +12,58 @@ class Guzzle
1212    const  ENDPOINT_DEV   = 'https://xivapi.local ' ;
1313    const  TIMEOUT  = 10.0 ;
1414    const  VERIFY  = false ;
15- 
15+     
16+     /** @var Client */ 
17+     private  static  $ clientnull ;
18+     /** @var bool */ 
19+     private  static  $ asyncfalse ;
20+     /** @var array */ 
1621    private  static  $ options
22+     
23+     /** 
24+      * Set the Guzzle client 
25+      */ 
26+     private  static  function  setClient ()
27+     {
28+         if  (self ::$ clientnull ) {
29+             self ::$ clientnew  Client ([
30+                 'base_uri '   => self ::ENDPOINT_PROD ,
31+                 'timeout '    => self ::TIMEOUT ,
32+                 'verify '     => self ::VERIFY ,
33+             ]);
34+         }
35+     }
1736
1837    public  static  function  query ($ method$ apiEndpoint$ options
1938    {
39+         self ::setClient ();
40+         
41+         // set XIVAPI key 
2042        if  ($ keygetenv (Environment::XIVAPI_KEY )) {
2143            $ optionsQUERY ]['key ' ] = $ key
2244        }
2345
46+         // set request queries 
2447        foreach  (self ::$ optionsas  $ query$ value
2548            $ valueis_array ($ valueimplode (', ' , $ value$ value
2649            $ optionsQUERY ][$ query$ value
2750        }
28- 
29-         $ clientnew  Client ([
30-             'base_uri '   => self ::ENDPOINT_PROD ,
31-             'timeout '    => self ::TIMEOUT ,
32-             'verify '     => self ::VERIFY ,
33-         ]);
51+         
52+         // allow async 
53+         if  (self ::$ async
54+             return  self ::$ clientrequestAsync ($ method$ apiEndpoint$ options
55+         }
3456
3557        return  \GuzzleHttp \json_decode (
36-             $ clientrequest ($ method$ apiEndpoint$ optionsgetBody ()
58+             self :: $ clientrequest ($ method$ apiEndpoint$ optionsgetBody ()
3759        );
3860    }
3961
62+     public  static  function  setAsync ()
63+     {
64+         self ::$ asynctrue ;
65+     }
66+     
4067    public  static  function  resetQuery ()
4168    {
4269        self ::$ options
0 commit comments