func (s *SparkCoreAdaptor) Variable(name string) (result string, err error) {
	url := fmt.Sprintf("%v/%s?access_token=%s", s.deviceURL(), name, s.AccessToken)
	resp, err := s.requestToSpark("GET", url, nil)
	if err != nil {
		return
	}
	val := resp["result"]
	switch val.(type) {
	case bool:
		result = strconv.FormatBool(val.(bool))
	case float64:
		result = strconv.FormatFloat(val.(float64), 'f', -1, 64)
	case string:
		result = val.(string)
	}
	return
}
Variable returns a core variable value as a string
package spark
import (
	"encoding/json"
	"errors"
	"fmt"
	"io/ioutil"
	"net/http"
	"net/url"
	"strconv"
	"github.com/donovanhide/eventsource"
	"github.com/hybridgroup/gobot"
)
type SparkCoreAdaptor struct {
	name        string
	DeviceID    string
	AccessToken string
	APIServer   string
	gobot.Eventer
}
type Event struct {
	Name  string
	Data  string
	Error error
}
var eventSource = func(url string) (chan eventsource.Event, chan error, error) {
	stream, err := eventsource.Subscribe(url, "")
	if err != nil {
		return nil, nil, err
	}
	return stream.Events, stream.Errors, nil
}
func NewSparkCoreAdaptor(name string, deviceID string, accessToken string) *SparkCoreAdaptor {
	return &SparkCoreAdaptor{
		name:        name,
		DeviceID:    deviceID,
		AccessToken: accessToken,
		APIServer:   "https://api.spark.io",
		Eventer:     gobot.NewEventer(),
	}
}
func (s *SparkCoreAdaptor) Name() string { return s.name }
func (s *SparkCoreAdaptor) Connect() (errs []error) {
	return
}
func (s *SparkCoreAdaptor) Finalize() (errs []error) {
	return
}
func (s *SparkCoreAdaptor) AnalogRead(pin string) (val int, err error) {
	params := url.Values{
		"params":       {pin},
		"access_token": {s.AccessToken},
	}
	url := fmt.Sprintf("%v/analogread", s.deviceURL())
	resp, err := s.requestToSpark("POST", url, params)
	if err == nil {
		val = int(resp["return_value"].(float64))
		return
	}
	return 0, err
}
func (s *SparkCoreAdaptor) PwmWrite(pin string, level byte) (err error) {
	return s.AnalogWrite(pin, level)
}
func (s *SparkCoreAdaptor) AnalogWrite(pin string, level byte) (err error) {
	params := url.Values{
		"params":       {fmt.Sprintf("%v,%v", pin, level)},
		"access_token": {s.AccessToken},
	}
	url := fmt.Sprintf("%v/analogwrite", s.deviceURL())
	_, err = s.requestToSpark("POST", url, params)
	return
}
func (s *SparkCoreAdaptor) DigitalWrite(pin string, level byte) (err error) {
	params := url.Values{
		"params":       {fmt.Sprintf("%v,%v", pin, s.pinLevel(level))},
		"access_token": {s.AccessToken},
	}
	url := fmt.Sprintf("%v/digitalwrite", s.deviceURL())
	_, err = s.requestToSpark("POST", url, params)
	return err
}
func (s *SparkCoreAdaptor) DigitalRead(pin string) (val int, err error) {
	params := url.Values{
		"params":       {pin},
		"access_token": {s.AccessToken},
	}
	url := fmt.Sprintf("%v/digitalread", s.deviceURL())
	resp, err := s.requestToSpark("POST", url, params)
	if err == nil {
		val = int(resp["return_value"].(float64))
		return
	}
	return -1, err
}
func (s *SparkCoreAdaptor) EventStream(source string, name string) (event *gobot.Event, err error) {
	var url string
	switch source {
	case "all":
		url = fmt.Sprintf("%s/v1/events/%s?access_token=%s", s.APIServer, name, s.AccessToken)
	case "devices":
		url = fmt.Sprintf("%s/v1/devices/events/%s?access_token=%s", s.APIServer, name, s.AccessToken)
	case "device":
		url = fmt.Sprintf("%s/events/%s?access_token=%s", s.deviceURL(), name, s.AccessToken)
	default:
		err = errors.New("source param should be: all, devices or device")
		return
	}
	events, _, err := eventSource(url)
	if err != nil {
		return
	}
	go func() {
		for {
			select {
			case ev := <-events:
				if ev.Event() != "" && ev.Data() != "" {
					s.Publish(ev.Event(), ev.Data())
				}
			}
		}
	}()
	return
}