|
1 | 1 | wp-api-angularjs |
2 | 2 | ================ |
3 | 3 |
|
4 | | -wp-api-angularjs is under development and will only cover GET methods of the [WP-API](https://github.com/WP-API/WP-API) master branch. |
| 4 | +AngularJS services to consume [WP-API v2](http://v2.wp-api.org/) |
5 | 5 |
|
6 | | -## Install |
| 6 | +## Documentation |
7 | 7 |
|
8 | | -include the bundled version ```wp-api-angularjs.bundle.js``` (Contains underscore and Restangular) and add the library to your dependencies: |
| 8 | +<http://shprink.github.io/wp-api-angularjs/> |
9 | 9 |
|
10 | | -``` |
11 | | -angular.module('myApp', ['wp-api-angularjs']); |
12 | | -``` |
13 | | - |
14 | | -## Services |
15 | | - |
16 | | -### WpApiProvider |
17 | | - |
18 | | -wp-api-angularjs is based on Restangular therefore you can use any of the [Restangular Provider methods](https://github.com/mgonto/restangular/tree/1.4.0#configuring-in-the-config) |
| 10 | +## oAuth1 |
19 | 11 |
|
20 | | -``` |
21 | | -.config(function(WpApiProvider) { |
22 | | - var RestangularProvider = WpApiProvider.getRestangularProvider(); |
23 | | - RestangularProvider.setBaseUrl('/api/v1'); |
24 | | -}); |
25 | | -``` |
26 | | - |
27 | | -wp-api-angularjs always returns promises: |
28 | | - |
29 | | -``` |
30 | | -$wpApiPosts.$get(id).then(function(post) { |
31 | | - // OK |
32 | | - }).catch(function() { |
33 | | - // KO |
34 | | - }); |
35 | | -``` |
| 12 | +<http://v2.wp-api.org/guide/authentication/> |
36 | 13 |
|
37 | | -### Posts ```$wpApiPosts``` |
| 14 | +### Install OAuth1 plugin |
38 | 15 |
|
39 | | -``` |
40 | | -// Get latests posts |
41 | | -$wpApiPosts.$getList(); |
42 | | -
|
43 | | -// Get filtered posts |
44 | | -$wpApiPosts.$getList({ |
45 | | - "page" : 2, |
46 | | - "filter[category_name]": "uncategorized", |
47 | | - "filter[posts_per_page]": 5, |
48 | | - "filter[orderby]": "date", |
49 | | - "filter[order]": "desc", |
50 | | - "filter[post_status]": "publish" |
51 | | -}); |
52 | | -
|
53 | | -$wpApiPosts.$get(id); |
54 | | -
|
55 | | -# DOES NOT WORK FOR NOW |
56 | | -$wpApiPosts.$create(); |
57 | | -``` |
| 16 | +Export <https://github.com/WP-API/OAuth1> zip and upload it into your WP instance. |
58 | 17 |
|
59 | | -### Media ```$wpApiMedia``` |
| 18 | +### Install WP-CLI |
60 | 19 |
|
61 | 20 | ``` |
62 | | -$wpApiMedia.$getList(); |
63 | | -$wpApiMedia.$get(id); |
64 | | -
|
65 | | -# DOES NOT WORK FOR NOW |
66 | | -$wpApiMedia.$create(); |
| 21 | +curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar |
| 22 | +chmod +x wp-cli.phar |
| 23 | +sudo mv wp-cli.phar /usr/local/bin/wp |
67 | 24 | ``` |
68 | 25 |
|
69 | | -### Users ```$wpApiUsers``` |
70 | | - |
71 | | -Requires [authentication](http://wp-api.org/guides/authentication.html) |
| 26 | +More info: <http://wp-cli.org/> |
72 | 27 |
|
73 | | -``` |
74 | | -$wpApiUsers.$getList(); |
75 | | -$wpApiUsers.$get(id); |
76 | | -$wpApiUsers.$getMe(); |
| 28 | +### Create a consumer: |
77 | 29 |
|
78 | | -# DOES NOT WORK FOR NOW |
79 | | -$wpApiMedia.$create(); |
80 | 30 | ``` |
| 31 | +$ wp oauth1 add |
81 | 32 |
|
82 | | -### Taxonomies ```$wpApiTaxonomies``` |
83 | | - |
84 | | -``` |
85 | | -$wpApiTaxonomies.$getList(); |
86 | | -$wpApiTaxonomies.$get(taxonomy); |
87 | | -$wpApiTaxonomies.$getTermList(taxonomy); |
88 | | -$wpApiTaxonomies.$getTerm(taxonomy, id); |
| 33 | +ID: 4 |
| 34 | +Key: sDc51JgH2mFu |
| 35 | +Secret: LnUdIsyhPFnURkatekRIAUfYV7nmP4iF3AVxkS5PRHPXxgOW |
89 | 36 | ``` |
90 | 37 |
|
91 | 38 | ## Contribute |
92 | 39 |
|
93 | 40 | ``` |
94 | | -sudo npm install webpack webpack-dev-server -g |
95 | 41 | npm install |
96 | | -webpack-dev-server |
| 42 | +cp config.dist.json config.json |
| 43 | +
|
| 44 | +# Open two terminals |
| 45 | +# and run watch to build on the lib files changes |
| 46 | +npm run watch |
| 47 | +
|
| 48 | +# in the other terminal run following to build the test page and the doc |
| 49 | +npm run devserver |
97 | 50 | ``` |
98 | 51 |
|
99 | | -Open ```http://localhost:8080/test.html``` |
| 52 | +Open ```http://localhost:8080``` |
0 commit comments