Skip to content
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

Made the requested changes to pull request 11 #51

Closed
wants to merge 2 commits into from
Closed
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
21 changes: 21 additions & 0 deletions lib/fields.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,27 @@ maps.labels = createFieldMaps({
viewItem: "view_item"
});

maps.user = createFieldMaps({
bio: /* string */ "bio",
displayName: /* string */ "display_name",
email: /* string */ "email",
firstName: /* string */ "first_name",
id: /* string */ "user_id",
lastName: /* string */ "last_name",
nicename: /* string */ "nicename",
nickname: /* string */ "nickname",
registered: /* datetime */ "registered",
roles: /* string */ "roles",
url: /* string */ "url",
userName: /* string */ "username"
});

maps.author = createFieldMaps({
blogId: /* string */ "blog_id",
displayName: /* string */ "display_name",
userLogin: /* string */ "user_login"
});

maps.post = createFieldMaps({
author: /* int */ "post_author",
commentStatus: /* string */ "comment_status",
Expand Down
87 changes: 87 additions & 0 deletions lib/wordpress.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,93 @@ extend( Client.prototype, {
}
});

extend( Client.prototype, {
getUser: function( id, fields, fn ) {
if ( typeof fields === "function" ) {
fn = fields;
fields = null;
}

if ( fields ) {
fields = fieldMap.array( fields, "user" );
}

this.authenticatedCall( "wp.getUser", id, fields, function( error, user ) {
if ( error ) {
return fn( error );
}

fn( null, fieldMap.from( user, "user" ) );
});
},

getUsers: function( filter, fields, fn ) {
if ( typeof filter === "function" ) {
fn = filter;
fields = null;
filter = {};
}

if ( typeof fields === "function" ) {
fn = fields;
fields = null;
}

if ( filter.orderby ) {
filter.orderby = fieldMap.array( [ filter.orderby ], "user" )[ 0 ];
}

if ( fields ) {
fields = fieldMap.array( fields, "user" );
}

this.authenticatedCall( "wp.getUsers", filter, fields, function( error, users ) {
if ( error ) {
return fn( error );
}

fn( null, users.map(function( user ) {
return fieldMap.from( user, "user" );
}));
});
},

getProfile: function( fields, fn ) {
if ( typeof fields === "function" ) {
fn = fields;
fields = null;
}

if ( fields ) {
fields = fieldMap.from( fields, "user" );
}

this.authenticatedCall( "wp.getProfile", fields, function( error, user ) {
if ( error ) {
return fn( error );
}

fn( null, fieldMap.from( user, "user" ) );
});
},

editProfile: function( data, fn ) {
this.authenticatedCall( "wp.editProfile", fieldMap.to( data, "user" ), fn );
},

getAuthors: function( fn ) {
this.authenticatedCall( "wp.getAuthors", function( error, authors ) {
if ( error ) {
return fn( error );
}

fn( null, authors.map(function( author ) {
return fieldMap.from( author, "author" );
}));
});
}
});

module.exports = {
Client: Client,

Expand Down
52 changes: 52 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,38 @@ Uploads a file to Wordpress.
* `callback` (`function( error, file )`): A callback to invoke when the API call is complete.
* `file`: An object containing the file data.

### Users

#### client.getUser( id [,fields], callback )

* `id`: The ID of the user to get.
* `fields`: (optional): An array of fields to return.
* `callback` (`function( error, user )`): A callback to invoke when the API call is complete.
* `user`: An object containing the user data.

#### client.getUsers( [filter] [, fields], callback )

* `filter`: (optional): A hash of key/value pairs for filtering which users to get.
* `fields`: (optional): An array of fields to return.
* `callback`: (`function( error, users )`): A callback to invoke when the API call is complete.
* `users`: An array containing the users.

#### client.getProfile( [fields], callback )

* `fields`: (optional): An array of fields to return.
* `callback`: (`function( error, profile )`): A callback to invoke when the API call is complete.
* `profile`: An object containing the profile data.

#### client.editProfile( data, callback )

* `data`: The data to update the profile
* `callback`: (`function( error )`): A callback to invoke when the API call is complete.

#### client.getAuthors( callback )

* `callback`: (`function( error, authors )`): A callback to invoke when the API call is complete.
* `authors`: An array containing the authors.

### Utilities

#### client.listMethods( callback )
Expand Down Expand Up @@ -357,6 +389,26 @@ Invokes a method with the username and password provided by the client.
* termId
* termTaxonomyId

#### Users

* bio
* displayName
* email
* firstName
* id
* lastName
* nicename
* nickname
* registered
* roles
* url
* userName

##### Authors

* blogId
* displayName
* userLogin


## License
Expand Down