@@ -122,7 +122,8 @@ class WordPress {
122122 return fetchUser (username: username);
123123 }
124124
125- async .Future <User > _authenticateViaJWT (String username, String password) async {
125+ async .Future <User > _authenticateViaJWT (
126+ String username, String password) async {
126127 final body = {
127128 'username' : username,
128129 'password' : password,
@@ -254,8 +255,15 @@ class WordPress {
254255 bool fetchTags = false ,
255256 bool fetchFeaturedMedia = false ,
256257 bool fetchAttachments = false ,
258+ String postType,
257259 }) async {
258- final StringBuffer url = new StringBuffer (_baseUrl + URL_POSTS );
260+ StringBuffer url;
261+
262+ if (postType != null ) {
263+ url = new StringBuffer (_baseUrl + URL_WP_BASE + "/" + postType);
264+ } else {
265+ url = new StringBuffer (_baseUrl + URL_POSTS );
266+ }
259267
260268 url.write (postParams.toString ());
261269
@@ -627,7 +635,6 @@ class WordPress {
627635 ///
628636 ///
629637
630-
631638 async .Future <Post > createPost ({@required Post post}) async {
632639 final StringBuffer url = new StringBuffer (_baseUrl + URL_POSTS );
633640
@@ -656,8 +663,10 @@ class WordPress {
656663 final StringBuffer url = new StringBuffer (_baseUrl + URL_USERS );
657664
658665 HttpClient httpClient = new HttpClient ();
659- HttpClientRequest request = await httpClient.postUrl (Uri .parse (url.toString ()));
660- request.headers.set (HttpHeaders .contentTypeHeader, "application/json; charset=UTF-8" );
666+ HttpClientRequest request =
667+ await httpClient.postUrl (Uri .parse (url.toString ()));
668+ request.headers
669+ .set (HttpHeaders .contentTypeHeader, "application/json; charset=UTF-8" );
661670 request.headers.set (HttpHeaders .acceptHeader, "application/json" );
662671 request.headers.set ('Authorization' , "${_urlHeader ['Authorization' ]}" );
663672
@@ -669,8 +678,7 @@ class WordPress {
669678 } else {
670679 response.transform (utf8.decoder).listen ((contents) {
671680 try {
672- WordPressError err =
673- WordPressError .fromJson (json.decode (contents));
681+ WordPressError err = WordPressError .fromJson (json.decode (contents));
674682 throw err;
675683 } catch (e) {
676684 throw new WordPressError (message: contents);
@@ -687,8 +695,10 @@ class WordPress {
687695 final StringBuffer url = new StringBuffer (_baseUrl + URL_POSTS + '/$id ' );
688696
689697 HttpClient httpClient = new HttpClient ();
690- HttpClientRequest request = await httpClient.postUrl (Uri .parse (url.toString ()));
691- request.headers.set (HttpHeaders .contentTypeHeader, "application/json; charset=UTF-8" );
698+ HttpClientRequest request =
699+ await httpClient.postUrl (Uri .parse (url.toString ()));
700+ request.headers
701+ .set (HttpHeaders .contentTypeHeader, "application/json; charset=UTF-8" );
692702 request.headers.set (HttpHeaders .acceptHeader, "application/json" );
693703 request.headers.set ('Authorization' , "${_urlHeader ['Authorization' ]}" );
694704
@@ -700,8 +710,7 @@ class WordPress {
700710 } else {
701711 response.transform (utf8.decoder).listen ((contents) {
702712 try {
703- WordPressError err =
704- WordPressError .fromJson (json.decode (contents));
713+ WordPressError err = WordPressError .fromJson (json.decode (contents));
705714 throw err;
706715 } catch (e) {
707716 throw new WordPressError (message: contents);
@@ -710,12 +719,15 @@ class WordPress {
710719 }
711720 }
712721
713- async .Future <bool > updateComment ({@required int id, @required Comment comment}) async {
722+ async .Future <bool > updateComment (
723+ {@required int id, @required Comment comment}) async {
714724 final StringBuffer url = new StringBuffer (_baseUrl + URL_COMMENTS + '/$id ' );
715725
716726 HttpClient httpClient = new HttpClient ();
717- HttpClientRequest request = await httpClient.postUrl (Uri .parse (url.toString ()));
718- request.headers.set (HttpHeaders .contentTypeHeader, "application/json; charset=UTF-8" );
727+ HttpClientRequest request =
728+ await httpClient.postUrl (Uri .parse (url.toString ()));
729+ request.headers
730+ .set (HttpHeaders .contentTypeHeader, "application/json; charset=UTF-8" );
719731 request.headers.set (HttpHeaders .acceptHeader, "application/json" );
720732 request.headers.set ('Authorization' , "${_urlHeader ['Authorization' ]}" );
721733
@@ -727,8 +739,7 @@ class WordPress {
727739 } else {
728740 response.transform (utf8.decoder).listen ((contents) {
729741 try {
730- WordPressError err =
731- WordPressError .fromJson (json.decode (contents));
742+ WordPressError err = WordPressError .fromJson (json.decode (contents));
732743 throw err;
733744 } catch (e) {
734745 throw new WordPressError (message: contents);
@@ -741,8 +752,10 @@ class WordPress {
741752 final StringBuffer url = new StringBuffer (_baseUrl + URL_USERS + '/$id ' );
742753
743754 HttpClient httpClient = new HttpClient ();
744- HttpClientRequest request = await httpClient.postUrl (Uri .parse (url.toString ()));
745- request.headers.set (HttpHeaders .contentTypeHeader, "application/json; charset=UTF-8" );
755+ HttpClientRequest request =
756+ await httpClient.postUrl (Uri .parse (url.toString ()));
757+ request.headers
758+ .set (HttpHeaders .contentTypeHeader, "application/json; charset=UTF-8" );
746759 request.headers.set (HttpHeaders .acceptHeader, "application/json" );
747760 request.headers.set ('Authorization' , "${_urlHeader ['Authorization' ]}" );
748761
@@ -754,8 +767,7 @@ class WordPress {
754767 } else {
755768 response.transform (utf8.decoder).listen ((contents) {
756769 try {
757- WordPressError err =
758- WordPressError .fromJson (json.decode (contents));
770+ WordPressError err = WordPressError .fromJson (json.decode (contents));
759771 throw err;
760772 } catch (e) {
761773 throw new WordPressError (message: contents);
@@ -776,8 +788,10 @@ class WordPress {
776788 final StringBuffer url = new StringBuffer (_baseUrl + URL_POSTS + '/$id ' );
777789
778790 HttpClient httpClient = new HttpClient ();
779- HttpClientRequest request = await httpClient.deleteUrl (Uri .parse (url.toString ()));
780- request.headers.set (HttpHeaders .contentTypeHeader, "application/json; charset=UTF-8" );
791+ HttpClientRequest request =
792+ await httpClient.deleteUrl (Uri .parse (url.toString ()));
793+ request.headers
794+ .set (HttpHeaders .contentTypeHeader, "application/json; charset=UTF-8" );
781795 request.headers.set (HttpHeaders .acceptHeader, "application/json" );
782796 request.headers.set ('Authorization' , "${_urlHeader ['Authorization' ]}" );
783797
@@ -788,8 +802,7 @@ class WordPress {
788802 } else {
789803 response.transform (utf8.decoder).listen ((contents) {
790804 try {
791- WordPressError err =
792- WordPressError .fromJson (json.decode (contents));
805+ WordPressError err = WordPressError .fromJson (json.decode (contents));
793806 throw err;
794807 } catch (e) {
795808 throw new WordPressError (message: contents);
@@ -802,8 +815,10 @@ class WordPress {
802815 final StringBuffer url = new StringBuffer (_baseUrl + URL_COMMENTS + '/$id ' );
803816
804817 HttpClient httpClient = new HttpClient ();
805- HttpClientRequest request = await httpClient.deleteUrl (Uri .parse (url.toString ()));
806- request.headers.set (HttpHeaders .contentTypeHeader, "application/json; charset=UTF-8" );
818+ HttpClientRequest request =
819+ await httpClient.deleteUrl (Uri .parse (url.toString ()));
820+ request.headers
821+ .set (HttpHeaders .contentTypeHeader, "application/json; charset=UTF-8" );
807822 request.headers.set (HttpHeaders .acceptHeader, "application/json" );
808823 request.headers.set ('Authorization' , "${_urlHeader ['Authorization' ]}" );
809824
@@ -814,8 +829,7 @@ class WordPress {
814829 } else {
815830 response.transform (utf8.decoder).listen ((contents) {
816831 try {
817- WordPressError err =
818- WordPressError .fromJson (json.decode (contents));
832+ WordPressError err = WordPressError .fromJson (json.decode (contents));
819833 throw err;
820834 } catch (e) {
821835 throw new WordPressError (message: contents);
@@ -824,25 +838,30 @@ class WordPress {
824838 }
825839 }
826840
827- async .Future <bool > deleteUser ({@required int id, @required int reassign,}) async {
841+ async .Future <bool > deleteUser ({
842+ @required int id,
843+ @required int reassign,
844+ }) async {
828845 final StringBuffer url = new StringBuffer (_baseUrl + URL_USERS + '/$id ' );
829846
830847 HttpClient httpClient = new HttpClient ();
831- HttpClientRequest request = await httpClient.deleteUrl (Uri .parse (url.toString ()));
832- request.headers.set (HttpHeaders .contentTypeHeader, "application/json; charset=UTF-8" );
848+ HttpClientRequest request =
849+ await httpClient.deleteUrl (Uri .parse (url.toString ()));
850+ request.headers
851+ .set (HttpHeaders .contentTypeHeader, "application/json; charset=UTF-8" );
833852 request.headers.set (HttpHeaders .acceptHeader, "application/json" );
834853 request.headers.set ('Authorization' , "${_urlHeader ['Authorization' ]}" );
835854
836- request.add (utf8.encode (json.encode ({"reassign" : reassign, "force" : true })));
855+ request
856+ .add (utf8.encode (json.encode ({"reassign" : reassign, "force" : true })));
837857 HttpClientResponse response = await request.close ();
838858
839859 if (response.statusCode >= 200 && response.statusCode < 300 ) {
840860 return true ;
841861 } else {
842862 response.transform (utf8.decoder).listen ((contents) {
843863 try {
844- WordPressError err =
845- WordPressError .fromJson (json.decode (contents));
864+ WordPressError err = WordPressError .fromJson (json.decode (contents));
846865 throw err;
847866 } catch (e) {
848867 throw new WordPressError (message: contents);
0 commit comments