Skip to content

Commit

Permalink
Breaking: Rewritten to a class
Browse files Browse the repository at this point in the history
  • Loading branch information
fvdm committed Oct 6, 2021
1 parent b5b165f commit efda580
Show file tree
Hide file tree
Showing 3 changed files with 328 additions and 303 deletions.
105 changes: 39 additions & 66 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,95 +11,68 @@ Search and lookup art in various archives across Europe.
* [API documentation](https://pro.europeana.eu/)


Example
-------
## Usage example

```js
const europeana = require ('europeana') ('abc123');
const EuropeanaAPI = require ('europeana');
const europeana = new EuropeanaAPI ({
wskey: 'abc123',
});

// console.log is too limited
function out (data) {
console.dir (data, {
depth: null,
colors: true,
});
}


// Search
const params = {
europeana.search ({
query: 'et in arcadia ego',
rows: 5,
};

europeana ('search', params, console.log);
})
.then (out)
.catch (console.error)
;


// Record
const recordId = '/08501/03F4577D418DC84979C4E2EE36F99FECED4C7B11';

europeana (`record${recordId}`, console.log);
europeana.getRecord ({
id: '08501/03F4577D418DC84979C4E2EE36F99FECED4C7B11',
})
.then (out)
.catch (console.error)
;
```


Installation
------------

`npm i europeana`


Configuration
-------------

You _must_ specify an API key which you can request **[here](http://labs.europeana.eu/api/registration)**

param | type | required | default | description
:-------|:-------|:---------|:--------|:----------------------
apikey | string | yes | | Your API key. Do not use your private key.
timeout | number | no | 5000 | Request time out in ms


#### Example

```js
const apikey = 'abc123';
const timeout = 3000;

var europeana = require ('europeana') (apikey, timeout);
```
## Installation

`npm install europeana`

Callback
--------

Each method requires a callback _function_ to receive the results.
## Configuration

It receives two parameters: `err` and `data`.
You _must_ specify an API key which you can request
**[here](http://pro.europeana.eu/api/registration)**

property | type | default | description
:--------|:-------|:--------|:-----------------------------
err | Error | null | Includes `.code` and `.error`
data | Object | | Result object
param | type | default | description
:---------|:-------|:--------|:-----------
wskey | string | | API key. Do not use your private key.
[timeout] | number | `5000` | Request timeout in ms


#### Example

```js
function myCallback (err, data) {
if (err) return console.error (err);

console.dir (data, {
depth: null,
colors: true,
});
}

// Search
europeana ('search', { query: 'vincent van gogh' }, myCallback);
const EuropeanaAPI = require ('europeana');
const europeana = new EuropeanaAPI ({
wskey: 'abc123',
timeout: 5000,
});
```


#### Errors

message | description | additional
:----------------|:-----------------------------|:-----------------------
apikey missing | You did not set your API key |
request failed | The request failed | `err.error`
invalid response | API returned invalid data |
API error | API returned an error | `err.error`, `err.code`


Unlicense
---------

Expand Down

0 comments on commit efda580

Please sign in to comment.