Browse Source

Update auth-library-swift dependency in Google samples, fix Linux problem in Datastore sample.

Tim Burks 8 years ago
parent
commit
d69c4e32ef

+ 1 - 1
Examples/Google/Datastore/Package.swift

@@ -19,7 +19,7 @@ let package = Package (
     dependencies: [
         .Package(url: "https://github.com/grpc/grpc-swift.git", Version(0,3,2)),
         .Package(url: "https://github.com/apple/swift-protobuf.git", Version(1,0,2)),
-        .Package(url: "https://github.com/google/auth-library-swift.git", Version(0,3,4)),
+        .Package(url: "https://github.com/google/auth-library-swift.git", Version(0,3,6)),
 	.Package(url: "https://github.com/kylef/Commander.git", Version(0,8,0)),
     ]
 )

+ 15 - 4
Examples/Google/Datastore/Sources/main.swift

@@ -14,6 +14,7 @@
  * limitations under the License.
  */
 import Foundation
+import Dispatch
 import gRPC
 import OAuth2
 import Commander
@@ -21,8 +22,13 @@ import Commander
 // Convert Encodable objects to dictionaries of property-value pairs.
 class PropertiesEncoder {
   static func encode<T : Encodable>(_ value : T) throws -> [String:Any]? {
-    let plist = try PropertyListEncoder().encode(value)
-    let properties = try PropertyListSerialization.propertyList(from:plist, options:[], format:nil)
+    #if os(OSX)
+      let plist = try PropertyListEncoder().encode(value)
+      let properties = try PropertyListSerialization.propertyList(from:plist, options:[], format:nil)
+    #else
+      let data = try JSONEncoder().encode(value)
+      let properties = try JSONSerialization.jsonObject(with:data, options:[])
+    #endif
     return properties as? [String:Any]
   }
 }
@@ -30,8 +36,13 @@ class PropertiesEncoder {
 // Create Decodable objects from dictionaries of property-value pairs.
 class PropertiesDecoder {
   static func decode<T: Decodable>(_ type: T.Type, from: [String:Any]) throws -> T {
-    let plist = try PropertyListSerialization.data(fromPropertyList: from, format: .binary, options:0)
-    return try PropertyListDecoder().decode(type, from: plist)
+    #if os(OSX)
+      let plist = try PropertyListSerialization.data(fromPropertyList: from, format: .binary, options:0)
+      return try PropertyListDecoder().decode(type, from: plist)
+    #else
+      let data = try JSONSerialization.data(withJSONObject: from, options:[])
+      return try JSONDecoder().decode(type, from: data)
+    #endif
   }
 }
 

+ 1 - 1
Examples/Google/NaturalLanguage/Package.swift

@@ -19,6 +19,6 @@ let package = Package (
     dependencies: [
         .Package(url: "https://github.com/grpc/grpc-swift.git", Version(0,3,2)),
         .Package(url: "https://github.com/apple/swift-protobuf.git", Version(1,0,2)),
-        .Package(url: "https://github.com/google/auth-library-swift.git", Version(0,3,4)),
+        .Package(url: "https://github.com/google/auth-library-swift.git", Version(0,3,6)),
     ]
 )

+ 1 - 1
Examples/Google/Spanner/Package.swift

@@ -19,7 +19,7 @@ let package = Package (
     dependencies: [
         .Package(url: "https://github.com/grpc/grpc-swift.git", Version(0,3,2)),
         .Package(url: "https://github.com/apple/swift-protobuf.git", Version(1,0,2)),
-        .Package(url: "https://github.com/google/auth-library-swift.git", Version(0,3,4)),
+        .Package(url: "https://github.com/google/auth-library-swift.git", Version(0,3,6)),
 	.Package(url: "https://github.com/kylef/Commander.git", Version(0,8,0)),
     ]
 )