Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add js client samples #1

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
45 changes: 45 additions & 0 deletions js/addresses.js
@@ -0,0 +1,45 @@
let TapyrusApi = require('tapyrus_api');

// Set your Access Token
let access_token = ""

let defaultClient = TapyrusApi.ApiClient.instance;
defaultClient.defaultHeaders = { Authorization: `Bearer ${access_token}` }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is no problem here so far. It is good to consider improving the authentication method in later steps.


// You can change the host name and port number
// defaultClient.basePath = 'http://localhost:3000/api/v1'

let api = new TapyrusApi.AddressApi();

function post_address() {
return new Promise((resolve, reject) => {
api.address((err, data, response) => {
if (err) reject(err);
resolve(data);
})
})
}

function get_addresses(opts) {
return new Promise((resolve, reject) => {
api.addresses(opts, (err, data) => {
if (err) reject(err);
resolve(data);
})
})
}

// Verification: Success
// @route POST /api/v1/addresses
// @desc Generate new Address
post_address()
.then(data => console.log(data))
.catch(err => console.log(err))

// Verification: Success
// @route GET /api/v1/addresses
// @desc Get the list of addresses
let opts = { per: 10, page: 1 };
get_addresses(opts)
.then(data => console.log(data))
.catch(err => console.log(err))
30 changes: 30 additions & 0 deletions js/payments.js
@@ -0,0 +1,30 @@
let TapyrusApi = require('tapyrus_api');

// Set your Access Token
let access_token = ""

let defaultClient = TapyrusApi.ApiClient.instance;
defaultClient.defaultHeaders = { Authorization: `Bearer ${access_token}` }

// You can change the host name and port number
// defaultClient.basePath = 'http://localhost:3000/api/v1'

let api = new TapyrusApi.PaymentApi();


function post_payment(opts) {
return new Promise((resolve, reject) => {
api.payment(opts, (err, data, response) => {
if (err) reject(err);
resolve(data);
})
})
}

// Verification: Failed
// @route POST /api/v1/payment
// @desc Sending tapyrus
let opts = { address: 'mnzdZUieW2Hqe9GzZzVbcA7nHkDeFhJFzd', amount: 100000 };
post_payment(opts)
.then(data => console.log(data))
.catch(err => console.log(err))
45 changes: 45 additions & 0 deletions js/timestamps.js
@@ -0,0 +1,45 @@
let TapyrusApi = require('tapyrus_api');

// Set your Access Token
let access_token = ""

let defaultClient = TapyrusApi.ApiClient.instance;
defaultClient.defaultHeaders = { Authorization: `Bearer ${access_token}` }

// You can change the host name and port number
// defaultClient.basePath = 'http://localhost:3000/api/v1'

let api = new TapyrusApi.TimestampApi();

function add_timestamp(opts) {
return new Promise((resolve, reject) => {
api.addTImestamp(opts, (err, data, response) => {
if (err) reject(err);
resolve(response);
})
})
}

function get_timestamps() {
return new Promise((resolve, reject) => {
api.getTimestamps((err, data, response) => {
if (err) reject(err);
resolve(data);
})
})
}

// Verification: Success
// @route POST /api/v1/timestamp
// @desc Genetate new timestamp
let opts = { content_hash: "9ccc644b03a88358a754962903a659a2d338767ee61674dde5434702a6256e6d", prefix: "app" }
add_timestamp(opts)
.then(response => console.log(response))
.catch(err => console.log(err))

// Verification: Success
// @route GET /api/v1/timestamps
// @desc Get the list of timestamps
get_timestamps()
.then(response => console.log(response))
.catch(err => console.log(err))
35 changes: 35 additions & 0 deletions js/tokens.js
@@ -0,0 +1,35 @@
let TapyrusApi = require('tapyrus_api');

// Set your Access Token
let access_token = ""

let defaultClient = TapyrusApi.ApiClient.instance;
defaultClient.defaultHeaders = { Authorization: `Bearer ${access_token}` }

// You can change the host name and port number
// defaultClient.basePath = 'http://localhost:3000/api/v1'

function get_tokens(opts) {
return new Promise((resolve, reject) => {
api.tokensGet(opts, (err, data, response) => {
if (err) reject(err);
resolve(data);
})
})
}

// Verification: Success
// @route GET /api/v1/tokens
// @desc Get the list of tokens
let opts = {};
get_tokens(opts)
.then(data => console.log(data))
.catch(err => console.log(err))

// Verification: Failed
// @route POST /api/v1/tokens/issue
// @desc Get the list of tokens
let post_tokens_opts = { amount: 1000 };
post_tokens(post_tokens_opts)
.then(data => console.log(data))
.catch(err => console.log(err))