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 support for Bundle IDs and Capabilities endpoints #57

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// DisableCapability.swift
// AppStoreConnect-Swift-SDK
//
// Created by Patrick Balestra on 12/23/19.
//

import Foundation
BalestraPatrick marked this conversation as resolved.
Show resolved Hide resolved

extension APIEndpoint where T == Void {

/// Disable a capability for a bundle ID.
///
/// - Parameters:
/// - id: (Required) An opaque resource ID that uniquely identifies the bundle identifier.
public static func disableCapability(id: String) -> APIEndpoint {

return APIEndpoint(
path: "bundleIdCapabilities/\(id)",
method: .delete,
parameters: nil)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// EnableCapability.swift
// AppStoreConnect-Swift-SDK
//
// Created by Patrick Balestra on 12/23/19.
//

import Foundation

extension APIEndpoint where T == BundleIdCapabilityResponse {

/// Enable a capability for a bundle ID.
///
/// - Parameters:
/// - id: (Required) An opaque resource ID that uniquely identifies the bundle identifier.
/// - capabilityType: The capability type.
/// - settings: An optional array of settings for this capability.
public static func enableCapability(
id: String,
capabilityType: CapabilityType,
settings: [CapabilitySetting]? = nil) -> APIEndpoint {

let request = BundleIdCapabilityCreateRequest(
bundleId: id,
capabilityType: capabilityType,
settings: settings
)

return APIEndpoint(
path: "bundleIdCapabilities",
method: .post,
parameters: nil,
body: try? JSONEncoder().encode(request))
Copy link
Owner

Choose a reason for hiding this comment

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

If encoding here fails, it would fail silently. This might make it harder to debug eventually if it's causing the request to fail as well. What do you think about making the enableCapability method throwing?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I took inspiration from all other methods that don't propagate the failure right now. There are other 36 instances of try? JSONEncoder().encode(request) in the project, so not sure it's worth changing these new methods to a new convention.

Copy link
Owner

Choose a reason for hiding this comment

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

Hmm, you're right! Lets keep it like this for now.

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// ModifyCapabilityConfiguration.swift
// AppStoreConnect-Swift-SDK
//
// Created by Patrick Balestra on 12/23/19.
//

import Foundation

extension APIEndpoint where T == BundleIdCapabilityResponse {

/// Update the configuration of a specific capability.
///
/// - Parameters:
/// - id: (Required) An opaque resource ID that uniquely identifies the bundle identifier.
/// - capabilityType: (Required) The capability type.
/// - settings: (Required) An optional array of settings for this capability.
public static func modifyCapability(
id: String,
capabilityType: CapabilityType,
settings: [CapabilitySetting]? = nil) -> APIEndpoint {

let request = BundleIdCapabilityUpdateRequest(
bundleId: id,
capabilityType: capabilityType,
settings: settings
)

return APIEndpoint(
path: "bundleIdCapabilities/\(id)",
method: .patch,
parameters: nil,
body: try? JSONEncoder().encode(request))
}
}
23 changes: 23 additions & 0 deletions Sources/Endpoints/Provisioning/Bundle IDs/DeleteBundleID.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// DeleteBundleID.swift
// AppStoreConnect-Swift-SDK
//
// Created by Patrick Balestra on 12/22/19.
//

import Foundation

extension APIEndpoint where T == Void {

/// Delete a bundle ID that is used for app development.
///
/// - Parameters:
/// - id: (Required) An opaque resource ID that uniquely identifies the bundle identifier.
public static func delete(bundleWithId id: String) -> APIEndpoint {

return APIEndpoint(
path: "bundleIds/\(id)",
method: .delete,
parameters: nil)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// GetAllProfileIdsForBundleId.swift
// AppStoreConnect-Swift-SDK
//
// Created by Patrick Balestra on 12/23/19.
//

import Foundation

extension APIEndpoint where T == BundleIdBundleIdCapabilitiesLinkagesResponse {

/// Get the resource IDs for all capabilities associated with a specific bundle ID.
///
/// - Parameters:
/// - id: (Required) An opaque resource ID that uniquely identifies the bundle identifier.
/// - limit: Number of resources to return.
public static func getAllCapabililityIdsForBundleId(
id: String,
limit: Int? = nil) -> APIEndpoint {

var parameters = [String: Any]()
if let limit = limit { parameters["limit"] = limit }

return APIEndpoint(
path: "bundleIds/\(id)/relationships/bundleIdCapabilities",
method: .get,
parameters: parameters)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// GetAllProfileIdsForBundleId.swift
// AppStoreConnect-Swift-SDK
//
// Created by Patrick Balestra on 12/23/19.
//

import Foundation

extension APIEndpoint where T == BundleIdProfilesLinkagesResponse {

/// Get the resource IDs for all profiles associated with a specific bundle ID.
///
/// - Parameters:
/// - id: (Required) An opaque resource ID that uniquely identifies the bundle identifier.
/// - limit: Number of resources to return.
public static func getAllProfileIdsForBundleId(
id: String,
limit: Int? = nil) -> APIEndpoint {

var parameters = [String: Any]()
if let limit = limit { parameters["limit"] = limit }

return APIEndpoint(
path: "bundleIds/\(id)/relationships/profiles",
method: .get,
parameters: parameters)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//
// ListAllCapabilitiesForBundleId.swift
// AppStoreConnect-Swift-SDK
//
// Created by Patrick Balestra on 12/23/19.
//

import Foundation

extension APIEndpoint where T == BundleIdCapabilitiesResponse {

/// Get a list of all capabilities for a specific bundle ID.
///
/// - Parameters:
/// - id: (Required) An opaque resource ID that uniquely identifies the bundle identifier.
/// - fields: Fields to return for included related types.
/// - limit: Number of resources to return.
public static func listAllCapabilitiesForBundleId(
id: String,
fields: [BundleIds.Field]? = nil,
limit: Int? = nil) -> APIEndpoint {

var parameters = [String: Any]()
if let fields = fields { parameters.add(fields) }
if let limit = limit { parameters["limit"] = limit }

return APIEndpoint(
path: "bundleIds/\(id)/bundleIdCapabilities",
method: .get,
parameters: parameters)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//
// GetAllProfileIdsForBundleId.swift
// AppStoreConnect-Swift-SDK
//
// Created by Patrick Balestra on 12/23/19.
//

import Foundation

extension APIEndpoint where T == ProfilesResponse {

/// Get a list of all profiles for a specific bundle ID.
///
/// - Parameters:
/// - id: (Required) An opaque resource ID that uniquely identifies the bundle identifier.
/// - fields: Fields to return for included related types.
/// - limit: Number of resources to return.
public static func listAllProfilesForBundleId(
id: String,
fields: [BundleIds.Field]? = nil,
limit: Int? = nil) -> APIEndpoint {

var parameters = [String: Any]()
if let fields = fields { parameters.add(fields) }
if let limit = limit { parameters["limit"] = limit }

return APIEndpoint(
path: "bundleIds/\(id)/profiles",
method: .get,
parameters: parameters)
}
}
131 changes: 131 additions & 0 deletions Sources/Endpoints/Provisioning/Bundle IDs/ListBundleIds.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
//
// ListBundleIDs.swift
// AppStoreConnect-Swift-SDK
//
// Created by Patrick Balestra on 12/22/19.
//

import Foundation

extension APIEndpoint where T == BundleIdsResponse {

/// Find and list bundle IDs that are registered to your team.
///
/// - Parameters:
/// - fields: Fields to return for included related types.
/// - filter: Attributes, relationships, and IDs by which to filter.
/// - sort: Attributes by which to sort.
/// - limit: Number of resources to return.
/// - next: The next URL to use as a base. See `PagedDocumentLinks`.
public static func listBundleIds(
fields: [BundleIds.Field]? = nil,
filter: [BundleIds.Filter]? = nil,
sort: [BundleIds.Sort]? = nil,
limit: Int? = nil,
next: PagedDocumentLinks? = nil) -> APIEndpoint {

var parameters = [String: Any]()
if let fields = fields { parameters.add(fields) }
if let filter = filter { parameters.add(filter) }
if let sort = sort { parameters.add(sort) }
if let limit = limit { parameters["limit"] = limit }
if let nextCursor = next?.nextCursor { parameters["cursor"] = nextCursor }

return APIEndpoint(
path: "bundleIds",
method: .get,
parameters: parameters)
}
}

public struct BundleIds {

public enum Field: NestableQueryParameter {
case bundleIds([BundleIds])
case profiles([Profiles])
case bundleIdCapabilities([BundleIdCapabilities])

static var key: String = "fields"
var pair: Pair {
switch self {
case .bundleIds(let values):
return (BundleIds.key, values.map({ $0.pair.value }).joinedByCommas())
case .profiles(let values):
return (Profiles.key, values.map({ $0.pair.value }).joinedByCommas())
case .bundleIdCapabilities(let values):
return (BundleIdCapabilities.key, values.map({ $0.pair.value }).joinedByCommas())
}
}
}

/// Attributes, relationships, and IDs by which to filter.
public enum Filter: NestableQueryParameter {
case id([String]), identifier([String]), name([String]), platform([Platform]), seedId([String])

static var key: String = "filter"
var pair: Pair {
switch self {
case .id(let values):
return ("id", values.joinedByCommas())
case .identifier(let values):
return ("identifier", values.joinedByCommas())
case .name(let values):
return ("name", values.joinedByCommas())
case .platform(let values):
return ("platform", values.map { $0.rawValue }.joinedByCommas())
case .seedId(let values):
return ("seedId", values.joinedByCommas())
}
}
}

/// Relationship data to include in the response.
public enum Include: String, CaseIterable, NestableQueryParameter {
case bundleIdCapabilities, profiles

static var key: String = "include"
var pair: NestableQueryParameter.Pair { return (nil, rawValue) }
}

/// Attributes by which to sort.
public enum Sort: String, CaseIterable, NestableQueryParameter {
case idAscending = "+id"
case idDescending = "-id"

case nameAscending = "+name"
case nameDescending = "-name"

case platformAscending = "+platform"
case platformDescending = "-platform"

case seedIdAscending = "+seedId"
case seedIdDescending = "-seedId"

static var key: String = "sort"
var pair: NestableQueryParameter.Pair { return (nil, rawValue) }
}
}

extension BundleIds.Field {

public enum BundleIds: String, CaseIterable, NestableQueryParameter {
case bundleIdCapabilities, identifier, name, platform, profiles, seedId

static var key: String = "bundleIds"
var pair: NestableQueryParameter.Pair { return (nil, rawValue) }
}

public enum Profiles: String, CaseIterable, NestableQueryParameter {
case bundleId, certificates, createdDate, devices, expirationDate, name, platform, profileContent, profileState, profileType, uuid

static var key: String = "profiles"
var pair: NestableQueryParameter.Pair { return (nil, rawValue) }
}

public enum BundleIdCapabilities: String, CaseIterable, NestableQueryParameter {
case bundleId, capabilityType, settings

static var key: String = "bundleIdCapabilities"
var pair: NestableQueryParameter.Pair { return (nil, rawValue) }
}
}
Loading