From 4f8237fe79d320eb5f758e6d9e8aa38a98f2064c Mon Sep 17 00:00:00 2001 From: olivierapivideo Date: Tue, 25 Jan 2022 13:33:56 +0000 Subject: [PATCH] feat(nodejs): add applicationName parameter --- ApiVideoClient.podspec | 4 ++-- CHANGELOG.md | 3 +++ README.md | 4 ++-- Sources/APIs.swift | 19 ++++++++++++++++++- .../Integration/VideosApiTests.swift | 1 + project.yml | 2 +- 6 files changed, 27 insertions(+), 6 deletions(-) diff --git a/ApiVideoClient.podspec b/ApiVideoClient.podspec index 10d7abe..69f5006 100644 --- a/ApiVideoClient.podspec +++ b/ApiVideoClient.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 = '1.0.0' - s.source = { :git => 'https://github.com/apivideo/api.video-ios-client', :tag => 'v1.0.0' } + s.version = '1.0.1' + s.source = { :git => 'https://github.com/apivideo/api.video-ios-client', :tag => 'v1.0.1' } 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 2a37043..bbeebfb 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.1] - 2022-01-24 +- Add applicationName parameter (to allow user agent extension) + ## [1.0.0] - 2022-01-07 - Add watermark endpoints - Add video clips diff --git a/README.md b/README.md index 6f7bd11..9541d3a 100644 --- a/README.md +++ b/README.md @@ -42,14 +42,14 @@ api.video's iOS client streamlines the coding process. Chunking files is handled Specify it in your `Cartfile`: ``` -github "apivideo/api.video-ios-client" ~> 1.0.0 +github "apivideo/api.video-ios-client" ~> 1.0.1 ``` Run `carthage update` ### CocoaPods -Add `pod 'ApiVideoClient', '1.0.0'` in your `Podfile` +Add `pod 'ApiVideoClient', '1.0.1'` in your `Podfile` Run `pod install` diff --git a/Sources/APIs.swift b/Sources/APIs.swift index 7a7f36e..a287f69 100644 --- a/Sources/APIs.swift +++ b/Sources/APIs.swift @@ -5,10 +5,16 @@ // import Foundation +enum ApiVideoClientError: Error { + case invalidApplicationName +} + public class ApiVideoClient { + private static let DEFAULT_USER_AGENT = "api.video client (iOS; v:1.0.1; )"; + public static var apiKey: String? = nil public static var basePath = "https://ws.api.video" - internal static var customHeaders: [String: String] = ["User-Agent": "api.video client (iOS; v:; )"] + internal static var customHeaders:[String: String] = ["User-Agent": ApiVideoClient.DEFAULT_USER_AGENT] private static var chunkSize: Int = 50 * 1024 * 1024 internal static var requestBuilderFactory: RequestBuilderFactory = AlamofireRequestBuilderFactory() internal static var credential = ApiVideoCredential() @@ -27,6 +33,17 @@ public class ApiVideoClient { public static func getChunkSize() -> Int { return ApiVideoClient.chunkSize } + + public static func setApplicationName(applicationName: String) throws { + let pattern = #"^[\w\-.\/]{1,50}$"# + 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) + if(matches.isEmpty) { + throw ApiVideoClientError.invalidApplicationName + } + ApiVideoClient.customHeaders["User-Agent"] = ApiVideoClient.DEFAULT_USER_AGENT + " " + applicationName + } } open class RequestBuilder { diff --git a/Tests/ApiVideoClient/Integration/VideosApiTests.swift b/Tests/ApiVideoClient/Integration/VideosApiTests.swift index 1c2f459..7e651d3 100644 --- a/Tests/ApiVideoClient/Integration/VideosApiTests.swift +++ b/Tests/ApiVideoClient/Integration/VideosApiTests.swift @@ -13,6 +13,7 @@ internal class UploadTestCase: XCTestCase { try XCTSkipIf(Parameters.apiKey == "INTEGRATION_TESTS_API_TOKEN", "Can't get API key") ApiVideoClient.apiKey = Parameters.apiKey ApiVideoClient.basePath = Environment.sandbox.rawValue + try? ApiVideoClient.setApplicationName(applicationName: "client-integration-tests") continueAfterFailure = false } diff --git a/project.yml b/project.yml index 718d876..8ac5436 100644 --- a/project.yml +++ b/project.yml @@ -7,7 +7,7 @@ targets: sources: [Sources] info: path: ./Info.plist - version: 1.0.0 + version: 1.0.1 settings: APPLICATION_EXTENSION_API_ONLY: true scheme: {}