Skip to content

Commit

Permalink
DocC documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Maia-jp committed Mar 29, 2024
1 parent 5ff79b4 commit 772cb99
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 14 deletions.
27 changes: 27 additions & 0 deletions Sources/aiXplainKit/Extensions/URL+MimeType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,33 @@
import Foundation
import UniformTypeIdentifiers
extension URL {
/**
Returns the MIME type associated with the file at the URL's path.

The `mimeType()` method returns a `String` representing the MIME type of the file at the URL's path. If the file extension is recognized by the system, the method returns the preferred MIME type for that extension. If the file extension is not recognized, the method returns the default MIME type `"application/octet-stream"`.

MIME types, or Multipurpose Internet Mail Extensions, are used to identify the type of data being transmitted over the Internet. They are especially important when transferring files, as they allow recipient applications to determine how to handle the incoming data.

- Semantics:
- If the URL's path extension is recognized by the system, the method returns the preferred MIME type for that extension.
- If the URL's path extension is not recognized, the method returns `"application/octet-stream"`.
- If the URL does not have a path extension, the method returns `"application/octet-stream"`.

- Returns: The MIME type associated with the file at the URL's path.

- Examples:
```swift
let fileURL = URL(fileURLWithPath: "/path/to/file.pdf")
let mimeType = fileURL.mimeType() // Returns "application/pdf"
```
In this example, the `mimeType()` method returns `"application/pdf"` because the `.pdf` extension is recognized by the system, and the preferred MIME type for PDF files is `"application/pdf"`.

```swift
let fileURL = URL(fileURLWithPath: "/path/to/file.unknown")
let mimeType = fileURL.mimeType() // Returns "application/octet-stream"
```
In this example, the `mimeType()` method returns `"application/octet-stream"` because the `.unknown` extension is not recognized by the system, and `"application/octet-stream"` is the default MIME type for unknown file types.
*/
public func mimeType() -> String {
if let mimeType = UTType(filenameExtension: self.pathExtension)?.preferredMIMEType {
return mimeType
Expand Down
45 changes: 33 additions & 12 deletions Sources/aiXplainKit/Provider/PipelineProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,39 +24,60 @@
import Foundation
import OSLog


/**
The `PipelineProvider` class is responsible for fetching `Pipeline` objects from the AiXplain backend.

This class handles the network request to retrieve pipeline data and parses the response into a `Pipeline` object.

- Important: You must have a valid API key and backend URL configured in `APIKeyManager` to use this class.

*/
public final class PipelineProvider {
private let logger = Logger(subsystem: "AiXplain", category: "PipelineProvider")

var networking = Networking()

public init() {
self.networking = Networking()
}

internal init(networking: Networking) {
self.networking = networking
}


/**
Fetches a `Pipeline` object from the AiXplain backend.

This method sends a GET request to the backend URL with the provided `pipelineID` and parses the response into a `Pipeline` object.

- Parameter pipelineID: The unique identifier of the pipeline to fetch.
- Throws: `PipelineError.missingBackendURL` if the backend URL is missing.
`ModelError.invalidURL` if the backend URL is invalid.
`NetworkingError.invalidStatusCode` if the server returns an unexpected status code.
An error of type `Error` for any other error that may occur during the request or parsing process.
- Returns: A `Pipeline` object containing the data for the requested pipeline.
*/
public func get(_ pipelineID: String) async throws -> Pipeline {

let headers: [String: String] = try networking.buildHeader()

guard let url = APIKeyManager.shared.BACKEND_URL else {
throw PipelineError.missingBackendURL
}

let endpoint = Networking.Endpoint.pipelines(pipelineIdentifier: pipelineID)
guard let url = URL(string: url.absoluteString + endpoint.path) else {
throw ModelError.invalidURL(url: url.absoluteString + endpoint.path)
}

let response = try await networking.get(url: url, headers: headers)

if let httpUrlResponse = response.1 as? HTTPURLResponse,
httpUrlResponse.statusCode != 200 {
throw NetworkingError.invalidStatusCode(statusCode: httpUrlResponse.statusCode)
}

do {
let fetchedPipeline = try JSONDecoder().decode(Pipeline.self, from: response.0)
fetchedPipeline.id = pipelineID
Expand All @@ -65,7 +86,7 @@ public final class PipelineProvider {
logger.error("\(error.localizedDescription)")
throw error
}

}

}
2 changes: 0 additions & 2 deletions Sources/aiXplainKit/aiXplainKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@

import Foundation

/// Test
public final class AiXplainKit {
public let keyManager = APIKeyManager.shared
public static let shared = AiXplainKit()
// public var logLevel: ParrotLogger.LogSeverity = .info

}

0 comments on commit 772cb99

Please sign in to comment.