func (c *Client) GetTask(id string) *GetTaskResult {
	resp, err := c.do("GET", fmt.Sprintf("/tasks/%v", id), ContentTypeJSON, nil)
	if err != nil {
		return &GetTaskResult{Err: err}
	}
	switch resp.Meta.Type {
	case rbody.ScheduledTaskReturnedType:
		return &GetTaskResult{resp.Body.(*rbody.ScheduledTaskReturned), nil}
	case rbody.ErrorType:
		return &GetTaskResult{Err: resp.Body.(*rbody.Error)}
	default:
		return &GetTaskResult{Err: ErrAPIResponseMetaType}
	}
}
GetTask retrieves the task given a task id through an HTTP GET call.
A scheduled task returns if it succeeds. Otherwise, an error is returned.
package client
import (
	"bufio"
	"encoding/json"
	"errors"
	"fmt"
	"net/http"
	"strings"
	"time"
	"github.com/intelsdi-x/snap/core"
	"github.com/intelsdi-x/snap/mgmt/rest/v1/rbody"
	"github.com/intelsdi-x/snap/scheduler/wmap"
)
type Schedule struct {
	Type string `json:"type,omitempty"`
	Interval string `json:"interval,omitempty"`
	StartTimestamp *time.Time `json:"start_timestamp,omitempty"`
	StopTimestamp *time.Time `json:"stop_timestamp,omitempty"`
	Count uint `json:"count,omitempty"`
}
func (c *Client) CreateTask(s *Schedule, wf *wmap.WorkflowMap, name string, deadline string, startTask bool, maxFailures int) *CreateTaskResult {
	t := core.TaskCreationRequest{
		Schedule: &core.Schedule{
			Type:           s.Type,
			Interval:       s.Interval,
			StartTimestamp: s.StartTimestamp,
			StopTimestamp:  s.StopTimestamp,
			Count:          s.Count,
		},
		Workflow:    wf,
		Start:       startTask,
		MaxFailures: maxFailures,
	}
	if name != "" {
		t.Name = name
	}
	if deadline != "" {
		t.Deadline = deadline
	}
	j, err := json.Marshal(t)
	if err != nil {
		return &CreateTaskResult{Err: err}
	}
	resp, err := c.do("POST", "/tasks", ContentTypeJSON, j)
	if err != nil {
		return &CreateTaskResult{Err: err}
	}
	switch resp.Meta.Type {
	case rbody.AddScheduledTaskType:
		return &CreateTaskResult{resp.Body.(*rbody.AddScheduledTask), nil}
	case rbody.ErrorType:
		return &CreateTaskResult{Err: resp.Body.(*rbody.Error)}
	default:
		return &CreateTaskResult{Err: ErrAPIResponseMetaType}
	}
}
func (c *Client) WatchTask(id string) *WatchTasksResult {
	oldTimeout := c.http.Timeout
	c.http.Timeout = time.Duration(0)
	r := &WatchTasksResult{
		EventChan: make(chan *rbody.StreamedTaskEvent),
		DoneChan:  make(chan struct{}),
	}
	url := fmt.Sprintf("%s/tasks/%v/watch", c.prefix, id)
	req, err := http.NewRequest("GET", url, nil)
	addAuth(req, c.Username, c.Password)
	if err != nil {
		r.Err = err
		r.Close()
		return r
	}
	resp, err := c.http.Do(req)
	if err != nil {
		if strings.Contains(err.Error(), "tls: oversized record") || strings.Contains(err.Error(), "malformed HTTP response") {
			r.Err = fmt.Errorf("error connecting to API URI: %s. Do you have an http/https mismatch?", c.URL)
		} else {
			r.Err = err
		}
		r.Close()
		return r
	}
	if resp.StatusCode != 200 {
		ar, err := httpRespToAPIResp(resp)
		if err != nil {
			r.Err = err
		} else {
			r.Err = errors.New(ar.Meta.Message)
		}
		r.Close()
		return r
	}
	go func() {
		reader := bufio.NewReader(resp.Body)
		defer func() { c.http.Timeout = oldTimeout }()
		for {
			select {
			case <-r.DoneChan:
				resp.Body.Close()
				return
			default:
				line, _ := reader.ReadBytes('\n')
				sline := string(line)
				if sline == "" || sline == "\n" {
					continue
				}
				if strings.HasPrefix(sline, "data:") {
					sline = strings.TrimPrefix(sline, "data:")
					line = []byte(sline)
				}
				ste := &rbody.StreamedTaskEvent{}
				err := json.Unmarshal(line, ste)
				if err != nil {
					r.Err = err
					r.Close()
					return
				}
				switch ste.EventType {
				case rbody.TaskWatchTaskDisabled:
					r.EventChan <- ste
					r.Close()
				case rbody.TaskWatchTaskStopped, rbody.TaskWatchTaskEnded, rbody.TaskWatchTaskStarted, rbody.TaskWatchMetricEvent:
					r.EventChan <- ste
				}
			}
		}
	}()
	return r
}
func (c *Client) GetTasks() *GetTasksResult {
	resp, err := c.do("GET", "/tasks", ContentTypeJSON, nil)
	if err != nil {
		return &GetTasksResult{Err: err}
	}
	switch resp.Meta.Type {
	case rbody.ScheduledTaskListReturnedType:
		return &GetTasksResult{resp.Body.(*rbody.ScheduledTaskListReturned), nil}
	case rbody.ErrorType:
		return &GetTasksResult{Err: resp.Body.(*rbody.Error)}
	default:
		return &GetTasksResult{Err: ErrAPIResponseMetaType}
	}
}