Skip to content

Commit

Permalink
Merge pull request #57 from BalestraPatrick/bundle-ids-and-capabiliti…
Browse files Browse the repository at this point in the history
…es-endpoints

Add support for Bundle IDs and Capabilities endpoints
  • Loading branch information
AvdLee authored Jan 6, 2020
2 parents 0800af4 + eff427f commit f2a3a29
Show file tree
Hide file tree
Showing 44 changed files with 1,359 additions and 102 deletions.
8 changes: 6 additions & 2 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
## Changelog

### Next
- Updated CI to make sure PR requests are reviewed using Danger.
- Removed custom Result type.
- Updated CI to make sure PR requests are reviewed using Danger. (@AvdLee)
- Add support for all [Certificates](https://developer.apple.com/documentation/appstoreconnectapi/certificates) endpoints. (@BalestraPatrick)
- Add support for all [Bundle ID](https://developer.apple.com/documentation/appstoreconnectapi/bundle_ids) endpoints. (@ruipfcosta, @BalestraPatrick)
- Add support for all [Bundle ID Capabilities](https://developer.apple.com/documentation/appstoreconnectapi/bundle_id_capabilities) endpoints. (@BalestraPatrick)
- Updated CI to make sure PR requests are reviewed using Danger. (@AvdLee)
- Removed custom Result type. (@ruipfcosta)
- Fixed typo for downloadSalesAndTrendsReports ([Issue 42](https://github.com/AvdLee/appstoreconnect-swift-sdk/issues/42))
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// DisableCapability.swift
// AppStoreConnect-Swift-SDK
//
// Created by Patrick Balestra on 12/23/19.
//

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))
}
}
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))
}
}
21 changes: 21 additions & 0 deletions Sources/Endpoints/Provisioning/Bundle IDs/DeleteBundleID.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// DeleteBundleID.swift
// AppStoreConnect-Swift-SDK
//
// Created by Patrick Balestra on 12/22/19.
//

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,27 @@
//
// GetAllProfileIdsForBundleId.swift
// AppStoreConnect-Swift-SDK
//
// Created by Patrick Balestra on 12/23/19.
//

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,27 @@
//
// GetAllProfileIdsForBundleId.swift
// AppStoreConnect-Swift-SDK
//
// Created by Patrick Balestra on 12/23/19.
//

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,30 @@
//
// ListAllCapabilitiesForBundleId.swift
// AppStoreConnect-Swift-SDK
//
// Created by Patrick Balestra on 12/23/19.
//

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,30 @@
//
// GetAllProfileIdsForBundleId.swift
// AppStoreConnect-Swift-SDK
//
// Created by Patrick Balestra on 12/23/19.
//

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)
}
}
129 changes: 129 additions & 0 deletions Sources/Endpoints/Provisioning/Bundle IDs/ListBundleIds.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
//
// ListBundleIDs.swift
// AppStoreConnect-Swift-SDK
//
// Created by Patrick Balestra on 12/22/19.
//

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

0 comments on commit f2a3a29

Please sign in to comment.