Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0.14.0 #131

Merged
merged 22 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
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
19 changes: 19 additions & 0 deletions Documentation/REST API.md
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,25 @@ uploadcare.deleteWebhook(forTargetUrl: url) { error in
}
```

## Document info ([API Reference](https://uploadcare.com/api-refs/rest-api/v0.7.0/#tag/Conversion/operation/documentConvertInfo)) ##

The method allows you to determine the document format and possible conversion formats:

```swift
// Async:
let documentInfo = try await uploadcare.documentInfo("fileUUID")

// With a completion callback:
uploadcare.documentInfo("fileUUID") { result in
switch result {
case .failure(let error):
print(error)
case .success(let documentInfo):
print(documentInfo)
}
}
```

## Convert document ([API Reference](https://uploadcare.com/docs/transformations/document_conversion/#convert)) ##

You can convert multiple files with one request:
Expand Down
2 changes: 1 addition & 1 deletion Sources/Uploadcare/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ internal let RESTAPIHost = "api.uploadcare.com"
/// Library name
internal let libraryName = "UploadcareSwift"
/// Library version
internal let libraryVersion = "0.13.1"
internal let libraryVersion = "0.14.0"

/// API version
internal let APIVersion = "0.7"
6 changes: 6 additions & 0 deletions Sources/Uploadcare/PrivacyInfo.xcprivacy
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
</dict>
</plist>
57 changes: 57 additions & 0 deletions Sources/Uploadcare/Uploadcare.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1775,6 +1775,63 @@ extension Uploadcare {
}
}

#if !os(Linux)
/// The method allows you to determine the document format and possible conversion formats.
///
/// Example:
/// ```swift
/// uploadcare.documentInfo("fileUUID") { result in
/// switch result {
/// case .failure(let error):
/// print(error)
/// case .success(let documentInfo):
/// print(documentInfo)
/// }
/// }
/// ```
///
/// - Parameters:
/// - uuid: File uuid.
/// - completionHandler: Completion handler.
public func documentInfo(
_ uuid: String,
_ completionHandler: @escaping (Result<DocumentInfo, RESTAPIError>) -> Void
) {
let url = urlWithPath("/convert/document/\(uuid)/")
var urlRequest = requestManager.makeUrlRequest(fromURL: url, method: .get)
requestManager.signRequest(&urlRequest)

requestManager.performRequest(urlRequest) { (result: Result<DocumentInfo, Error>) in
switch result {
case .failure(let error): completionHandler(.failure(RESTAPIError.fromError(error)))
case .success(let response): completionHandler(.success(response))
}
}
}
#endif

/// The method allows you to determine the document format and possible conversion formats.
///
/// Example:
/// ```swift
/// let documentInfo = try await uploadcare.documentInfo("fileUUID")
/// ```
/// - Parameter uuid: File uuid.
/// - Returns: Document format and possible conversion formats.
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
public func documentInfo(_ uuid: String) async throws -> DocumentInfo {
let url = urlWithPath("/convert/document/\(uuid)/")
var urlRequest = requestManager.makeUrlRequest(fromURL: url, method: .get)
requestManager.signRequest(&urlRequest)

do {
let response: DocumentInfo = try await requestManager.performRequest(urlRequest)
return response
} catch {
throw RESTAPIError.fromError(error)
}
makoni marked this conversation as resolved.
Show resolved Hide resolved
}

#if !os(Linux)
/// Uploadcare allows converting documents to the following target formats: DOC, DOCX, XLS, XLSX, ODT, ODS, RTF, TXT, PDF, JPG, PNG.
///
Expand Down
74 changes: 74 additions & 0 deletions Sources/Uploadcare/models/REST/DocumentInfo.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
//
// DocumentInfo.swift
//
//
// Created by Sergei Armodin on 23.05.2024.
// Copyright © 2024 Uploadcare, Inc. All rights reserved.
//

import Foundation

public struct ConversionFormat: Codable {
/// Supported target document format.
public let name: String

enum CodingKeys: String, CodingKey {
case name
}

public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)

self.name = try container.decodeIfPresent(String.self, forKey: .name) ?? ""
}
}

public struct DocumentFormat: Codable {
internal init(name: String, conversionFormats: [ConversionFormat]) {
self.name = name
self.conversionFormats = conversionFormats
}

/// A detected document format.
public let name: String

/// The conversions that are supported for the document.
public let conversionFormats: [ConversionFormat]

enum CodingKeys: String, CodingKey {
case name
case conversionFormats = "conversion_formats"
}

public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)

self.name = try container.decodeIfPresent(String.self, forKey: .name) ?? ""
self.conversionFormats = try container.decodeIfPresent([ConversionFormat].self, forKey: .conversionFormats) ?? []
}
}

public struct DocumentInfo: Codable {
/// Holds an error if your document can't be handled.
public let error: String?

/// Document format details.
public let format: DocumentFormat

/// Information about already converted groups.
public let convertedGroups: [String: String]?

enum CodingKeys: String, CodingKey {
case error
case format
case convertedGroups = "converted_groups"
}

public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)

self.error = try container.decodeIfPresent(String.self, forKey: .error)
self.format = try container.decodeIfPresent(DocumentFormat.self, forKey: .format) ?? DocumentFormat(name: "", conversionFormats: [])
self.convertedGroups = try container.decodeIfPresent([String: String].self, forKey: .convertedGroups)
}
}
21 changes: 21 additions & 0 deletions Tests/UploadcareTests/RESTAPIIntegrationAsyncTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -560,4 +560,25 @@ final class RESTAPIIntegrationAsyncTests: XCTestCase {
let status = try await uploadcare.performRemoveBG(fileUUID: uuid, parameters: parameters)
XCTAssertTrue(status.status != .unknown)
}

func test31_document_info() async throws {
let url = URL(string: "https://source.unsplash.com/featured")!
let data = try! Data(contentsOf: url)
DLog("size of file: \(sizeString(ofData: data))")

// upload random image
let resultDictionary = try await uploadcare.uploadAPI.directUploadInForeground(files: ["random_file_name.jpg": data], store: .doNotStore)
guard let uuid = resultDictionary.values.first else {
XCTFail()
return
}

try await Task.sleep(nanoseconds: 1 * NSEC_PER_SEC)

let documentInfo = try await uploadcare.documentInfo(uuid)

XCTAssertNil(documentInfo.error)
XCTAssertFalse(documentInfo.format.name.isEmpty)
XCTAssertFalse(documentInfo.format.conversionFormats.isEmpty)
}
makoni marked this conversation as resolved.
Show resolved Hide resolved
}
37 changes: 37 additions & 0 deletions Tests/UploadcareTests/RESTAPIIntegrationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1005,5 +1005,42 @@ final class RESTAPIIntegrationTests: XCTestCase {

wait(for: [expectation], timeout: 20.0)
}

func test27_document_info() {
let expectation = XCTestExpectation(description: "test27_document_info")

let url = URL(string: "https://source.unsplash.com/featured")!
let data = try! Data(contentsOf: url)
makoni marked this conversation as resolved.
Show resolved Hide resolved
DLog("size of file: \(sizeString(ofData: data))")

// upload random image
uploadcare.uploadAPI.directUpload(files: ["random_file_name.jpg": data], store: .doNotStore) { result in
switch result {
case .failure(let error):
expectation.fulfill()
XCTFail(error.detail)
case .success(let resultDictionary):
guard let uuid = resultDictionary.values.first else {
XCTFail()
makoni marked this conversation as resolved.
Show resolved Hide resolved
expectation.fulfill()
return
}

self.uploadcare.documentInfo(uuid) { result in
defer { expectation.fulfill() }

switch result {
case .failure(let error): XCTFail(error.detail)
case .success(let documentInfo):
XCTAssertNil(documentInfo.error)
XCTAssertFalse(documentInfo.format.name.isEmpty)
XCTAssertFalse(documentInfo.format.conversionFormats.isEmpty)
}
}
}
}

wait(for: [expectation], timeout: 20.0)
}
}
#endif
2 changes: 1 addition & 1 deletion Uploadcare.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'Uploadcare'
s.version = '0.13.1'
s.version = '0.14.0'
s.summary = 'Swift integration for Uploadcare'

# This description is used to generate tags and improve search results.
Expand Down
28 changes: 28 additions & 0 deletions Uploadcare.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,14 @@
245DBB4D24901B9B002FB70B /* Uploadcare_watchOS.h in Headers */ = {isa = PBXBuildFile; fileRef = 245DBB4B24901B9B002FB70B /* Uploadcare_watchOS.h */; settings = {ATTRIBUTES = (Public, ); }; };
24875B1D243B33EC003F3E06 /* Uploadcare_tvOS.h in Headers */ = {isa = PBXBuildFile; fileRef = 24875B1B243B33EB003F3E06 /* Uploadcare_tvOS.h */; settings = {ATTRIBUTES = (Public, ); }; };
24875B37243B3518003F3E06 /* Uploadcare_macOS.h in Headers */ = {isa = PBXBuildFile; fileRef = 24875B35243B3518003F3E06 /* Uploadcare_macOS.h */; settings = {ATTRIBUTES = (Public, ); }; };
24F8B88B2BFFE11100D86B6A /* DocumentInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24F8B88A2BFFE11100D86B6A /* DocumentInfo.swift */; };
24F8B88C2BFFE11100D86B6A /* DocumentInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24F8B88A2BFFE11100D86B6A /* DocumentInfo.swift */; };
24F8B88D2BFFE11100D86B6A /* DocumentInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24F8B88A2BFFE11100D86B6A /* DocumentInfo.swift */; };
24F8B88E2BFFE11100D86B6A /* DocumentInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24F8B88A2BFFE11100D86B6A /* DocumentInfo.swift */; };
24F8B8952BFFE38D00D86B6A /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = 24F8B8932BFFE38D00D86B6A /* PrivacyInfo.xcprivacy */; };
24F8B8962BFFE38D00D86B6A /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = 24F8B8932BFFE38D00D86B6A /* PrivacyInfo.xcprivacy */; };
24F8B8972BFFE50200D86B6A /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = 24F8B8932BFFE38D00D86B6A /* PrivacyInfo.xcprivacy */; };
24F8B8992BFFE51900D86B6A /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = 24F8B8932BFFE38D00D86B6A /* PrivacyInfo.xcprivacy */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand Down Expand Up @@ -318,6 +326,8 @@
248BD549243627B600B4A3CA /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
2495945323B77F51006BB9BF /* Uploadcare.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Uploadcare.framework; sourceTree = BUILT_PRODUCTS_DIR; };
2495945623B7801A006BB9BF /* Alamofire.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Alamofire.framework; path = Carthage/Build/iOS/Alamofire.framework; sourceTree = "<group>"; };
24F8B88A2BFFE11100D86B6A /* DocumentInfo.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DocumentInfo.swift; sourceTree = "<group>"; };
24F8B8932BFFE38D00D86B6A /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; name = PrivacyInfo.xcprivacy; path = Sources/Uploadcare/PrivacyInfo.xcprivacy; sourceTree = "<group>"; };
OBJ_12 /* UploadcareTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UploadcareTests.swift; sourceTree = "<group>"; };
OBJ_13 /* XCTestManifests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = XCTestManifests.swift; sourceTree = "<group>"; };
OBJ_38 /* Carthage */ = {isa = PBXFileReference; lastKnownFileType = folder; path = Carthage; sourceTree = SOURCE_ROOT; };
Expand Down Expand Up @@ -403,6 +413,7 @@
24464E3728F763C400688FF0 /* convertion */,
24464E4028F763C400688FF0 /* responses */,
24464E4828F763C400688FF0 /* Collaborator.swift */,
24F8B88A2BFFE11100D86B6A /* DocumentInfo.swift */,
24464E4928F763C400688FF0 /* Project.swift */,
24464E4A28F763C400688FF0 /* File.swift */,
24464E4B28F763C400688FF0 /* PaginationQuery.swift */,
Expand Down Expand Up @@ -624,6 +635,7 @@
OBJ_5 = {
isa = PBXGroup;
children = (
24F8B8932BFFE38D00D86B6A /* PrivacyInfo.xcprivacy */,
OBJ_6 /* Package.swift */,
24B7217E2502AFE000462BD8 /* Sources */,
OBJ_10 /* Tests */,
Expand Down Expand Up @@ -742,6 +754,7 @@
buildPhases = (
2495944C23B77F51006BB9BF /* Sources */,
2495944E23B77F51006BB9BF /* Frameworks */,
24F8B8982BFFE51600D86B6A /* Resources */,
);
buildRules = (
);
Expand Down Expand Up @@ -809,20 +822,31 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
24F8B8962BFFE38D00D86B6A /* PrivacyInfo.xcprivacy in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
24875B17243B33EB003F3E06 /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
24F8B8972BFFE50200D86B6A /* PrivacyInfo.xcprivacy in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
24875B31243B3518003F3E06 /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
24F8B8952BFFE38D00D86B6A /* PrivacyInfo.xcprivacy in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
24F8B8982BFFE51600D86B6A /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
24F8B8992BFFE51900D86B6A /* PrivacyInfo.xcprivacy in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -855,6 +879,7 @@
24464F2028F763C400688FF0 /* UploadTask.swift in Sources */,
24464E7828F763C400688FF0 /* VideoInfo.swift in Sources */,
24464EC428F763C400688FF0 /* CopyFileToLocalStorageResponse.swift in Sources */,
24F8B88E2BFFE11100D86B6A /* DocumentInfo.swift in Sources */,
24464E9828F763C400688FF0 /* ClamAVAddonExecutionParams.swift in Sources */,
24464F4828F763C400688FF0 /* APIStore.swift in Sources */,
24464EB428F763C400688FF0 /* ConvertVideoJobStatus.swift in Sources */,
Expand Down Expand Up @@ -919,6 +944,7 @@
24464F1E28F763C400688FF0 /* UploadTask.swift in Sources */,
24464E7628F763C400688FF0 /* VideoInfo.swift in Sources */,
24464EC228F763C400688FF0 /* CopyFileToLocalStorageResponse.swift in Sources */,
24F8B88C2BFFE11100D86B6A /* DocumentInfo.swift in Sources */,
24464E9628F763C400688FF0 /* ClamAVAddonExecutionParams.swift in Sources */,
24464F4628F763C400688FF0 /* APIStore.swift in Sources */,
24464EB228F763C400688FF0 /* ConvertVideoJobStatus.swift in Sources */,
Expand Down Expand Up @@ -983,6 +1009,7 @@
24464F1F28F763C400688FF0 /* UploadTask.swift in Sources */,
24464E7728F763C400688FF0 /* VideoInfo.swift in Sources */,
24464EC328F763C400688FF0 /* CopyFileToLocalStorageResponse.swift in Sources */,
24F8B88D2BFFE11100D86B6A /* DocumentInfo.swift in Sources */,
24464E9728F763C400688FF0 /* ClamAVAddonExecutionParams.swift in Sources */,
24464F4728F763C400688FF0 /* APIStore.swift in Sources */,
24464EB328F763C400688FF0 /* ConvertVideoJobStatus.swift in Sources */,
Expand Down Expand Up @@ -1047,6 +1074,7 @@
24464F1D28F763C400688FF0 /* UploadTask.swift in Sources */,
24464E7528F763C400688FF0 /* VideoInfo.swift in Sources */,
24464EC128F763C400688FF0 /* CopyFileToLocalStorageResponse.swift in Sources */,
24F8B88B2BFFE11100D86B6A /* DocumentInfo.swift in Sources */,
24464E9528F763C400688FF0 /* ClamAVAddonExecutionParams.swift in Sources */,
24464F4528F763C400688FF0 /* APIStore.swift in Sources */,
24464EB128F763C400688FF0 /* ConvertVideoJobStatus.swift in Sources */,
Expand Down
Loading