Skip to content

Commit 2e8c6bd

Browse files
committed
Add private API templates
1 parent 22f933d commit 2e8c6bd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+2754
-2
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
formatter: swift
2+
options:
3+
name: CampaignAPI # the name of the API
4+
fixedWidthIntegers: false # whether to use types like Int32 and Int64
5+
mutableModels: true # whether model properties are mutable
6+
modelPrefix: "PCCampaign" # applied to model classes and enums
7+
requestPrefix: "CampaignAPI" # applied to model classes and enums
8+
modelSuffix: null # applied to model classes
9+
modelType: class # can be struct or class
10+
modelInheritance: true # must be false for struct modelType
11+
modelProtocol: APIModel # the protocol all models conform to
12+
modelNames: {} # override model type names
13+
enumNames: {} # override enum type names
14+
enumUndecodableCase: false # whether to add undecodable case to enums
15+
codableResponses: false # constrains all responses/model to be Codable
16+
propertyNames: {} # override property names
17+
anyType: Any # override Any in generated models
18+
baseURL: "https://api.pace.cloud/campaign" # override given base url from swagger file
19+
numberType: Double
20+
decimalType: Decimal
21+
typeAliases:
22+
ID: String
23+
DateTime: Date
24+
File: Data
25+
templateFiles:
26+
- path: Common/README.md
27+
destination: "README.md"
28+
- path: Common/API.swift
29+
destination: "CampaignAPI.swift"
30+
- path: Common/Coding.swift
31+
destination: "./../../Generated/Common/Coding.swift"
32+
- path: Common/AnyResponse.swift
33+
destination: "./../../Generated/Common/AnyResponse.swift"
34+
- path: Common/APIRequestUtils.swift
35+
destination: "./../../Generated/Common/APIRequestUtils.swift"
36+
- path: Common/APIRequest.swift
37+
destination: "CampaignAPIRequest.swift"
38+
- path: Common/AnyRequest.swift
39+
destination: "AnyCampaignRequest.swift"
40+
- path: Common/APIClient.swift
41+
destination: "CampaignAPIClient.swift"
42+
- path: Common/APIClient+URLProtocol.swift
43+
destination: "CampaignAPIClient+URLProtocol.swift"
44+
- path: Common/APIService.swift
45+
destination: "CampaignAPIService.swift"
46+
- path: Common/APIClientError.swift
47+
destination: "./../../Generated/Common/APIClientError.swift"
48+
- path: Common/APIResponseUtils.swift
49+
destination: "./../../Generated/Common/APIResponseUtils.swift"
50+
- path: Common/APIResponse.swift
51+
destination: "CampaignAPIResponse.swift"
52+
- path: Common/APIResult.swift
53+
destination: "./../../Generated/Common/APIResult.swift"
54+
- path: Common/RequestBehaviour.swift
55+
destination: "CampaignRequestBehaviour.swift"
56+
- path: Common/AnyCodable.swift
57+
destination: "./../../Generated/Common/AnyCodable.swift"
58+
- path: Common/URLEncoding.swift
59+
destination: "./../../Generated/Common/URLEncoding.swift"
60+
- path: Common/APIContainer.swift
61+
destination: "./../../Generated/Common/API.swift"
62+
- path: Common/Enum.swift
63+
context: enums
64+
destination: "Enums/{{ enumName }}.swift"
65+
- path: Common/Model.swift
66+
context: schemas
67+
destination: "./../../Generated/Models/{{ type }}.swift"
68+
- path: Common/Request.swift
69+
context: operations
70+
destination: "Requests{% if tag %}/{{ tag|upperCamelCase }}{% endif %}/{{ fileName }}.swift"
File renamed without changes.

Templates/Swift/Common/APIClient+URLProtocol.swift renamed to Templates/SwiftPrivateAPIs/Common/APIClient+URLProtocol.swift

File renamed without changes.

Templates/SwiftPrivateAPIs/Common/APIClient.swift

Lines changed: 392 additions & 0 deletions
Large diffs are not rendered by default.
File renamed without changes.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{% include "Common/Includes/Header.stencil" %}
2+
3+
import Foundation
4+
import PACECloudSDK
5+
6+
public struct API {
7+
/**
8+
The access token to be used for API requests.
9+
10+
This token will be set automatically when using IDKit.
11+
*/
12+
public static var accessToken: String?
13+
}
14+
15+
public extension API {
16+
/**
17+
Determines if an API request should be retried.
18+
19+
It takes into account if the request has failed due to network connection errors or timeouts and if the maximum number of retries has been exceeded.
20+
21+
- parameter currentRetryCount: The current number of retries for a specific request.
22+
- parameter maxRetryCount: The maximum number of retries allowed for a specific request.
23+
- parameter response: The most recent URL response of a specific request or `nil` if not available.
24+
*/
25+
static func shouldRetryRequest(currentRetryCount: Int,
26+
maxRetryCount: Int,
27+
response: URLResponse?) -> Bool {
28+
guard currentRetryCount <= maxRetryCount else { return false }
29+
guard let response = response as? HTTPURLResponse else { return true }
30+
return response.statusCode == HttpStatusCode.requestTimeout.rawValue
31+
}
32+
33+
/**
34+
Returns the number of seconds an API request should be delayed before the next retry is executed.
35+
36+
It calculates the number of seconds based on an exponential backoff algorithm.
37+
38+
- parameter currentRetryCount: The current number of retries for a specific request.
39+
- parameter delayUpperBound: The maximum number of seconds a request should be delayed. Defaults to `64`.
40+
- returns: The request delay in seconds.
41+
*/
42+
static func nextExponentialBackoffRequestDelay(currentRetryCount: Int, delayUpperBound: Int = 64) -> Int {
43+
let nextDelayIteration = NSDecimalNumber(decimal: pow(2, currentRetryCount - 1))
44+
let delay = min(Int(truncating: nextDelayIteration), delayUpperBound)
45+
return delay
46+
}
47+
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)