UNPKG

@owstack/ows-wallet-servlet-coinbase

Version:

An OWS Wallet servlet plugin for Coinbase.

53 lines (41 loc) 1.22 kB
'use strict'; angular.module('owsWalletPlugin.apiHandlers').service('getBuyPrice', function(coinbaseService, /* @namespace owsWalletPluginClient.api */ Utils) { var root = {}; var REQUIRED_PARAMS = [ 'currency' ]; root.respond = function(message, callback) { // Check required parameters. var missing = Utils.checkRequired(REQUIRED_PARAMS, message.request.data); if (missing.length > 0) { message.response = { statusCode: 400, statusText: 'REQUEST_NOT_VALID', data: { message: 'The request does not include ' + missing.toString() + '.' } }; return callback(message); } var currency = message.request.params.currency; coinbaseService.buyPrice(currency).then(function(response) { message.response = { statusCode: 200, statusText: 'OK', data: response }; return callback(message); }).catch(function(error) { message.response = { statusCode: error.statusCode || 500, statusText: error.statusText || 'UNEXPECTED_ERROR', data: { message: error.message } }; return callback(message); }); }; return root; });