Skip to content

Commit

Permalink
switching NIOHTTPClient for AsyncHTTPClient
Browse files Browse the repository at this point in the history
  • Loading branch information
rafiki270 committed Jul 12, 2019
1 parent 96a2de8 commit 7f5eaf1
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 22 deletions.
20 changes: 10 additions & 10 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,30 @@
"object": {
"pins": [
{
"package": "swift-nio",
"repositoryURL": "https://github.com/apple/swift-nio.git",
"package": "async-http-client",
"repositoryURL": "https://github.com/swift-server/async-http-client.git",
"state": {
"branch": null,
"revision": "ed50f8a41ece8db20afa8d1188fc0960f95263df",
"version": "2.2.0"
"revision": "a42fe83781b5c4822e00706eaf6a4380b256be8a",
"version": "1.0.0-alpha.1"
}
},
{
"package": "swift-nio-http-client",
"repositoryURL": "https://github.com/vapor/swift-nio-http-client.git",
"package": "swift-nio",
"repositoryURL": "https://github.com/apple/swift-nio.git",
"state": {
"branch": null,
"revision": "93682abeb568b3df47f0744558c4436bb325f860",
"version": "0.0.0"
"revision": "334815f6580b5256409d48431751938c4e966e72",
"version": "2.4.0"
}
},
{
"package": "swift-nio-ssl",
"repositoryURL": "https://github.com/apple/swift-nio-ssl.git",
"state": {
"branch": null,
"revision": "dc23a24fbe5d59429eacf45a9add82fdf6ab90e6",
"version": "2.1.0"
"revision": "77173ac9038e8e9b92f3efe8780923447e3c890b",
"version": "2.1.1"
}
}
]
Expand Down
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ let package = Package(
.library(name: "GitHubKit", targets: ["GitHubKit"])
],
dependencies: [
.package(url: "https://github.com/vapor/swift-nio-http-client.git", from: "0.0.0")
.package(url: "https://github.com/swift-server/async-http-client.git", from: "1.0.0-alpha.1")
],
targets: [
.target(
name: "GitHubKit",
dependencies: [
"NIOHTTPClient"
"AsyncHTTPClient"
]
)
]
Expand Down
4 changes: 4 additions & 0 deletions Sources/GitHubKit/Exports.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@
//

@_exported import Foundation
@_exported import class NIO.EventLoopFuture
@_exported import enum NIOHTTP1.HTTPMethod
@_exported import struct NIOHTTP1.HTTPHeaders
@_exported import class AsyncHTTPClient.HTTPClient
20 changes: 10 additions & 10 deletions Sources/GitHubKit/Github.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import Foundation
import NIO
import NIOHTTP1
import NIOHTTPClient
import AsyncHTTPClient


/// Server value convertible
Expand Down Expand Up @@ -71,14 +71,14 @@ public class Github {
/// Copy of the given configuration
public let config: Config

let client: HTTPClient
let client: AsyncHTTPClient.HTTPClient

/// Initializer
public init(_ config: Config, eventLoopGroupProvider provider: EventLoopGroupProvider = .createNew, proxy: HTTPClient.Proxy? = nil) throws {
public init(_ config: Config, eventLoopGroupProvider provider: AsyncHTTPClient.HTTPClient.EventLoopGroupProvider = .createNew, proxy: AsyncHTTPClient.HTTPClient.Proxy? = nil) throws {
self.config = config
var conf = HTTPClient.Configuration()
var conf = AsyncHTTPClient.HTTPClient.Configuration()
conf.proxy = proxy
self.client = HTTPClient(
self.client = AsyncHTTPClient.HTTPClient(
eventLoopGroupProvider: provider,
configuration: conf
)
Expand All @@ -87,7 +87,7 @@ public class Github {
/// Initializer
public init(_ config: Config, eventLoop: EventLoop) throws {
self.config = config
self.client = HTTPClient(eventLoopGroupProvider: .shared(eventLoop))
self.client = AsyncHTTPClient.HTTPClient(eventLoopGroupProvider: .shared(eventLoop))
}

var eventLoop: EventLoop {
Expand All @@ -101,7 +101,7 @@ public class Github {
}


extension HTTPClient.Response {
extension AsyncHTTPClient.HTTPClient.Response {

mutating func data() -> Data? {
guard var byteBuffer = body else {
Expand All @@ -118,9 +118,9 @@ extension HTTPClient.Response {

extension Github {

fileprivate func req(_ method: HTTPMethod, _ path: String, _ body: HTTPClient.Body? = nil) throws -> HTTPClient.Request {
fileprivate func req(_ method: HTTPMethod, _ path: String, _ body: AsyncHTTPClient.HTTPClient.Body? = nil) throws -> AsyncHTTPClient.HTTPClient.Request {
let url = config.url(for: path)
let req = try HTTPClient.Request(
let req = try AsyncHTTPClient.HTTPClient.Request(
url: url,
method: method,
headers: headers,
Expand Down Expand Up @@ -214,7 +214,7 @@ extension Github {

/// Send a request
private func send<C, E>(method: HTTPMethod, path: String, post: E? = nil) throws -> EventLoopFuture<C?> where C: Decodable, E: Encodable {
let body: HTTPClient.Body?
let body: AsyncHTTPClient.HTTPClient.Body?
if let post = post {
let jsonData = try JSONEncoder().encode(post)
body = .data(jsonData)
Expand Down

0 comments on commit 7f5eaf1

Please sign in to comment.