Navigation Menu

Skip to content

Commit

Permalink
Update user agent and add an example
Browse files Browse the repository at this point in the history
nodemw/0.12.1 (node.js v10.10.0; linux x64)
  • Loading branch information
macbre committed Sep 16, 2018
1 parent 99d6f28 commit e3d80c8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
22 changes: 22 additions & 0 deletions examples/article.js
@@ -0,0 +1,22 @@
#!/usr/bin/env node
/**
* Example script getting MW version
*/

const Bot = require( '..' ),
wikipedia = new Bot( {
protocol: 'https',
server: 'pl.wikipedia.org',
path: '/w',
debug: true
} );

wikipedia.getArticleRevisions( 'Tórshavna', ( err, data ) => {
if ( err ) {
wikipedia.log( 'An error occured!' );
wikipedia.log( err );
return;
}

wikipedia.log( 'Article metadata:', data );
} );
7 changes: 5 additions & 2 deletions lib/api.js
Expand Up @@ -209,13 +209,16 @@ module.exports = ( function () {
// HTTP client
this.formatUrl = require( 'url' ).format;

this.userAgent = options.userAgent || ( `nodemw v${VERSION} (node.js ${process.version}; ${process.platform} ${process.arch})` );
this.userAgent = options.userAgent || ( `nodemw/${VERSION} (node.js ${process.version}; ${process.platform} ${process.arch})` );
this.version = VERSION;

// debug info
this.info( process.argv.join( ' ' ) );
this.info( this.userAgent );
this.info( `Using <${this.protocol}://${this.server}:${this.port}${this.path}/api.php> as API entry point` );

let port = this.port ? `:${this.port}` : '';

this.info( `Using <${this.protocol}://${this.server}${port}${this.path}/api.php> as API entry point` );
this.info( '----' );
};

Expand Down

0 comments on commit e3d80c8

Please sign in to comment.