diff --git a/.gitignore b/.gitignore index 133ada1..de34df1 100644 --- a/.gitignore +++ b/.gitignore @@ -34,3 +34,6 @@ aot/ aot2/ angular2-webpack-starter/ testionic/ + +# VS code +.vscode diff --git a/package.json b/package.json index ee665c7..1d16ff3 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "wp-api-angular", - "version": "3.0.0-beta8", - "description": "WordPress WP-API v2 client for Angular2", + "version": "4.0.0", + "description": "WordPress WP-API v2 client for Angular2+", "main": "wp-api-angular.js", "typings": "wp-api-angular.d.ts", "scripts": { @@ -24,7 +24,9 @@ "angularjs", "rest", "restfull", - "client" + "client", + "wordpress", + "json" ], "author": "shprink ", "license": "MIT", @@ -32,31 +34,27 @@ "url": "https://github.com/shprink/wp-api-angular/issues" }, "homepage": "https://github.com/shprink/wp-api-angular", - "peerDependencies": { - "@angular/core": "^4.0.0", - "@angular/http": "^4.0.0" - }, "dependencies": { - "@angular/common": "^4.0.0", - "@angular/compiler": "^4.0.0", - "@angular/platform-browser": "^4.0.0", - "@angular/platform-browser-dynamic": "^4.0.0", - "rxjs": "^5.0.0" + "@angular/common": "^11.0.0", + "@angular/compiler": "^11.0.0", + "@angular/core": "^11.0.0", + "@angular/platform-browser": "^11.0.0", + "@angular/platform-browser-dynamic": "^11.0.0", + "rxjs": "~6.5.5" }, "devDependencies": { - "@angular/compiler-cli": "^4.0.0", + "@angular/compiler-cli": "^11.0.0", "babel-core": "^6.10.4", "babel-loader": "^6.2.4", - "core-js": "^2.4.0", "html-webpack-plugin": "~2.22.0", "json-loader": "^0.5.2", "path": "^0.4.9", "reflect-metadata": "^0.1.3", "ts-loader": "0.8.1", - "typescript": "^2.1.5", + "typescript": "~4.0.3", "util": "^0.10.3", "webpack": "~1.13.1", "webpack-dev-server": "~1.14.1", - "zone.js": "^0.6.12" + "zone.js": "^0.10.2" } } diff --git a/src/Comments.ts b/src/Comments.ts index 2403735..90cff45 100644 --- a/src/Comments.ts +++ b/src/Comments.ts @@ -1,28 +1,19 @@ -import { Injectable, Inject } from '@angular/core'; -import { Http } from '@angular/http'; -// Need to import interfaces dependencies -// Bug TypeScript https://github.com/Microsoft/TypeScript/issues/5938 -import { Observable } from 'rxjs/Observable'; -import { RequestOptionsArgs } from '@angular/http/src/interfaces'; -import { Response } from '@angular/http/src/static_response'; - -import { WpApiParent } from './Parent'; - +import { HttpClient } from '@angular/common/http'; +import { Injectable } from '@angular/core'; +import { IWpApiComments } from './interfaces'; import { WpApiLoader } from './Loaders'; +import { WpApiParent } from './Parent'; -export interface IWpApiComments { - getList(options?: RequestOptionsArgs): Observable; - get(commentId: number, options?: RequestOptionsArgs): Observable; - create(body: any, options?: RequestOptionsArgs): Observable; - update(commentId: number, body: any, options?: RequestOptionsArgs): Observable; - delete(commentId: number, options?: RequestOptionsArgs): Observable; -} +/****************************************************************************** +* Service: WpApiComments +******************************************************************************/ @Injectable() export class WpApiComments extends WpApiParent implements IWpApiComments { + constructor( public wpApiLoader: WpApiLoader, - public http: Http + public http: HttpClient ) { super(wpApiLoader, http); } diff --git a/src/Custom.ts b/src/Custom.ts index 03697c6..54fe1ad 100644 --- a/src/Custom.ts +++ b/src/Custom.ts @@ -1,28 +1,14 @@ -import { Injectable, Inject } from '@angular/core'; -import { Http } from '@angular/http'; - -// Need to import interfaces dependencies -// Bug TypeScript https://github.com/Microsoft/TypeScript/issues/5938 -import { Observable } from 'rxjs/Observable'; -import { RequestOptionsArgs } from '@angular/http/src/interfaces'; -import { Response } from '@angular/http/src/static_response'; - -import { WpApiParent } from './Parent'; - +import { HttpClient } from '@angular/common/http'; +import { Injectable } from '@angular/core'; +import { IWpApiCustom } from './interfaces'; import { WpApiLoader } from './Loaders'; +import { WpApiParent } from './Parent'; -export interface IWpApiCustom { - getList(options?: RequestOptionsArgs): Observable; - get(customId: number, options?: RequestOptionsArgs): Observable; - create(body: any, options?: RequestOptionsArgs): Observable; - update(customId: number, body: any, options?: RequestOptionsArgs): Observable; - delete(customId: number, options?: RequestOptionsArgs): Observable; -} export class Custom extends WpApiParent implements IWpApiCustom { constructor( public wpApiLoader: WpApiLoader, - public http: Http, + public http: HttpClient, public entityName: string ) { super(wpApiLoader, http); @@ -44,17 +30,19 @@ export class Custom extends WpApiParent implements IWpApiCustom { } } - +/****************************************************************************** +* Service: WpApiCustom +******************************************************************************/ @Injectable() export class WpApiCustom extends WpApiParent { constructor( public wpApiLoader: WpApiLoader, - public http: Http + public http: HttpClient ) { super(wpApiLoader, http); } - getInstance(entityName = '') { + getInstance(entityName: string = '') { if (typeof entityName !== 'string') { throw new Error(`getInstance needs an entity name`); } diff --git a/src/Loaders.ts b/src/Loaders.ts index 1dcc273..e58a8db 100644 --- a/src/Loaders.ts +++ b/src/Loaders.ts @@ -1,14 +1,20 @@ -import { Http, HttpModule } from '@angular/http'; + +import { HttpClient } from '@angular/common/http'; import { stripTrailingSlash } from './utils'; export abstract class WpApiLoader { abstract getWebServiceUrl(postfix: string): string; } +/****************************************************************************** +* Class: WpApiStaticLoader +******************************************************************************/ export class WpApiStaticLoader implements WpApiLoader { + completeUrl: string; + constructor( - private http: Http, + private http: HttpClient, private baseUrl: string = 'http://changeYourDomainHere.com/wp-json', private namespace: string = '/wp/v2' ) { @@ -18,4 +24,5 @@ export class WpApiStaticLoader implements WpApiLoader { public getWebServiceUrl(postfix: string): string { return `${this.completeUrl}${postfix}` } + } diff --git a/src/Media.ts b/src/Media.ts index c94c5f8..6f89397 100644 --- a/src/Media.ts +++ b/src/Media.ts @@ -1,29 +1,14 @@ -import { Injectable, Inject } from '@angular/core'; -import { Http } from '@angular/http'; - -// Need to import interfaces dependencies -// Bug TypeScript https://github.com/Microsoft/TypeScript/issues/5938 -import { Observable } from 'rxjs/Observable'; -import { RequestOptionsArgs } from '@angular/http/src/interfaces'; -import { Response } from '@angular/http/src/static_response'; - -import { WpApiParent } from './Parent'; - +import { HttpClient } from '@angular/common/http'; +import { Injectable } from '@angular/core'; +import { IWpApiMedia } from './interfaces'; import { WpApiLoader } from './Loaders'; - -export interface IWpApiMedia { - getList(options?: RequestOptionsArgs): Observable; - get(mediaId: number, options?: RequestOptionsArgs): Observable; - create(body: any, options?: RequestOptionsArgs): Observable; - update(mediaId: number, body: any, options?: RequestOptionsArgs): Observable; - delete(mediaId: number, options?: RequestOptionsArgs): Observable; -} +import { WpApiParent } from './Parent'; @Injectable() export class WpApiMedia extends WpApiParent implements IWpApiMedia { constructor( public wpApiLoader: WpApiLoader, - public http: Http + public http: HttpClient ) { super(wpApiLoader, http); } diff --git a/src/Pages.ts b/src/Pages.ts index 52bb621..2a76132 100644 --- a/src/Pages.ts +++ b/src/Pages.ts @@ -1,33 +1,15 @@ -import { Injectable, Inject } from '@angular/core'; -import { Http } from '@angular/http'; - -// Need to import interfaces dependencies -// Bug TypeScript https://github.com/Microsoft/TypeScript/issues/5938 -import { Observable } from 'rxjs/Observable'; -import { RequestOptionsArgs } from '@angular/http/src/interfaces'; -import { Response } from '@angular/http/src/static_response'; - -import { WpApiParent } from './Parent'; - +import { HttpClient } from '@angular/common/http'; +import { Injectable } from '@angular/core'; +import { IWpApiPages } from './interfaces'; import { WpApiLoader } from './Loaders'; +import { WpApiParent } from './Parent'; -export interface IWpApiPages { - getList(options?: RequestOptionsArgs): Observable; - get(pageId: number, options?: RequestOptionsArgs): Observable; - create(body: any, options?: RequestOptionsArgs): Observable; - update(pageId: number, body: any, options?: RequestOptionsArgs): Observable; - delete(pageId: number, options?: RequestOptionsArgs): Observable; - getMetaList(pageId: number, options?: RequestOptionsArgs): Observable; - getMeta(pageId: number, metaId: number, options?: RequestOptionsArgs): Observable; - getRevisionList(pageId: number, options?: RequestOptionsArgs): Observable; - getRevision(pageId: number, revisionId: number, options?: RequestOptionsArgs): Observable; -} @Injectable() export class WpApiPages extends WpApiParent implements IWpApiPages { constructor( public wpApiLoader: WpApiLoader, - public http: Http + public http: HttpClient ) { super(wpApiLoader, http); } diff --git a/src/Parent.ts b/src/Parent.ts index 9ee449c..147abf7 100644 --- a/src/Parent.ts +++ b/src/Parent.ts @@ -1,30 +1,18 @@ -import { Injectable, Inject } from '@angular/core'; -import { Http } from '@angular/http'; - -// Need to import interfaces dependencies -// Bug TypeScript https://github.com/Microsoft/TypeScript/issues/5938 -import { Observable } from 'rxjs/Observable'; -import { RequestOptionsArgs } from '@angular/http/src/interfaces'; -import { Response } from '@angular/http/src/static_response'; - +import { HttpClient } from '@angular/common/http'; +import { Injectable } from '@angular/core'; +import { IParent } from './interfaces'; import { WpApiLoader } from './Loaders'; -import { stripTrailingSlash } from './utils'; -export interface IParent { - httpGet(url: string, options?: RequestOptionsArgs): Observable; - httpHead(url: string, options?: RequestOptionsArgs): Observable; - httpDelete(url: string, options?: RequestOptionsArgs): Observable; - httpPost(url: string, body: any, options?: RequestOptionsArgs): Observable; - httpPut(url: string, body: any, options?: RequestOptionsArgs): Observable; - httpPatch(url: string, body: any, options?: RequestOptionsArgs): Observable; -} - +/****************************************************************************** +* Service: WpApiParent +******************************************************************************/ @Injectable() export class WpApiParent implements IParent { + constructor( public wpApiLoader: WpApiLoader, - public http: Http + public http: HttpClient ) { } httpGet(url: string, options = {}) { diff --git a/src/Posts.ts b/src/Posts.ts index 4c2cf1c..ff0336d 100644 --- a/src/Posts.ts +++ b/src/Posts.ts @@ -1,37 +1,15 @@ -import { Injectable, Inject } from '@angular/core'; -import { Http } from '@angular/http'; - -// Need to import interfaces dependencies -// Bug TypeScript https://github.com/Microsoft/TypeScript/issues/5938 -import { Observable } from 'rxjs/Observable'; -import { RequestOptionsArgs } from '@angular/http/src/interfaces'; -import { Response } from '@angular/http/src/static_response'; - -import { WpApiParent } from './Parent'; - +import { HttpClient } from '@angular/common/http'; +import { Injectable } from '@angular/core'; +import { IWpApiPosts } from './interfaces'; import { WpApiLoader } from './Loaders'; +import { WpApiParent } from './Parent'; -export interface IWpApiPosts { - getList(options?: RequestOptionsArgs): Observable; - get(postId: number, options?: RequestOptionsArgs): Observable; - create(body: any, options?: RequestOptionsArgs): Observable; - update(postId: number, body: any, options?: RequestOptionsArgs): Observable; - delete(postId: number, options?: RequestOptionsArgs): Observable; - getMetaList(postId: number, options?: RequestOptionsArgs): Observable; - getMeta(postId: number, metaId: number, options?: RequestOptionsArgs): Observable; - getRevisionList(postId: number, options?: RequestOptionsArgs): Observable; - getRevision(postId: number, revisionId: number, options?: RequestOptionsArgs): Observable; - getCategoryList(postId: number, options?: RequestOptionsArgs): Observable; - getCategory(postId: number, categoryId, options?: RequestOptionsArgs): Observable; - getTagList(postId: number, options?: RequestOptionsArgs): Observable; - getTag(postId: number, tagId, options?: RequestOptionsArgs): Observable; -} @Injectable() export class WpApiPosts extends WpApiParent implements IWpApiPosts { constructor( public wpApiLoader: WpApiLoader, - public http: Http + public http: HttpClient ) { super(wpApiLoader, http); } diff --git a/src/RequestOptionsArgs.ts b/src/RequestOptionsArgs.ts new file mode 100644 index 0000000..7d40695 --- /dev/null +++ b/src/RequestOptionsArgs.ts @@ -0,0 +1,11 @@ + +type RequestMethod = "get" | "post" | "put" | "delete"; + +export class RequestOptionsArgs { + url : string + method : string|RequestMethod + search : string|URLSearchParams + headers : Headers + body : any + withCredentials : boolean +} diff --git a/src/Statuses.ts b/src/Statuses.ts index 9692ea4..134c936 100644 --- a/src/Statuses.ts +++ b/src/Statuses.ts @@ -1,26 +1,14 @@ -import { Injectable, Inject } from '@angular/core'; -import { Http } from '@angular/http'; - -// Need to import interfaces dependencies -// Bug TypeScript https://github.com/Microsoft/TypeScript/issues/5938 -import { Observable } from 'rxjs/Observable'; -import { RequestOptionsArgs } from '@angular/http/src/interfaces'; -import { Response } from '@angular/http/src/static_response'; - -import { WpApiParent } from './Parent'; - +import { HttpClient } from '@angular/common/http'; +import { Injectable } from '@angular/core'; +import { IWpApiStatuses } from './interfaces'; import { WpApiLoader } from './Loaders'; - -export interface IWpApiStatuses { - getList(options?: RequestOptionsArgs): Observable; - get(statusesName: string, options?: RequestOptionsArgs): Observable; -} +import { WpApiParent } from './Parent'; @Injectable() export class WpApiStatuses extends WpApiParent implements IWpApiStatuses { constructor( public wpApiLoader: WpApiLoader, - public http: Http + public http: HttpClient ) { super(wpApiLoader, http); } diff --git a/src/Taxonomies.ts b/src/Taxonomies.ts index 4175ba5..174d603 100644 --- a/src/Taxonomies.ts +++ b/src/Taxonomies.ts @@ -1,26 +1,17 @@ -import { Injectable, Inject } from '@angular/core'; -import { Http } from '@angular/http'; - -// Need to import interfaces dependencies -// Bug TypeScript https://github.com/Microsoft/TypeScript/issues/5938 -import { Observable } from 'rxjs/Observable'; -import { RequestOptionsArgs } from '@angular/http/src/interfaces'; -import { Response } from '@angular/http/src/static_response'; - +import { HttpClient } from '@angular/common/http'; +import { Injectable } from '@angular/core'; +import { IWpApiTaxonomies } from './interfaces'; +import { WpApiLoader } from './Loaders'; import { WpApiParent } from './Parent'; -import { WpApiLoader } from './Loaders'; -export interface IWpApiTaxonomies { - getList(options?: RequestOptionsArgs): Observable; - get(taxonomiesType: string, options?: RequestOptionsArgs): Observable; -} + @Injectable() export class WpApiTaxonomies extends WpApiParent implements IWpApiTaxonomies { constructor( public wpApiLoader: WpApiLoader, - public http: Http + public http: HttpClient ) { super(wpApiLoader, http); } diff --git a/src/Terms.ts b/src/Terms.ts index ccad587..be3ba1a 100644 --- a/src/Terms.ts +++ b/src/Terms.ts @@ -1,23 +1,9 @@ -import { Injectable, Inject } from '@angular/core'; -import { Http } from '@angular/http'; - -// Need to import interfaces dependencies -// Bug TypeScript https://github.com/Microsoft/TypeScript/issues/5938 -import { Observable } from 'rxjs/Observable'; -import { RequestOptionsArgs } from '@angular/http/src/interfaces'; -import { Response } from '@angular/http/src/static_response'; - -import { WpApiParent } from './Parent'; - +import { HttpClient } from '@angular/common/http'; +import { Injectable } from '@angular/core'; +import { IWpApiTerms } from './interfaces'; import { WpApiLoader } from './Loaders'; +import { WpApiParent } from './Parent'; -export interface IWpApiTerms { - getList(taxonomiesType: string, options?: RequestOptionsArgs): Observable; - get(taxonomiesType: string, termId: number, options?: RequestOptionsArgs): Observable; - create(taxonomiesType: string, body: any, options?: RequestOptionsArgs): Observable; - update(taxonomiesType: string, termId: number, body: any, options?: RequestOptionsArgs): Observable; - delete(taxonomiesType: string, termId: number, options?: RequestOptionsArgs): Observable; -} const defaultTaxoType = 'categories'; @@ -25,7 +11,7 @@ const defaultTaxoType = 'categories'; export class WpApiTerms extends WpApiParent implements IWpApiTerms { constructor( public wpApiLoader: WpApiLoader, - public http: Http + public http: HttpClient ) { super(wpApiLoader, http); } diff --git a/src/Types.ts b/src/Types.ts index 7c51478..d1d36a2 100644 --- a/src/Types.ts +++ b/src/Types.ts @@ -1,26 +1,16 @@ -import { Injectable, Inject } from '@angular/core'; -import { Http } from '@angular/http'; - -// Need to import interfaces dependencies -// Bug TypeScript https://github.com/Microsoft/TypeScript/issues/5938 -import { Observable } from 'rxjs/Observable'; -import { RequestOptionsArgs } from '@angular/http/src/interfaces'; -import { Response } from '@angular/http/src/static_response'; - +import { HttpClient } from '@angular/common/http'; +import { Injectable } from '@angular/core'; +import { IWpApiTypes } from './interfaces'; +import { WpApiLoader } from './Loaders'; import { WpApiParent } from './Parent'; -import { WpApiLoader } from './Loaders'; -export interface IWpApiTypes { - getList(options?: RequestOptionsArgs): Observable; - get(postType: string, options?: RequestOptionsArgs): Observable; -} @Injectable() export class WpApiTypes extends WpApiParent implements IWpApiTypes { constructor( public wpApiLoader: WpApiLoader, - public http: Http + public http: HttpClient ) { super(wpApiLoader, http); } diff --git a/src/Users.ts b/src/Users.ts index 93f8305..233cdc0 100644 --- a/src/Users.ts +++ b/src/Users.ts @@ -1,30 +1,14 @@ -import { Injectable, Inject } from '@angular/core'; -import { Http } from '@angular/http'; - -// Need to import interfaces dependencies -// Bug TypeScript https://github.com/Microsoft/TypeScript/issues/5938 -import { Observable } from 'rxjs/Observable'; -import { RequestOptionsArgs } from '@angular/http/src/interfaces'; -import { Response } from '@angular/http/src/static_response'; - -import { WpApiParent } from './Parent'; - +import { HttpClient } from '@angular/common/http'; +import { Injectable } from '@angular/core'; +import { IWpApiUsers } from './interfaces'; import { WpApiLoader } from './Loaders'; - -export interface IWpApiUsers { - getList(options?: RequestOptionsArgs): Observable; - me(options?: RequestOptionsArgs): Observable; - get(userId: number, options?: RequestOptionsArgs): Observable; - create(body: any, options?: RequestOptionsArgs): Observable; - update(userId: number, body: any, options?: RequestOptionsArgs): Observable; - delete(userId: number, options?: RequestOptionsArgs): Observable; -} +import { WpApiParent } from './Parent'; @Injectable() export class WpApiUsers extends WpApiParent implements IWpApiUsers { constructor( public wpApiLoader: WpApiLoader, - public http: Http + public http: HttpClient ) { super(wpApiLoader, http); } diff --git a/src/interfaces.ts b/src/interfaces.ts index d888f7d..53edb48 100644 --- a/src/interfaces.ts +++ b/src/interfaces.ts @@ -1,97 +1,95 @@ -import { Observable } from 'rxjs/Observable'; -import { RequestOptionsArgs } from '@angular/http/src/interfaces'; -import { Response } from '@angular/http/src/static_response'; - +import { Observable } from "rxjs"; +import { RequestOptionsArgs } from './RequestOptionsArgs'; export interface IParent { - httpGet(url: string, options?: RequestOptionsArgs): Observable; - httpHead(url: string, options?: RequestOptionsArgs): Observable; - httpDelete(url: string, options?: RequestOptionsArgs): Observable; - httpPost(url: string, body: any, options?: RequestOptionsArgs): Observable; - httpPut(url: string, body: any, options?: RequestOptionsArgs): Observable; - httpPatch(url: string, body: any, options?: RequestOptionsArgs): Observable; + httpGet(url: string, options?: RequestOptionsArgs): Observable; + httpHead(url: string, options?: RequestOptionsArgs): Observable; + httpDelete(url: string, options?: RequestOptionsArgs): Observable; + httpPost(url: string, body: any, options?: RequestOptionsArgs): Observable; + httpPut(url: string, body: any, options?: RequestOptionsArgs): Observable; + httpPatch(url: string, body: any, options?: RequestOptionsArgs): Observable; } export interface IWpApiPosts { - getList(options?: RequestOptionsArgs): Observable; - get(postId: number, options?: RequestOptionsArgs): Observable; - create(body: any, options?: RequestOptionsArgs): Observable; - update(postId: number, body: any, options?: RequestOptionsArgs): Observable; - delete(postId: number, options?: RequestOptionsArgs): Observable; - getMetaList(postId: number, options?: RequestOptionsArgs): Observable; - getMeta(postId: number, metaId: number, options?: RequestOptionsArgs): Observable; - getRevisionList(postId: number, options?: RequestOptionsArgs): Observable; - getRevision(postId: number, revisionId: number, options?: RequestOptionsArgs): Observable; - getCategoryList(postId: number, options?: RequestOptionsArgs): Observable; - getCategory(postId: number, categoryId, options?: RequestOptionsArgs): Observable; - getTagList(postId: number, options?: RequestOptionsArgs): Observable; - getTag(postId: number, tagId, options?: RequestOptionsArgs): Observable; + getList(options?: RequestOptionsArgs): Observable; + get(postId: number, options?: RequestOptionsArgs): Observable; + create(body: any, options?: RequestOptionsArgs): Observable; + update(postId: number, body: any, options?: RequestOptionsArgs): Observable; + delete(postId: number, options?: RequestOptionsArgs): Observable; + getMetaList(postId: number, options?: RequestOptionsArgs): Observable; + getMeta(postId: number, metaId: number, options?: RequestOptionsArgs): Observable; + getRevisionList(postId: number, options?: RequestOptionsArgs): Observable; + getRevision(postId: number, revisionId: number, options?: RequestOptionsArgs): Observable; + getCategoryList(postId: number, options?: RequestOptionsArgs): Observable; + getCategory(postId: number, categoryId, options?: RequestOptionsArgs): Observable; + getTagList(postId: number, options?: RequestOptionsArgs): Observable; + getTag(postId: number, tagId, options?: RequestOptionsArgs): Observable; } export interface IWpApiPages { - getList(options?: RequestOptionsArgs): Observable; - get(pageId: number, options?: RequestOptionsArgs): Observable; - create(body: any, options?: RequestOptionsArgs): Observable; - update(pageId: number, body: any, options?: RequestOptionsArgs): Observable; - delete(pageId: number, options?: RequestOptionsArgs): Observable; - getMetaList(pageId: number, options?: RequestOptionsArgs): Observable; - getMeta(pageId: number, metaId: number, options?: RequestOptionsArgs): Observable; - getRevisionList(pageId: number, options?: RequestOptionsArgs): Observable; - getRevision(pageId: number, revisionId: number, options?: RequestOptionsArgs): Observable; + getList(options?: RequestOptionsArgs): Observable; + get(pageId: number, options?: RequestOptionsArgs): Observable; + create(body: any, options?: RequestOptionsArgs): Observable; + update(pageId: number, body: any, options?: RequestOptionsArgs): Observable; + delete(pageId: number, options?: RequestOptionsArgs): Observable; + getMetaList(pageId: number, options?: RequestOptionsArgs): Observable; + getMeta(pageId: number, metaId: number, options?: RequestOptionsArgs): Observable; + getRevisionList(pageId: number, options?: RequestOptionsArgs): Observable; + getRevision(pageId: number, revisionId: number, options?: RequestOptionsArgs): Observable; } export interface IWpApiComments { - getList(options?: RequestOptionsArgs): Observable; - get(commentId: number, options?: RequestOptionsArgs): Observable; - create(body: any, options?: RequestOptionsArgs): Observable; - update(commentId: number, body: any, options?: RequestOptionsArgs): Observable; - delete(commentId: number, options?: RequestOptionsArgs): Observable; + getList(options?: RequestOptionsArgs): Observable; + get(commentId: number, options?: RequestOptionsArgs): Observable; + create(body: any, options?: RequestOptionsArgs): Observable; + update(commentId: number, body: any, options?: RequestOptionsArgs): Observable; + delete(commentId: number, options?: RequestOptionsArgs): Observable; } export interface IWpApiTypes { - getList(options?: RequestOptionsArgs): Observable; - get(postType: string, options?: RequestOptionsArgs): Observable; + getList(options?: RequestOptionsArgs): Observable; + get(postType: string, options?: RequestOptionsArgs): Observable; } export interface IWpApiMedia { - getList(options?: RequestOptionsArgs): Observable; - get(mediaId: number, options?: RequestOptionsArgs): Observable; - create(body: any, options?: RequestOptionsArgs): Observable; - update(mediaId: number, body: any, options?: RequestOptionsArgs): Observable; - delete(mediaId: number, options?: RequestOptionsArgs): Observable; + getList(options?: RequestOptionsArgs): Observable; + get(mediaId: number, options?: RequestOptionsArgs): Observable; + create(body: any, options?: RequestOptionsArgs): Observable; + update(mediaId: number, body: any, options?: RequestOptionsArgs): Observable; + delete(mediaId: number, options?: RequestOptionsArgs): Observable; } export interface IWpApiUsers { - getList(options?: RequestOptionsArgs): Observable; - me(options?: RequestOptionsArgs): Observable; - get(userId: number, options?: RequestOptionsArgs): Observable; - create(body: any, options?: RequestOptionsArgs): Observable; - update(userId: number, body: any, options?: RequestOptionsArgs): Observable; - delete(userId: number, options?: RequestOptionsArgs): Observable; + getList(options?: RequestOptionsArgs): Observable; + me(options?: RequestOptionsArgs): Observable; + get(userId: number, options?: RequestOptionsArgs): Observable; + create(body: any, options?: RequestOptionsArgs): Observable; + update(userId: number, body: any, options?: RequestOptionsArgs): Observable; + delete(userId: number, options?: RequestOptionsArgs): Observable; } export interface IWpApiTaxonomies { - getList(options?: RequestOptionsArgs): Observable; - get(taxonomiesType: string, options?: RequestOptionsArgs): Observable; + getList(options?: RequestOptionsArgs): Observable; + get(taxonomiesType: string, options?: RequestOptionsArgs): Observable; } export interface IWpApiStatuses { - getList(options?: RequestOptionsArgs): Observable; - get(statusesName: string, options?: RequestOptionsArgs): Observable; + getList(options?: RequestOptionsArgs): Observable; + get(statusesName: string, options?: RequestOptionsArgs): Observable; } export interface IWpApiTerms { - getList(taxonomiesType: string, options?: RequestOptionsArgs): Observable; - get(taxonomiesType: string, termId: number, options?: RequestOptionsArgs): Observable; - create(taxonomiesType: string, body: any, options?: RequestOptionsArgs): Observable; - update(taxonomiesType: string, termId: number, body: any, options?: RequestOptionsArgs): Observable; - delete(taxonomiesType: string, termId: number, options?: RequestOptionsArgs): Observable; + getList(taxonomiesType: string, options?: RequestOptionsArgs): Observable; + get(taxonomiesType: string, termId: number, options?: RequestOptionsArgs): Observable; + create(taxonomiesType: string, body: any, options?: RequestOptionsArgs): Observable; + update(taxonomiesType: string, termId: number, body: any, options?: RequestOptionsArgs): Observable; + delete(taxonomiesType: string, termId: number, options?: RequestOptionsArgs): Observable; } export interface IWpApiCustom { - getList(options?: RequestOptionsArgs): Observable; - get(customId: number, options?: RequestOptionsArgs): Observable; - create(body: any, options?: RequestOptionsArgs): Observable; - update(customId: number, body: any, options?: RequestOptionsArgs): Observable; - delete(customId: number, options?: RequestOptionsArgs): Observable; + getList(options?: RequestOptionsArgs): Observable; + get(customId: number, options?: RequestOptionsArgs): Observable; + create(body: any, options?: RequestOptionsArgs): Observable; + update(customId: number, body: any, options?: RequestOptionsArgs): Observable; + delete(customId: number, options?: RequestOptionsArgs): Observable; } diff --git a/src/wp-api-angular.ts b/src/wp-api-angular.ts index 5d06eec..944aaa2 100644 --- a/src/wp-api-angular.ts +++ b/src/wp-api-angular.ts @@ -1,46 +1,41 @@ -import { - Provider, - NgModule, - ModuleWithProviders -} from '@angular/core'; -import 'rxjs'; -import { Http, HttpModule } from '@angular/http'; +import { HttpClient, HttpClientModule } from "@angular/common/http"; +import { ModuleWithProviders, NgModule } from "@angular/core"; +import "rxjs"; +import { WpApiComments } from "./Comments"; +import { WpApiCustom } from "./Custom"; +import { WpApiLoader, WpApiStaticLoader } from "./Loaders"; +import { WpApiMedia } from "./Media"; +import { WpApiPages } from "./Pages"; +import { WpApiPosts } from "./Posts"; +import { WpApiStatuses } from "./Statuses"; +import { WpApiTaxonomies } from "./Taxonomies"; +import { WpApiTerms } from "./Terms"; +import { WpApiTypes } from "./Types"; +import { WpApiUsers } from "./Users"; -import { WpApiPosts } from './Posts'; -import { WpApiPages } from './Pages'; -import { WpApiComments } from './Comments'; -import { WpApiTypes } from './Types'; -import { WpApiMedia } from './Media'; -import { WpApiUsers } from './Users'; -import { WpApiTaxonomies } from './Taxonomies'; -import { WpApiStatuses } from './Statuses'; -import { WpApiTerms } from './Terms'; -import { WpApiCustom } from './Custom'; -import { WpApiLoader, WpApiStaticLoader } from './Loaders'; -export { WpApiPosts } from './Posts'; -export { WpApiPages } from './Pages'; -export { WpApiComments } from './Comments'; -export { WpApiTypes } from './Types'; -export { WpApiMedia } from './Media'; -export { WpApiUsers } from './Users'; -export { WpApiTaxonomies } from './Taxonomies'; -export { WpApiStatuses } from './Statuses'; -export { WpApiTerms } from './Terms'; -export { WpApiCustom } from './Custom'; -export { WpApiLoader, WpApiStaticLoader } from './Loaders'; +export { WpApiComments } from "./Comments"; +export { WpApiCustom } from "./Custom"; +export { WpApiLoader, WpApiStaticLoader } from "./Loaders"; +export { WpApiMedia } from "./Media"; +export { WpApiPages } from "./Pages"; +export { WpApiPosts } from "./Posts"; +export { WpApiStatuses } from "./Statuses"; +export { WpApiTaxonomies } from "./Taxonomies"; +export { WpApiTerms } from "./Terms"; +export { WpApiTypes } from "./Types"; +export { WpApiUsers } from "./Users"; -export function WpApiLoaderFactory(http: Http) { +export function WpApiLoaderFactory(http: HttpClient) { return new WpApiStaticLoader(http); } +/****************************************************************************** +* Module: WpApiModule +******************************************************************************/ @NgModule({ - imports: [ - HttpModule - ], - exports: [ - HttpModule - ], + imports: [HttpClientModule], + exports: [HttpClientModule], providers: [ WpApiPosts, WpApiPages, @@ -51,20 +46,23 @@ export function WpApiLoaderFactory(http: Http) { WpApiTaxonomies, WpApiStatuses, WpApiTerms, - WpApiCustom - ] + WpApiCustom, + ], }) export class WpApiModule { - static forRoot(providedLoader: any = { - provide: WpApiLoader, - useFactory: WpApiLoaderFactory, - deps: [Http] - }): ModuleWithProviders { + + public static forRoot( + providedLoader: any = { + provide: WpApiLoader, + useFactory: WpApiLoaderFactory, + deps: [HttpClient], + } + ): ModuleWithProviders { + return { ngModule: WpApiModule, - providers: [ - providedLoader - ] + providers: [providedLoader], }; + } }