Skip to content

Commit

Permalink
Allow API host to be overridable
Browse files Browse the repository at this point in the history
  • Loading branch information
mauryaratan committed Oct 13, 2023
1 parent be4e48c commit 86e070d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Sources/LemonSqueezy/LemonSqueezy+API.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ extension LemonSqueezy {

var components = URLComponents()
components.scheme = "https"
components.host = "api.lemonsqueezy.com"
components.host = self.baseHost
components.path = "\(route.resolvedPath.path)"
components.queryItems = combinedQueryItems

Expand Down
7 changes: 6 additions & 1 deletion Sources/LemonSqueezy/LemonSqueezy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,18 @@ import Combine
public class LemonSqueezy: NSObject, ObservableObject {
public private(set) var apiKey: String

/// Base URL to API endpoint, without https prefix.
public private(set) var baseHost: String

internal let decoder: JSONDecoder
internal let encoder: JSONEncoder

public init(_ apiKey: String) {
public init(_ apiKey: String, _ baseHost: String = "") {
self.decoder = Self.initializeDecoder()
self.encoder = Self.initializeEncoder()
self.apiKey = apiKey

self.baseHost = baseHost.isEmpty ? "api.lemonsqueezy.com" : baseHost
}

static internal func initializeDecoder() -> JSONDecoder {
Expand Down

0 comments on commit 86e070d

Please sign in to comment.