Skip to content

Commit f5958e0

Browse files
Merge pull request #33 from apivideo/feature/origin_sdk_header
feat(ios): add origin sdk field support
2 parents aa92cea + 4f82bfb commit f5958e0

File tree

6 files changed

+45
-36
lines changed

6 files changed

+45
-36
lines changed

ApiVideoClient.podspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ Pod::Spec.new do |s|
44
s.osx.deployment_target = '10.12'
55
s.tvos.deployment_target = '10.0'
66
s.watchos.deployment_target = '3.0'
7-
s.version = '1.0.4'
8-
s.source = { :git => 'https://github.com/apivideo/api.video-ios-client', :tag => 'v1.0.4' }
7+
s.version = '1.0.5'
8+
s.source = { :git => 'https://github.com/apivideo/api.video-ios-client', :tag => 'v1.0.5' }
99
s.authors = { 'Ecosystem Team' => 'ecosystem@api.video' }
1010
s.license = { :type => 'MIT' }
1111
s.homepage = 'https://docs.api.video'

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Changelog
22
All changes to this project will be documented in this file.
33

4+
## [1.0.5] - 2022-06-30
5+
- Add SDK origin header
6+
47
## [1.0.4] - 2022-04-21
58
- Fix `video.publishedAt` type
69

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,14 @@ api.video's iOS streamlines the coding process. Chunking files is handled for y
4242
Specify it in your `Cartfile`:
4343

4444
```
45-
github "apivideo/api.video-ios-client" ~> 1.0.4
45+
github "apivideo/api.video-ios-client" ~> 1.0.5
4646
```
4747

4848
Run `carthage update`
4949

5050
### CocoaPods
5151

52-
Add `pod 'ApiVideoClient', '1.0.4'` in your `Podfile`
52+
Add `pod 'ApiVideoClient', '1.0.5'` in your `Podfile`
5353

5454
Run `pod install`
5555

Sources/APIs.swift

Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,14 @@
66

77
import Foundation
88
enum ApiVideoClientError: Error {
9-
case invalidApplicationName
10-
case invalidApplicationVersion
11-
case missingApplicationName
9+
case invalidName
10+
case invalidVersion
1211
}
1312

1413
public class ApiVideoClient {
15-
1614
public static var apiKey: String? = nil
1715
public static var basePath = "https://ws.api.video"
18-
internal static var customHeaders:[String: String] = ["AV-Origin-Client": "ios:1.0.4"]
16+
internal static var customHeaders:[String: String] = ["AV-Origin-Client": "ios:1.0.5"]
1917
private static var chunkSize: Int = 50 * 1024 * 1024
2018
internal static var requestBuilderFactory: RequestBuilderFactory = AlamofireRequestBuilderFactory()
2119
internal static var credential = ApiVideoCredential()
@@ -35,36 +33,44 @@ public class ApiVideoClient {
3533
return ApiVideoClient.chunkSize
3634
}
3735

38-
39-
public static func setApplicationName(applicationName: String, applicationVersion: String?) throws {
40-
if(applicationName.isEmpty) {
41-
if(applicationVersion != nil && !applicationVersion!.isEmpty) {
42-
throw ApiVideoClientError.missingApplicationName
43-
}
44-
ApiVideoClient.customHeaders["AV-Origin-App"] = nil
45-
return
46-
}
47-
48-
let pattern = #"^[\w\-]{1,50}$"#
36+
static func isValid(pattern: String, field: String) -> Bool {
4937
let regex = try! NSRegularExpression(pattern: pattern, options: .anchorsMatchLines)
50-
let stringRange = NSRange(location: 0, length: applicationName.utf16.count)
51-
let matches = regex.matches(in: applicationName, range: stringRange)
38+
let stringRange = NSRange(location: 0, length: field.utf16.count)
39+
let matches = regex.matches(in: field, range: stringRange)
5240
if(matches.isEmpty) {
53-
throw ApiVideoClientError.invalidApplicationName
41+
return false
42+
} else {
43+
return true
5444
}
45+
}
46+
47+
static func isValidVersion(version: String) -> Bool {
48+
let pattern = #"^\d{1,3}(\.\d{1,3}(\.\d{1,3})?)?$"#
49+
return isValid(pattern: pattern, field: version)
50+
}
5551

56-
if(applicationVersion != nil && !applicationVersion!.isEmpty) {
57-
let pattern2 = #"^[\w\-]{1,50}$"#
58-
let regex2 = try! NSRegularExpression(pattern: pattern2, options: .anchorsMatchLines)
59-
let stringRange2 = NSRange(location: 0, length: applicationVersion!.utf16.count)
60-
let matches2 = regex2.matches(in: applicationVersion!, range: stringRange2)
61-
if(matches2.isEmpty) {
62-
throw ApiVideoClientError.invalidApplicationVersion
63-
}
64-
ApiVideoClient.customHeaders["AV-Origin-App"] = applicationName + ":" + applicationVersion!
65-
return
52+
static func isValidName(name: String) -> Bool {
53+
let pattern = #"^[\w\-]{1,50}$"#
54+
return isValid(pattern: pattern, field: name)
55+
}
56+
57+
static func setName(key: String, name: String, version: String) throws {
58+
if(!isValidName(name: name)) {
59+
throw ApiVideoClientError.invalidName
60+
}
61+
62+
if(!isValidVersion(version: version)) {
63+
throw ApiVideoClientError.invalidVersion
6664
}
67-
ApiVideoClient.customHeaders["AV-Origin-App"] = applicationName
65+
ApiVideoClient.customHeaders[key] = name + ":" + version
66+
}
67+
68+
public static func setSdkName(name: String, version: String) throws {
69+
try setName(key: "AV-Origin-Sdk", name: name, version: version)
70+
}
71+
72+
public static func setApplicationName(name: String, version: String) throws {
73+
try setName(key: "AV-Origin-App", name: name, version: version)
6874
}
6975

7076
}

Tests/ApiVideoClient/Integration/VideosApiTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ internal class UploadTestCase: XCTestCase {
1313
try XCTSkipIf(Parameters.apiKey == "INTEGRATION_TESTS_API_KEY", "Can't get API key")
1414
ApiVideoClient.apiKey = Parameters.apiKey
1515
ApiVideoClient.basePath = Environment.sandbox.rawValue
16-
try? ApiVideoClient.setApplicationName(applicationName: "client-integration-tests", applicationVersion: nil)
16+
try? ApiVideoClient.setApplicationName(name: "client-integration-tests", version: "0")
1717

1818
continueAfterFailure = false
1919
}

project.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ targets:
77
sources: [Sources]
88
info:
99
path: ./Info.plist
10-
version: 1.0.4
10+
version: 1.0.5
1111
settings:
1212
APPLICATION_EXTENSION_API_ONLY: true
1313
scheme: {}

0 commit comments

Comments
 (0)