Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://gitlab.com/pinage404/wikiquote-api
Small APi for [Wikiquote](https://www.wikiquote.org)
https://gitlab.com/pinage404/wikiquote-api
api quote quotes search wiki wikidata wikiquote
Last synced: 17 days ago
JSON representation
Small APi for [Wikiquote](https://www.wikiquote.org)
- Host: gitlab.com
- URL: https://gitlab.com/pinage404/wikiquote-api
- Owner: pinage404
- License: mit
- Created: 2017-05-07T13:03:43.680Z (over 7 years ago)
- Default Branch: master
- Last Synced: 2024-07-30T21:03:20.779Z (3 months ago)
- Topics: api, quote, quotes, search, wiki, wikidata, wikiquote
- Stars: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Wikiquote API
[![Pipeline status][pipeline_badge]][pipeline_url]
[![Published on NPM][npm_badge]][npm_url]Small APi for [Wikiquote][wikiquote]
- [How to install](#how-to-install)
- [How to use](#how-to-use)
- [Import library](#import-library)
- [ES2017 Module style](#es2017-module-style)
- [In browser](#in-browser)
- [In Node](#in-node)
- [Old style](#old-style)
- [Old style in browser](#old-style-in-browser)
- [Old style in Node](#old-style-in-node)
- [API](#api)
- [Examples](#examples)
- [Get all pages tile related to a given subject](#get-all-pages-tile-related-to-a-given-subject)
- [Get HTML content for a given page title](#get-html-content-for-a-given-page-title)
- [Get all content as `HTMLElement` for a given subject](#get-all-content-as-htmlelement-for-a-given-subject)
- [Powered by Wikidata](#powered-by-wikidata)
- [Yet another Wikidata API](#yet-another-wikidata-api)
- [License](#license)## How to install
With [`Yarn`][yarn]
```bash
yarn add wikiquote-api
```or with `NPM`
```bash
npm install wikiquote-api --save
```## How to use
### Import library
#### ES2017 Module style
##### In browser
```html
```
##### In Node
```javascript
import 'babel-polyfill'
import WikiquoteApi from './node_modules/wikiquote-api/dist/WikiquoteApi.module.mjs'
```#### Old style
##### Old style in browser
```html
```
##### Old style in Node
```javascript
require('babel-polyfill')
const WikiquoteApi = require('wikiquote-api')
```### API
`WikiquoteApi` provides this functions
```typescript
async function searchQuotePage(
searchTerm: string,
lang?: string,
searchUrlConfig?: (lang: string) => string
): string[];async function getQuotePage(
pageTitle: string,
lang?: string,
pageUrlConfig?: (lang: string) => string,
ambiguousPageConfig?: (lang: string) => string
): string;async function getQuotePageDOM(
pageTitle: string,
lang?: string,
pageUrlConfig?: (lang: string) => string,
ambiguousPageConfig?: (lang: string) => string
): HTMLElement;async function getFullQuotePage(
searchTerm: string,
lang?: string,
searchUrlConfig?: (lang: string) => string,
pageUrlConfig?: (lang: string) => string,
ambiguousPageConfig?: (lang: string) => string
): Map;async function getFullQuotePageDOM(
searchTerm: string,
lang?: string,
searchUrlConfig?: (lang: string) => string,
pageUrlConfig?: (lang: string) => string,
ambiguousPageConfig?: (lang: string) => string
): Map;
```And this exceptions under the scope `exception`
- `WikiquoteApiException`
- `UnsupportedLanguageException`
- `NoSuchPageException`
- `DisambiguationPageException`### Examples
#### Get all pages tile related to a given subject
```javascript
// returns a promise that resolve with all Spiderman related pages title
WikiquoteApi.searchQuotePage('Spiderman').then(console.log)
/*
Output:
[ 'Spider-Man',
'Spider-Man 3',
'Spider-Man 2',
'Spider-Man: The Animated Series',
'Spider-Man (2002 film)',
'Spider-Man: Homecoming',
'Spider-Man (2000 video game)',
'Spider-Man: Shattered Dimensions',
'Spider-Man 2: Enter Electro',
'Spider-Man: Web of Shadows',
'Spider-Man: Edge of Time',
'Spider-Man 3 (video game)',
'Spider-Man 2 (Video Game)' ]
*/
```#### Get HTML content for a given page title
```javascript
// returns a promise that resolve with a HTMLElement with the Spider-Man (2002 film)'s HTML content
WikiquoteApi.getQuotePage('Spider-Man (2002 film)').then(console.log)
/*
Output:Spider-Man is a 2002 film based on the eponymous Marvel comic. It stars Tobey Maguire and Willem Dafoe and explains the story ofPeter Parker's struggle to balance between his normal life and his life as Spider Man. This movie is released theaters May 3, 2002 in United States.
...
(last words of the movie) Whatever life holds in store for me, I will never forget these words: "With great power comes great responsibility." This is my gift, my curse. Who am I? I'm Spider-Man.
...
*/
```#### Get all content as `HTMLElement` for a given subject
```javascript
// returns a promise that resolve with a Map of each pages related to Spiderman
WikiquoteApi.getFullQuotePageDOM('Iron Man').then(console.log)
/*
Output:
Map {
'https://en.wikiquote.org/wiki/Iron%20Man%20(2008%20film)' => HTMLDivElement {},
'https://en.wikiquote.org/wiki/Iron%20Man%3A%20Armored%20Adventures' => HTMLDivElement {},
'https://en.wikiquote.org/wiki/Iron%20Man%20(comics)' => HTMLDivElement {},
'https://en.wikiquote.org/wiki/Iron%20Man%203' => HTMLDivElement {},
'https://en.wikiquote.org/wiki/Iron%20Man%202' => HTMLDivElement {},
'https://en.wikiquote.org/wiki/Ted%20Hughes' => HTMLDivElement {},
'https://en.wikiquote.org/wiki/Iron%20Maiden' => HTMLDivElement {} }
*/
```## Powered by Wikidata
Don't forget to add `Powered by Wikidata` to your project
[![Powered by Wikidata][powered_by_wikidata_img]][powered_by_wikidata_url]
## Yet another Wikidata API
After tried severals [Javascript API client for Wikidata][wikidata_js_client_url] nothing really suits to my needs or was too big :
- too many dependencies
- too many features not used[![One more comic][commitstrip_one_more_img]][commitstrip_one_more_url]
[![Standards comic][xkcd_standards_img]][xkcd_standards_url]
So, i created this small API for [Wikiquote][wikiquote]
## License
[MIT][license]
[pipeline_badge]: https://gitlab.com/pinage404/wikiquote-api/badges/master/pipeline.svg
[pipeline_url]: https://gitlab.com/pinage404/wikiquote-api/commits/master[npm_badge]: https://img.shields.io/npm/v/wikiquote-api.svg
[npm_url]: https://www.npmjs.com/package/wikiquote-api[wikiquote]: https://www.wikiquote.org
[yarn]: https://yarnpkg.com
[powered_by_wikidata_img]: https://upload.wikimedia.org/wikipedia/commons/thumb/a/ae/Wikidata_Stamp_Rec_Dark.svg/640px-Wikidata_Stamp_Rec_Dark.svg.png
[powered_by_wikidata_url]: https://www.wikidata.org/wiki/Wikidata:Data_access#Best_practices_to_follow[wikidata_js_client_url]: https://www.mediawiki.org/wiki/API:Client_code#JavaScript
[commitstrip_one_more_img]: https://www.commitstrip.com/wp-content/uploads/2017/03/Strip-X%C3%A8me-plugin-open-source-english650-final.jpg
[commitstrip_one_more_url]: http://www.commitstrip.com/en/2017/03/22/one-more/[xkcd_standards_img]: https://imgs.xkcd.com/comics/standards.png
[xkcd_standards_url]: https://xkcd.com/927/[license]: https://gitlab.com/pinage404/wikiquote-api/blob/master/LICENSE