Skip to content
This repository has been archived by the owner on Dec 11, 2020. It is now read-only.

Commit

Permalink
Merge pull request #28 from WeTransfer/feature/transfer-board-split
Browse files Browse the repository at this point in the history
SDK V2
  • Loading branch information
PimCoumans authored Oct 18, 2018
2 parents 73fe433 + 5230efd commit 5bc39b5
Show file tree
Hide file tree
Showing 44 changed files with 1,127 additions and 454 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
language: objective-c
osx_image: xcode9.4
osx_image: xcode10
gemfile: Gemfile
bundler_args: "--without documentation --path bundle"
cache:
Expand All @@ -10,7 +10,7 @@ env:
global:
- NOKOGIRI_USE_SYSTEM_LIBRARIES=true
script:
- "./Submodules/WeTransfer-iOS-CI/Scripts/travis.sh WeTransfer"
- "./Submodules/WeTransfer-iOS-CI/Scripts/travis.sh WeTransfer WeTransfer-iOS"
before_install:
- openssl aes-256-cbc -K $encrypted_fce2bbf28b94_key -iv $encrypted_fce2bbf28b94_iv
-in WeTransferTests/Secrets.plist.enc -out WeTransferTests/Secrets.plist -d
2 changes: 1 addition & 1 deletion Submodules/WeTransfer-iOS-CI
4 changes: 2 additions & 2 deletions WeTransfer Sample Project/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<string>2.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<string>2</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSAppleMusicUsageDescription</key>
Expand Down
4 changes: 2 additions & 2 deletions WeTransfer Sample Project/MainViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ extension MainViewController {
let files = selectedMedia.map({ $0.url })

// Creates a transfer and uploads all provided files
WeTransfer.uploadTransfer(named: "Sample Transfer", containing: files) { [weak self] state in
WeTransfer.uploadTransfer(saying: "Sample Transfer", containing: files) { [weak self] state in
switch state {
case .uploading(let progress):
self?.viewState = .transferInProgress
Expand Down Expand Up @@ -184,7 +184,7 @@ extension MainViewController {
case .transferCompleted(let shortURL):
titleLabel.text = "Transfer completed"
bodyLabel.text = nil
let attributes: [NSAttributedStringKey: Any] = [.underlineStyle: NSUnderlineStyle.styleSingle.rawValue,
let attributes: [NSAttributedString.Key: Any] = [.underlineStyle: NSUnderlineStyle.single.rawValue,
.foregroundColor: urlButton.currentTitleColor]
let attributedURLText = NSAttributedString(string: shortURL.absoluteString, attributes: attributes)
urlButton.setAttributedTitle(attributedURLText, for: .normal)
Expand Down
6 changes: 3 additions & 3 deletions WeTransfer Sample Project/MediaPicker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ final class MediaPicker: NSObject {
// Get first frame if video
let imageGenerator = AVAssetImageGenerator(asset: asset)
imageGenerator.appliesPreferredTrackTransform = true
if let image = try? imageGenerator.copyCGImage(at: kCMTimeZero, actualTime: nil) {
if let image = try? imageGenerator.copyCGImage(at: CMTime.zero, actualTime: nil) {
pickedMedia = Media(url: url, previewImage: UIImage(cgImage: image))
}
} else {
Expand All @@ -104,8 +104,8 @@ extension MediaPicker: UIImagePickerControllerDelegate, UINavigationControllerDe
finish(with: nil)
}

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String: Any]) {
guard let url = info[UIImagePickerControllerImageURL] as? URL ?? info[UIImagePickerControllerMediaURL] as? URL else {
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey: Any]) {
guard let url = info[UIImagePickerController.InfoKey.imageURL] as? URL ?? info[UIImagePickerController.InfoKey.mediaURL] as? URL else {
finish(with: nil)
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ final class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
return true
}
}
4 changes: 2 additions & 2 deletions WeTransfer-Swift-SDK.podspec
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
Pod::Spec.new do |s|
s.name = "WeTransfer-Swift-SDK"
s.version = "1.0"
s.version = "2.0"
s.summary = "A Swift SDK for WeTransfer’s public API"
s.homepage = "https://github.com/WeTransfer/WeTransfer-Swift-SDK"
s.license = "MIT"
s.author = { "Pim Coumans" => "[email protected]" }
s.source = { :git => "https://github.com/WeTransfer/WeTransfer-Swift-SDK.git", :tag => "v#{s.version}" }

s.swift_version = "4.1"
s.swift_version = "4.2"
s.ios.deployment_target = "9.0"
s.osx.deployment_target = "10.10"

Expand Down
154 changes: 124 additions & 30 deletions WeTransfer.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion WeTransfer/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<string>2.0</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSPrincipalClass</key>
Expand Down
55 changes: 55 additions & 0 deletions WeTransfer/Models/Board.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
//
// Transfer.swift
// WeTransfer Swift SDK
//
// Created by Pim Coumans on 01/10/2018.
// Copyright © 2018 WeTransfer. All rights reserved.
//

import Foundation

/// Describes a single board to be created, adding files to and uploading files from. Used as an identifier between each request to be made and a local representation of the server-side board.
/// Files should be added through the appropriate addFiles method
public final class Board: Transferable {
public private(set) var identifier: String?

/// The name of the board. This name will be shown when viewing the transfer on wetransfer.com
public let name: String
/// Optional description of the board. This will be shown when viewing the transfer on wetransfer.com
public let description: String?

/// References to all the files added to the board. Files can be added with the public method on the WeTransfer struct
public private(set) var files: [File] = []

/// Available when the board is created on the server
public private(set) var shortURL: URL?

/// Internal initializer with required properties
init(name: String, description: String?) {
self.name = name
self.description = description
}
}

// MARK: - Private updating methods
extension Board {

/// Updates the board with server-side information
///
/// - Parameters:
/// - identifier: Identifier to point to global board
/// - shortURL: URL of where the board can be found online
func update(with identifier: String, shortURL: URL) {
self.identifier = identifier
self.shortURL = shortURL
}

/// Adds provided files to the board locally
///
/// - Parameter files: Files to be added to the board
func add(_ files: [File]) {
for file in files where !self.files.contains(file) {
self.files.append(file)
}
}
}
9 changes: 5 additions & 4 deletions WeTransfer/Models/Chunk.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@

import Foundation

/// Represents a chunk of data from a file in a transfer. Used only in the uploading proces
/// Represents a chunk of data from a file in a transfer or board. Used only in the uploading proces
struct Chunk: Encodable {

/// Size of all chunks except the last, as the last chunk holds the remaining data (filesize % defaultChunkSize)
/// Fallback size chunks except the last, as the last chunk holds the remaining data (filesize % defaultChunkSize)
static let defaultChunkSize: Bytes = (6 * 1024 * 1024)

/// Zero-based index of chunk
Expand All @@ -37,11 +37,12 @@ extension Chunk {
/// - chunkIndex: The index of the chunk
/// - uploadURL: The URL to where the chunk should be uploaded
init(file: File, chunkIndex: Int, uploadURL: URL) {
let byteOffset = Chunk.defaultChunkSize * Bytes(chunkIndex)
let chunkSize = file.chunkSize ?? Chunk.defaultChunkSize
let byteOffset = chunkSize * Bytes(chunkIndex)
self.init(chunkIndex: chunkIndex,
fileURL: file.url,
uploadURL: uploadURL,
size: min(file.filesize - byteOffset, Chunk.defaultChunkSize),
size: min(file.filesize - byteOffset, chunkSize),
byteOffset: byteOffset)
}
}
Expand Down
17 changes: 9 additions & 8 deletions WeTransfer/Models/File.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import Foundation
/// Amount of bytes in a file or chunk
public typealias Bytes = UInt64

/// A file used in a Transfer object. Should be initialized with a URL pointing only to a local file
/// As files should be readily available for uploading, only local files accessible by NSFileManager should be used for transfers
/// A file used in a Transfer or a Board. Should be initialized with a URL pointing only to a local file
/// As files should be readily available for uploading, only local files accessible by NSFileManager should be used
public final class File: Encodable {

public enum Error: Swift.Error, LocalizedError {
Expand All @@ -30,7 +30,7 @@ public final class File: Encodable {
/// Location of the file on disk
public let url: URL

/// Server-side identifier when file is added to the transfer on the server
/// Server-side identifier when file is added to the transfer or board on the server
public private(set) var identifier: String?

/// Will be set to yes when all chunks of the file have been uploaded
Expand All @@ -44,8 +44,8 @@ public final class File: Encodable {
/// Size of the file in Bytes
public let filesize: Bytes

/// Unique identifier to keep track of files locally
let localIdentifier = UUID().uuidString
/// Maximum size that each chunk needs to be
public internal(set) var chunkSize: Bytes?

public private(set) var numberOfChunks: Int?
private(set) var multipartUploadIdentifier: String?
Expand All @@ -62,17 +62,18 @@ public final class File: Encodable {
}

extension File: Equatable {
/// Only compares the url and localIdentifier of the File
/// Only compares the url and optional identifier of the file
/// Note: Disregards any state, so the `uploaded` property is ignored
public static func == (lhs: File, rhs: File) -> Bool {
return lhs.url == rhs.url && lhs.localIdentifier == rhs.localIdentifier
return lhs.url == rhs.url && lhs.identifier == rhs.identifier
}
}

extension File {
func update(with identifier: String, numberOfChunks: Int, multipartUploadIdentifier: String) {
func update(with identifier: String, numberOfChunks: Int, chunkSize: Bytes, multipartUploadIdentifier: String?) {
self.identifier = identifier
self.numberOfChunks = numberOfChunks
self.chunkSize = chunkSize
self.multipartUploadIdentifier = multipartUploadIdentifier
}
}
35 changes: 11 additions & 24 deletions WeTransfer/Models/Transfer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,23 @@

import Foundation

/// Desribes a single transfer to be created, updated and sent. Used as an identifier between each request to be made and a local representation of the server-side transfer.
/// Can be initialized with files or these can be added later through the add files function
public final class Transfer {
public private(set) var identifier: String?
/// Describes a single transfer to be created and uploaded. Used as an identifier between each request to be made and a local representation of the server-side transfer.
public final class Transfer: Transferable {
public let identifier: String?

/// The name of the transfer. This name will be shown when viewing the transfer on wetransfer.com
public let name: String
/// Optional description of the transfer. This will be shown when viewing the transfer on wetransfer.com
public let description: String?
public let message: String

/// References to all the files added to the transfer. Add other files with the public method on the WeTransfer struct or add them directly when initializing the transfer object
public private(set) var files: [File] = []
/// References to all the files added to the transfer
public let files: [File]

/// Available when the transfer is created on the server
public private(set) var shortURL: URL?

public init(name: String, description: String?, files: [File] = []) {
self.name = name
self.description = description
/// Internal initializer with required properties
init(identifier: String, message: String, files: [File] = []) {
self.identifier = identifier
self.message = message
self.files = files
}
}
Expand All @@ -37,19 +35,8 @@ extension Transfer {
/// Updates the transfer with server-side information
///
/// - Parameters:
/// - identifier: Identifier to point to global transfer
/// - shortURL: URL of where the transfer can be found online
func update(with identifier: String, shortURL: URL) {
self.identifier = identifier
func update(with shortURL: URL) {
self.shortURL = shortURL
}

/// Adds provided files to the transfer locally
///
/// - Parameter files: Files to be added to the transfer
func add(_ files: [File]) {
for file in files where !self.files.contains(file) {
self.files.append(file)
}
}
}
16 changes: 16 additions & 0 deletions WeTransfer/Models/Transferable.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// Transferable.swift
// WeTransfer
//
// Created by Pim Coumans on 04/10/2018.
// Copyright © 2018 WeTransfer. All rights reserved.
//

import Foundation

/// Shared properties for both transfers and boards
public protocol Transferable {
var identifier: String? { get }
var files: [File] { get }
var shortURL: URL? { get }
}
1 change: 1 addition & 0 deletions WeTransfer/Server/APIClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ extension APIClient {

var request = URLRequest(endpoint: endpoint, baseURL: baseURL, apiKey: apiKey)
request = authenticator.authenticatedRequest(from: request)
request.setValue("application/json", forHTTPHeaderField: "Content-Type")

if let data = data {
request.httpBody = data
Expand Down
Loading

0 comments on commit 5bc39b5

Please sign in to comment.