I'm hoping to use the Coinbase Bitcoin Exchange node.js API from inside ClojureScript.
The goal is to replicate the first javascript example on the page:
var CoinbaseExchange = require('coinbase-exchange');
var publicClient = new CoinbaseExchange.PublicClient();
But in my following code I've started by trying to access PublicClient at all:
(ns plutus.core
(:require
[cljs.nodejs :as nodejs]))
(def coinb (nodejs/require "coinbase-exchange"))
(nodejs/enable-util-print!)
(defn -main [& args]
(def pc (js/PublicClient.)))
(println pc))
(set! *main-cli-fn* -main)
This throws a ReferenceError: PublicClient is not defined, though I've also tried (along with similar variations):
(def pc (. coinb (PublicClient)))(def pc (.PublicClient coinb))(def pc (:PublicClient coinb))
All of which have failed by printing nil. I've pretty closely studied this article for any relevant examples, but I'm confused on how using node.js affects the naming of things, if at all.
2 Answers 2
Really its not a naming issue, its more about how to use new with nested properties in an object. Unfortunately, you can't get a reference to PublicClient and then new that after the fact.
(new (.-PublicClient coinb))
It does not work even though (.-PublicClient coinb) returns a function.
You need to point to the location of the function, by using it's dot notation within ClojureScript:
(new coinb.PublicClient)
;; OR, more idiomatic
(coinb.PublicClient.)
That should give you what you want.
Comments
Anybody else seeing this?
> ((.-getProducts (cb.PublicClient.)) (fn [_ _ _] nil))
#object[TypeError TypeError: self.makeRelativeURI is not a function]