Skip to content
This repository has been archived by the owner on Apr 20, 2024. It is now read-only.

Commit

Permalink
Merge pull request #20 from nodes-vapor/bugfix/runtime-crash-client
Browse files Browse the repository at this point in the history
Set the client on boot(_ drop:)
  • Loading branch information
siemensikkema authored Jan 24, 2018
2 parents ad325bb + ba1bd9d commit ad648f0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
14 changes: 8 additions & 6 deletions Sources/UAPusher/ConnectionManager.swift
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
import Vapor
import HTTP
import Foundation
import HTTP
import TLS
import Vapor

public final class ConnectionManager {
static let baseUrl = "https://go.urbanairship.com"
private let client: ClientProtocol
private let config: UAPusherConfig

public init(clientFactory: ClientFactoryProtocol, config: UAPusherConfig) throws {
self.config = config
self.client = try clientFactory.makeClient(
public init(
config: UAPusherConfig,
clientFactory: ClientFactoryProtocol
) throws {
client = try clientFactory.makeClient(
hostname: ConnectionManager.baseUrl,
port: 443,
securityLayer: .tls(Context(.client))
)
self.config = config
}

/// Defines the headers of the request with the given appKey and
Expand Down Expand Up @@ -50,7 +53,6 @@ public final class ConnectionManager {
/// - Returns: array of Status for each request made
/// - Throws: if POST fails
func post(slug: String, content: JSON) throws -> [Response] {

let url = ConnectionManager.baseUrl + slug
let body = content.makeBody()

Expand Down
10 changes: 5 additions & 5 deletions Sources/UAPusher/Provider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@ import Vapor
public final class Provider: Vapor.Provider {
let config: UAPusherConfig
public static var repositoryName: String = "uapusher"
private var connectionManager: ConnectionManager

public func boot(_ config: Config) throws {}

public func boot(_ drop: Droplet) throws {
let connectionManager = try ConnectionManager(
config: self.config,
clientFactory: drop.config.resolveClient()
)

drop.uapusher = UAManager(connectionManager: connectionManager)
}

public init(config: Config) throws {
self.config = try UAPusherConfig(config: config)
connectionManager = try ConnectionManager(
clientFactory: config.resolveClient(),
config: self.config
)
}

/// Called before the Droplet begins serving
Expand Down

0 comments on commit ad648f0

Please sign in to comment.