8
8
class Client
9
9
{
10
10
private $ guzzleClient ;
11
- private const MODELS_NAMESPACE = __NAMESPACE__ . " \\Models \\" ;
11
+ private const MODELS_NAMESPACE = __NAMESPACE__ . ' \\Models \\' ;
12
12
private $ models_match = [
13
- 'TaskList ' => 'list '
13
+ 'TaskList ' => 'list ' ,
14
14
];
15
15
16
16
public function __construct ($ apiToken )
@@ -24,7 +24,7 @@ public function __construct($apiToken)
24
24
}
25
25
26
26
/**
27
- * client
27
+ * client.
28
28
*
29
29
* @return Client
30
30
*/
@@ -34,65 +34,91 @@ public function client()
34
34
}
35
35
36
36
/**
37
- * __call
37
+ * __call.
38
+ *
39
+ * @param mixed $name
40
+ * @param mixed $arguments
38
41
*
39
- * @param mixed $name
40
- * @param mixed $arguments
41
42
* @return void
42
43
*/
43
44
public function __call (string $ name , array $ arguments )
44
45
{
45
- if (class_exists (self ::MODELS_NAMESPACE . ucfirst ($ name )) === false ) {
46
+ if (class_exists (self ::MODELS_NAMESPACE . ucfirst ($ name )) === false ) {
46
47
throw new \Exception ("` $ name` is not a method or object " , 1 );
47
48
}
48
49
$ model = ucfirst ($ name );
49
- $ model_namespaced = self ::MODELS_NAMESPACE . $ model ;
50
+ $ model_namespaced = self ::MODELS_NAMESPACE . $ model ;
50
51
51
52
if (array_key_exists ($ model , $ this ->models_match )) {
52
53
$ model = $ this ->models_match [$ model ];
53
54
}
54
55
55
56
$ object = new $ model_namespaced ($ this , $ arguments [0 ] ?? null );
57
+
56
58
return $ object ;
57
59
}
58
60
59
61
/**
60
- * @param string $method
61
- * @param array $params
62
62
* @return mixed
63
63
*/
64
- public function get ($ method , $ params = [])
64
+ public function get (string $ method , array $ params = [])
65
65
{
66
66
$ response = $ this ->guzzleClient ->request ('GET ' , $ method , ['query ' => $ params ]);
67
+
67
68
return json_decode ($ response ->getBody (), true );
68
69
}
69
70
70
71
/**
71
- * @param string $method
72
- * @param array $body
73
72
* @return mixed
74
73
*/
75
- public function post ($ method , $ body = [])
74
+ public function post (string $ method , array $ body = [])
76
75
{
77
76
$ response = $ this ->guzzleClient ->request ('POST ' , $ method , ['json ' => $ body ]);
77
+
78
78
return json_decode ($ response ->getBody (), true );
79
79
}
80
80
81
81
/**
82
- * delete
82
+ * delete.
83
+ *
84
+ * @param mixed $method
83
85
*
84
- * @param mixed $method
85
86
* @return int
86
87
*/
87
- public function delete ($ method )
88
+ public function delete (string $ method )
88
89
{
89
90
$ response = $ this ->guzzleClient ->request ('DELETE ' , $ method );
91
+
90
92
return $ response ->getStatusCode ();
91
93
}
92
94
93
- public function put ($ method , $ body = [])
95
+ /**
96
+ * put.
97
+ *
98
+ * @param mixed $method
99
+ * @param mixed $body
100
+ *
101
+ * @return void
102
+ */
103
+ public function put (string $ method , array $ body = [])
94
104
{
95
105
$ response = $ this ->guzzleClient ->request ('PUT ' , $ method , ['json ' => $ body ]);
106
+
107
+ return json_decode ($ response ->getBody (), true );
108
+ }
109
+
110
+ /**
111
+ * multipart.
112
+ *
113
+ * @param mixed $method
114
+ * @param mixed $attachment
115
+ *
116
+ * @return void
117
+ */
118
+ public function multipart (string $ method , $ attachment )
119
+ {
120
+ $ response = $ this ->guzzleClient ->request ('POST ' , $ method , $ attachment );
121
+
96
122
return json_decode ($ response ->getBody (), true );
97
123
}
98
124
}
0 commit comments