Skip to content

Bumping to Angular v11 & removing duplicate interfaces #48

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,6 @@ aot/
aot2/
angular2-webpack-starter/
testionic/

# VS code
.vscode
30 changes: 14 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand All @@ -24,39 +24,37 @@
"angularjs",
"rest",
"restfull",
"client"
"client",
"wordpress",
"json"
],
"author": "shprink <[email protected]>",
"license": "MIT",
"bugs": {
"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"
}
}
27 changes: 9 additions & 18 deletions src/Comments.ts
Original file line number Diff line number Diff line change
@@ -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<Response>;
get(commentId: number, options?: RequestOptionsArgs): Observable<Response>;
create(body: any, options?: RequestOptionsArgs): Observable<Response>;
update(commentId: number, body: any, options?: RequestOptionsArgs): Observable<Response>;
delete(commentId: number, options?: RequestOptionsArgs): Observable<Response>;
}

/******************************************************************************
* Service: WpApiComments
******************************************************************************/
@Injectable()
export class WpApiComments extends WpApiParent implements IWpApiComments {

constructor(
public wpApiLoader: WpApiLoader,
public http: Http
public http: HttpClient
) {
super(wpApiLoader, http);
}
Expand Down
32 changes: 10 additions & 22 deletions src/Custom.ts
Original file line number Diff line number Diff line change
@@ -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<Response>;
get(customId: number, options?: RequestOptionsArgs): Observable<Response>;
create(body: any, options?: RequestOptionsArgs): Observable<Response>;
update(customId: number, body: any, options?: RequestOptionsArgs): Observable<Response>;
delete(customId: number, options?: RequestOptionsArgs): Observable<Response>;
}

export class Custom extends WpApiParent implements IWpApiCustom {
constructor(
public wpApiLoader: WpApiLoader,
public http: Http,
public http: HttpClient,
public entityName: string
) {
super(wpApiLoader, http);
Expand All @@ -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`);
}
Expand Down
11 changes: 9 additions & 2 deletions src/Loaders.ts
Original file line number Diff line number Diff line change
@@ -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'
) {
Expand All @@ -18,4 +24,5 @@ export class WpApiStaticLoader implements WpApiLoader {
public getWebServiceUrl(postfix: string): string {
return `${this.completeUrl}${postfix}`
}

}
25 changes: 5 additions & 20 deletions src/Media.ts
Original file line number Diff line number Diff line change
@@ -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<Response>;
get(mediaId: number, options?: RequestOptionsArgs): Observable<Response>;
create(body: any, options?: RequestOptionsArgs): Observable<Response>;
update(mediaId: number, body: any, options?: RequestOptionsArgs): Observable<Response>;
delete(mediaId: number, options?: RequestOptionsArgs): Observable<Response>;
}
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);
}
Expand Down
28 changes: 5 additions & 23 deletions src/Pages.ts
Original file line number Diff line number Diff line change
@@ -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<Response>;
get(pageId: number, options?: RequestOptionsArgs): Observable<Response>;
create(body: any, options?: RequestOptionsArgs): Observable<Response>;
update(pageId: number, body: any, options?: RequestOptionsArgs): Observable<Response>;
delete(pageId: number, options?: RequestOptionsArgs): Observable<Response>;
getMetaList(pageId: number, options?: RequestOptionsArgs): Observable<Response>;
getMeta(pageId: number, metaId: number, options?: RequestOptionsArgs): Observable<Response>;
getRevisionList(pageId: number, options?: RequestOptionsArgs): Observable<Response>;
getRevision(pageId: number, revisionId: number, options?: RequestOptionsArgs): Observable<Response>;
}

@Injectable()
export class WpApiPages extends WpApiParent implements IWpApiPages {
constructor(
public wpApiLoader: WpApiLoader,
public http: Http
public http: HttpClient
) {
super(wpApiLoader, http);
}
Expand Down
28 changes: 8 additions & 20 deletions src/Parent.ts
Original file line number Diff line number Diff line change
@@ -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<Response>;
httpHead(url: string, options?: RequestOptionsArgs): Observable<Response>;
httpDelete(url: string, options?: RequestOptionsArgs): Observable<Response>;
httpPost(url: string, body: any, options?: RequestOptionsArgs): Observable<Response>;
httpPut(url: string, body: any, options?: RequestOptionsArgs): Observable<Response>;
httpPatch(url: string, body: any, options?: RequestOptionsArgs): Observable<Response>;
}

/******************************************************************************
* Service: WpApiParent
******************************************************************************/
@Injectable()
export class WpApiParent implements IParent {

constructor(
public wpApiLoader: WpApiLoader,
public http: Http
public http: HttpClient
) { }

httpGet(url: string, options = {}) {
Expand Down
32 changes: 5 additions & 27 deletions src/Posts.ts
Original file line number Diff line number Diff line change
@@ -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<Response>;
get(postId: number, options?: RequestOptionsArgs): Observable<Response>;
create(body: any, options?: RequestOptionsArgs): Observable<Response>;
update(postId: number, body: any, options?: RequestOptionsArgs): Observable<Response>;
delete(postId: number, options?: RequestOptionsArgs): Observable<Response>;
getMetaList(postId: number, options?: RequestOptionsArgs): Observable<Response>;
getMeta(postId: number, metaId: number, options?: RequestOptionsArgs): Observable<Response>;
getRevisionList(postId: number, options?: RequestOptionsArgs): Observable<Response>;
getRevision(postId: number, revisionId: number, options?: RequestOptionsArgs): Observable<Response>;
getCategoryList(postId: number, options?: RequestOptionsArgs): Observable<Response>;
getCategory(postId: number, categoryId, options?: RequestOptionsArgs): Observable<Response>;
getTagList(postId: number, options?: RequestOptionsArgs): Observable<Response>;
getTag(postId: number, tagId, options?: RequestOptionsArgs): Observable<Response>;
}

@Injectable()
export class WpApiPosts extends WpApiParent implements IWpApiPosts {
constructor(
public wpApiLoader: WpApiLoader,
public http: Http
public http: HttpClient
) {
super(wpApiLoader, http);
}
Expand Down
11 changes: 11 additions & 0 deletions src/RequestOptionsArgs.ts
Original file line number Diff line number Diff line change
@@ -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
}
22 changes: 5 additions & 17 deletions src/Statuses.ts
Original file line number Diff line number Diff line change
@@ -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<Response>;
get(statusesName: string, options?: RequestOptionsArgs): Observable<Response>;
}
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);
}
Expand Down
Loading