Coder Social home page Coder Social logo

Comments (9)

hugolpz avatar hugolpz commented on June 14, 2024 1

Former d3-style API proposal below.


API

# .site_name(language[,options]): {description}

  • language: string.
  • options: object.

# .login(username, password, API_URL): login into the target API using the provided username and password.

  • username: string - Account username. For bot, see [Special:BotPasswords] on your wiki.
  • password: string - Account's password. For bot, see [Special:BotPasswords] on your wiki.
  • API_URL: string (url) - Target wiki's API url.

# .query(parameters[,options]): {description}

  • parameters:
  • options: object.

# .page(title[,options]): given a title, returns the page's data.

  • title: string.
  • options: object.

# .tracking_revisions(title,to_search[,options]): {description}

  • title: string.
  • to_search: …
  • options: object.

# .edit_page(title, function(d){…}[,options]): edits content of target page.

  • title: string.
  • conent: string - Use function(d){…} to return the new wikicode, where d is the page data.
  • options: object.
    • bot: boolean.
    • nocreate: boolean - Avoid creating new page.
    • minor: boolean - Edit is minor.
    • summary: string - Edit summary.

# .edit(content[,options]) {…}: to use with and after edit_page. {description}

  • content: …
  • options: object.

# .move_to(move_to_title[,options]): move page to new title address.

  • move_to_title: string.
  • options: object.
    • reason: string.
    • noredirect: boolean
    • movetalk: boolean.

# .move_page(move_from_title, move_to_title[,options]): moves target page to new title address.

  • move_from_title: string.
  • move_to_title: string.
  • options: object.
    • reason: string.
    • noredirect: boolean
    • movetalk: boolean.

# .purge(title[,options]): {description}

  • title: string.
  • options: object.

# .listen(listener[,options]listener, options) {}: to use with and after …. {description}

  • listener: …
  • options: object.

# .category_tree(root_category[,options]): {description}

  • root_category: string.
  • options: object.

# .search(key[,options]): {description}

  • key: …
  • options: object.

# .redirects_root(title[,options]): {description}

  • title: string.
  • options: object.

# .redirects_here(title[,options]): {description}

  • title: string.
  • options: object.

# .register_redirects(template_name[,options]): {description}

  • template_name: string.
  • options: object.

# .upload(file_data): given a target file, upload it to the target wiki.

  • file_data: object - Upload configurations.
    • file_path: string - Local path. Alternative to media_url.
    • media_url: string - URL path. Alternative to file_path.
    • comment: string - Upload comment.
    • text: string - Wikicode which to fill the file's page. Alternative for most fields below.
    • description: string - File description.
    • date: date string - YYYY-MM-DD, ex: new Date() || '2021-01-01'.
    • source_url: string - Source where the file comes from, typically an url.
    • author: string - Author's name or username in wikicode, ex: '[[User:Yoda|Yoda]]'.
    • permission: string - …, ex: '{{cc-by-sa-2.5}}'.
    • other_versions: string - Wikicode displaying alternative files.
    • other_fields: string - …
    • license: array of strings - License under which the file is uploaded, ex: ['{{cc-by-sa-2.5}}'].
    • categories: array of strings - Categories for this file, ex: ['[[Category:test images]]'].
    • ignorewarnings: boolean=0 - Overwrite existing files.

# .get_featured_content(options): {description}

  • options: object.

# .for_each_page(page_list, for_each[,options]): {description}

  • page_list: …
  • for_each: …
  • options: object.

# .for_each(type, title, for_each[,options]): {description}

  • type: …
  • title: string.
  • for_each: …
  • options: object.

# .data(key, property[,options]): {description}

  • key: …
  • property: string.
  • options: object.

# .convert_Chinese(text[,options]): {description}

  • text: string - … <------------------- wikicode ? raw text ?
  • options: object.

# .run_SQL(SQL, for_each_row): {description}

  • SQL: …
  • for_each_row: …

# .setup_layout_elements(options): {description}

  • options: object.

Helpers

Here we could list all options ?

Here comes page_data's explainer

Other tricks



Notes and Q&A

  1. Missing contents as .
  2. Missing {description}. Good practice is Given {input} does {something} or Given {input} return {something} in {format}. Format being string, object, array, number, etc.
  3. Missing get_featured_content and setup_layout_elements.
  4. Missing categoryembers :

# .categorymembers(title[,options]): returns an array of members.

  • title: string. Category's name.
  1. Missing .data() sub-methods : .entity(), .modify().

Comment

Well....I didn't expected this but I did it most of it. I thing you can complete the blanks easily. 😁

from wikiapi.

kanasimi avatar kanasimi commented on June 14, 2024 1

Maybe we can also use https://github.com/jsdoc/jsdoc ?

from wikiapi.

kanasimi avatar kanasimi commented on June 14, 2024 1

try https://kanasimi.github.io/wikiapi/

from wikiapi.

kanasimi avatar kanasimi commented on June 14, 2024 1

Substantial changes of documents have ended now.

from wikiapi.

hugolpz avatar hugolpz commented on June 14, 2024

I don't know yet how to create this man, as a readme, or by improving the in-code phrasing within wikiapi.js and test.js. But for reference, see best practice for README.md API with d3-array :

# d3.max(iterable[, accessor]) · Source.
Returns .... If ..., returns.... An optional option_name does ....
See also related_stuff.

I'am starting work below. Still a testing around, style and things can change. Please tell me if I'am on the right road. Help welcome. Kanasimi, I believe you have the userrights to edit my post, feel free to do so 😁 . The content below is intended to complete the current readme.md.

from wikiapi.

hugolpz avatar hugolpz commented on June 14, 2024

TL;DR: expand readme above will be faster. Code clean up required. Then JSdoc3 can come over.

Long version : I'am discovering JSdoc3. On the long run it's a very good idea. But as of now I lack visibility.

Your wikiapi.js code currently has (i think) a mix of comment syntaxes. I have no idea how it will play out with installing JSdoc. Aside, JSdoc renderings that I checked are not concise.

Meanwhile, the markdown API draft above is 1~2h away from becoming a clean documentation for +90% of wikiapi.js code and methods. This will be concise and elegant.

Later on, this markdown can be converted back into JSdoc3, when ready. Namely :

  1. wikiapi.js comments cleaned up,
  2. you/we properly learnt JSdoc3 syntaxes,
  3. we know which template to use,
  4. we know which project to use (JSDoc GitHub Action, jsdoc-to-markdown, other ?)

Then, some regex will help convert :

<a name="move_to" href="#move_to">#</a> .<b>move_to</b>(<i>move_to_title</i>[,<i>options</i>]): move page to new title address.
* `move_to_title`: string - target page's title.
* `options`: object - options.
  * `reason`: string - reason for the move.
  * `noredirect`: boolean
  * `movetalk`: boolean.

...into...

/**
 * @alias .move_to 
 * @description Moves page to new title address.
 * @param {String} move_to_title - target page's title.
 * @param {Object} [options] - options.
 * @param {String} [options.reason] - reason for the move.
 * @param {Boolean=1} [options.noredirect] - do not leave a redirect.
 * @param {Boolean=1} [options.movetalk] - move the talkpage as well.
 * @returns {Object} - returns (does not exist on .move_to but I put it here for demo)
 * @memberof Wikiapi.prototype
 * @example
 * result = await targetWiki.move_page('Page A', 'Page Alpha', { reason: 'Correcting name.', noredirect: true, movetalk: true });
 */
function move_to (move_to_title,options) { 
    // do stuff here
}

If you have the ability to make a quick, full JSdoc3 migration (points 1, 2, 3 and 4 above), go ahead.

But overall and given the main objective is to provide an API soon, I suggest to expand the markdown API drafted above. It will give you time to clean the wikiapi.js's comments and other improvements you see fit. Both actions prepare for a later JSdoc3 migration.

(Also since I have to catch upover my IRL todo list, I should better not be active this weekend and the coming week.)

from wikiapi.

hugolpz avatar hugolpz commented on June 14, 2024

Nice 😎

from wikiapi.

hugolpz avatar hugolpz commented on June 14, 2024

Saw today changes. Starts to be awesome !
Screenshot_2021-03-31_11-36-42

from wikiapi.

hugolpz avatar hugolpz commented on June 14, 2024

Good work done. Close. Thank @kanasimi !

from wikiapi.

Related Issues (20)

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.