Skip to content

Commit 0eabffc

Browse files
Merge pull request #18 from apivideo/user-agent-extension
feat(nodejs): add applicationName parameter
2 parents 192c525 + 4f8237f commit 0eabffc

File tree

6 files changed

+27
-6
lines changed

6 files changed

+27
-6
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.0'
8-
s.source = { :git => 'https://github.com/apivideo/api.video-ios-client', :tag => 'v1.0.0' }
7+
s.version = '1.0.1'
8+
s.source = { :git => 'https://github.com/apivideo/api.video-ios-client', :tag => 'v1.0.1' }
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.1] - 2022-01-24
5+
- Add applicationName parameter (to allow user agent extension)
6+
47
## [1.0.0] - 2022-01-07
58
- Add watermark endpoints
69
- Add video clips

README.md

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

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

4848
Run `carthage update`
4949

5050
### CocoaPods
5151

52-
Add `pod 'ApiVideoClient', '1.0.0'` in your `Podfile`
52+
Add `pod 'ApiVideoClient', '1.0.1'` in your `Podfile`
5353

5454
Run `pod install`
5555

Sources/APIs.swift

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,16 @@
55
//
66

77
import Foundation
8+
enum ApiVideoClientError: Error {
9+
case invalidApplicationName
10+
}
11+
812
public class ApiVideoClient {
13+
private static let DEFAULT_USER_AGENT = "api.video client (iOS; v:1.0.1; )";
14+
915
public static var apiKey: String? = nil
1016
public static var basePath = "https://ws.api.video"
11-
internal static var customHeaders: [String: String] = ["User-Agent": "api.video client (iOS; v:; )"]
17+
internal static var customHeaders:[String: String] = ["User-Agent": ApiVideoClient.DEFAULT_USER_AGENT]
1218
private static var chunkSize: Int = 50 * 1024 * 1024
1319
internal static var requestBuilderFactory: RequestBuilderFactory = AlamofireRequestBuilderFactory()
1420
internal static var credential = ApiVideoCredential()
@@ -27,6 +33,17 @@ public class ApiVideoClient {
2733
public static func getChunkSize() -> Int {
2834
return ApiVideoClient.chunkSize
2935
}
36+
37+
public static func setApplicationName(applicationName: String) throws {
38+
let pattern = #"^[\w\-.\/]{1,50}$"#
39+
let regex = try! NSRegularExpression(pattern: pattern, options: .anchorsMatchLines)
40+
let stringRange = NSRange(location: 0, length: applicationName.utf16.count)
41+
let matches = regex.matches(in: applicationName, range: stringRange)
42+
if(matches.isEmpty) {
43+
throw ApiVideoClientError.invalidApplicationName
44+
}
45+
ApiVideoClient.customHeaders["User-Agent"] = ApiVideoClient.DEFAULT_USER_AGENT + " " + applicationName
46+
}
3047
}
3148

3249
open class RequestBuilder<T> {

Tests/ApiVideoClient/Integration/VideosApiTests.swift

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

1718
continueAfterFailure = false
1819
}

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.0
10+
version: 1.0.1
1111
settings:
1212
APPLICATION_EXTENSION_API_ONLY: true
1313
scheme: {}

0 commit comments

Comments
 (0)