@@ -43,7 +43,48 @@ public function get($id = null, array $params = null)
43
43
try {
44
44
45
45
$ qs = new QueryString ();
46
- $ qs ->add ('_fields ' , array ('id ' , 'title ' , 'link ' , 'author ' , 'metadata ' , 'excerpt ' ));;
46
+
47
+ $ uri = $ this ->getEndpoint ();
48
+ $ uri .= (is_null ($ id ) ? '' : '/ ' . $ id );
49
+ $ uri .= (is_null ($ params ) ? '' : '? ' . http_build_query ($ params ));
50
+
51
+
52
+ $ request = new Request ('GET ' , $ uri , [
53
+ 'connect_timeout ' => 10 ,
54
+ 'timeout ' => 30
55
+ ]);
56
+
57
+ $ response = $ this ->client ->send ($ request );
58
+ if (
59
+ $ response ->hasHeader ('Content-Type ' )
60
+ && substr ($ response ->getHeader ('Content-Type ' )[0 ], 0 , 16 ) === 'application/json '
61
+ ) {
62
+ $ dataRespon = [
63
+ 'body ' => json_decode ($ response ->getBody ()->getContents (), true ),
64
+ 'total ' => $ response ->getHeader ('X-WP-Total ' ),
65
+ 'totalpages ' => $ response ->getHeader ('X-WP-TotalPages ' ),
66
+ ];
67
+
68
+ return $ dataRespon ;
69
+ }
70
+ } catch (Exception $ e ) {
71
+ return GuzzleAdapter::handleException ($ e );
72
+ }
73
+ }
74
+
75
+ /**
76
+ * @param int $id
77
+ * @param array $params - parameters that can be passed to GET
78
+ * e.g. for tags: https://developer.wordpress.org/rest-api/reference/tags/#arguments
79
+ * @return array
80
+ * @throws \RuntimeException
81
+ */
82
+ public function getPaginations ($ id = null , array $ params = null )
83
+ {
84
+ try {
85
+
86
+ $ qs = new QueryString ();
87
+ $ qs ->add ('_fields ' , array ('id ' , 'title ' , 'link ' , 'author ' , 'metadata ' , 'excerpt ' , 'date ' ));;
47
88
$ uri = $ this ->getEndpoint ();
48
89
$ uri .= (is_null ($ id ) ? '' : '/ ' . $ id );
49
90
$ uri .= (is_null ($ params ) ? '' : '? ' . $ qs ->build () . '& ' . http_build_query ($ params ));
0 commit comments