-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #144 from Automattic/add/site-wordads-endpoints
Add site.wordAds() stuff
- Loading branch information
Showing
8 changed files
with
519 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/** | ||
* `SiteWordAdsEarnings` constructor. | ||
* | ||
* *Example:* | ||
* // Require `wpcom-unpublished` library | ||
* import wpcomUnpublished from 'wpcom-unpublished'; | ||
* | ||
* // Create a `wpcomUnpublished` instance | ||
* var wpcom = wpcomUnpublished(); | ||
* | ||
* // Create a `SiteWordAdsEarnings` instance | ||
* var wordAds = wpcom | ||
* .site( 'my-blog.wordpress.com' ) | ||
* .wordAds() | ||
* .earnings(); | ||
* | ||
* | ||
* @param {String} sid - site identifier | ||
* @param {WPCOM} wpcom - wpcom instance | ||
* @return {Null} null | ||
*/ | ||
function SiteWordAdsEarnings( sid, wpcom ) { | ||
if ( ! ( this instanceof SiteWordAdsEarnings ) ) { | ||
return new SiteWordAdsEarnings( sid, wpcom ); | ||
} | ||
|
||
this._sid = sid; | ||
this.wpcom = wpcom; | ||
} | ||
|
||
/** | ||
* Get detailed WordAds earnings information about the site. | ||
* | ||
* *Example:* | ||
* // Get site earnings information | ||
* wpcom | ||
* .site( 'my-blog.wordpress.com' ) | ||
* .wordAds() | ||
* .earnings() | ||
* .get( function( err, data ) { | ||
* // `earnings` information object | ||
* } ); | ||
* | ||
* @param {Object} [query] - query object parameter | ||
* @param {Function} fn - callback function | ||
* @return {Function} request handler | ||
*/ | ||
SiteWordAdsEarnings.prototype.get = function( query, fn ) { | ||
return this.wpcom.req.get( '/sites/' + this._sid + '/wordads/earnings', query, fn ); | ||
}; | ||
|
||
/** | ||
* Expose `SiteWordAdsEarnings` module | ||
*/ | ||
|
||
module.exports = SiteWordAdsEarnings; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/** | ||
* Module dependencies. | ||
*/ | ||
import SiteWordAdsSettings from './site.wordads.settings'; | ||
import SiteWordAdsEarnings from './site.wordads.earnings'; | ||
import SiteWordAdsTOS from './site.wordads.tos'; | ||
|
||
/** | ||
* `SiteWordAds` constructor. | ||
* | ||
* Use a `WPCOM#Me` instance to create a new `SiteWordAds` instance. | ||
* | ||
* *Example:* | ||
* // Require `wpcom-unpublished` library | ||
* import wpcomUnpublished from 'wpcom-unpublished'; | ||
* | ||
* // Create a `wpcomUnpublished` instance | ||
* var wpcom = wpcomUnpublished(); | ||
* | ||
* // Create a `SiteWordAds` instance | ||
* var wordAds = wpcom | ||
* .site( 'my-blog.wordpress.com' ) | ||
* .wordAds(); | ||
* | ||
* @param {String} sid - site identifier | ||
* @param {WPCOM} wpcom - wpcom instance | ||
* @return {Null} null | ||
*/ | ||
function SiteWordAds( sid, wpcom ) { | ||
if ( ! ( this instanceof SiteWordAds ) ) { | ||
return new SiteWordAds( sid, wpcom ); | ||
} | ||
|
||
this._sid = sid; | ||
this.wpcom = wpcom; | ||
} | ||
|
||
/** | ||
* Return a `SiteWordAdsSettings` instance. | ||
* | ||
* *Example:* | ||
* // Create a SiteWordAdsSettings instance | ||
* | ||
* var wordAds = wpcom | ||
* .site( 'my-blog.wordpress.com' ) | ||
* .wordAds() | ||
* .settings(); | ||
* | ||
* @return {SiteWordAdsSettings} site WordAds settings instance | ||
*/ | ||
SiteWordAds.prototype.settings = function() { | ||
return new SiteWordAdsSettings( this._sid, this.wpcom ); | ||
}; | ||
|
||
/** | ||
* Return a `SiteWordAdsEarnings` instance. | ||
* | ||
* *Example:* | ||
* // Create a SiteWordAdsEarnings instance | ||
* | ||
* var wordAds = wpcom | ||
* .site( 'my-blog.wordpress.com' ) | ||
* .wordAds() | ||
* .earnings(); | ||
* | ||
* @return {SiteWordAdsEarnings} site WordAds earnings instance | ||
*/ | ||
SiteWordAds.prototype.earnings = function() { | ||
return new SiteWordAdsEarnings( this._sid, this.wpcom ); | ||
}; | ||
|
||
/** | ||
* Return a `SiteWordAdsTOS` instance. | ||
* | ||
* *Example:* | ||
* // Create a SiteWordAdsTOS instance | ||
* | ||
* var wordAds = wpcom | ||
* .site( 'my-blog.wordpress.com' ) | ||
* .wordAds() | ||
* .tos(); | ||
* | ||
* Return SiteWordAdsTOS object for the site. | ||
* | ||
* @return {SiteWordAdsTOS} site wordAds TOS instance | ||
*/ | ||
SiteWordAds.prototype.tos = function() { | ||
return new SiteWordAdsTOS( this._sid, this.wpcom ); | ||
}; | ||
|
||
/** | ||
* Expose `SiteWordAds` module | ||
*/ | ||
module.exports = SiteWordAds; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/** | ||
* `SiteWordAdsSettings` constructor. | ||
* | ||
* *Example:* | ||
* // Require `wpcom-unpublished` library | ||
* import wpcomUnpublished from 'wpcom-unpublished'; | ||
* | ||
* // Create a `wpcomUnpublished` instance | ||
* var wpcom = wpcomUnpublished(); | ||
* | ||
* // Create a `SiteWordAdsSettings` instance | ||
* var wordAds = wpcom | ||
* .site( 'my-blog.wordpress.com' ) | ||
* .wordAds() | ||
* .settings(); | ||
* | ||
* | ||
* @param {String} sid - site identifier | ||
* @param {WPCOM} wpcom - wpcom instance | ||
* @return {Null} null | ||
*/ | ||
function SiteWordAdsSettings( sid, wpcom ) { | ||
if ( ! ( this instanceof SiteWordAdsSettings ) ) { | ||
return new SiteWordAdsSettings( sid, wpcom ); | ||
} | ||
|
||
this._sid = sid; | ||
this.wpcom = wpcom; | ||
} | ||
|
||
/** | ||
* Get detailed WordAds settings information about the site. | ||
* | ||
* *Example:* | ||
* // Get site settings information | ||
* wpcom | ||
* .site( 'my-blog.wordpress.com' ) | ||
* .wordAds() | ||
* .settings() | ||
* .get( function( err, data ) { | ||
* // `settings` information object | ||
* } ); | ||
* | ||
* @param {Object} [query] - query object parameter | ||
* @param {Function} fn - callback function | ||
* @return {Function} request handler | ||
*/ | ||
SiteWordAdsSettings.prototype.get = function( query, fn ) { | ||
return this.wpcom.req.get( '/sites/' + this._sid + '/wordads/settings', query, fn ); | ||
}; | ||
|
||
/** | ||
* Update WordAds settings for the site. | ||
* | ||
* *Example:* | ||
* var settings = {}; // your settings here | ||
* | ||
* // Get site settings information | ||
* wpcom | ||
* .site( 'my-blog.wordpress.com' ) | ||
* .wordAds() | ||
* .settings() | ||
* .update( settings, function( err, data ) { | ||
* // data settings information object | ||
* } ); | ||
* | ||
* @param {Object} [query] - query object parameter | ||
* @param {Object} body - body object parameter | ||
* @param {Function} fn - callback function | ||
* @return {Function} request handler | ||
*/ | ||
SiteWordAdsSettings.prototype.update = function( query, body, fn ) { | ||
var path = '/sites/' + this._sid + '/wordads/settings'; | ||
return this.wpcom.req.post( path, query, body, fn ); | ||
}; | ||
|
||
/** | ||
* Expose `SiteWordAdsSettings` module | ||
*/ | ||
module.exports = SiteWordAdsSettings; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/** | ||
* `SiteWordAdsTOS` constructor. | ||
* | ||
* *Example:* | ||
* // Require `wpcom-unpublished` library | ||
* import wpcomUnpublished from 'wpcom-unpublished'; | ||
* | ||
* // Create a `wpcomUnpublished` instance | ||
* var wpcom = wpcomUnpublished(); | ||
* | ||
* // Create a `SiteWordAdsTOS` instance | ||
* var wordAds = wpcom | ||
* .site( 'my-blog.wordpress.com' ) | ||
* .wordAds() | ||
* .tos(); | ||
* | ||
* @param {String} sid - site identifier | ||
* @param {WPCOM} wpcom - wpcom instance | ||
* @return {Null} null | ||
*/ | ||
function SiteWordAdsTOS( sid, wpcom ) { | ||
if ( ! ( this instanceof SiteWordAdsTOS ) ) { | ||
return new SiteWordAdsTOS( sid, wpcom ); | ||
} | ||
|
||
this._sid = sid; | ||
this.wpcom = wpcom; | ||
} | ||
|
||
/** | ||
* GET site's WordAds TOS | ||
* | ||
* *Example:* | ||
* // Get site TOS information | ||
* wpcom | ||
* .site( 'my-blog.wordpress.com' ) | ||
* .wordAds() | ||
* .tos() | ||
* .get( function( err, data ) { | ||
* // `settings` information object | ||
* } ); | ||
|
||
* @param {Object} [query] - query object parameter | ||
* @param {Function} fn - callback function | ||
* @return {Function} request handler | ||
*/ | ||
SiteWordAdsTOS.prototype.get = function( query, fn ) { | ||
return this.wpcom.req.get( '/sites/' + this._sid + '/wordads/tos', query, fn ); | ||
}; | ||
|
||
/** | ||
* UPDATE site's WordAds TOS | ||
* | ||
* *Example:* | ||
* // Update TOS | ||
* wpcom | ||
* .site( 'my-blog.wordpress.com' ) | ||
* .wordAds() | ||
* .tos() | ||
* .update( { tos: 'signed' }, function( err, data ) { | ||
* // data settings information object | ||
* } ); | ||
* | ||
* @param {Object} [query] - query object parameter | ||
* @param {Object} body - body object parameter | ||
* @param {Function} fn - callback function | ||
* @return {Function} request handler | ||
*/ | ||
SiteWordAdsTOS.prototype.update = function( query, body, fn ) { | ||
var path = '/sites/' + this._sid + '/wordads/tos'; | ||
return this.wpcom.req.post( path, query, body, fn ); | ||
}; | ||
|
||
/** | ||
* SIGN site's WordAds TOS | ||
* | ||
* *Example:* | ||
* // Sign TOS | ||
* wpcom | ||
* .site( 'my-blog.wordpress.com' ) | ||
* .wordAds() | ||
* .tos() | ||
* .sign( function( err, data ) { | ||
* // data settings information object | ||
* } ); | ||
* | ||
* @param {Object} [query] - query object parameter | ||
* @param {Function} fn - callback function | ||
* @return {Function} request handler | ||
*/ | ||
SiteWordAdsTOS.prototype.sign = function( query, fn ) { | ||
var path = '/sites/' + this._sid + '/wordads/tos'; | ||
return this.wpcom.req.post( path, query, { tos: 'signed' }, fn ); | ||
}; | ||
|
||
/** | ||
* Expose `SiteWordAdsTOS` module | ||
*/ | ||
module.exports = SiteWordAdsTOS; |
Oops, something went wrong.