Skip to content

Commit

Permalink
Update to newly built Swift Client from GH Run 185 (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
joerghartmann authored Nov 25, 2022
1 parent 79ad26b commit 0a8dafd
Show file tree
Hide file tree
Showing 45 changed files with 450 additions and 137 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ C8yAlarm.registerAdditionalProperty<C: Codable>(typeName: String, for type: C.Ty

Each of the extensible objects contains a dictionary object holding instances of custom fragments. Use the custom fragment's key to access it's value.

In addition, developers may create subclasses. The client implementation respects subclassing by using generic type arguments.

### Working with errors

Use `sink(receiveCompletion:receiveValue:)` to observe values received by the publisher and process them using a closure you specify. HTTP error codes will be forwarded and can be accessed using a completion handler.
Expand Down
20 changes: 16 additions & 4 deletions Sources/CumulocityCoreLibrary/Api/AlarmsApi.swift
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ public class AlarmsApi: AdaptableApi {
/// Unprocessable Entity – invalid payload.
/// - Parameters:
/// - body
/// - xCumulocityProcessingMode
/// Used to explicitly control the processing mode of the request. See [Processing mode](#processing-mode) for more details.
/// - createdFrom
/// Start date or date and time of the alarm creation.
/// - createdTo
Expand All @@ -150,7 +152,7 @@ public class AlarmsApi: AdaptableApi {
/// When set to `true` also alarms for related source assets will be included in the request. When this parameter is provided a `source` must be specified.
/// - withSourceDevices
/// When set to `true` also alarms for related source devices will be included in the request. When this parameter is provided a `source` must be specified.
public func updateAlarms(body: C8yAlarm, createdFrom: String? = nil, createdTo: String? = nil, dateFrom: String? = nil, dateTo: String? = nil, resolved: Bool? = nil, severity: String? = nil, source: String? = nil, status: String? = nil, withSourceAssets: Bool? = nil, withSourceDevices: Bool? = nil) -> AnyPublisher<Data, Error> {
public func updateAlarms(body: C8yAlarm, xCumulocityProcessingMode: String? = nil, createdFrom: String? = nil, createdTo: String? = nil, dateFrom: String? = nil, dateTo: String? = nil, resolved: Bool? = nil, severity: String? = nil, source: String? = nil, status: String? = nil, withSourceAssets: Bool? = nil, withSourceDevices: Bool? = nil) -> AnyPublisher<Data, Error> {
var requestBody = body
requestBody.firstOccurrenceTime = nil
requestBody.severity = nil
Expand Down Expand Up @@ -183,6 +185,7 @@ public class AlarmsApi: AdaptableApi {
let builder = URLRequestBuilder()
.set(resourcePath: "/alarm/alarms")
.set(httpMethod: "put")
.add(header: "X-Cumulocity-Processing-Mode", value: String(describing: xCumulocityProcessingMode))
.add(header: "Content-Type", value: "application/vnd.com.nsn.cumulocity.alarm+json")
.add(header: "Accept", value: "application/json")
.set(queryItems: queryItems)
Expand Down Expand Up @@ -242,7 +245,9 @@ public class AlarmsApi: AdaptableApi {
/// Unprocessable Entity – invalid payload.
/// - Parameters:
/// - body
public func createAlarm(body: C8yAlarm) -> AnyPublisher<C8yAlarm, Error> {
/// - xCumulocityProcessingMode
/// Used to explicitly control the processing mode of the request. See [Processing mode](#processing-mode) for more details.
public func createAlarm(body: C8yAlarm, xCumulocityProcessingMode: String? = nil) -> AnyPublisher<C8yAlarm, Error> {
var requestBody = body
requestBody.firstOccurrenceTime = nil
requestBody.lastUpdated = nil
Expand All @@ -260,6 +265,7 @@ public class AlarmsApi: AdaptableApi {
let builder = URLRequestBuilder()
.set(resourcePath: "/alarm/alarms")
.set(httpMethod: "post")
.add(header: "X-Cumulocity-Processing-Mode", value: String(describing: xCumulocityProcessingMode))
.add(header: "Content-Type", value: "application/vnd.com.nsn.cumulocity.alarm+json")
.add(header: "Accept", value: "application/vnd.com.nsn.cumulocity.error+json, application/vnd.com.nsn.cumulocity.alarm+json")
.set(httpBody: encodedRequestBody)
Expand Down Expand Up @@ -297,6 +303,8 @@ public class AlarmsApi: AdaptableApi {
/// - 403
/// Not authorized to perform this operation.
/// - Parameters:
/// - xCumulocityProcessingMode
/// Used to explicitly control the processing mode of the request. See [Processing mode](#processing-mode) for more details.
/// - createdFrom
/// Start date or date and time of the alarm creation.
/// - createdTo
Expand All @@ -319,7 +327,7 @@ public class AlarmsApi: AdaptableApi {
/// When set to `true` also alarms for related source assets will be included in the request. When this parameter is provided a `source` must be specified.
/// - withSourceDevices
/// When set to `true` also alarms for related source devices will be included in the request. When this parameter is provided a `source` must be specified.
public func deleteAlarms(createdFrom: String? = nil, createdTo: String? = nil, dateFrom: String? = nil, dateTo: String? = nil, resolved: Bool? = nil, severity: String? = nil, source: String? = nil, status: String? = nil, type: [String]? = nil, withSourceAssets: Bool? = nil, withSourceDevices: Bool? = nil) -> AnyPublisher<Data, Error> {
public func deleteAlarms(xCumulocityProcessingMode: String? = nil, createdFrom: String? = nil, createdTo: String? = nil, dateFrom: String? = nil, dateTo: String? = nil, resolved: Bool? = nil, severity: String? = nil, source: String? = nil, status: String? = nil, type: [String]? = nil, withSourceAssets: Bool? = nil, withSourceDevices: Bool? = nil) -> AnyPublisher<Data, Error> {
var queryItems: [URLQueryItem] = []
if let parameter = createdFrom { queryItems.append(URLQueryItem(name: "createdFrom", value: String(parameter))) }
if let parameter = createdTo { queryItems.append(URLQueryItem(name: "createdTo", value: String(parameter))) }
Expand All @@ -335,6 +343,7 @@ public class AlarmsApi: AdaptableApi {
let builder = URLRequestBuilder()
.set(resourcePath: "/alarm/alarms")
.set(httpMethod: "delete")
.add(header: "X-Cumulocity-Processing-Mode", value: String(describing: xCumulocityProcessingMode))
.add(header: "Accept", value: "application/json")
.set(queryItems: queryItems)
return self.session.dataTaskPublisher(for: adapt(builder: builder).build()).tryMap({ element -> Data in
Expand Down Expand Up @@ -418,7 +427,9 @@ public class AlarmsApi: AdaptableApi {
/// - body
/// - id
/// Unique identifier of the alarm.
public func updateAlarm(body: C8yAlarm, id: String) -> AnyPublisher<C8yAlarm, Error> {
/// - xCumulocityProcessingMode
/// Used to explicitly control the processing mode of the request. See [Processing mode](#processing-mode) for more details.
public func updateAlarm(body: C8yAlarm, id: String, xCumulocityProcessingMode: String? = nil) -> AnyPublisher<C8yAlarm, Error> {
var requestBody = body
requestBody.firstOccurrenceTime = nil
requestBody.lastUpdated = nil
Expand All @@ -438,6 +449,7 @@ public class AlarmsApi: AdaptableApi {
let builder = URLRequestBuilder()
.set(resourcePath: "/alarm/alarms/\(id)")
.set(httpMethod: "put")
.add(header: "X-Cumulocity-Processing-Mode", value: String(describing: xCumulocityProcessingMode))
.add(header: "Content-Type", value: "application/vnd.com.nsn.cumulocity.alarm+json")
.add(header: "Accept", value: "application/vnd.com.nsn.cumulocity.error+json, application/vnd.com.nsn.cumulocity.alarm+json")
.set(httpBody: encodedRequestBody)
Expand Down
10 changes: 8 additions & 2 deletions Sources/CumulocityCoreLibrary/Api/ApplicationBinariesApi.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,15 @@ public class ApplicationBinariesApi: AdaptableApi {
/// The ZIP file to be uploaded.
/// - id
/// Unique identifier of the application.
public func uploadApplicationAttachment(file: Data, id: String) -> AnyPublisher<C8yApplication, Error> {
/// - xCumulocityProcessingMode
/// Used to explicitly control the processing mode of the request. See [Processing mode](#processing-mode) for more details.
public func uploadApplicationAttachment(file: Data, id: String, xCumulocityProcessingMode: String? = nil) -> AnyPublisher<C8yApplication, Error> {
let multipartBuilder = MultipartFormDataBuilder()
multipartBuilder.addBodyPart(named: "file", data: file, mimeType: "application/zip");
let builder = URLRequestBuilder()
.set(resourcePath: "/application/applications/\(id)/binaries")
.set(httpMethod: "post")
.add(header: "X-Cumulocity-Processing-Mode", value: String(describing: xCumulocityProcessingMode))
.add(header: "Content-Type", value: "multipart/form-data")
.add(header: "Accept", value: "application/vnd.com.nsn.cumulocity.error+json, application/vnd.com.nsn.cumulocity.application+json")
.add(header: "Content-Type", value: multipartBuilder.contentType)
Expand Down Expand Up @@ -163,10 +166,13 @@ public class ApplicationBinariesApi: AdaptableApi {
/// Unique identifier of the application.
/// - binaryId
/// Unique identifier of the binary.
public func deleteApplicationAttachment(id: String, binaryId: String) -> AnyPublisher<Data, Error> {
/// - xCumulocityProcessingMode
/// Used to explicitly control the processing mode of the request. See [Processing mode](#processing-mode) for more details.
public func deleteApplicationAttachment(id: String, binaryId: String, xCumulocityProcessingMode: String? = nil) -> AnyPublisher<Data, Error> {
let builder = URLRequestBuilder()
.set(resourcePath: "/application/applications/\(id)/binaries/\(binaryId)")
.set(httpMethod: "delete")
.add(header: "X-Cumulocity-Processing-Mode", value: String(describing: xCumulocityProcessingMode))
.add(header: "Accept", value: "application/json")
return self.session.dataTaskPublisher(for: adapt(builder: builder).build()).tryMap({ element -> Data in
guard let httpResponse = element.response as? HTTPURLResponse else {
Expand Down
20 changes: 16 additions & 4 deletions Sources/CumulocityCoreLibrary/Api/ApplicationsApi.swift
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ public class ApplicationsApi: AdaptableApi {
/// Unprocessable Entity – invalid payload.
/// - Parameters:
/// - body
public func createApplication(body: C8yApplication) -> AnyPublisher<C8yApplication, Error> {
/// - xCumulocityProcessingMode
/// Used to explicitly control the processing mode of the request. See [Processing mode](#processing-mode) for more details.
public func createApplication(body: C8yApplication, xCumulocityProcessingMode: String? = nil) -> AnyPublisher<C8yApplication, Error> {
var requestBody = body
requestBody.owner = nil
requestBody.activeVersionId = nil
Expand All @@ -126,6 +128,7 @@ public class ApplicationsApi: AdaptableApi {
let builder = URLRequestBuilder()
.set(resourcePath: "/application/applications")
.set(httpMethod: "post")
.add(header: "X-Cumulocity-Processing-Mode", value: String(describing: xCumulocityProcessingMode))
.add(header: "Content-Type", value: "application/vnd.com.nsn.cumulocity.application+json")
.add(header: "Accept", value: "application/vnd.com.nsn.cumulocity.error+json, application/vnd.com.nsn.cumulocity.application+json")
.set(httpBody: encodedRequestBody)
Expand Down Expand Up @@ -201,7 +204,9 @@ public class ApplicationsApi: AdaptableApi {
/// - body
/// - id
/// Unique identifier of the application.
public func updateApplication(body: C8yApplication, id: String) -> AnyPublisher<C8yApplication, Error> {
/// - xCumulocityProcessingMode
/// Used to explicitly control the processing mode of the request. See [Processing mode](#processing-mode) for more details.
public func updateApplication(body: C8yApplication, id: String, xCumulocityProcessingMode: String? = nil) -> AnyPublisher<C8yApplication, Error> {
var requestBody = body
requestBody.owner = nil
requestBody.activeVersionId = nil
Expand All @@ -218,6 +223,7 @@ public class ApplicationsApi: AdaptableApi {
let builder = URLRequestBuilder()
.set(resourcePath: "/application/applications/\(id)")
.set(httpMethod: "put")
.add(header: "X-Cumulocity-Processing-Mode", value: String(describing: xCumulocityProcessingMode))
.add(header: "Content-Type", value: "application/vnd.com.nsn.cumulocity.application+json")
.add(header: "Accept", value: "application/vnd.com.nsn.cumulocity.error+json, application/vnd.com.nsn.cumulocity.application+json")
.set(httpBody: encodedRequestBody)
Expand Down Expand Up @@ -261,12 +267,15 @@ public class ApplicationsApi: AdaptableApi {
/// Unique identifier of the application.
/// - force
/// Force deletion by unsubscribing all tenants from the application first and then deleting the application itself.
public func deleteApplication(id: String, force: Bool? = nil) -> AnyPublisher<Data, Error> {
/// - xCumulocityProcessingMode
/// Used to explicitly control the processing mode of the request. See [Processing mode](#processing-mode) for more details.
public func deleteApplication(id: String, force: Bool? = nil, xCumulocityProcessingMode: String? = nil) -> AnyPublisher<Data, Error> {
var queryItems: [URLQueryItem] = []
if let parameter = force { queryItems.append(URLQueryItem(name: "force", value: String(parameter))) }
let builder = URLRequestBuilder()
.set(resourcePath: "/application/applications/\(id)")
.set(httpMethod: "delete")
.add(header: "X-Cumulocity-Processing-Mode", value: String(describing: xCumulocityProcessingMode))
.add(header: "Accept", value: "application/json")
.set(queryItems: queryItems)
return self.session.dataTaskPublisher(for: adapt(builder: builder).build()).tryMap({ element -> Data in
Expand Down Expand Up @@ -309,10 +318,13 @@ public class ApplicationsApi: AdaptableApi {
/// - Parameters:
/// - id
/// Unique identifier of the application.
public func copyApplication(id: String) -> AnyPublisher<C8yApplication, Error> {
/// - xCumulocityProcessingMode
/// Used to explicitly control the processing mode of the request. See [Processing mode](#processing-mode) for more details.
public func copyApplication(id: String, xCumulocityProcessingMode: String? = nil) -> AnyPublisher<C8yApplication, Error> {
let builder = URLRequestBuilder()
.set(resourcePath: "/application/applications/\(id)/clone")
.set(httpMethod: "post")
.add(header: "X-Cumulocity-Processing-Mode", value: String(describing: xCumulocityProcessingMode))
.add(header: "Accept", value: "application/vnd.com.nsn.cumulocity.error+json, application/vnd.com.nsn.cumulocity.application+json")
return self.session.dataTaskPublisher(for: adapt(builder: builder).build()).tryMap({ element -> Data in
guard let httpResponse = element.response as? HTTPURLResponse else {
Expand Down
20 changes: 16 additions & 4 deletions Sources/CumulocityCoreLibrary/Api/AttachmentsApi.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,13 @@ public class AttachmentsApi: AdaptableApi {
/// - body
/// - id
/// Unique identifier of the event.
public func replaceEventAttachment(body: Data, id: String) -> AnyPublisher<C8yEventBinary, Error> {
/// - xCumulocityProcessingMode
/// Used to explicitly control the processing mode of the request. See [Processing mode](#processing-mode) for more details.
public func replaceEventAttachment(body: Data, id: String, xCumulocityProcessingMode: String? = nil) -> AnyPublisher<C8yEventBinary, Error> {
let builder = URLRequestBuilder()
.set(resourcePath: "/event/events/\(id)/binaries")
.set(httpMethod: "put")
.add(header: "X-Cumulocity-Processing-Mode", value: String(describing: xCumulocityProcessingMode))
.add(header: "Content-Type", value: "text/plain")
.add(header: "Accept", value: "application/vnd.com.nsn.cumulocity.error+json, application/vnd.com.nsn.cumulocity.event+json")
.set(httpBody: body)
Expand Down Expand Up @@ -145,10 +148,13 @@ public class AttachmentsApi: AdaptableApi {
/// - body
/// - id
/// Unique identifier of the event.
public func uploadEventAttachment(body: Data, id: String) -> AnyPublisher<C8yEventBinary, Error> {
/// - xCumulocityProcessingMode
/// Used to explicitly control the processing mode of the request. See [Processing mode](#processing-mode) for more details.
public func uploadEventAttachment(body: Data, id: String, xCumulocityProcessingMode: String? = nil) -> AnyPublisher<C8yEventBinary, Error> {
let builder = URLRequestBuilder()
.set(resourcePath: "/event/events/\(id)/binaries")
.set(httpMethod: "post")
.add(header: "X-Cumulocity-Processing-Mode", value: String(describing: xCumulocityProcessingMode))
.add(header: "Content-Type", value: "text/plain")
.add(header: "Accept", value: "application/vnd.com.nsn.cumulocity.error+json, application/vnd.com.nsn.cumulocity.event+json")
.set(httpBody: body)
Expand Down Expand Up @@ -222,7 +228,9 @@ public class AttachmentsApi: AdaptableApi {
/// Path of the file to be uploaded.
/// - id
/// Unique identifier of the event.
public func uploadEventAttachment(`object`: C8yBinaryInfo, file: Data, id: String) -> AnyPublisher<C8yEventBinary, Error> {
/// - xCumulocityProcessingMode
/// Used to explicitly control the processing mode of the request. See [Processing mode](#processing-mode) for more details.
public func uploadEventAttachment(`object`: C8yBinaryInfo, file: Data, id: String, xCumulocityProcessingMode: String? = nil) -> AnyPublisher<C8yEventBinary, Error> {
let multipartBuilder = MultipartFormDataBuilder()
do {
try multipartBuilder.addBodyPart(named: "object", codable: `object`, mimeType: "application/json");
Expand All @@ -233,6 +241,7 @@ public class AttachmentsApi: AdaptableApi {
let builder = URLRequestBuilder()
.set(resourcePath: "/event/events/\(id)/binaries")
.set(httpMethod: "post")
.add(header: "X-Cumulocity-Processing-Mode", value: String(describing: xCumulocityProcessingMode))
.add(header: "Content-Type", value: "multipart/form-data")
.add(header: "Accept", value: "application/vnd.com.nsn.cumulocity.error+json, application/vnd.com.nsn.cumulocity.event+json")
.add(header: "Content-Type", value: multipartBuilder.contentType)
Expand Down Expand Up @@ -270,10 +279,13 @@ public class AttachmentsApi: AdaptableApi {
/// - Parameters:
/// - id
/// Unique identifier of the event.
public func deleteEventAttachment(id: String) -> AnyPublisher<Data, Error> {
/// - xCumulocityProcessingMode
/// Used to explicitly control the processing mode of the request. See [Processing mode](#processing-mode) for more details.
public func deleteEventAttachment(id: String, xCumulocityProcessingMode: String? = nil) -> AnyPublisher<Data, Error> {
let builder = URLRequestBuilder()
.set(resourcePath: "/event/events/\(id)/binaries")
.set(httpMethod: "delete")
.add(header: "X-Cumulocity-Processing-Mode", value: String(describing: xCumulocityProcessingMode))
.add(header: "Accept", value: "application/json")
return self.session.dataTaskPublisher(for: adapt(builder: builder).build()).tryMap({ element -> Data in
guard let httpResponse = element.response as? HTTPURLResponse else {
Expand Down
5 changes: 4 additions & 1 deletion Sources/CumulocityCoreLibrary/Api/AuditsApi.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ public class AuditsApi: AdaptableApi {
/// Authentication information is missing or invalid.
/// - Parameters:
/// - body
public func createAuditRecord(body: C8yAuditRecord) -> AnyPublisher<C8yAuditRecord, Error> {
/// - xCumulocityProcessingMode
/// Used to explicitly control the processing mode of the request. See [Processing mode](#processing-mode) for more details.
public func createAuditRecord(body: C8yAuditRecord, xCumulocityProcessingMode: String? = nil) -> AnyPublisher<C8yAuditRecord, Error> {
var requestBody = body
requestBody.severity = nil
requestBody.application = nil
Expand All @@ -118,6 +120,7 @@ public class AuditsApi: AdaptableApi {
let builder = URLRequestBuilder()
.set(resourcePath: "/audit/auditRecords")
.set(httpMethod: "post")
.add(header: "X-Cumulocity-Processing-Mode", value: String(describing: xCumulocityProcessingMode))
.add(header: "Content-Type", value: "application/vnd.com.nsn.cumulocity.auditrecord+json")
.add(header: "Accept", value: "application/vnd.com.nsn.cumulocity.error+json, application/vnd.com.nsn.cumulocity.auditrecord+json")
.set(httpBody: encodedRequestBody)
Expand Down
Loading

0 comments on commit 0a8dafd

Please sign in to comment.