You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwhisk.apache.org by da...@apache.org on 2017/08/17 03:24:19 UTC
[incubator-openwhisk-client-swift] branch master updated: Update
.swift and .h files to ASF license headers.
This is an automated email from the ASF dual-hosted git repository.
daisyguo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-openwhisk-client-swift.git
The following commit(s) were added to refs/heads/master by this push:
new 7062e68 Update .swift and .h files to ASF license headers.
7062e68 is described below
commit 7062e6848d516b70d76606c4693c5ab8ac78ad42
Author: Matt Rutkowski <mr...@us.ibm.com>
AuthorDate: Thu Jul 6 12:03:03 2017 -0500
Update .swift and .h files to ASF license headers.
---
OpenWhisk/Config.swift | 61 +++---
OpenWhisk/OpenWhisk.h | 13 +-
OpenWhisk/OpenWhiskButton.swift | 75 +++----
OpenWhisk/OpenWhiskSDK.swift | 219 +++++++++++----------
OpenWhiskTests/OpenWhiskTests.swift | 197 +++++++++---------
Package.swift | 31 +--
.../OpenWhiskStarterApp/AppDelegate.swift | 29 +--
.../OpenWhiskStarterApp/FilterForecast.swift | 17 +-
.../OpenWhiskStarterApp/ResultSetCell.swift | 31 +--
.../ResultSetTableController.swift | 76 +++----
.../SelfSignedNetworkDelegate.swift | 31 +--
.../iOS/starterapp/OpenWhiskStarterApp/Utils.swift | 19 +-
.../OpenWhiskStarterApp/ViewController.swift | 93 ++++-----
13 files changed, 452 insertions(+), 440 deletions(-)
diff --git a/OpenWhisk/Config.swift b/OpenWhisk/Config.swift
index 90d620f..5ef1515 100644
--- a/OpenWhisk/Config.swift
+++ b/OpenWhisk/Config.swift
@@ -1,18 +1,19 @@
/*
-* Copyright 2015-2016 IBM Corporation
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
import Foundation
@@ -20,7 +21,7 @@ import Foundation
Retrieves basic configuration information for the SDK specified in WhiskConfig.plist or environment variables
*/
public class Config {
-
+
class func getHostAndPath(type:String) -> String? {
var url: String? = nil
@@ -29,21 +30,21 @@ public class Config {
} else {
print("Configuration file missing, cannot config network call")
}
-
+
return url
}
-
-
+
+
private class func getConfigDictionary() -> NSDictionary? {
-
+
// Attempt 1, load the bundle from a local reference to this classes bundle
// I'am assuming the WhiskResources bundle is in the framework's root bundle
let frameworkBundle = Bundle(for: Config.self)
-
+
if let bundlePath = frameworkBundle.path(forResource: "OpenWhiskResources", ofType: "bundle") {
if let bundle = Bundle(path: bundlePath) {
let configFile = bundle.path(forResource: "OpenWhiskConfig", ofType: "plist")
-
+
if let configFile = configFile {
let config = NSDictionary(contentsOfFile: configFile) as? [String: AnyObject]
if let config = config {
@@ -55,7 +56,7 @@ public class Config {
} else if let bundlePath = frameworkBundle.path(forResource: "OpenWhiskWatchResources", ofType: "bundle") {
if let bundle = Bundle(path: bundlePath) {
let configFile = bundle.path(forResource: "OpenWhiskConfig", ofType: "plist")
-
+
if let configFile = configFile {
let config = NSDictionary(contentsOfFile: configFile) as? [String: AnyObject]
if let config = config {
@@ -75,24 +76,24 @@ public class Config {
print("Can't find configuration information")
}
}
-
+
return nil
-
+
}
-
-
-
+
+
+
/*
Can be used to read authentication credentials from env variables. Useful for unit tests and maybe some build tasks
but not much else?
*/
public class func getAuthToken() -> (apiKey: String?, apiSecret: String?)? {
-
+
let dict = ProcessInfo.processInfo.environment
let key = dict["OPENWHISK_TESTAPIKEY"]
let secret = dict["OPENWHISK_TESTAPISECRET"]
-
+
return(key, secret)
}
-
+
}
diff --git a/OpenWhisk/OpenWhisk.h b/OpenWhisk/OpenWhisk.h
index 6b134c6..ccf3189 100644
--- a/OpenWhisk/OpenWhisk.h
+++ b/OpenWhisk/OpenWhisk.h
@@ -1,11 +1,12 @@
/*
- * Copyright 2015-2016 IBM Corporation
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
diff --git a/OpenWhisk/OpenWhiskButton.swift b/OpenWhisk/OpenWhiskButton.swift
index 9808d56..8de1778 100644
--- a/OpenWhisk/OpenWhiskButton.swift
+++ b/OpenWhisk/OpenWhiskButton.swift
@@ -1,11 +1,12 @@
/*
- * Copyright 2015-2016 IBM Corporation
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -17,103 +18,103 @@
import UIKit
/*
-
+
Convenience UI element that allows you to invoke whisk actions. You can use like a normal UIButton and handle all the press events yourself, or you can have the button "self-contained". If you set listenForPressEvents = true it will listen for its own press events and invoke the the configured action.
-
+
*/
@objc(WhiskButton) public class WhiskButton: UIButton {
-
+
var whisk: Whisk?
var urlSession: URLSession?
-
+
var actionParameters: Dictionary<String,AnyObject>?
var actionHasResult: Bool = false
var actionName: String?
var actionPackage: String?
var actionNamespace: String?
var isListeningToSelf: Bool?
-
+
public required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
-
+
public override init(frame: CGRect) {
super.init(frame: frame)
}
-
+
public var listenForPressEvents: Bool? {
get {
return isListeningToSelf
}
-
+
set {
if newValue == true {
self.addTarget(self, action: #selector(WhiskButton.buttonPressed), for: .touchUpInside)
} else {
self.removeTarget(self, action: #selector(WhiskButton.buttonPressed), for: .touchUpInside)
}
-
+
isListeningToSelf = newValue
}
}
public var actionButtonCallback: ((Dictionary<String,AnyObject>?, WhiskError?) -> Void)?
-
-
+
+
func buttonPressed() {
invokeAction(parameters: nil, actionCallback: actionButtonCallback)
}
-
+
public func setupWhiskAction(qualifiedName qName:String, credentials: WhiskCredentials, hasResult: Bool = false,parameters: Dictionary<String, AnyObject>? = nil, urlSession: URLSession? = nil, baseUrl: String? = nil) throws {
-
+
let pathParts = try Whisk.processQualifiedName(qName)
-
+
setupWhiskAction(pathParts.name, package: pathParts.package, namespace: pathParts.namespace, credentials: credentials, hasResult: hasResult, parameters: parameters, urlSession: urlSession, baseUrl: baseUrl)
}
-
+
public func setupWhiskAction(_ name: String, package: String? = nil, namespace: String = "_", credentials: WhiskCredentials, hasResult: Bool = false,parameters: Dictionary<String, AnyObject>? = nil, urlSession: URLSession? = nil, baseUrl: String? = nil) {
-
+
whisk = Whisk(credentials: credentials)
-
+
if let session = urlSession {
whisk?.urlSession = session
}
-
+
if let baseUrl = baseUrl {
whisk?.baseURL = baseUrl
}
-
+
actionParameters = parameters
actionName = name
actionPackage = package
actionNamespace = namespace
actionHasResult = hasResult
}
-
+
public func invokeAction(parameters: [String:AnyObject]? = nil, actionCallback: ((Dictionary<String,AnyObject>?, WhiskError?) -> Void)?) {
-
+
if let whisk = whisk, let actionName = actionName, let actionNamespace = actionNamespace {
-
+
let queue = DispatchQueue(label:"com.ibm.mobilefirst.openwhisk.invokeAction")
queue.async(qos: .userInitiated) {
do {
-
+
var params:[String:AnyObject]?
-
+
if let parameters = parameters {
params = parameters
} else {
params = self.actionParameters
}
-
+
try whisk.invokeAction(name: actionName, package: self.actionPackage, namespace: actionNamespace, parameters: params as AnyObject?, hasResult: self.actionHasResult, callback: {(reply, error) in
-
-
+
+
// note callback is in main queue already we should be on the UI thread
if let actionCallback = actionCallback {
actionCallback(reply, error)
}
-
-
+
+
})
} catch {
print("Error invoking action: \(error)")
@@ -122,7 +123,7 @@ import UIKit
} else {
print("WhiskButton action not initialized")
}
-
+
}
-
+
}
diff --git a/OpenWhisk/OpenWhiskSDK.swift b/OpenWhisk/OpenWhiskSDK.swift
index 2fbd582..4ce7e4b 100644
--- a/OpenWhisk/OpenWhiskSDK.swift
+++ b/OpenWhisk/OpenWhiskSDK.swift
@@ -1,18 +1,19 @@
/*
-* Copyright 2015-2016 IBM Corporation
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
import Foundation
@@ -29,16 +30,16 @@ public struct WhiskCredentials {
self.sessionToken = sessionToken
self.jwtToken = jwtToken
}
-
+
// whisk credentials
public var accessKey: String?
public var accessToken: String?
public var sessionToken: String?
-
+
// optional app credentials
public var appKey: String?
public var appSecret: String?
-
+
// optional token for custom authentication flow
public var jwtToken: String?
}
@@ -60,39 +61,39 @@ enum WhiskType {
/* Main class to hold the calls to invoke Actions and fire Triggers */
public class Whisk {
-
+
// Secrets needed to call Whisk API
let AccessKey: String? // Whisk key
let AccessToken: String? // Whisk token
let AppKey: String? // application Key (currently not used)
let AppSecret: String? // application Secret (curently not used)
-
+
// api Host for Whisk backend
public var whiskBaseURL: String?
-
+
// set to non-nil if using a custom session
public var urlSession: URLSession?
-
+
public var verboseReplies: Bool = false
-
+
// Set these if you want to run unit tests and mock
// calls to Whisk backend.
public var useMock: Bool = false
public var mockReply: [String: AnyObject]?
public var mockError: WhiskError?
-
-
+
+
// return base URL of backend including common path for all API calls
public var baseURL: String? {
set {
if let url = newValue {
-
+
let c = url.characters.last
-
+
let separater = c == "/" ? "" : "/"
-
+
whiskBaseURL = url + separater + "api/v1/"
-
+
} else {
whiskBaseURL = nil
}
@@ -101,7 +102,7 @@ public class Whisk {
return whiskBaseURL
}
}
-
+
// Initialize with credentials, region currently not used
public init(credentials: WhiskCredentials, region: String = "US-East-1") {
// initialize
@@ -109,28 +110,28 @@ public class Whisk {
AccessToken = credentials.accessToken
AppKey = credentials.appKey
AppSecret = credentials.appSecret
-
+
}
-
-
+
+
/* Base function to fire Whisk Trigger identified by qualified name */
public func fireTrigger(qualifiedName: String, parameters: AnyObject? = nil, callback: @escaping (Dictionary<String,AnyObject>?, WhiskError?)->Void) throws {
-
+
let pathParts = try Whisk.processQualifiedName(qualifiedName)
try fireTrigger(name: pathParts.name, package: pathParts.package, namespace: pathParts.namespace, parameters: parameters, callback: callback)
}
-
+
/* Base function to invoke Whisk Action identified by qualified name */
public func invokeAction(qualifiedName: String, parameters: AnyObject?, hasResult: Bool = false, callback: @escaping (Dictionary<String,AnyObject>?, WhiskError?)->Void) throws {
-
+
let pathParts = try Whisk.processQualifiedName(qualifiedName)
try invokeAction(name: pathParts.name, package: pathParts.package, namespace: pathParts.namespace, parameters: parameters, hasResult: hasResult, callback: callback)
}
-
-
+
+
/* Base function to fire Whisk Trigger identified by components */
public func fireTrigger(name: String, package: String? = nil, namespace: String = "_", parameters: AnyObject? = nil, callback: @escaping (Dictionary<String,AnyObject>?, WhiskError?)->Void) throws {
-
+
if let accessKey = AccessKey, let accessToken = AccessToken {
try httpRequestWhiskAPI(accessKey: accessKey, accessToken: accessToken, namespace: namespace, verb: "POST", type: .trigger, package: package, name:name, parameters: parameters, isSync: false, callback: { (jsonArray, error) in
if let error = error {
@@ -142,43 +143,43 @@ public class Whisk {
} else {
throw WhiskError.credentialError(description: "Access key and token not set")
}
-
-
+
+
}
-
+
/* Base function to invoke Whisk Action identified by components */
public func invokeAction(name: String, package: String? = nil, namespace: String = "_", parameters: AnyObject?, hasResult:Bool = false, callback: @escaping (Dictionary<String,AnyObject>?, WhiskError?)-> Void) throws {
if let accessKey = AccessKey, let accessToken = AccessToken {
-
+
try httpRequestWhiskAPI(accessKey: accessKey, accessToken: accessToken, namespace: namespace, verb: "POST", type: .action, package: package, name: name, parameters: parameters, isSync: hasResult, callback: {(jsonDict, error) in
if let error = error {
callback(nil, error)
} else {
callback(jsonDict, nil)
}
-
+
})
} else {
throw WhiskError.credentialError(description: "Access key and token not set")
}
-
+
}
-
+
/* can redirect call here, e.g. if mocking */
func httpRequestWhiskAPI(accessKey: String, accessToken: String, namespace: String, verb: String, type: WhiskType, package: String?, name: String, parameters: AnyObject?, isSync: Bool, callback: @escaping (Dictionary<String,AnyObject>?, WhiskError?) ->Void) throws {
-
+
if useMock {
callback(mockReply, mockError)
-
+
} else {
try whiskAPI(accessKey: accessKey, accessToken: accessToken, namespace: namespace, verb: verb, type: type, package: package, name: name, parameters: parameters, isSync: isSync, callback: callback)
}
}
-
-
+
+
/* Network call */
func whiskAPI(accessKey: String, accessToken: String, namespace: String, verb: String, type: WhiskType, package: String?, name: String, parameters: AnyObject?, isSync: Bool, callback: @escaping (Dictionary<String,AnyObject>?,WhiskError?) ->Void) throws {
-
+
// set parameters
var paramsIsDict = false
if let parameters = parameters {
@@ -186,14 +187,14 @@ public class Whisk {
paramsIsDict = true
}
}
-
+
// set authorization string
let loginString = NSString(format: "%@:%@", accessKey, accessToken)
let loginData: Data = loginString.data(using: String.Encoding.utf8.rawValue)!
let base64LoginString = loginData.base64EncodedString(options: NSData.Base64EncodingOptions(rawValue: 0))
-
+
let typeStr: String!
-
+
// set type
switch type {
case .action:
@@ -201,22 +202,22 @@ public class Whisk {
case .trigger:
typeStr = "triggers"
}
-
+
// get base URL
guard let actionURL = baseURL != nil ? baseURL : Config.getHostAndPath(type: typeStr) else {
callback(nil, WhiskError.httpError(description: "Base URL not set, try using whisk.baseUrl setting", statusCode: 400))
return
}
-
+
// append namespace and trigger/action path
var syncName = "namespaces/"
-
+
var namespaceStr = namespace
-
+
if namespace.characters.count == 0 {
namespaceStr = "_"
}
-
+
if let package = package {
if package.characters.count == 0 {
syncName = syncName + namespaceStr+"/"+typeStr+"/"+name
@@ -226,40 +227,40 @@ public class Whisk {
} else {
syncName = syncName + namespaceStr+"/"+typeStr+"/"+name
}
-
+
// if action has results, specify as blocking
if isSync == true {
syncName += "?blocking=true"
}
-
+
// use this for verbose replies
let restCall = actionURL+syncName
-
+
guard let encodedPath = syncName.addingPercentEncoding(withAllowedCharacters: CharacterSet.urlQueryAllowed) else {
callback(nil, WhiskError.httpError(description: "URL Encode error \(syncName)", statusCode: 400))
return
}
-
+
syncName = encodedPath
-
+
// create request
guard let url = URL(string:actionURL+syncName) else {
// send back error on main queue
-
+
callback(nil, WhiskError.httpError(description: "Malformed url \(actionURL+syncName)", statusCode: 400))
-
+
return
-
+
}
-
+
var request = URLRequest(url: url)
request.setValue("application/json; charset=utf-8", forHTTPHeaderField: "Content-Type")
request.addValue("Basic \(base64LoginString)", forHTTPHeaderField: "Authorization")
request.httpMethod = verb
-
+
// create JSON from parameters dictionary
do {
-
+
if let parameters = parameters {
if paramsIsDict {
request.httpBody = try JSONSerialization.data(withJSONObject: parameters, options: JSONSerialization.WritingOptions())
@@ -273,12 +274,12 @@ public class Whisk {
}
}
}
-
+
} catch {
print("Error parsing JSON in Whisk request: \(error)")
}
-
-
+
+
// retrieve session as default or use developer specified session
let sess: URLSession!
if let _ = urlSession {
@@ -287,14 +288,14 @@ public class Whisk {
let sessConfig = URLSessionConfiguration.default
sess = URLSession(configuration: sessConfig)
}
-
+
// perform network request
let task = sess.dataTask(with: request) {
data, response, error in
let statusCode: Int!
-
+
if let error = error {
-
+
if let httpResponse = response as? HTTPURLResponse {
statusCode = httpResponse.statusCode
} else {
@@ -304,28 +305,28 @@ public class Whisk {
DispatchQueue.main.async {
callback(nil, WhiskError.httpError(description: "\(error.localizedDescription)", statusCode: statusCode))
}
-
+
return
-
+
} else {
-
+
if let httpResponse = response as? HTTPURLResponse {
statusCode = httpResponse.statusCode
do {
// success
if statusCode < 300 {
-
+
switch verb {
// is an action invocation
case "POST":
var jsonDict = [String:AnyObject]()
-
+
let respDict = try JSONSerialization.jsonObject(with: data!, options: JSONSerialization.ReadingOptions.mutableContainers) as! Dictionary<String, AnyObject>
jsonDict = respDict
-
-
+
+
if let whiskError = jsonDict["error"] as? String {
-
+
var errorCode = -1
if let code = jsonDict["code"] as? Int {
errorCode = code
@@ -334,14 +335,14 @@ public class Whisk {
DispatchQueue.main.async {
callback(nil, WhiskError.whiskProcessingError(description: "errorCode:\(errorCode), \(whiskError)", errorCode: errorCode))
}
-
+
} else {
-
+
var whiskReply = [String:AnyObject]()
-
+
if self.verboseReplies == true {
whiskReply = jsonDict
-
+
// add the rest call made to verbose replies for debugging
switch type {
case .action:
@@ -349,24 +350,24 @@ public class Whisk {
case .trigger:
whiskReply["triggerUrl"] = restCall as AnyObject?
}
-
+
} else {
let reply = jsonDict
whiskReply["activationId"] = reply["activationId"]
-
+
if isSync == true {
if let whiskResponse = reply["response"] as? [String:AnyObject] {
-
+
if let actionResult = whiskResponse["result"] {
-
+
//if let payload = actionResult["payload"] {
-
+
let payload:AnyObject? = actionResult
if payload is String {
do {
-
+
let payloadObj = try JSONSerialization.jsonObject(with: (payload as! String).data(using: String.Encoding.utf8)!, options: [])
-
+
whiskReply["result"] = payloadObj as AnyObject
} catch {
print("Error parsing payload into JSON, defaulting to string")
@@ -380,33 +381,33 @@ public class Whisk {
}
}
}
-
+
// send back successful response on main queue
DispatchQueue.main.async {
callback(whiskReply, nil)
}
}
-
+
// get info about actions/triggers
// not used right now
case "GET":
let jsonArray = try JSONSerialization.jsonObject(with: data!, options: JSONSerialization.ReadingOptions.mutableContainers) as! NSArray
let jsonDict:Dictionary<String, AnyObject> = ["array":jsonArray]
-
+
DispatchQueue.main.async {
callback(jsonDict, nil)
}
-
+
default:
break
-
+
}
} else {
DispatchQueue.main.async {
callback(nil, WhiskError.httpError(description: "Whisk returned HTTP error code", statusCode: statusCode))
}
}
-
+
} catch {
print("Error parsing JSON from Whisk response: \(error)")
DispatchQueue.main.async {
@@ -416,25 +417,25 @@ public class Whisk {
}
}
}
-
+
task.resume()
-
-
+
+
}
-
+
/* Convert qualified name string into component parts of action or trigger call */
class func processQualifiedName(_ qName: String) throws -> (namespace:String, package: String?, name: String) {
var namespace = "_"
var package: String? = nil
var name = ""
var doesSpecifyNamespace = false
-
+
if qName.characters.first == "/" {
doesSpecifyNamespace = true
}
-
+
let pathParts = qName.characters.split { $0 == "/" }.map(String.init)
-
+
if doesSpecifyNamespace == true {
if pathParts.count == 2 {
namespace = pathParts[0]
@@ -456,10 +457,10 @@ public class Whisk {
throw WhiskError.qualifiedNameFormat(description: "Cannot parse \(qName)")
}
}
-
+
return (namespace, package, name)
}
-
+
}
diff --git a/OpenWhiskTests/OpenWhiskTests.swift b/OpenWhiskTests/OpenWhiskTests.swift
index 51e502c..ed3e743 100644
--- a/OpenWhiskTests/OpenWhiskTests.swift
+++ b/OpenWhiskTests/OpenWhiskTests.swift
@@ -1,11 +1,12 @@
/*
- * Copyright 2015-2016 IBM Corporation
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -18,7 +19,7 @@ import XCTest
import OpenWhisk
class NetworkUtilsDelegate: NSObject, URLSessionDelegate {
-
+
func urlSession(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
completionHandler(Foundation.URLSession.AuthChallengeDisposition.useCredential, URLCredential(trust: challenge.protectionSpace.serverTrust!))
}
@@ -26,77 +27,77 @@ class NetworkUtilsDelegate: NSObject, URLSessionDelegate {
}
class OpenWhiskTests: XCTestCase {
-
+
let Timeout:TimeInterval = 100 // time to wait for whisk action to complete
-
+
var apiKey: String?
var apiSecret: String?
-
+
override func setUp() {
super.setUp()
-
-
+
+
if let config = Config.getAuthToken() {
apiKey = config.apiKey
apiSecret = config.apiSecret
}
-
+
}
-
+
override func tearDown() {
super.tearDown()
}
-
-
-
+
+
+
func testWhiskParameterizedAction() {
-
+
if let apiKey = apiKey, let apiSecret = apiSecret {
// allow for self-signed certificates
let session = URLSession(configuration: URLSessionConfiguration.default, delegate: NetworkUtilsDelegate(), delegateQueue:OperationQueue.main)
-
+
let credentials = WhiskCredentials(accessKey: apiKey, accessToken: apiSecret)
let whisk = Whisk(credentials: credentials)
whisk.urlSession = session
-
+
// setup for async testing
let expectation = self.expectation(description: "Whisk Callback")
-
+
do {
try whisk.invokeAction(name: "date", package: "utils", namespace: "whisk.system", parameters: nil, hasResult: true,
callback: {(reply, error) in
-
+
if let error = error {
if case let WhiskError.httpError(description, statusCode) = error {
-
+
print("Error: \(description) statusCode: \(statusCode))")
-
+
if statusCode != 401 && statusCode != 404 && statusCode != 408 && statusCode != 500 {
XCTFail("Error: \(description) statusCode: \(statusCode))")
}
-
+
}
}
-
+
if let reply = reply {
-
+
print("Reply is \(reply)")
XCTAssertNotNil(reply["activationId"])
let id = reply["activationId"] as! String
print("Got id \(id)")
}
-
+
expectation.fulfill()
-
-
+
+
})
} catch {
print(error)
XCTFail("Error invoking action \(error)")
}
-
+
waitForExpectations(timeout: Timeout, handler: { error in
-
+
if let error = error {
print("Error: \(error)")
}
@@ -105,52 +106,52 @@ class OpenWhiskTests: XCTestCase {
XCTFail("No credentials available to run test")
}
}
-
+
func testWhiskQualifiedNameAction() {
-
+
if let apiKey = apiKey, let apiSecret = apiSecret {
// setup for async testing
let expectation = self.expectation(description: "Whisk Callback")
// allow for self-signed certificates
let session = URLSession(configuration: URLSessionConfiguration.default, delegate: NetworkUtilsDelegate(), delegateQueue:OperationQueue.main)
-
+
let credentials = WhiskCredentials(accessKey: apiKey, accessToken: apiSecret)
let whisk = Whisk(credentials: credentials)
whisk.urlSession = session
do {
try whisk.invokeAction(qualifiedName: "/whisk.system/utils/date", parameters: nil, hasResult: true, callback: {(reply, error) in
-
+
if let error = error {
if case let WhiskError.httpError(description, statusCode) = error {
-
+
print("Error: \(description) statusCode: \(statusCode))")
-
+
if statusCode != 401 && statusCode != 404 && statusCode != 408 && statusCode != 500 {
XCTFail("Error: \(description) statusCode: \(statusCode))")
}
-
+
}
}
-
+
if let reply = reply {
-
+
print("Reply is \(reply)")
XCTAssertNotNil(reply["activationId"])
let id = reply["activationId"] as! String
print("Got id \(id)")
}
-
+
expectation.fulfill()
-
-
+
+
})
} catch {
print(error)
XCTFail("Error invoking action \(error)")
}
-
+
waitForExpectations(timeout: Timeout, handler: { error in
-
+
if let error = error {
print("Error: \(error)")
}
@@ -159,154 +160,154 @@ class OpenWhiskTests: XCTestCase {
XCTFail("No credentials available to run test")
}
}
-
+
func testWhiskSettingBaseUrl() {
-
+
if let apiKey = apiKey, let apiSecret = apiSecret {
// setup for async testing
let expectation = self.expectation(description: "Whisk Callback")
-
+
// allow for self-signed certificates
let session = URLSession(configuration: URLSessionConfiguration.default, delegate: NetworkUtilsDelegate(), delegateQueue:OperationQueue.main)
-
+
let credentials = WhiskCredentials(accessKey: apiKey, accessToken: apiSecret)
let whisk = Whisk(credentials: credentials)
whisk.urlSession = session
-
+
do {
whisk.baseURL = "https://openwhisk.ng.bluemix.net"
-
+
try whisk.invokeAction(qualifiedName: "/whisk.system/utils/date", parameters: nil, hasResult: true, callback: {(reply, error) in
-
+
if let error = error {
if case let WhiskError.httpError(description, statusCode) = error {
-
+
print("Error: \(description) statusCode: \(statusCode))")
-
+
if statusCode != 401 && statusCode != 404 && statusCode != 408 && statusCode != 500 {
XCTFail("Error: \(description) statusCode: \(statusCode))")
}
-
+
}
}
-
+
if let reply = reply {
-
+
print("Reply is \(reply)")
XCTAssertNotNil(reply["activationId"])
let id = reply["activationId"] as! String
print("Got id \(id)")
}
-
+
expectation.fulfill()
-
-
+
+
})
} catch {
print(error)
XCTFail("Error invoking action \(error)")
}
-
+
waitForExpectations(timeout: Timeout, handler: { error in
-
+
if let error = error {
print("Error: \(error)")
}
})
-
+
} else {
XCTFail("No credentials available to run test")
}
}
-
+
func testWhiskVerboseReplies() {
-
+
if let apiKey = apiKey, let apiSecret = apiSecret {
// setup for async testing
let expectation = self.expectation(description: "Whisk Callback")
-
+
// allow for self-signed certificates
let session = URLSession(configuration: URLSessionConfiguration.default, delegate: NetworkUtilsDelegate(), delegateQueue:OperationQueue.main)
-
+
let credentials = WhiskCredentials(accessKey: apiKey, accessToken: apiSecret)
let whisk = Whisk(credentials: credentials)
whisk.urlSession = session
whisk.baseURL = "https://openwhisk.ng.bluemix.net"
-
+
do {
whisk.verboseReplies = true
-
+
try whisk.invokeAction(qualifiedName: "/whisk.system/utils/date", parameters: nil, hasResult: true, callback: {(reply, error) in
-
+
if let error = error {
if case let WhiskError.httpError(description, statusCode) = error {
-
+
print("Error: \(description) statusCode: \(statusCode))")
-
+
if statusCode != 401 && statusCode != 404 && statusCode != 408 && statusCode != 500 {
XCTFail("Error: \(description) statusCode: \(statusCode))")
}
-
+
}
}
-
+
if let reply = reply {
-
+
print("Reply is \(reply)")
XCTAssertNotNil(reply["activationId"])
let id = reply["activationId"] as! String
print("Got id \(id)")
}
-
+
expectation.fulfill()
-
-
+
+
})
} catch {
print(error)
XCTFail("Error invoking action \(error)")
}
-
+
waitForExpectations(timeout: Timeout, handler: { error in
-
+
if let error = error {
print("Error: \(error)")
}
})
-
+
} else {
XCTFail("No credentials available to run test")
}
}
-
+
func testWhiskTrigger() {
-
+
if let apiKey = apiKey, let apiSecret = apiSecret {
// setup for async testing
let expectation = self.expectation(description: "Whisk Callback")
-
+
// allow for self-signed certificates
let session = URLSession(configuration: URLSessionConfiguration.default, delegate: NetworkUtilsDelegate(), delegateQueue:OperationQueue.main)
-
+
let credentials = WhiskCredentials(accessKey: apiKey, accessToken: apiSecret)
let whisk = Whisk(credentials: credentials)
whisk.urlSession = session
whisk.baseURL = "https://openwhisk.ng.bluemix.net"
-
+
do {
-
+
try whisk.fireTrigger(name: "myTrigger", callback: { (reply, error) in
-
+
if let error = error {
if case let WhiskError.httpError(description, statusCode) = error {
-
+
print("Error: \(description) statusCode: \(statusCode))")
-
+
// actually any of these status codes are probably OK since the API call succeeded
if statusCode != 401 && statusCode != 404 && statusCode != 408 && statusCode != 500 {
XCTFail("Error: \(description) statusCode: \(statusCode))")
}
-
+
}
} else if let reply = reply {
print("\(reply)")
@@ -314,24 +315,24 @@ class OpenWhiskTests: XCTestCase {
print("No error or response")
}
})
-
+
expectation.fulfill()
-
+
} catch {
print(error)
XCTFail("Error invoking trigger \(error)")
}
-
+
waitForExpectations(timeout: Timeout, handler: { error in
-
+
if let error = error {
print("Error: \(error)")
}
})
-
+
} else {
XCTFail("No credentials available to run test")
}
}
-
+
}
diff --git a/Package.swift b/Package.swift
index 7c04fb6..737138b 100644
--- a/Package.swift
+++ b/Package.swift
@@ -1,22 +1,23 @@
/*
-* Copyright 2015-2016 IBM Corporation
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
import PackageDescription
let package = Package(
- name: "OpenWhisk",
+ name: "OpenWhisk",
exclude: ["OpenWhiskWatch","OpenWhiskTests", "OpenWhisk/OpenWhiskButton.swift"]
)
\ No newline at end of file
diff --git a/mobile/iOS/starterapp/OpenWhiskStarterApp/AppDelegate.swift b/mobile/iOS/starterapp/OpenWhiskStarterApp/AppDelegate.swift
index 0c3e6f6..847ee85 100644
--- a/mobile/iOS/starterapp/OpenWhiskStarterApp/AppDelegate.swift
+++ b/mobile/iOS/starterapp/OpenWhiskStarterApp/AppDelegate.swift
@@ -1,18 +1,19 @@
/*
-* Copyright 2015-2016 IBM Corporation
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
import UIKit
diff --git a/mobile/iOS/starterapp/OpenWhiskStarterApp/FilterForecast.swift b/mobile/iOS/starterapp/OpenWhiskStarterApp/FilterForecast.swift
index 07443de..994e17d 100644
--- a/mobile/iOS/starterapp/OpenWhiskStarterApp/FilterForecast.swift
+++ b/mobile/iOS/starterapp/OpenWhiskStarterApp/FilterForecast.swift
@@ -1,11 +1,12 @@
/*
- * Copyright 2015-2016 IBM Corporation
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -43,10 +44,10 @@ func main(args:[String:Any]) -> [String:Any] {
terse["min_temp"] = forecast["min_temp"]
terse["max_temp"] = forecast["max_temp"]
filteredForecasts.append(terse)
-
+
}
}
-
+
#endif
return [ "forecasts": filteredForecasts ]
}
diff --git a/mobile/iOS/starterapp/OpenWhiskStarterApp/ResultSetCell.swift b/mobile/iOS/starterapp/OpenWhiskStarterApp/ResultSetCell.swift
index 8dd219f..4e4b93e 100644
--- a/mobile/iOS/starterapp/OpenWhiskStarterApp/ResultSetCell.swift
+++ b/mobile/iOS/starterapp/OpenWhiskStarterApp/ResultSetCell.swift
@@ -1,18 +1,19 @@
/*
-* Copyright 2015-2016 IBM Corporation
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
import UIKit
@@ -21,5 +22,5 @@ class ResultSetCell: UITableViewCell {
@IBOutlet weak var valueLabel: UILabel!
@IBOutlet weak var nameLabel: UILabel!
-
+
}
diff --git a/mobile/iOS/starterapp/OpenWhiskStarterApp/ResultSetTableController.swift b/mobile/iOS/starterapp/OpenWhiskStarterApp/ResultSetTableController.swift
index eea4b3a..ea47f5c 100644
--- a/mobile/iOS/starterapp/OpenWhiskStarterApp/ResultSetTableController.swift
+++ b/mobile/iOS/starterapp/OpenWhiskStarterApp/ResultSetTableController.swift
@@ -1,50 +1,50 @@
/*
-* Copyright 2015-2016 IBM Corporation
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
import UIKit
class ResultSetTableController: UITableViewController {
-
+
var resultSet: [String: AnyObject]!
var names = [String]()
var values = [String]()
var isComplex = [Bool]()
-
+
override func viewDidLoad() {
super.viewDidLoad()
-
-
+
+
tableView.estimatedRowHeight = 44
tableView.rowHeight = UITableViewAutomaticDimension
-
+
navigationItem.title = "Action Results"
-
+
reloadTable()
}
-
+
func reloadTable() {
-
+
names = [String]()
values = [String]()
-
+
if let resultSet = resultSet , resultSet.count > 0 {
for (name, value) in resultSet {
names.append(name)
-
+
if let value = (value as? String) {
values.append(value)
isComplex.append(false)
@@ -77,31 +77,31 @@ class ResultSetTableController: UITableViewController {
}
}
}
-
-
+
+
}
-
-
+
+
// MARK UITableViewDataSource
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return resultSet.count
}
-
+
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "resultCell") as! ResultSetCell
-
+
cell.nameLabel.text = names[(indexPath as NSIndexPath).row]
cell.valueLabel.text = values[(indexPath as NSIndexPath).row]
-
+
if isComplex[(indexPath as NSIndexPath).row] == true {
cell.accessoryType = UITableViewCellAccessoryType.disclosureIndicator
}
-
-
+
+
return cell
-
+
}
-
-
-
+
+
+
}
diff --git a/mobile/iOS/starterapp/OpenWhiskStarterApp/SelfSignedNetworkDelegate.swift b/mobile/iOS/starterapp/OpenWhiskStarterApp/SelfSignedNetworkDelegate.swift
index 8f16746..c390b53 100644
--- a/mobile/iOS/starterapp/OpenWhiskStarterApp/SelfSignedNetworkDelegate.swift
+++ b/mobile/iOS/starterapp/OpenWhiskStarterApp/SelfSignedNetworkDelegate.swift
@@ -1,25 +1,26 @@
/*
-* Copyright 2015-2016 IBM Corporation
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
import Foundation
class SelfSignedNetworkDelegate: NSObject, URLSessionDelegate {
func urlSession(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
-
+
completionHandler(Foundation.URLSession.AuthChallengeDisposition.useCredential, URLCredential(trust: challenge.protectionSpace.serverTrust!))
}
}
diff --git a/mobile/iOS/starterapp/OpenWhiskStarterApp/Utils.swift b/mobile/iOS/starterapp/OpenWhiskStarterApp/Utils.swift
index d48cf86..2a13873 100644
--- a/mobile/iOS/starterapp/OpenWhiskStarterApp/Utils.swift
+++ b/mobile/iOS/starterapp/OpenWhiskStarterApp/Utils.swift
@@ -1,11 +1,12 @@
/*
- * Copyright 2015-2016 IBM Corporation
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -18,9 +19,9 @@
import Foundation
func convertReply(input: [String:AnyObject]) -> [String:Any] {
-
+
var output = [String:Any]()
-
+
for (key, value) in input {
if let value = value as? [[String: AnyObject]] {
var newValue = [[String:Any]]()
@@ -34,7 +35,7 @@ func convertReply(input: [String:AnyObject]) -> [String:Any] {
output[key] = newValue
}
}
-
+
return output
}
diff --git a/mobile/iOS/starterapp/OpenWhiskStarterApp/ViewController.swift b/mobile/iOS/starterapp/OpenWhiskStarterApp/ViewController.swift
index eda2f76..82205b4 100644
--- a/mobile/iOS/starterapp/OpenWhiskStarterApp/ViewController.swift
+++ b/mobile/iOS/starterapp/OpenWhiskStarterApp/ViewController.swift
@@ -1,18 +1,19 @@
/*
-* Copyright 2015-2016 IBM Corporation
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
import UIKit
@@ -20,59 +21,59 @@ import OpenWhisk
import CoreLocation
class ViewController: UIViewController, CLLocationManagerDelegate {
-
+
@IBOutlet weak var whiskButton: WhiskButton!
@IBOutlet weak var outputText: UITextView!
@IBOutlet weak var statusLabel: UILabel!
-
+
// Change to your whisk app key and secret.
let WhiskAppKey: String = "MyAppKey"
let WhiskAppSecret: String = "MyAppSecret"
-
+
// the URL for Whisk backend
let baseUrl: String? = "https://openwhisk.ng.bluemix.net"
-
+
// The action to invoke.
-
+
// Choice: specify components
let MyNamespace: String = "whisk.system"
let MyPackage: String? = "utils"
let MyWhiskAction: String = "date"
-
+
var MyActionParameters: [String:AnyObject]? = nil
let HasResult: Bool = true // true if the action returns a result
-
+
var session: URLSession!
-
+
let locationManager = CLLocationManager()
var currentLocation: [CLLocation]?
-
+
override func viewDidLoad() {
super.viewDidLoad()
-
+
// create custom session that allows self-signed certificates
let session = URLSession(configuration: URLSessionConfiguration.default, delegate: SelfSignedNetworkDelegate(), delegateQueue:OperationQueue.main)
-
+
// create whisk credentials token
let creds = WhiskCredentials(accessKey: WhiskAppKey,accessToken: WhiskAppSecret)
-
+
// Setup action using components
whiskButton.setupWhiskAction(MyWhiskAction, package: MyPackage, namespace: MyNamespace, credentials: creds, hasResult: HasResult, parameters: MyActionParameters, urlSession: session, baseUrl: baseUrl)
-
+
// setup location
locationManager.delegate = self
locationManager.requestWhenInUseAuthorization()
-
+
navigationItem.title = "Whisk"
-
+
}
-
+
@IBAction func whiskButtonPressed(sender: AnyObject) {
// Set latitude and longitude parameters.
if let currentLocation = currentLocation {
MyActionParameters = ["latitude": currentLocation[0].coordinate.latitude as AnyObject, "longitude": currentLocation[0].coordinate.longitude as AnyObject]
}
-
+
// Invoke action with parameters.
whiskButton.invokeAction(parameters: MyActionParameters, actionCallback: { reply, error in
if let error = error {
@@ -92,14 +93,14 @@ class ViewController: UIViewController, CLLocationManagerDelegate {
}
})
}
-
-
+
+
func displayOutput(reply: [String:AnyObject]) {
if let date = reply["date"] as? String{
self.outputText.text = "The date is \(reformatDate(dateStr: date))"
}
}
-
+
// Optional, can be used to display results in a UITableView
func displayResultView(reply: [String: AnyObject]) {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
@@ -107,43 +108,43 @@ class ViewController: UIViewController, CLLocationManagerDelegate {
vc.resultSet = reply
self.navigationController?.pushViewController(vc, animated: true)
}
-
-
+
+
// CLLocationDelegate Functions
func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {
print("Got location manager authorization status \(status)")
locationManager.startUpdatingLocation()
}
-
+
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
currentLocation = locations
}
-
-
+
+
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
-
+
// Convert string timestamp to a display format
func reformatDate(dateStr: String) -> String {
-
+
var newDateStr = dateStr
let formatter = DateFormatter()
formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZ"
-
+
formatter.timeZone = TimeZone(abbreviation: "UTC") //NSTimeZone(name: "UTC")
-
+
if let date = formatter.date(from: dateStr) {
formatter.dateFormat = "MMM dd EEEE yyyy HH:mm"
formatter.timeZone = TimeZone(abbreviation: "UTC")
newDateStr = formatter.string(from: date)
}
-
+
return newDateStr
}
-
-
+
+
}
--
To stop receiving notification emails like this one, please contact
['"commits@openwhisk.apache.org" <co...@openwhisk.apache.org>'].