File tree Expand file tree Collapse file tree 11 files changed +418
-30
lines changed Expand file tree Collapse file tree 11 files changed +418
-30
lines changed Original file line number Diff line number Diff line change 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.
5
+
6
+ ## Services
7
+
8
+ ### WpApiProvider
9
+
10
+ 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 )
11
+
12
+ ```
13
+ .config(function(WpApiProvider) {
14
+ var RestangularProvider = WpApiProvider.getRestangularProvider();
15
+ RestangularProvider.setBaseUrl('/api/v1');
16
+ });
17
+ ```
18
+
19
+ ### Posts ``` $wpApiPosts ```
20
+
21
+ ```
22
+ $wpApiPosts.$getList();
23
+ $wpApiPosts.$get(id);
24
+
25
+ # DOES NOT WORK FOR NOW
26
+ $wpApiPosts.$create();
27
+ ```
28
+
29
+ ### Media ``` $wpApiMedia ```
30
+
31
+ ```
32
+ $wpApiMedia.$getList();
33
+ $wpApiMedia.$get(id);
34
+
35
+ # DOES NOT WORK FOR NOW
36
+ $wpApiMedia.$create();
37
+ ```
38
+
39
+ ### Users ``` $wpApiUsers ```
40
+
41
+ Requires [ authentication] ( http://wp-api.org/guides/authentication.html )
42
+
43
+ ```
44
+ $wpApiUsers.$getList();
45
+ $wpApiUsers.$get(id);
46
+ $wpApiUsers.$getMe();
47
+
48
+ # DOES NOT WORK FOR NOW
49
+ $wpApiMedia.$create();
50
+ ```
51
+
52
+ ### Taxonomies ``` $wpApiTaxonomies ```
53
+
54
+ ```
55
+ $wpApiTaxonomies.$getList();
56
+ $wpApiTaxonomies.$get(taxonomy);
57
+ $wpApiTaxonomies.$getTermList(taxonomy);
58
+ $wpApiTaxonomies.$getTerm(taxonomy, id);
59
+ ```
60
+
61
+ ## Contribute
4
62
5
63
```
6
64
sudo npm install webpack webpack-dev-server -g
Original file line number Diff line number Diff line change
1
+ module . exports = angular . module ( 'wp-api-angularjs.provider' , [
2
+ 'restangular'
3
+ ] ) . provider ( 'WpApi' , function WpApiProvider ( RestangularProvider ) {
4
+ var restangularProvider = RestangularProvider ;
5
+
6
+ this . getRestangularProvider = function ( ) {
7
+ return restangularProvider ;
8
+ } ;
9
+
10
+ this . $get = function ( ) {
11
+ return restangularProvider ;
12
+ } ;
13
+ } ) ;
Original file line number Diff line number Diff line change
1
+ module . exports = angular
2
+ . module ( 'wp-api-angularjs.services.media' , [ 'restangular' ] )
3
+ . factory ( '$wpApiMedia' , function ( Restangular ) {
4
+ var media = Restangular . service ( 'media' ) ;
5
+
6
+ media . $getList = getList ;
7
+ media . $get = get ;
8
+ media . $create = create ;
9
+
10
+ return media ;
11
+
12
+ function getList ( ) {
13
+ return media . getList ( ) ;
14
+ }
15
+
16
+ function get ( id ) {
17
+ return media . one ( id ) . get ( ) ;
18
+ }
19
+
20
+ function create ( object ) {
21
+ return media . post ( object ) ;
22
+ }
23
+ } ) ;
Original file line number Diff line number Diff line change 1
1
module . exports = angular
2
- . module ( 'wp-api-angularjs.services.posts' , [ ] )
3
- . factory ( '$wpApiPosts' , function ( $log , Restangular ) {
4
- return Restangular . service ( 'posts' ) ;
2
+ . module ( 'wp-api-angularjs.services.posts' , [ 'restangular' ] )
3
+ . factory ( '$wpApiPosts' , function ( Restangular ) {
4
+ var posts = Restangular . service ( 'posts' ) ;
5
+
6
+ posts . $getList = getList ;
7
+ posts . $get = get ;
8
+ posts . $create = create ;
9
+
10
+ return posts ;
11
+
12
+ function getList ( ) {
13
+ return posts . getList ( ) ;
14
+ }
15
+
16
+ function get ( id , query ) {
17
+ var query = query || { } ;
18
+ return posts . one ( id ) . get ( query ) ;
19
+ }
20
+
21
+ function create ( object ) {
22
+ return posts . post ( object ) ;
23
+ }
5
24
} ) ;
Original file line number Diff line number Diff line change 1
1
module . exports = angular . module ( 'wp-api-angularjs.services' , [
2
- require ( './Posts' ) . name
2
+ require ( './Posts' ) . name ,
3
+ require ( './Media' ) . name ,
4
+ require ( './Users' ) . name ,
5
+ require ( './Taxonimies' ) . name
3
6
] ) ;
Original file line number Diff line number Diff line change
1
+ module . exports = angular
2
+ . module ( 'wp-api-angularjs.services.taxonomies' , [ 'restangular' ] )
3
+ . factory ( '$wpApiTaxonomies' , function ( Restangular ) {
4
+ var taxonomies = Restangular . service ( 'taxonomies' ) ;
5
+
6
+ taxonomies . $getList = getList ;
7
+ taxonomies . $get = get ;
8
+ taxonomies . $getTermList = getTerms ;
9
+ taxonomies . $getTerm = getTerm ;
10
+
11
+ return taxonomies ;
12
+
13
+ function getList ( ) {
14
+ return taxonomies . getList ( ) ;
15
+ }
16
+
17
+ function get ( taxonomy ) {
18
+ return taxonomies . one ( taxonomy ) . get ( ) ;
19
+ }
20
+
21
+ function getTerms ( taxonomy ) {
22
+ return taxonomies . one ( taxonomy ) . getList ( 'terms' ) ;
23
+ }
24
+
25
+ function getTerm ( taxonomy , id ) {
26
+ return taxonomies . one ( taxonomy ) . one ( 'terms' , id ) . get ( ) ;
27
+ }
28
+ } ) ;
Original file line number Diff line number Diff line change
1
+ module . exports = angular
2
+ . module ( 'wp-api-angularjs.services.users' , [ 'restangular' ] )
3
+ . factory ( '$wpApiUsers' , function ( Restangular ) {
4
+ var users = Restangular . service ( 'users' ) ;
5
+
6
+ users . $getList = getList ;
7
+ users . $get = get ;
8
+ users . $getMe = getMe ;
9
+ users . $create = create ;
10
+
11
+ return users ;
12
+
13
+ function getList ( ) {
14
+ return users . getList ( ) ;
15
+ }
16
+
17
+ function get ( id ) {
18
+ return users . one ( id ) . get ( ) ;
19
+ }
20
+
21
+ function getMe ( ) {
22
+ return get ( 'me' ) ;
23
+ }
24
+
25
+ function create ( object ) {
26
+ return users . post ( object ) ;
27
+ }
28
+ } ) ;
Original file line number Diff line number Diff line change 1
1
module . exports = angular . module ( 'wp-api-angularjs' , [
2
- 'restangular' ,
2
+ require ( './Provider' ) . name ,
3
3
require ( './Rest/Services' ) . name
4
- ] ) . config ( function ( RestangularProvider ) {
5
- RestangularProvider . setBaseUrl ( 'http://shprinkone.julienrenaux.fr/wp-json' ) ;
6
- RestangularProvider . setRestangularFields ( {
7
- id : "ID"
8
- } ) ;
9
- } ) ;
4
+ ] ) ;
You can’t perform that action at this time.
0 commit comments