diff --git a/ApiVideoUploader.podspec b/ApiVideoUploader.podspec index 676fbe3..3cf11ed 100644 --- a/ApiVideoUploader.podspec +++ b/ApiVideoUploader.podspec @@ -4,8 +4,8 @@ Pod::Spec.new do |s| s.osx.deployment_target = '10.12' s.tvos.deployment_target = '10.0' s.watchos.deployment_target = '3.0' - s.version = '0.1.5' - s.source = { :git => 'https://github.com/apivideo/api.video-ios-uploader', :tag => 'v0.1.5' } + s.version = '1.0.0' + s.source = { :git => 'https://github.com/apivideo/api.video-ios-uploader', :tag => 'v1.0.0' } s.authors = { 'Ecosystem Team' => 'ecosystem@api.video' } s.license = { :type => 'MIT' } s.homepage = 'https://docs.api.video' diff --git a/CHANGELOG.md b/CHANGELOG.md index 50866cd..0b6e2fe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ # Changelog All changes to this project will be documented in this file. +## [1.0.0] - 2022-07-05 +- Add SDK origin header + ## [0.1.5] - 2022-04-21 - Fix `video.publishedAt` type diff --git a/README.md b/README.md index c1f3083..c51c48b 100644 --- a/README.md +++ b/README.md @@ -39,14 +39,14 @@ It allows you to upload videos in two ways: Specify it in your `Cartfile`: ``` -github "apivideo/api.video-ios-uploader" ~> 0.1.5 +github "apivideo/api.video-ios-uploader" ~> 1.0.0 ``` Run `carthage update` ### CocoaPods -Add `pod 'ApiVideoUploader', '0.1.5'` in your `Podfile` +Add `pod 'ApiVideoUploader', '1.0.0'` in your `Podfile` Run `pod install` diff --git a/Sources/APIs.swift b/Sources/APIs.swift index 0e98a36..6e3765f 100644 --- a/Sources/APIs.swift +++ b/Sources/APIs.swift @@ -6,16 +6,14 @@ import Foundation enum ApiVideoUploaderError: Error { - case invalidApplicationName - case invalidApplicationVersion - case missingApplicationName + case invalidName + case invalidVersion } public class ApiVideoUploader { - public static var apiKey: String? = nil public static var basePath = "https://ws.api.video" - internal static var customHeaders:[String: String] = ["AV-Origin-Client": "ios-uploader:0.1.5"] + internal static var customHeaders:[String: String] = ["AV-Origin-Client": "ios-uploader:1.0.0"] private static var chunkSize: Int = 50 * 1024 * 1024 internal static var requestBuilderFactory: RequestBuilderFactory = AlamofireRequestBuilderFactory() internal static var credential = ApiVideoCredential() @@ -35,36 +33,44 @@ public class ApiVideoUploader { return ApiVideoUploader.chunkSize } - - public static func setApplicationName(applicationName: String, applicationVersion: String?) throws { - if(applicationName.isEmpty) { - if(applicationVersion != nil && !applicationVersion!.isEmpty) { - throw ApiVideoUploaderError.missingApplicationName - } - ApiVideoUploader.customHeaders["AV-Origin-App"] = nil - return - } - - let pattern = #"^[\w\-]{1,50}$"# + static func isValid(pattern: String, field: String) -> Bool { let regex = try! NSRegularExpression(pattern: pattern, options: .anchorsMatchLines) - let stringRange = NSRange(location: 0, length: applicationName.utf16.count) - let matches = regex.matches(in: applicationName, range: stringRange) + let stringRange = NSRange(location: 0, length: field.utf16.count) + let matches = regex.matches(in: field, range: stringRange) if(matches.isEmpty) { - throw ApiVideoUploaderError.invalidApplicationName + return false + } else { + return true } + } + + static func isValidVersion(version: String) -> Bool { + let pattern = #"^\d{1,3}(\.\d{1,3}(\.\d{1,3})?)?$"# + return isValid(pattern: pattern, field: version) + } - if(applicationVersion != nil && !applicationVersion!.isEmpty) { - let pattern2 = #"^[\w\-]{1,50}$"# - let regex2 = try! NSRegularExpression(pattern: pattern2, options: .anchorsMatchLines) - let stringRange2 = NSRange(location: 0, length: applicationVersion!.utf16.count) - let matches2 = regex2.matches(in: applicationVersion!, range: stringRange2) - if(matches2.isEmpty) { - throw ApiVideoUploaderError.invalidApplicationVersion - } - ApiVideoUploader.customHeaders["AV-Origin-App"] = applicationName + ":" + applicationVersion! - return + static func isValidName(name: String) -> Bool { + let pattern = #"^[\w\-]{1,50}$"# + return isValid(pattern: pattern, field: name) + } + + static func setName(key: String, name: String, version: String) throws { + if(!isValidName(name: name)) { + throw ApiVideoUploaderError.invalidName + } + + if(!isValidVersion(version: version)) { + throw ApiVideoUploaderError.invalidVersion } - ApiVideoUploader.customHeaders["AV-Origin-App"] = applicationName + ApiVideoUploader.customHeaders[key] = name + ":" + version + } + + public static func setSdkName(name: String, version: String) throws { + try setName(key: "AV-Origin-Sdk", name: name, version: version) + } + + public static func setApplicationName(name: String, version: String) throws { + try setName(key: "AV-Origin-App", name: name, version: version) } } diff --git a/project.yml b/project.yml index cf53f18..8c31322 100644 --- a/project.yml +++ b/project.yml @@ -7,7 +7,7 @@ targets: sources: [Sources] info: path: ./Info.plist - version: 0.1.5 + version: 1.0.0 settings: APPLICATION_EXTENSION_API_ONLY: true scheme: {}