Created
March 23, 2015 18:48
-
-
Save quintonwall/d0e50083abea0bff1f02 to your computer and use it in GitHub Desktop.
Complete TasksHandler file for Salesforce Wear with Apple Watch Webinar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// TaskHandler.swift | |
// SalesforceWatch | |
// | |
// Created by Quinton Wall on 3/23/15. | |
// Copyright (c) 2015 Salesforce, Inc. All rights reserved. | |
// | |
import Foundation | |
class TasksHandler: NSObject, SFRestDelegate { | |
var watchInfo : WatchInfo? | |
func getTasks() { | |
var sharedInstance = SFRestAPI.sharedInstance() | |
var request = sharedInstance.requestForQuery("SELECT Id, Status, Subject, Priority FROM Task Where IsClosed = false ORDER BY LastModifiedDate") | |
sharedInstance.send(request as SFRestRequest, delegate: self) | |
} | |
func updateTaskStatus(id: String, status: String, delegate: SFRestDelegate) { | |
let sharedInstance = SFRestAPI.sharedInstance() | |
let request = sharedInstance.requestForUpdateWithObjectType("Task", objectId: id, fields: ["Status" : status]) | |
sharedInstance.send(request, delegate: delegate) | |
} | |
func request(request: SFRestRequest?, didLoadResponse jsonResponse: AnyObject) { | |
var records = jsonResponse.objectForKey("records") as NSArray | |
println("request: Tasks: #records: \(records.count)"); | |
//send the block back to le watch | |
if let watchInfo = watchInfo { | |
let stuff = ["results" : records] | |
watchInfo.replyBlock(stuff) | |
} | |
} | |
func request(request: SFRestRequest?, didFailLoadWithError error:NSError) { | |
println("In Error: \(error)") | |
} | |
func requestDidCancelLoad(request: SFRestRequest) { | |
println("In requestDidCancelLoad \(request)") | |
} | |
func requestDidTimeout(request: SFRestRequest) { | |
println("In requestDidTimeout \(request)") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment