Giter VIP home page Giter VIP logo

wpcom.js's Introduction

This repository has moved!

It is now part of the Calypso repository.

The published npm package will continue to be available as before, no changes necessary!

wpcom.js

Official JavaScript library for the WordPress.com REST API. Compatible with Node.js and web browsers.

CircleCI

How to use

Node.js

Introduce the wpcom dependency into your package.json ...

npm install --save wpcom

... and then initialize it with your API token (optional).

// Edit a post on a site
var wpcom = require( 'wpcom' )( '<your-token>' );

wpcom
	.site( 'your-blog.wordpress.com' )
	.postsList( { number: 8 } )
		.then( list => { ... } )
		.catch( error => { ... } );

Browser

Include dist/wpcom.js.

<script src="wpcom.js"></script>
<script>
	var wpcom = WPCOM( '<your-token>' );
	var blog = wpcom.site( 'your-blog.wordpress.com' );
	blog.postsList( { number: 8 } )
		.then( list => { ... } )
		.catch( error => { ... } );
</script>

Authentication

Not all requests require a REST API token. For example, listing posts on a public site is something anyone can do.

If you do need a token, here are some links that will help you generate one:

API

Examples

// Edit a post on a site
var wpcom = require( 'wpcom' )( '<your-token>' );
var blog = wpcom.site( 'your-blog.wordpress.com' );
blog.post( { slug: 'a-post-slug' } ).update( data )
	.then( res => { ... } )
	.catch( err => { ... } );

You can omit the API token for operations that don't require permissions:

// List the last 8 posts on a site
var wpcom = require( 'wpcom' )();
var blog = wpcom.site( 'your-blog.wordpress.com' );
blog.postsList( { number: 8 } )
	.then( list => { ... } )
	.catch( error => { ... } );

More pre-made examples are in the examples/ directory.

Test

The token and site vars must be given to testing scripts either using TOKEN and SITE environment vars respectively or through of a config.json file into test/ folder like bellow:

{
	"site": "<site-id>",
	"token": "<token>"
}

Run tests:

$ make test-all

Also tests can be filtered using make test FILTER=<filter>:

$ make test FILTER=wpcom.site.post

License

MIT โ€“ Copyright 2014 Automattic

wpcom.js's People

Contributors

aduth avatar blowery avatar bluefuton avatar bperson avatar chengfred avatar dmsnell avatar jkudish avatar johngodley avatar jsnajdr avatar lezama avatar marekhrabe avatar mattsherman avatar mjangda avatar nylen avatar okossa avatar oskosk avatar rads avatar rauchg avatar retrofox avatar rralian avatar samouri avatar sirbrillig avatar sirreal avatar skeltoac avatar timmyc avatar tootallnate avatar tug avatar viper007bond avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

wpcom.js's Issues

Get rid of `wpcom+xhr` subclass and put XHR code into a separate module

I've been tripped up by the file structure of this module because it has both an index.js file and a main entry in the package.json. I didn't realize until later the actual entry point is wpcom+xhr.js. This structure also means you have to do some weird stuff to plug in a different request method. Here is my suggestion:

  • Move the logic in wpcom+xhr.js into a separate wpcom-xhr-request module that lives within this package or in its own repo.

  • We can then pass in the request function as a parameter to WPCOM:

    // default xhr method  
    wpcom = require('wpcom')(myToken);
    
    // same thing
    wpcom = require('wpcom')(require('wpcom-xhr-request'));
    
    // add your own
    wpcom = require('wpcom')(require('./my-proxy-request'));
    

Add `domains` endpoints

  • GET /domains/suggestions
  • GET /domains/supported-countries
  • GET /domains/supported-states/%s
  • GET /domains/%s/dns
  • POST /domains/%s/dns/add
  • POST /domains/%s/dns/delete
  • POST /domains/%s/email
  • POST /domains/%s/email/new
  • POST /domains/%s/email/%s/delete
  • GET /domains/%s/google-apps
  • GET /domains/%s/is-available
  • GET /domains/%s/is-mappable
  • GET /domains/%s/nameservers
  • POST /domains/%s/nameservers
  • POST /domains/%s/resend-icann
  • POST /domains/%s/transfer
  • GET /domains/%s/status
  • GET /domains/%s/whois
  • POST /domains/%s/whois
  • GET /domains/%s/%s/can-redirect

Add `ME` methods

Me

  • GET/me
  • GET /me/billing-history
  • GET /me/settings
  • POST /me/settings
  • POST /me/settings/password/validate
  • GET /me/settings/profile-links
  • POST /me/settings/profile-links/new
  • POST /me/settings/profile-links/$slug/delete
  • GET /me/connected-applications
  • GET /me/connected-applications/$ID
  • POST /me/connected-applications/$ID/delete
  • GET /me/two-step
  • POST /me/two-step/sms/new

  • GET /me/sites

  • GET /me/publicize-connections
  • GET /me/publicize-connections/$publicize_connection_ID
  • POST /me/publicize-connections/new
  • POST /me/publicize-connections/$publicize_connection_ID
  • POST /me/publicize-connections/$publicize_connection_ID/delete

  • GET /me/keyring-connectios/
  • GET /me/keyring-connectios/$keyring_connections_ID
  • POST /me/keyring-connectios/$keyring_connections_ID/delete

Call I use this library to display all the users and their avatars on my wp site

I'm trying to see if I can work with this, and the first example I was trying out of the box seems to be given me an error.

<script src="dist/wpcom.js"></script> <script> var wpcom = WPCOM(); var blog = wpcom.site('myblow.wordpress.com'); console.log(blog); blog.posts({ number: 8 },function(err, list) { console.log(list); }); </script>

Any help would be appreciated

Make repo public?

When are we going to make the Repo public? I was planning on using this for my presentation on WordCamp Belo Horizonte, but if it's not public I'll have to do the API requests manually...

Add Support for Stand Alone sites

Add support for stand alone sites.

in request, the url is built with the assumption
var url = proxyOrigin + '/rest/v' + apiVersion + params.path;

This prevents using wpcom.js on standalone sites without hacking.

Implement new "Media" section APIs

From: http://developer.wordpress.com/docs/api/

Perhaps something like:

// create a WPCOM instance
var wpcom = require('wpcom')('<your-token>');

// create a blog handler instance
var blog = wpcom.sites('tootallnate.wordpress.com');

// create media object handler instance for blog
var media = blog.media();

// get all media objects metadata
media.get(function(err, array){
  // ...
});

// get media object metadata for a specific "media_ID"
media.get({ mediaId: 'asdfasfd' }, function(err, info){
  // ...
});

Cannot resolve module fs

Hello!

I ran into this error just after installing the wpcom lib (via npm) and trying to bundle it using webpack:

ERROR in ./~/wpcom/dist/lib/site.media.js
Module not found: Error: Cannot resolve module 'fs' in /Users/xxx/client/node_modules/wpcom/dist/lib
 @ ./~/wpcom/dist/lib/site.media.js 4:9-22

Note this error disappear if I install the fsmodule via npm

post.author object

I noticed that when I use the WPCOM to read post from a Wordpress blog, the post.author object contains a property: login.

Is this the login name that the user uses to login to his blog? and if it is, is it smart to distribute that to anyone?

Cannot `npm install wpcom`

$ npm install --save wpcom
npm WARN package.json @ No description
npm WARN package.json @ No repository field.
npm WARN package.json @ No README data
|
> [email protected] postinstall /Users/james/code/wpcom/new-sites/node_modules/wpcom
> make babelify

module.js:338
    throw err;
          ^
Error: Cannot find module '/Users/james/code/wpcom/new-sites/node_modules/wpcom/node_modules/.bin/babel'
    at Function.Module._resolveFilename (module.js:336:15)
    at Function.Module._load (module.js:278:25)
    at Function.Module.runMain (module.js:501:10)
    at startup (node.js:129:16)
    at node.js:814:3
make: *** [babelify] Error 1
npm ERR! Darwin 14.5.0
npm ERR! argv "node" "/usr/local/bin/npm" "install" "--save" "wpcom"
npm ERR! node v0.12.0
npm ERR! npm  v2.5.1
npm ERR! code ELIFECYCLE

npm ERR! [email protected] postinstall: `make babelify`
npm ERR! Exit status 2
npm ERR! 
npm ERR! Failed at the [email protected] postinstall script 'make babelify'.
npm ERR! This is most likely a problem with the wpcom package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     make babelify
npm ERR! You can get their info via:
npm ERR!     npm owner ls wpcom
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /Users/james/code/wpcom/new-sites/npm-debug.log

๐Ÿ˜ž

Error on wpcom module import

Hello,

I ran over an issue when trying to import the wpcom as a module. When I type this:

const wpcom = require('wpcom')()

the browser raise this error:

TypeError: list.forEach is not a function. (In 'list.forEach', 'list.forEach' is undefined)

For information, I've tested it on Chrome & Safari and I use Webpack, ES6 & Babel for my projects.

Question regarding use without using Wordpress.com as host

Is there a way to use this client without using wordpress.com as a host? Do we just need to install Jetpack and it should all work? Sorry for a lazy issue, but I don't have time to test at the moment and are spec'ing out a new project and this came about.

send-request throws error if no query/body supplied for POST

Due to the check currently on line 44

if (query.apiVersion) {

in lib/util/send-request.js, this library can sometimes throw an error. If null is passed as the query (body) to a POST request for example, then this line throws an error:

Uncaught TypeError: Cannot read property 'apiVersion' of null

We probably want to confirm query in addition to query.apiVersion here.

Endpoints

For each endpoint:

  • Implement method
  • Add test
  • Document it

Users

  • GET /sites/$site/users
  • GET/me

Site

  • GET/sites/$site
  • GET /sites/$site/posts/
  • GET /sites/$site/posts/$post_ID
  • POST /sites/$site/posts/$post_ID
  • GET /sites/$site/posts/slug:$post_slug
  • POST /sites/$site/posts/new
  • POST /sites/$site/posts/$post_ID/delete
  • GET /sites/$site/posts/$post_ID/likes/
  • POST /sites/$site/posts/$post_ID/likes/new
  • POST /sites/$site/posts/$post_ID/likes/mine/delete
  • GET /sites/$site/posts/$post_ID/likes/mine/
  • GET /sites/$site/posts/$post_ID/reblogs/mine
  • POST /sites/$site/posts/$post_ID/reblogs/new
  • POST /sites/$site/posts/$post/related

Comments

  • GET /sites/$site/comments/
  • GET /sites/$site/posts/$post_ID/replies/
  • GET /sites/$site/comments/$comment_ID
  • POST /sites/$site/comments/$comment_ID
  • POST /sites/$site/posts/$post_ID/replies/new
  • POST /sites/$site/comments/$comment_ID/replies/new
  • POST /sites/$site/comments/$comment_ID/delete

Taxonomy

  • GET /sites/$site/categories/slug:$category
  • POST /sites/$site/categories/slug:$category
  • GET /sites/$site/categories
  • GET /sites/$site/tags
  • GET /sites/$site/tags/slug:$tag
  • POST /sites/$site/tags/slug:$tag
  • POST /sites/$site/categories/new
  • POST /sites/$site/tags/new
  • POST /sites/$site/categories/slug:$category/delete
  • POST /sites/$site/tags/slug:$tag/delete

Follow

  • GET /sites/$site/follows/
  • POST /sites/$site/follows/new
  • POST /sites/$site/follows/mine/delete
  • GET /sites/$site/follows/mine

Freshly Pressed

  • GET /freshly-pressed/

Notifications

  • GET /notifications/
  • GET /notifications/$note_ID
  • POST /notifications/seen
  • POST /notifications/read

Insights

  • GET /insights
  • GET /insights/$slug

Reader

  • GET /read/menu/
  • GET /read/following/
  • GET /read/liked/
  • GET /read/tags/$tag/posts
  • GET /read/tags
  • GET /read/tags/$tag
  • GET /read/tags/$tag/mine
  • POST /read/tags/$tag/mine/new
  • POST /read/tags/$tag/mine/delete
  • GET /read/following/mine
  • POST /read/following/mine/new
  • POST /read/following/mine/delete
  • GET /read/recommendations/mine/

Stats

  • GET /sites/$site/stats
  • GET /sites/$site/stats/visits
  • GET /sites/$site/stats/referrers
  • GET /sites/$site/stats/top-posts
  • GET /sites/$site/stats/country-views
  • GET /sites/$site/stats/clicks
  • GET /sites/$site/stats/search-terms

Media

  • GET /sites/$site/media
  • GET /sites/$site/media/$media_ID
  • POST /sites/$site/media/$media_ID
  • POST /sites/$site/media/new
  • POST /sites/$site/media/delete

Batch

  • GET /batch/

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.