-
Notifications
You must be signed in to change notification settings - Fork 6
/
repl.js
72 lines (65 loc) · 2.42 KB
/
repl.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/* eslint-env node */
/* eslint-disable no-console */
// Don't show an error when devDependencies (i.e. colors) is imported
/* eslint import/no-extraneous-dependencies: ["error", {"devDependencies": true}] */
const colors = require('colors');
const repl = require('repl');
const sharetribeIntegrationSdk = require('./src/index');
// Start REPL
const replInstance = repl.start('> ');
// Assign SDK as global
const ctx = replInstance.context;
ctx.sharetribeIntegrationSdk = sharetribeIntegrationSdk;
// Welcome message
colors.setTheme({
h1: 'yellow',
h2: 'yellow',
inline: 'gray',
block: 'gray',
});
console.log('');
console.log('');
console.log(' # REPL'.h1);
console.log(' ');
console.log(' With the REPL you can test and try out the SDK with real results from the API.');
console.log(' ');
console.log(' To start the REPL, type:');
console.log(' ');
console.log(' ```'.block);
console.log(' > yarn run repl'.block);
console.log(' ```'.block);
console.log(' ');
console.log(' ## Globals'.h2);
console.log(' ');
console.log(' The following globals are available:');
console.log(' ');
console.log(` - ${'`sharetribeIntegrationSdk`'.inline}: The SDK module`);
console.log(' ');
console.log(' ## Example usage'.h2);
console.log(' ');
console.log(' Create new SDK instance:');
console.log(' ');
console.log(' ```'.block);
console.log(' const clientId = "<your client ID here>";'.block);
console.log(' const clientSecret = "<your client secret here>";'.block);
console.log(' const integrationSdk = sharetribeIntegrationSdk.createInstance({'.block);
console.log(' clientId,'.block);
console.log(' clientSecret,'.block);
console.log(' tokenStore: sharetribeIntegrationSdk.tokenStore.memoryStore()'.block);
console.log(' });'.block);
console.log(' ```'.block);
console.log(' ');
console.log(' Fetch 10 listings:');
console.log(' ');
console.log(' ```'.block);
console.log(' integrationSdk.listings.query({per_page: 10}).then(response => {'.block);
console.log(' console.log("Fetched " + response.data.data.length + " listings.");'.block);
console.log(' response.data.data.forEach(listing => {'.block);
console.log(' console.log(listing.attributes.title);'.block);
console.log(' });'.block);
console.log(' });'.block);
console.log(' ```'.block);
console.log(' ');
console.log(` Type ${'`.exit`'.inline} when you want to exit the REPL`);
console.log(' ');
console.log(' Hit [Enter] when you\'re ready to start!');