@@ -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,9 @@ class WordPress {
254255 bool fetchTags = false ,
255256 bool fetchFeaturedMedia = false ,
256257 bool fetchAttachments = false ,
258+ String postType = "posts" ,
257259 }) async {
258- final StringBuffer url = new StringBuffer (_baseUrl + URL_POSTS );
260+ final StringBuffer url = new StringBuffer (_baseUrl + URL_WP_BASE + "/" + postType );
259261
260262 url.write (postParams.toString ());
261263
@@ -627,7 +629,6 @@ class WordPress {
627629 ///
628630 ///
629631
630-
631632 async .Future <Post > createPost ({@required Post post}) async {
632633 final StringBuffer url = new StringBuffer (_baseUrl + URL_POSTS );
633634
@@ -656,8 +657,10 @@ class WordPress {
656657 final StringBuffer url = new StringBuffer (_baseUrl + URL_USERS );
657658
658659 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" );
660+ HttpClientRequest request =
661+ await httpClient.postUrl (Uri .parse (url.toString ()));
662+ request.headers
663+ .set (HttpHeaders .contentTypeHeader, "application/json; charset=UTF-8" );
661664 request.headers.set (HttpHeaders .acceptHeader, "application/json" );
662665 request.headers.set ('Authorization' , "${_urlHeader ['Authorization' ]}" );
663666
@@ -669,8 +672,7 @@ class WordPress {
669672 } else {
670673 response.transform (utf8.decoder).listen ((contents) {
671674 try {
672- WordPressError err =
673- WordPressError .fromJson (json.decode (contents));
675+ WordPressError err = WordPressError .fromJson (json.decode (contents));
674676 throw err;
675677 } catch (e) {
676678 throw new WordPressError (message: contents);
@@ -687,8 +689,10 @@ class WordPress {
687689 final StringBuffer url = new StringBuffer (_baseUrl + URL_POSTS + '/$id ' );
688690
689691 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" );
692+ HttpClientRequest request =
693+ await httpClient.postUrl (Uri .parse (url.toString ()));
694+ request.headers
695+ .set (HttpHeaders .contentTypeHeader, "application/json; charset=UTF-8" );
692696 request.headers.set (HttpHeaders .acceptHeader, "application/json" );
693697 request.headers.set ('Authorization' , "${_urlHeader ['Authorization' ]}" );
694698
@@ -700,8 +704,7 @@ class WordPress {
700704 } else {
701705 response.transform (utf8.decoder).listen ((contents) {
702706 try {
703- WordPressError err =
704- WordPressError .fromJson (json.decode (contents));
707+ WordPressError err = WordPressError .fromJson (json.decode (contents));
705708 throw err;
706709 } catch (e) {
707710 throw new WordPressError (message: contents);
@@ -710,12 +713,15 @@ class WordPress {
710713 }
711714 }
712715
713- async .Future <bool > updateComment ({@required int id, @required Comment comment}) async {
716+ async .Future <bool > updateComment (
717+ {@required int id, @required Comment comment}) async {
714718 final StringBuffer url = new StringBuffer (_baseUrl + URL_COMMENTS + '/$id ' );
715719
716720 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" );
721+ HttpClientRequest request =
722+ await httpClient.postUrl (Uri .parse (url.toString ()));
723+ request.headers
724+ .set (HttpHeaders .contentTypeHeader, "application/json; charset=UTF-8" );
719725 request.headers.set (HttpHeaders .acceptHeader, "application/json" );
720726 request.headers.set ('Authorization' , "${_urlHeader ['Authorization' ]}" );
721727
@@ -727,8 +733,7 @@ class WordPress {
727733 } else {
728734 response.transform (utf8.decoder).listen ((contents) {
729735 try {
730- WordPressError err =
731- WordPressError .fromJson (json.decode (contents));
736+ WordPressError err = WordPressError .fromJson (json.decode (contents));
732737 throw err;
733738 } catch (e) {
734739 throw new WordPressError (message: contents);
@@ -741,8 +746,10 @@ class WordPress {
741746 final StringBuffer url = new StringBuffer (_baseUrl + URL_USERS + '/$id ' );
742747
743748 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" );
749+ HttpClientRequest request =
750+ await httpClient.postUrl (Uri .parse (url.toString ()));
751+ request.headers
752+ .set (HttpHeaders .contentTypeHeader, "application/json; charset=UTF-8" );
746753 request.headers.set (HttpHeaders .acceptHeader, "application/json" );
747754 request.headers.set ('Authorization' , "${_urlHeader ['Authorization' ]}" );
748755
@@ -754,8 +761,7 @@ class WordPress {
754761 } else {
755762 response.transform (utf8.decoder).listen ((contents) {
756763 try {
757- WordPressError err =
758- WordPressError .fromJson (json.decode (contents));
764+ WordPressError err = WordPressError .fromJson (json.decode (contents));
759765 throw err;
760766 } catch (e) {
761767 throw new WordPressError (message: contents);
@@ -776,8 +782,10 @@ class WordPress {
776782 final StringBuffer url = new StringBuffer (_baseUrl + URL_POSTS + '/$id ' );
777783
778784 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" );
785+ HttpClientRequest request =
786+ await httpClient.deleteUrl (Uri .parse (url.toString ()));
787+ request.headers
788+ .set (HttpHeaders .contentTypeHeader, "application/json; charset=UTF-8" );
781789 request.headers.set (HttpHeaders .acceptHeader, "application/json" );
782790 request.headers.set ('Authorization' , "${_urlHeader ['Authorization' ]}" );
783791
@@ -788,8 +796,7 @@ class WordPress {
788796 } else {
789797 response.transform (utf8.decoder).listen ((contents) {
790798 try {
791- WordPressError err =
792- WordPressError .fromJson (json.decode (contents));
799+ WordPressError err = WordPressError .fromJson (json.decode (contents));
793800 throw err;
794801 } catch (e) {
795802 throw new WordPressError (message: contents);
@@ -802,8 +809,10 @@ class WordPress {
802809 final StringBuffer url = new StringBuffer (_baseUrl + URL_COMMENTS + '/$id ' );
803810
804811 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" );
812+ HttpClientRequest request =
813+ await httpClient.deleteUrl (Uri .parse (url.toString ()));
814+ request.headers
815+ .set (HttpHeaders .contentTypeHeader, "application/json; charset=UTF-8" );
807816 request.headers.set (HttpHeaders .acceptHeader, "application/json" );
808817 request.headers.set ('Authorization' , "${_urlHeader ['Authorization' ]}" );
809818
@@ -814,8 +823,7 @@ class WordPress {
814823 } else {
815824 response.transform (utf8.decoder).listen ((contents) {
816825 try {
817- WordPressError err =
818- WordPressError .fromJson (json.decode (contents));
826+ WordPressError err = WordPressError .fromJson (json.decode (contents));
819827 throw err;
820828 } catch (e) {
821829 throw new WordPressError (message: contents);
@@ -824,25 +832,30 @@ class WordPress {
824832 }
825833 }
826834
827- async .Future <bool > deleteUser ({@required int id, @required int reassign,}) async {
835+ async .Future <bool > deleteUser ({
836+ @required int id,
837+ @required int reassign,
838+ }) async {
828839 final StringBuffer url = new StringBuffer (_baseUrl + URL_USERS + '/$id ' );
829840
830841 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" );
842+ HttpClientRequest request =
843+ await httpClient.deleteUrl (Uri .parse (url.toString ()));
844+ request.headers
845+ .set (HttpHeaders .contentTypeHeader, "application/json; charset=UTF-8" );
833846 request.headers.set (HttpHeaders .acceptHeader, "application/json" );
834847 request.headers.set ('Authorization' , "${_urlHeader ['Authorization' ]}" );
835848
836- request.add (utf8.encode (json.encode ({"reassign" : reassign, "force" : true })));
849+ request
850+ .add (utf8.encode (json.encode ({"reassign" : reassign, "force" : true })));
837851 HttpClientResponse response = await request.close ();
838852
839853 if (response.statusCode >= 200 && response.statusCode < 300 ) {
840854 return true ;
841855 } else {
842856 response.transform (utf8.decoder).listen ((contents) {
843857 try {
844- WordPressError err =
845- WordPressError .fromJson (json.decode (contents));
858+ WordPressError err = WordPressError .fromJson (json.decode (contents));
846859 throw err;
847860 } catch (e) {
848861 throw new WordPressError (message: contents);
0 commit comments