diff --git a/Cartfile b/Cartfile index 4ef73ba71..887d729ec 100644 --- a/Cartfile +++ b/Cartfile @@ -1,2 +1,2 @@ github "daltoniam/Starscream" ~> 3.0 -github "watson-developer-cloud/restkit" ~> 1.2 \ No newline at end of file +github "watson-developer-cloud/restkit" ~> 1.3 \ No newline at end of file diff --git a/Cartfile.resolved b/Cartfile.resolved index d42e4b1e5..66d9a6368 100644 --- a/Cartfile.resolved +++ b/Cartfile.resolved @@ -1,2 +1,2 @@ -github "daltoniam/Starscream" "3.0.5" -github "watson-developer-cloud/restkit" "1.2.0" +github "daltoniam/Starscream" "3.0.6" +github "watson-developer-cloud/restkit" "1.3.0" diff --git a/Source/DiscoveryV1/Discovery.swift b/Source/DiscoveryV1/Discovery.swift index 2b97a6118..ec8e26d3e 100644 --- a/Source/DiscoveryV1/Discovery.swift +++ b/Source/DiscoveryV1/Discovery.swift @@ -821,21 +821,22 @@ public class Discovery { // construct body let multipartFormData = MultipartFormData() if let configuration = configuration { - guard let configurationData = configuration.data(using: .utf8) else { - failure?(RestError.serializationError) - return + if let configurationData = configuration.data(using: .utf8) { + multipartFormData.append(configurationData, withName: "configuration") } - multipartFormData.append(configurationData, withName: "configuration") } if let file = file { - multipartFormData.append(file, withName: "file") + do { + try multipartFormData.append(file: file, withName: "file") + } catch { + failure?(error) + return + } } if let metadata = metadata { - guard let metadataData = metadata.data(using: .utf8) else { - failure?(RestError.serializationError) - return + if let metadataData = metadata.data(using: .utf8) { + multipartFormData.append(metadataData, withName: "metadata") } - multipartFormData.append(metadataData, withName: "metadata") } guard let body = try? multipartFormData.toData() else { failure?(RestError.encodingError) @@ -1472,14 +1473,17 @@ public class Discovery { // construct body let multipartFormData = MultipartFormData() if let file = file { - multipartFormData.append(file, withName: "file") + do { + try multipartFormData.append(file: file, withName: "file") + } catch { + failure?(error) + return + } } if let metadata = metadata { - guard let metadataData = metadata.data(using: .utf8) else { - failure?(RestError.serializationError) - return + if let metadataData = metadata.data(using: .utf8) { + multipartFormData.append(metadataData, withName: "metadata") } - multipartFormData.append(metadataData, withName: "metadata") } guard let body = try? multipartFormData.toData() else { failure?(RestError.encodingError) @@ -1620,14 +1624,17 @@ public class Discovery { // construct body let multipartFormData = MultipartFormData() if let file = file { - multipartFormData.append(file, withName: "file") + do { + try multipartFormData.append(file: file, withName: "file") + } catch { + failure?(error) + return + } } if let metadata = metadata { - guard let metadataData = metadata.data(using: .utf8) else { - failure?(RestError.serializationError) - return + if let metadataData = metadata.data(using: .utf8) { + multipartFormData.append(metadataData, withName: "metadata") } - multipartFormData.append(metadataData, withName: "metadata") } guard let body = try? multipartFormData.toData() else { failure?(RestError.encodingError) diff --git a/Source/LanguageTranslatorV2/LanguageTranslator.swift b/Source/LanguageTranslatorV2/LanguageTranslator.swift index 2690e6b79..29f0a2937 100644 --- a/Source/LanguageTranslatorV2/LanguageTranslator.swift +++ b/Source/LanguageTranslatorV2/LanguageTranslator.swift @@ -352,13 +352,28 @@ public class LanguageTranslator { // construct body let multipartFormData = MultipartFormData() if let forcedGlossary = forcedGlossary { - multipartFormData.append(forcedGlossary, withName: "forced_glossary") + do { + try multipartFormData.append(file: forcedGlossary, withName: "forced_glossary") + } catch { + failure?(error) + return + } } if let parallelCorpus = parallelCorpus { - multipartFormData.append(parallelCorpus, withName: "parallel_corpus") + do { + try multipartFormData.append(file: parallelCorpus, withName: "parallel_corpus") + } catch { + failure?(error) + return + } } if let monolingualCorpus = monolingualCorpus { - multipartFormData.append(monolingualCorpus, withName: "monolingual_corpus") + do { + try multipartFormData.append(file: monolingualCorpus, withName: "monolingual_corpus") + } catch { + failure?(error) + return + } } guard let body = try? multipartFormData.toData() else { failure?(RestError.encodingError) diff --git a/Source/LanguageTranslatorV3/LanguageTranslator.swift b/Source/LanguageTranslatorV3/LanguageTranslator.swift index d0286a500..e72fe0298 100644 --- a/Source/LanguageTranslatorV3/LanguageTranslator.swift +++ b/Source/LanguageTranslatorV3/LanguageTranslator.swift @@ -379,10 +379,20 @@ public class LanguageTranslator { // construct body let multipartFormData = MultipartFormData() if let forcedGlossary = forcedGlossary { - multipartFormData.append(forcedGlossary, withName: "forced_glossary") + do { + try multipartFormData.append(file: forcedGlossary, withName: "forced_glossary") + } catch { + failure?(error) + return + } } if let parallelCorpus = parallelCorpus { - multipartFormData.append(parallelCorpus, withName: "parallel_corpus") + do { + try multipartFormData.append(file: parallelCorpus, withName: "parallel_corpus") + } catch { + failure?(error) + return + } } guard let body = try? multipartFormData.toData() else { failure?(RestError.encodingError) diff --git a/Source/NaturalLanguageClassifierV1/NaturalLanguageClassifier.swift b/Source/NaturalLanguageClassifierV1/NaturalLanguageClassifier.swift index b11271674..edd19bc0e 100644 --- a/Source/NaturalLanguageClassifierV1/NaturalLanguageClassifier.swift +++ b/Source/NaturalLanguageClassifierV1/NaturalLanguageClassifier.swift @@ -245,8 +245,18 @@ public class NaturalLanguageClassifier { { // construct body let multipartFormData = MultipartFormData() - multipartFormData.append(metadata, withName: "training_metadata") - multipartFormData.append(trainingData, withName: "training_data") + do { + try multipartFormData.append(file: metadata, withName: "training_metadata") + } catch { + failure?(error) + return + } + do { + try multipartFormData.append(file: trainingData, withName: "training_data") + } catch { + failure?(error) + return + } guard let body = try? multipartFormData.toData() else { failure?(RestError.encodingError) return diff --git a/Source/SpeechToTextV1/SpeechToText.swift b/Source/SpeechToTextV1/SpeechToText.swift index b9366136c..fd8252b3a 100644 --- a/Source/SpeechToTextV1/SpeechToText.swift +++ b/Source/SpeechToTextV1/SpeechToText.swift @@ -1540,7 +1540,12 @@ public class SpeechToText { { // construct body let multipartFormData = MultipartFormData() - multipartFormData.append(corpusFile, withName: "corpus_file") + do { + try multipartFormData.append(file: corpusFile, withName: "corpus_file") + } catch { + failure?(error) + return + } guard let body = try? multipartFormData.toData() else { failure?(RestError.encodingError) return diff --git a/Source/VisualRecognitionV3/VisualRecognition.swift b/Source/VisualRecognitionV3/VisualRecognition.swift index d35db8277..c1116c868 100644 --- a/Source/VisualRecognitionV3/VisualRecognition.swift +++ b/Source/VisualRecognitionV3/VisualRecognition.swift @@ -176,35 +176,32 @@ public class VisualRecognition { // construct body let multipartFormData = MultipartFormData() if let imagesFile = imagesFile { - multipartFormData.append(imagesFile, withName: "images_file") + do { + try multipartFormData.append(file: imagesFile, withName: "images_file") + } catch { + failure?(error) + return + } } if let url = url { - guard let urlData = url.data(using: .utf8) else { - failure?(RestError.serializationError) - return + if let urlData = url.data(using: .utf8) { + multipartFormData.append(urlData, withName: "url") } - multipartFormData.append(urlData, withName: "url") } if let threshold = threshold { - guard let thresholdData = "\(threshold)".data(using: .utf8) else { - failure?(RestError.serializationError) - return + if let thresholdData = "\(threshold)".data(using: .utf8) { + multipartFormData.append(thresholdData, withName: "threshold") } - multipartFormData.append(thresholdData, withName: "threshold") } if let owners = owners { - guard let ownersData = owners.joined(separator: ",").data(using: .utf8) else { - failure?(RestError.serializationError) - return + if let ownersData = owners.joined(separator: ",").data(using: .utf8) { + multipartFormData.append(ownersData, withName: "owners") } - multipartFormData.append(ownersData, withName: "owners") } if let classifierIDs = classifierIDs { - guard let classifierIDsData = classifierIDs.joined(separator: ",").data(using: .utf8) else { - failure?(RestError.serializationError) - return + if let classifierIDsData = classifierIDs.joined(separator: ",").data(using: .utf8) { + multipartFormData.append(classifierIDsData, withName: "classifier_ids") } - multipartFormData.append(classifierIDsData, withName: "classifier_ids") } guard let body = try? multipartFormData.toData() else { failure?(RestError.encodingError) @@ -285,14 +282,17 @@ public class VisualRecognition { // construct body let multipartFormData = MultipartFormData() if let imagesFile = imagesFile { - multipartFormData.append(imagesFile, withName: "images_file", mimeType: "application/octet-stream") + do { + try multipartFormData.append(file: imagesFile, withName: "images_file") + } catch { + failure?(error) + return + } } if let url = url { - guard let urlData = url.data(using: .utf8) else { - failure?(RestError.serializationError) - return + if let urlData = url.data(using: .utf8) { + multipartFormData.append(urlData, withName: "url") } - multipartFormData.append(urlData, withName: "url") } guard let body = try? multipartFormData.toData() else { failure?(RestError.encodingError) @@ -366,16 +366,24 @@ public class VisualRecognition { { // construct body let multipartFormData = MultipartFormData() - guard let nameData = name.data(using: .utf8) else { - failure?(RestError.serializationError) - return + if let nameData = name.data(using: .utf8) { + multipartFormData.append(nameData, withName: "name") } - multipartFormData.append(nameData, withName: "name") positiveExamples.forEach { example in - multipartFormData.append(example.examples, withName: example.name + "_positive_examples") + do { + try multipartFormData.append(file: example.examples, withName: example.name + "_positive_examples") + } catch { + failure?(error) + return + } } if let negativeExamples = negativeExamples { - multipartFormData.append(negativeExamples, withName: "negative_examples") + do { + try multipartFormData.append(file: negativeExamples, withName: "negative_examples") + } catch { + failure?(error) + return + } } guard let body = try? multipartFormData.toData() else { failure?(RestError.encodingError) @@ -561,11 +569,21 @@ public class VisualRecognition { let multipartFormData = MultipartFormData() if let positiveExamples = positiveExamples { positiveExamples.forEach { example in - multipartFormData.append(example.examples, withName: example.name + "_positive_examples") + do { + try multipartFormData.append(file: example.examples, withName: example.name + "_positive_examples") + } catch { + failure?(error) + return + } } } if let negativeExamples = negativeExamples { - multipartFormData.append(negativeExamples, withName: "negative_examples") + do { + try multipartFormData.append(file: negativeExamples, withName: "negative_examples") + } catch { + failure?(error) + return + } } guard let body = try? multipartFormData.toData() else { failure?(RestError.encodingError)