Skip to content

Commit

Permalink
Merge pull request #37 from apivideo/feature/origin_sdk_header
Browse files Browse the repository at this point in the history
feat(ios): add origin sdk field support
  • Loading branch information
bot-api-video authored Jul 5, 2022
2 parents ae0009d + a6f5199 commit de358b3
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 35 deletions.
4 changes: 2 additions & 2 deletions ApiVideoUploader.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`

Expand Down
66 changes: 36 additions & 30 deletions Sources/APIs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)
}

}
Expand Down
2 changes: 1 addition & 1 deletion project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: {}
Expand Down

0 comments on commit de358b3

Please sign in to comment.