Skip to content

swiftty/AppStoreConnectKit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

70 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AppStoreConnectKit

App Store Connect API for Swift.

Installation

Swift Package Manager

dependencies: [
    .package(url: "https://github.com/swiftty/AppStoreConnectKit", from: "0.0.5")
]

Usage

import AppStoreConnectKit

var endpoint = V1.Apps.GET()
endpoint.parameters.fields[.apps] = [.name, .bundleId]
endpoint.parameters.limit[.builds] = 5

guard var request = try URLRequest(endpoint: endpoint) else { return }
request.setValue("Bearer \(<# json web token #>)", forHTTPHeaderField: "Authorization")

let (data, urlResponse) = try await URLSession.shared.data(for: request)

let response = try endpoint.response(from: data, urlResponse: urlResponse as! HTTPURLResponse)

print(response.data)

Paging

guard let endpoint = Cursor<V1.Apps.GET>(url: response.links.next) else { return }

guard var request = try URLRequest(endpoint: endpoint) else { return }
request.setValue("Bearer \(<# json web token #>)", forHTTPHeaderField: "Authorization")

let (data, urlResponse) = try await URLSession.shared.data(for: request)

let nextResponse = try endpoint.response(from: data, urlResponse: urlResponse as! HTTPURLResponse)

print(nextResponse.data)

Generate JWT (Optional)

you can use AppStoreConnectToken or any other JWT libraries.

import AppStoreConnectToken

let p8 = try P8(String(contentsOf: URL(fileURLWithPath: "<# path to p8 file #>"))
let jwt = JWT(keyIdentifier: "<# your key id #>",
              issuerIdentifier: "<# your issuer id #>",
              expiration: 60 * 60)

let token = try jwt.sign(using: p8)
// request.setValue("Bearer \(token)", forHTTPHeaderField: "Authorization")

Development

Download OpenAPISpecification from https://developer.apple.com/documentation/appstoreconnectapi. then,

git clone https://github.com/swiftty/AppStoreConnectKit.git
cd AppStoreConnectKit/tools
 swift run appstoreconnectgen --open-api-path $path_to_open_api.json --output ../Sources/AppStoreConnectKit/autogenerated/

License

AppStoreConnectKit is available under the MIT license, and uses source code from open source projects. See the LICENSE file for more info.