-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from willtempleton/update/v0-25
Updates for Typesense v0.25
- Loading branch information
Showing
39 changed files
with
922 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import Foundation | ||
|
||
public struct Analytics { | ||
static let resourcePath: String = "/analytics" | ||
|
||
private var analyticsRules: AnalyticsRules | ||
var apiCall: ApiCall | ||
|
||
init(config: Configuration) { | ||
self.apiCall = ApiCall(config: config) | ||
self.analyticsRules = AnalyticsRules(apiCall: apiCall) | ||
} | ||
|
||
func rule(id: String) -> AnalyticsRule { | ||
return AnalyticsRule(name: id, apiCall: self.apiCall) | ||
} | ||
|
||
func rules() -> AnalyticsRules { | ||
return AnalyticsRules(apiCall: self.apiCall) | ||
} | ||
} | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import Foundation | ||
|
||
public struct AnalyticsRule { | ||
var name: String | ||
private var apiCall: ApiCall | ||
init(name: String, apiCall: ApiCall) { | ||
self.name = name | ||
self.apiCall = apiCall | ||
} | ||
|
||
public func retrieve() async throws -> (AnalyticsRuleSchema?, URLResponse?) { | ||
let (data, response) = try await self.apiCall.get(endPoint: endpointPath()) | ||
if let result = data { | ||
if let notFound = try? decoder.decode(ApiResponse.self, from: result) { | ||
throw ResponseError.analyticsRuleDoesNotExist(desc: notFound.message) | ||
} | ||
let fetchedRule = try decoder.decode(AnalyticsRuleSchema.self, from: result) | ||
return (fetchedRule, response) | ||
} | ||
return (nil, response) | ||
} | ||
|
||
public func delete() async throws -> (AnalyticsRuleSchema?, URLResponse?) { | ||
let (data, response) = try await self.apiCall.delete(endPoint: endpointPath()) | ||
if let result = data { | ||
if let notFound = try? decoder.decode(ApiResponse.self, from: result) { | ||
throw ResponseError.analyticsRuleDoesNotExist(desc: notFound.message) | ||
} | ||
let deletedRule = try decoder.decode(AnalyticsRuleSchema.self, from: result) | ||
return (deletedRule, response) | ||
} | ||
return (nil, response) | ||
} | ||
|
||
private func endpointPath() -> String { | ||
return "\(AnalyticsRules.resourcePath)/\(name)" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import Foundation | ||
|
||
public struct AnalyticsRules { | ||
private var apiCall: ApiCall | ||
static var resourcePath: String = "\(Analytics.resourcePath)/rules" | ||
|
||
init(apiCall: ApiCall) { | ||
self.apiCall = apiCall | ||
} | ||
|
||
func upsert(params: AnalyticsRuleSchema) async throws -> (AnalyticsRuleSchema?, URLResponse?) { | ||
let ruleData = try encoder.encode(params) | ||
let (data, response) = try await self.apiCall.put(endPoint: endpointPath(params.name), body: ruleData) | ||
if let result = data { | ||
let ruleResult = try decoder.decode(AnalyticsRuleSchema.self, from: result) | ||
return (ruleResult, response) | ||
} | ||
|
||
return (nil, response) | ||
} | ||
|
||
func retrieveAll() async throws -> (AnalyticsRulesRetrieveSchema?, URLResponse?) { | ||
let (data, response) = try await self.apiCall.get(endPoint: endpointPath()) | ||
if let result = data { | ||
let rules = try decoder.decode(AnalyticsRulesRetrieveSchema.self, from: result) | ||
return (rules, response) | ||
} | ||
|
||
return (nil, response) | ||
} | ||
|
||
private func endpointPath(_ operation: String? = nil) -> String { | ||
if let operation = operation { | ||
return "\(AnalyticsRules.resourcePath)/\(operation)" | ||
} else { | ||
return AnalyticsRules.resourcePath | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// | ||
// AnalyticsRuleParameters.swift | ||
// | ||
// Generated by swagger-codegen | ||
// https://github.com/swagger-api/swagger-codegen | ||
// | ||
|
||
import Foundation | ||
|
||
|
||
|
||
public struct AnalyticsRuleParameters: Codable { | ||
|
||
public var source: AnalyticsRuleParametersSource | ||
public var destination: AnalyticsRuleParametersDestination | ||
public var limit: Int | ||
|
||
public init(source: AnalyticsRuleParametersSource, destination: AnalyticsRuleParametersDestination, limit: Int) { | ||
self.source = source | ||
self.destination = destination | ||
self.limit = limit | ||
} | ||
|
||
|
||
} |
21 changes: 21 additions & 0 deletions
21
Sources/Typesense/Models/AnalyticsRuleParametersDestination.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// | ||
// AnalyticsRuleParametersDestination.swift | ||
// | ||
// Generated by swagger-codegen | ||
// https://github.com/swagger-api/swagger-codegen | ||
// | ||
|
||
import Foundation | ||
|
||
|
||
|
||
public struct AnalyticsRuleParametersDestination: Codable { | ||
|
||
public var collection: String? | ||
|
||
public init(collection: String? = nil) { | ||
self.collection = collection | ||
} | ||
|
||
|
||
} |
21 changes: 21 additions & 0 deletions
21
Sources/Typesense/Models/AnalyticsRuleParametersSource.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// | ||
// AnalyticsRuleParametersSource.swift | ||
// | ||
// Generated by swagger-codegen | ||
// https://github.com/swagger-api/swagger-codegen | ||
// | ||
|
||
import Foundation | ||
|
||
|
||
|
||
public struct AnalyticsRuleParametersSource: Codable { | ||
|
||
public var collections: [String]? | ||
|
||
public init(collections: [String]? = nil) { | ||
self.collections = collections | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// | ||
// AnalyticsRuleSchema.swift | ||
// | ||
// Generated by swagger-codegen | ||
// https://github.com/swagger-api/swagger-codegen | ||
// | ||
|
||
import Foundation | ||
|
||
|
||
|
||
public struct AnalyticsRuleSchema: Codable { | ||
|
||
public var name: String | ||
public var type: String? | ||
public var params: AnalyticsRuleParameters? | ||
|
||
public init(name: String, type: String, params: AnalyticsRuleParameters) { | ||
self.name = name | ||
self.type = type | ||
self.params = params | ||
} | ||
|
||
|
||
} |
21 changes: 21 additions & 0 deletions
21
Sources/Typesense/Models/AnalyticsRulesRetrieveSchema.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// | ||
// AnalyticsRulesRetrieveSchema.swift | ||
// | ||
// Generated by swagger-codegen | ||
// https://github.com/swagger-api/swagger-codegen | ||
// | ||
|
||
import Foundation | ||
|
||
|
||
|
||
public struct AnalyticsRulesRetrieveSchema: Codable { | ||
|
||
public var rules: [AnalyticsRuleSchema]? | ||
|
||
public init(rules: [AnalyticsRuleSchema]? = nil) { | ||
self.rules = rules | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.