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

SDK V2 #28

Merged
merged 45 commits into from
Oct 18, 2018
Merged
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
0f988f5
Update main project for Swift 4.2
PimCoumans Sep 24, 2018
e9e0962
Updated sample project for Swift 4.2
PimCoumans Sep 24, 2018
cc036f8
Update to version 2.0
PimCoumans Sep 24, 2018
ceb75a1
Use Xcode 10 for CI
PimCoumans Sep 24, 2018
3fc76ac
Merge branch 'feature/swift4.2' into feature/transfer-board-split
PimCoumans Sep 24, 2018
d1fa5b4
[WIP] step one of new Transfer model
PimCoumans Oct 4, 2018
43dd510
Added Boards
PimCoumans Oct 4, 2018
8a6c7f6
Added now required Content-Type header
PimCoumans Oct 8, 2018
89114dc
Seperated tests for transfers and boards
PimCoumans Oct 8, 2018
dff5da6
Transferrable protocol for both transfers and boards
PimCoumans Oct 8, 2018
4ab199d
Board/Transfer agnostic operations, updated chunk creation logic
PimCoumans Oct 8, 2018
74ec086
Convenience init of CreateBoardOperation
PimCoumans Oct 8, 2018
71de593
Added FinalizeTransferOperation
PimCoumans Oct 8, 2018
6e60e48
Generic State, added finalize to transfer upload, simple board upload…
PimCoumans Oct 8, 2018
b6cd198
Always fulfull expectation, even when failing
PimCoumans Oct 8, 2018
80685a3
Legibility line ending
PimCoumans Oct 8, 2018
5f58d89
Use `zip()` to update each file with the response
PimCoumans Oct 8, 2018
bd1ee13
Correctly dating new files
PimCoumans Oct 8, 2018
ace8f54
Fixing typos
PimCoumans Oct 9, 2018
ea3891c
Transferrable -> Transferable
PimCoumans Oct 9, 2018
edd9589
Added documentation to FinalizeTransferOperation
PimCoumans Oct 9, 2018
c80090a
Added generic EmptyResponse
PimCoumans Oct 9, 2018
cd7d26f
Moved fatalError to bottom of if statements
PimCoumans Oct 9, 2018
80268e1
Fixed Swift 4.2 CI errors
PimCoumans Oct 9, 2018
b5dedd6
Corrected simple Board transfer adding CreateBoardOperation
PimCoumans Oct 9, 2018
60708a3
Renamed `Multipart` to more descriptive `UploadInfo`
PimCoumans Oct 15, 2018
93cbe6e
Removed unnecessary references to self
PimCoumans Oct 15, 2018
a4cd3ab
Simpler generic casting for UploadFilesOperation
PimCoumans Oct 15, 2018
99e4e29
Set a base test case for all tests using same configuration
PimCoumans Oct 15, 2018
462612c
Update WeTransferTests/BaseTestCase.swift
PimCoumans Oct 15, 2018
87ffcee
Split logic of transfer upload test
PimCoumans Oct 15, 2018
bb6cb18
Seperate Transfer and Board requests made in CompleteUploadOperation
PimCoumans Oct 15, 2018
7a5b6d9
Keep danger happy by defining base test case subclassability
PimCoumans Oct 15, 2018
cac6a3c
Fixing build errors
PimCoumans Oct 15, 2018
2cd125e
Selecting which scheme to check for Danger
PimCoumans Oct 16, 2018
2991301
Merge branch 'develop' into feature/transfer-board-split
PimCoumans Oct 16, 2018
d9f00d7
Update iOS CI changes
PimCoumans Oct 16, 2018
ea3c2d4
Use correct variable project scheme
PimCoumans Oct 16, 2018
17eb34c
Updated WeTransfer-iOS-CI submodule
PimCoumans Oct 16, 2018
7915a10
Trying a different way of handling the space in the scheme
PimCoumans Oct 16, 2018
9857d7f
Escaping the escape character
PimCoumans Oct 16, 2018
a58d99a
Using single quotes instead of escape character
PimCoumans Oct 16, 2018
6bbce38
Renamed schemes replacing whitespace with dash
PimCoumans Oct 16, 2018
eac1015
Updated sample app to use SDK V2
PimCoumans Oct 18, 2018
5230efd
Reordered model files
PimCoumans Oct 18, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .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 Down
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
2 changes: 1 addition & 1 deletion WeTransfer Sample Project/MainViewController.swift
Original file line number Diff line number Diff line change
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] = []
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Boards can contain links as well, which are not files. Rather call this Content

Copy link
Contributor Author

@PimCoumans PimCoumans Oct 9, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Links wil be added when addressing #8, for now boards and transfer only support files.


/// 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weird indent

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's just tabs, just like in the rest of the project. Will be addressed in future PR

}
}

// 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)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self is not needed. Also, can't you use append(contentsOf:) or the += operator?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self is used here as the parameter is also called files.
Just appending the array isn't a good idea here and I believe we've discussed this earlier in Transfer.swift. Using an array for this is easiest as there's no swift equivalent of NSOrderedSet but we need to make sure the array doesn't have duplicates so we can't just append them

}
}
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