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

Add additional details field for Event #770

Merged
merged 6 commits into from
Apr 20, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ __New Features and Enhancements:__
- Add support for folder lock functionality ([#759](https://github.com/box/box-ios-sdk/pull/759))
- Add support for copyInstanceOnItemCopy field for metadata templates ([#763](https://github.com/box/box-ios-sdk/pull/763))
- Add support for stream upload of new file versions and add support for 'If-Match' header when uploading new file versions ([#766](https://github.com/box/box-ios-sdk/pull/766))
- Add additional details field for `Event` model ([#770](https://github.com/box/box-ios-sdk/pull/770))

__Bug Fixes:__

Expand Down
4 changes: 2 additions & 2 deletions Sources/Core/BoxJSONDecoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import UIKit
// swiftlint:disable:next convenience_type
class BoxJSONDecoder {

private static func extractJSON<T>(json: [String: Any], key: String) throws -> T {
static func extractJSON<T>(json: [String: Any], key: String) throws -> T {
guard let objectJSON = json[key] else {
throw BoxCodingError(message: .notPresent(key: key))
}
Expand All @@ -24,7 +24,7 @@ class BoxJSONDecoder {
return object
}

private static func optionalExtractJSON<T>(json: [String: Any], key: String) throws -> T? {
static func optionalExtractJSON<T>(json: [String: Any], key: String) throws -> T? {
guard let objectJSON = json[key] else {
return nil
}
Expand Down
1 change: 0 additions & 1 deletion Sources/Modules/FilesModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,6 @@ public class FilesModule {
)
}


/// Upload a new version of an existing file.
///
/// - Parameters:
Expand Down
3 changes: 3 additions & 0 deletions Sources/Responses/Event.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public class Event: BoxModel {
public let createdAt: Date?
/// When the event was stored in the Box database.
public let recordedAt: Date?
/// Additional details for the event
public let additionalDetails: [String: Any]?

/// Initializer.
///
Expand All @@ -58,5 +60,6 @@ public class Event: BoxModel {
source = try BoxJSONDecoder.optionalDecode(json: json, forKey: "source")
createdAt = try BoxJSONDecoder.optionalDecodeDate(json: json, forKey: "created_at")
recordedAt = try BoxJSONDecoder.optionalDecodeDate(json: json, forKey: "recorded_at")
additionalDetails = try BoxJSONDecoder.optionalExtractJSON(json: json, key: "additional_details")
}
}
1 change: 0 additions & 1 deletion Sources/Responses/ZipDownload.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public class ZipDownload: BoxModel {
/// Conflicts that occur between items that have the same name.
public let nameConflicts: [ZipDownloadConflict]?


/// Initializer.
///
/// - Parameter json: JSON dictionary.
Expand Down
1 change: 0 additions & 1 deletion Sources/Responses/ZipDownloadStatus.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public class ZipDownloadStatus: BoxModel {
/// Conflicts that occur between items that have the same name. This is always initially nil and updated manually later, via the FilesModule.getZipDownloadStatus() method.
public var nameConflicts: [ZipDownloadConflict]?


/// Initializer.
///
/// - Parameter json: JSON dictionary.
Expand Down
10 changes: 5 additions & 5 deletions Tests/Client/BoxClientSpecs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ class BoxClientSpecs: QuickSpec {
}
}
}

it("should produce error when OAuth2 access token has been revoked") {
let clientID = "ksdjfksadfisdg"
let clientSecret = "liuwerfiberdus"
Expand All @@ -160,15 +160,15 @@ class BoxClientSpecs: QuickSpec {
let tokenInfo = TokenInfo(accessToken: accessToken, expiresIn: expiresIn)
sdk.getOAuth2Client(tokenInfo: tokenInfo, tokenStore: nil) { result in
switch result {
case .success(let c):
case let .success(c):
client = c
case .failure(let error):
case let .failure(error):
fail("Expected getting client to succeed, but instead got \(error)")
}
done()
}
}

stub(
condition: isHost("api.box.com")
&& isPath("/2.0/users/me")
Expand All @@ -186,7 +186,7 @@ class BoxClientSpecs: QuickSpec {
done()
return
}

expect(error).to(matchError(BoxAPIAuthError(message: .unauthorizedAccess)))
done()
}
Expand Down
1 change: 1 addition & 0 deletions Tests/Modules/EventsModuleSpecs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ class EventsModuleSpecs: QuickSpec {
default:
fail("Unable to get event source")
}
expect(event.additionalDetails?["size"] as? Int).to(equal(21696))
case let .failure(error):
fail("Unable to get event details, but instead got \(error)")
}
Expand Down
18 changes: 9 additions & 9 deletions Tests/Modules/FilesModuleSpecs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1920,15 +1920,15 @@ class FilesModuleSpecs: QuickSpec {
it("should download zip when API call succeeds") {
stub(
condition: isHost("api.box.com") &&
isPath("/2.0/zip_downloads") &&
isMethodPOST() &&
hasJsonBody([
"download_file_name": "New zip file 2",
"items": [[
"type": "file",
"id": "5000948880"
]]
])
isPath("/2.0/zip_downloads") &&
isMethodPOST() &&
hasJsonBody([
"download_file_name": "New zip file 2",
"items": [[
"type": "file",
"id": "5000948880"
]]
])
) { _ in
OHHTTPStubsResponse(
fileAtPath: OHPathForFile("ZipDownload.json", type(of: self))!,
Expand Down
6 changes: 4 additions & 2 deletions Tests/Modules/FolderModuleSpecs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -715,8 +715,10 @@ class FolderModuleSpecs: QuickSpec {

describe("listLocks()") {
it("should get folder locks") {
stub(condition: isHost("api.box.com") && isPath("/2.0/folder_locks") && isMethodGET() &&
containsQueryParams(["folder_id": "14176246"])) { _ in
stub(
condition: isHost("api.box.com") && isPath("/2.0/folder_locks") && isMethodGET() &&
containsQueryParams(["folder_id": "14176246"])
) { _ in
OHHTTPStubsResponse(
fileAtPath: OHPathForFile("FolderLocks.json", type(of: self))!,
statusCode: 200, headers: ["Content-Type": "application/json"]
Expand Down
2 changes: 1 addition & 1 deletion Tests/Modules/MetadataModuleSpecs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class MetadataModuleSpecs: QuickSpec {
["key": "FY14"],
["key": "FY15"]
],
"key": "fy", "displayName": "FY"]
"key": "fy", "displayName": "FY"]
swfree marked this conversation as resolved.
Show resolved Hide resolved
]
])
) { _ in
Expand Down