Skip to content

Commit 13b6ffd

Browse files
Merge pull request #25 from apivideo/origin-identification-headers
feat(java) Add origin identification headers
2 parents 5629b2a + 3e935a1 commit 13b6ffd

File tree

5 files changed

+37
-11
lines changed

5 files changed

+37
-11
lines changed

ApiVideoUploader.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 = '0.1.3'
8-
s.source = { :git => 'https://github.com/apivideo/api.video-ios-uploader', :tag => 'v0.1.3' }
7+
s.version = '0.1.4'
8+
s.source = { :git => 'https://github.com/apivideo/api.video-ios-uploader', :tag => 'v0.1.4' }
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+
## [0.1.4] - 2022-03-11
5+
- Add Origin identification headers
6+
47
## [0.1.3] - 2022-01-24
58
- Add applicationName parameter (to allow user agent extension)
69

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
# Project description
2626

27-
api.video's iOS uploader uploads videos to api.video using delegated upload token or API Key.
27+
api.video's iOS uploads videos to api.video using delegated upload token or API Key.
2828

2929
It allows you to upload videos in two ways:
3030
- standard upload: to send a whole video file in one go
@@ -39,14 +39,14 @@ It allows you to upload videos in two ways:
3939
Specify it in your `Cartfile`:
4040

4141
```
42-
github "apivideo/api.video-ios-uploader" ~> 0.1.3
42+
github "apivideo/api.video-ios-uploader" ~> 0.1.4
4343
```
4444

4545
Run `carthage update`
4646

4747
### CocoaPods
4848

49-
Add `pod 'ApiVideoUploader', '0.1.3'` in your `Podfile`
49+
Add `pod 'ApiVideoUploader', '0.1.4'` in your `Podfile`
5050

5151
Run `pod install`
5252

Sources/APIs.swift

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@
77
import Foundation
88
enum ApiVideoUploaderError: Error {
99
case invalidApplicationName
10+
case invalidApplicationVersion
11+
case missingApplicationName
1012
}
1113

1214
public class ApiVideoUploader {
13-
private static let DEFAULT_USER_AGENT = "api.video uploader (iOS; v:0.1.3; )";
1415

1516
public static var apiKey: String? = nil
1617
public static var basePath = "https://ws.api.video"
17-
internal static var customHeaders:[String: String] = ["User-Agent": ApiVideoUploader.DEFAULT_USER_AGENT]
18+
internal static var customHeaders:[String: String] = ["AV-Origin-Client": "ios-uploader:0.1.4"]
1819
private static var chunkSize: Int = 50 * 1024 * 1024
1920
internal static var requestBuilderFactory: RequestBuilderFactory = AlamofireRequestBuilderFactory()
2021
internal static var credential = ApiVideoCredential()
@@ -34,16 +35,38 @@ public class ApiVideoUploader {
3435
return ApiVideoUploader.chunkSize
3536
}
3637

37-
public static func setApplicationName(applicationName: String) throws {
38-
let pattern = #"^[\w\-.\/]{1,50}$"#
38+
39+
public static func setApplicationName(applicationName: String, applicationVersion: String?) throws {
40+
if(applicationName.isEmpty) {
41+
if(applicationVersion != nil && !applicationVersion!.isEmpty) {
42+
throw ApiVideoUploaderError.missingApplicationName
43+
}
44+
ApiVideoUploader.customHeaders["AV-Origin-App"] = nil
45+
return
46+
}
47+
48+
let pattern = #"^[\w\-]{1,50}$"#
3949
let regex = try! NSRegularExpression(pattern: pattern, options: .anchorsMatchLines)
4050
let stringRange = NSRange(location: 0, length: applicationName.utf16.count)
4151
let matches = regex.matches(in: applicationName, range: stringRange)
4252
if(matches.isEmpty) {
4353
throw ApiVideoUploaderError.invalidApplicationName
4454
}
45-
ApiVideoUploader.customHeaders["User-Agent"] = ApiVideoUploader.DEFAULT_USER_AGENT + " " + applicationName
55+
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 ApiVideoUploaderError.invalidApplicationVersion
63+
}
64+
ApiVideoUploader.customHeaders["AV-Origin-App"] = applicationName + ":" + applicationVersion!
65+
return
66+
}
67+
ApiVideoUploader.customHeaders["AV-Origin-App"] = applicationName
4668
}
69+
4770
}
4871

4972
open class RequestBuilder<T> {

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

0 commit comments

Comments
 (0)