From 4e093a261fa3018e6bc3c5e3e81631774f9dbd72 Mon Sep 17 00:00:00 2001
From: Nanocryk <nanocryk@gmail.com>
Date: Thu, 9 Nov 2017 10:50:09 +0100
Subject: [PATCH] feature : working calls from nodejs

---
 .gitignore        |  2 ++
 lib/index.js      | 17 +++++++++++++++--
 native/src/lib.rs |  6 +++---
 3 files changed, 20 insertions(+), 5 deletions(-)

diff --git a/.gitignore b/.gitignore
index 49b3073..b8629ce 100644
--- a/.gitignore
+++ b/.gitignore
@@ -6,3 +6,5 @@ native/artifacts.json
 **/.DS_Store
 
 *.bk
+
+*.wot
diff --git a/lib/index.js b/lib/index.js
index ab3e271..baa4804 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -1,3 +1,16 @@
-var addon = require('../native');
+let WebOfTrust = require('../native').WebOfTrust;
 
-console.log(addon.hello());
+{
+    let wot = new WebOfTrust(3);
+    console.log(wot.add_node());
+    console.log(wot.size())
+}
+
+{
+    let wot = new WebOfTrust("hey.wot");
+
+    console.log("Hello, world !");
+    console.log(wot.add_node());
+    console.log(wot.size());
+    console.log(wot.to_file("hey.wot"));
+}
diff --git a/native/src/lib.rs b/native/src/lib.rs
index 0a475ad..e937989 100644
--- a/native/src/lib.rs
+++ b/native/src/lib.rs
@@ -4,7 +4,7 @@
 extern crate neon;
 extern crate duniter_rs_wotb;
 
-use neon::js::{Value, JsInteger, JsString, JsBoolean, JsFunction, JsArray, JsNumber, Object};
+use neon::js::{Value, JsInteger, JsString, JsBoolean, JsFunction, JsArray, JsNumber, JsObject, Object};
 use neon::js::class::{Class, JsClass};
 use neon::mem::Handle;
 use neon::vm::{Throw, Lock};
@@ -19,14 +19,14 @@ declare_types! {
             let scope = call.scope;
             let arg0 = try!(call.arguments.require(scope, 0));
 
-            if let Ok(max_cert) = arg0.check::<JsInteger>() {
+            if let Some(max_cert) = arg0.downcast::<JsInteger>() {
                 let max_cert = max_cert.value();
 
                 match max_cert > 0 {
                     true => Ok(WebOfTrust::new(max_cert as usize)),
                     false => Err(Throw),
                 }
-            } else if let Ok(path) = arg0.check::<JsString>() {
+            } else if let Some(path) = arg0.downcast::<JsString>() {
                 let path = path.value();
 
                 match WebOfTrust::from_file(path.as_str()) {
-- 
GitLab