Skip to content

Commit 4bf8088

Browse files
committed
Merge branch 'release/3.0.0-alpha1' into develop
2 parents d1b61e4 + f89a6f9 commit 4bf8088

File tree

94 files changed

+1727
-21147
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+1727
-21147
lines changed

.editorconfig

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# EditorConfig helps developers define and maintain consistent
2+
# coding styles between different editors and IDEs
3+
# editorconfig.org
4+
5+
root = true
6+
7+
[*]
8+
9+
# Change these settings to your own preference
10+
indent_style = space
11+
indent_size = 2
12+
13+
# We recommend you to keep these unchanged
14+
end_of_line = lf
15+
charset = utf-8
16+
trim_trailing_whitespace = true
17+
insert_final_newline = true
18+
19+
[*.md]
20+
trim_trailing_whitespace = false

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,4 @@ node_modules
2929

3030
www/
3131
config.json
32+
typings

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<a name="3.0.0-alpha1"></a>
2+
### 3.0.0-alpha1 (2016-07-23)
3+
4+
First version for ng2.

README.md

+149-49
Original file line numberDiff line numberDiff line change
@@ -1,96 +1,196 @@
11
wp-api-angularjs
22
================
33

4-
AngularJS services to consume [WP-API v2](http://v2.wp-api.org/)
4+
Angular2 services to consume [WP-API v2](http://v2.wp-api.org/) (< 2.5kb gziped)
55

6-
## Documentation
7-
8-
<http://shprink.github.io/wp-api-angularjs/>
6+
If you want to use AngularJS v1, here is the latest version: [v2.0.0-rc3](https://github.com/shprink/wp-api-angularjs/tree/v2.0.0-rc3)
97

108
## Installation
119

12-
### npm
10+
### Dependencies
1311

14-
```
15-
npm install wp-api-angularjs
16-
```
12+
make sure you have those packages installed:
1713

18-
then import the dist file
14+
- '@angular/core'
15+
- '@angular/http'
16+
- 'rxjs'
1917

20-
```
21-
# ES5
22-
require('wp-api-angularjs');
18+
### via npm
2319

24-
# or ES6
25-
import 'wp-api-angularjs';
20+
```shell
21+
npm install wp-api-angularjs@v3.0.x
2622
```
2723

28-
### Bower
24+
## Bootstrap
2925

30-
```
31-
bower install shprink/wp-api-angularjs
32-
```
3326

34-
## Setup
27+
```js
28+
import {
29+
WPAPI_PROVIDERS,
30+
defaultWpApi
31+
} from 'wp-api-angularjs';
3532

36-
To setup wp-api-angularjs in your app:
33+
import {App} from './app';
34+
35+
bootstrap(App, [
36+
WPAPI_PROVIDERS,
37+
defaultWpApi({
38+
baseUrl: "http://YOUR_DOMAIN/wp-json/",
39+
namespace: '/wp/v2' // (optional, default: '/wp/v2')
40+
})
41+
]);
3742

3843
```
39-
var app = angular.module('app', ['wp-api-angularjs']);
4044

41-
app.config(function (WpApiProvider) {
42-
WpApiProvider.setBaseUrl('http://www.example.com/wp-json/');
43-
});
45+
## API
4446

45-
app.controller('PostsController', ['$scope', '$wpApiPosts', PostsController]);
47+
Every method return an Obervable. If you want to get a Promise you will need to add the rxjs `toPromise` operator:
4648

47-
function PostsController($scope, $wpApiPosts) {
48-
$scope.posts = [];
49+
```js
50+
import 'rxjs/add/operator/toPromise';
4951

50-
$wpApiPosts.getList({
51-
page: 1,
52-
per_page: 10
53-
}).then(function (posts) {
54-
$scope.posts = posts.data;
55-
});
52+
class Test {
53+
constructor(private wpApiPosts: WpApiPosts) {
54+
this.wpApiPosts.getList()
55+
.toPromise()
56+
.then(response => response.json())
57+
.then(body => {})
58+
.catch(error => {})
59+
}
5660
}
5761

62+
```
5863

64+
### RequestOptionsArgs
65+
66+
Every request can have an optional [`RequestOptionsArgs`](https://angular.io/docs/ts/latest/api/http/index/RequestOptionsArgs-interface.html) object.
67+
68+
```js
69+
class RequestOptionsArgs {
70+
url : string
71+
method : string|RequestMethod
72+
search : string|URLSearchParams
73+
headers : Headers
74+
body : any
75+
withCredentials : boolean
76+
}
5977
```
6078

61-
## Authentication
79+
This is where you can add query string to your request or change the headers.
80+
81+
### WpApiPosts
82+
83+
```ts
84+
getList(options?: RequestOptionsArgs): Observable<Response>;
85+
get(postId, options?: RequestOptionsArgs): Observable<Response>;
86+
create(body: any, options?: RequestOptionsArgs): Observable<Response>;
87+
update(postId, body: any, options?: RequestOptionsArgs): Observable<Response>;
88+
delete(postId, options?: RequestOptionsArgs): Observable<Response>;
89+
getMetaList(postId, options?: RequestOptionsArgs): Observable<Response>;
90+
getMeta(postId, metaId, options?: RequestOptionsArgs): Observable<Response>;
91+
getRevisionList(postId, options?: RequestOptionsArgs): Observable<Response>;
92+
getRevision(postId, revisionId, options?: RequestOptionsArgs): Observable<Response>;
93+
getCategoryList(postId, options?: RequestOptionsArgs): Observable<Response>;
94+
getCategory(postId, categoryId, options?: RequestOptionsArgs): Observable<Response>;
95+
getTagList(postId, options?: RequestOptionsArgs): Observable<Response>;
96+
getTag(postId, tagId, options?: RequestOptionsArgs): Observable<Response>;
97+
```
98+
99+
### WpApiPages
100+
101+
```ts
102+
getList(options?: RequestOptionsArgs): Observable<Response>;
103+
get(pageId: number, options?: RequestOptionsArgs): Observable<Response>;
104+
create(body: any, options?: RequestOptionsArgs): Observable<Response>;
105+
update(pageId: number, body: any, options?: RequestOptionsArgs): Observable<Response>;
106+
delete(pageId: number, options?: RequestOptionsArgs): Observable<Response>;
107+
getMetaList(pageId: number, options?: RequestOptionsArgs): Observable<Response>;
108+
getMeta(pageId: number, metaId: number, options?: RequestOptionsArgs): Observable<Response>;
109+
getRevisionList(pageId: number, options?: RequestOptionsArgs): Observable<Response>;
110+
getRevision(pageId: number, revisionId: number, options?: RequestOptionsArgs): Observable<Response>;
111+
```
62112
63-
This library only supports basic auth. OAuth1 not being suitable for JS clients (it would mean exposing key and password out of the open)
113+
### WpApiComments
64114
65-
### Basic auth
115+
```ts
116+
getList(options?: RequestOptionsArgs): Observable<Response>;
117+
get(commentId: number, options?: RequestOptionsArgs): Observable<Response>;
118+
create(body: any, options?: RequestOptionsArgs): Observable<Response>;
119+
update(commentId: number, body: any, options?: RequestOptionsArgs): Observable<Response>;
120+
delete(commentId: number, options?: RequestOptionsArgs): Observable<Response>;
121+
```
122+
123+
### WpApiTypes
66124
67-
Basic auth is only secured to use if used during the app run time and used with a secured connection to your Blog (via SSL).
125+
```ts
126+
getList(options?: RequestOptionsArgs): Observable<Response>;
127+
get(postType: string, options?: RequestOptionsArgs): Observable<Response>;
128+
```
68129
69-
#### During run time
130+
### WpApiMedia
70131
71-
Make sure your WP-API runs with an SSL certificate (https) otherwise this will expose your credentials at every request.
132+
```ts
133+
getList(options?: RequestOptionsArgs): Observable<Response>;
134+
get(mediaId: number, options?: RequestOptionsArgs): Observable<Response>;
135+
create(body: any, options?: RequestOptionsArgs): Observable<Response>;
136+
update(mediaId: number, body: any, options?: RequestOptionsArgs): Observable<Response>;
137+
delete(mediaId: number, options?: RequestOptionsArgs): Observable<Response>;
138+
```
72139
73-
Display a form for users to connect and use the following code to register credentials:
140+
### WpApiUsers
74141
142+
```ts
143+
getList(options?: RequestOptionsArgs): Observable<Response>;
144+
me(options?: RequestOptionsArgs): Observable<Response>;
145+
get(userId: number, options?: RequestOptionsArgs): Observable<Response>;
146+
create(body: any, options?: RequestOptionsArgs): Observable<Response>;
147+
update(userId: number, body: any, options?: RequestOptionsArgs): Observable<Response>;
148+
delete(userId: number, options?: RequestOptionsArgs): Observable<Response>;
75149
```
76-
.controller(function(WpApi){
77-
WpApi.setBasicCredentials(<login>, <password>);
78-
});
150+
151+
### WpApiTaxonomies
152+
153+
```ts
154+
getList(options?: RequestOptionsArgs): Observable<Response>;
155+
get(taxonomiesType: string, options?: RequestOptionsArgs): Observable<Response>;
79156
```
80157
81-
#### During configuration
158+
### WpApiStatuses
159+
160+
```ts
161+
getList(options?: RequestOptionsArgs): Observable<Response>;
162+
get(statusesName: string, options?: RequestOptionsArgs): Observable<Response>;
163+
```
82164
83-
You can also set basic credentials during the configuration but use this should only be used for testing as it embed credentials in the application code.
165+
### WpApiTerms
84166
167+
`taxonomiesType` can be `tags`, `categories` and more.
168+
169+
```ts
170+
getList(taxonomiesType: string, options?: RequestOptionsArgs): Observable<Response>;
171+
get(taxonomiesType: string, termId: number, options?: RequestOptionsArgs): Observable<Response>;
172+
create(taxonomiesType: string, body: any, options?: RequestOptionsArgs): Observable<Response>;
173+
update(taxonomiesType: string, termId: number, body: any, options?: RequestOptionsArgs): Observable<Response>;
174+
delete(taxonomiesType: string, termId: number, options?: RequestOptionsArgs): Observable<Response>;
85175
```
86-
.config(function(WpApiProvider){
87-
WpApiProvider.setBasicCredentials(<login>, <password>);
88-
});
176+
177+
### WpApiCustom
178+
179+
```ts
180+
getList(options?: RequestOptionsArgs): Observable<Response>;
181+
get(customId: number, options?: RequestOptionsArgs): Observable<Response>;
182+
create(body: any, options?: RequestOptionsArgs): Observable<Response>;
183+
update(customId: number, body: any, options?: RequestOptionsArgs): Observable<Response>;
184+
delete(customId: number, options?: RequestOptionsArgs): Observable<Response>;
89185
```
90186
187+
## Authentication
188+
189+
TO BE DEFINED
190+
91191
## Contribute
92192
93-
```
193+
```shell
94194
npm install
95195
cp config.dist.json config.json
96196

bower.json

-14
This file was deleted.

0 commit comments

Comments
 (0)