From 7598f3b74b9410b588ed8d798daa45720debd983 Mon Sep 17 00:00:00 2001 From: maximedegreve Date: Mon, 16 Mar 2015 22:38:17 +0000 Subject: [PATCH] Little fixes --- ...date All Artboards to Project....sketchplugin | 2 +- ...Selected Artboards to Project....sketchplugin | 2 +- Marvel/api.js | 16 ++++++++-------- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Marvel/Send or Update All Artboards to Project....sketchplugin b/Marvel/Send or Update All Artboards to Project....sketchplugin index b9fb45c..d340d06 100755 --- a/Marvel/Send or Update All Artboards to Project....sketchplugin +++ b/Marvel/Send or Update All Artboards to Project....sketchplugin @@ -29,7 +29,7 @@ if (getActiveTokenFromComputer() == false) { } else { var projectNamesArray = getProjectNamesArray() - if(projectNamesArray.count > 0){ + if(projectNamesArray){ fireSendArtboards(projectNamesArray, 1) } else{ fireError("You don\'t have any projects.","Make first a project on marvelapp.com"); diff --git a/Marvel/Send or Update Selected Artboards to Project....sketchplugin b/Marvel/Send or Update Selected Artboards to Project....sketchplugin index 7566bc8..6ac8ae6 100755 --- a/Marvel/Send or Update Selected Artboards to Project....sketchplugin +++ b/Marvel/Send or Update Selected Artboards to Project....sketchplugin @@ -29,7 +29,7 @@ if (getActiveTokenFromComputer() == false) { } else { var projectNamesArray = getProjectNamesArray() - if(projectNamesArray.count > 0){ + if(projectNamesArray){ fireSendArtboards(projectNamesArray, 0) } else{ fireError("You don\'t have any projects.","Make first a project on marvelapp.com"); diff --git a/Marvel/api.js b/Marvel/api.js index b20895b..4731c02 100755 --- a/Marvel/api.js +++ b/Marvel/api.js @@ -488,12 +488,12 @@ function getProjectNamesArray() { var token = getActiveTokenFromComputer() - NSLog("token is " + token); + NSLog("token for project names fetch is " + token); var task = NSTask.alloc().init() task.setLaunchPath("/usr/bin/curl"); - var args = NSArray.arrayWithObjects("-v", "GET", "--header", "User-Agent: Sketch", "--header", "Content-Type: application/x-www-form-urlencoded", "--header", "Authorization: Token " + token, "--header", "HTTP_AUTHORIZATION: " + token, rootURL + "project/all/", nil); + var args = NSArray.arrayWithObjects("-v", "GET", "-H", "User-Agent: Sketch", "-H", "Content-Type: application/x-www-form-urlencoded", "-H", "Authorization: Token " + token, "-H", "HTTP_AUTHORIZATION: " + token, rootURL + "project/all/", nil); task.setArguments(args); var outputPipe = [NSPipe pipe]; [task setStandardOutput:outputPipe]; @@ -501,16 +501,16 @@ function getProjectNamesArray() { var outputData = [[outputPipe fileHandleForReading] readDataToEndOfFile]; if(outputData) { - - var error; - var res = [NSJSONSerialization JSONObjectWithData:outputData options:NSJSONReadingMutableLeaves error:error]; - NSLog("Convert output data to string") - var stringRead = [[NSString alloc] initWithData:outputData encoding:NSUTF8StringEncoding]; + var stringRead = [[NSString alloc] initWithData:outputData encoding:NSUTF8StringEncoding]; NSLog("Return data " + stringRead) NSLog("Convert output data to string finished") - + + var error; + + var res = [NSJSONSerialization JSONObjectWithData:outputData options:NSJSONReadingMutableLeaves error:error];; + if(res.detail && res.detail == "Invalid token"){ deleteActiveTokenFromComputer() fireError("Your token is not valid anymore, please login again.","After you are logged in again please try again.")