Skip to content

Commit

Permalink
Merge pull request #37 from vapor-community/vapor3
Browse files Browse the repository at this point in the history
Updated for Vapor 3 official release.
  • Loading branch information
Andrewangeta authored May 7, 2018
2 parents 92481e4 + 555d3b9 commit cdeb5da
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ let package = Package(
.library(name: "Stripe", targets: ["Stripe"])
],
dependencies: [
.package(url: "https://github.com/vapor/vapor.git", from: "3.0.0-rc"),
.package(url: "https://github.com/vapor/vapor.git", from: "3.0.0"),
],
targets: [
.target(name: "Stripe", dependencies: ["Vapor"]),
Expand Down
10 changes: 4 additions & 6 deletions Sources/Stripe/API/StripeRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ public class StripeAPIRequest: StripeRequest {
}

public func send<SM: StripeModel>(method: HTTPMethod, path: String, query: String, body: String, headers: HTTPHeaders) throws -> Future<SM> {
let encodedHTTPBody = HTTPBody(string: body)

var finalHeaders: HTTPHeaders = .stripeDefault

headers.forEach { finalHeaders.add(name: $0.name, value: $0.value) }
Expand All @@ -74,10 +72,10 @@ public class StripeAPIRequest: StripeRequest {
let apiKey = self.httpClient.container.environment == .development ? (self.testApiKey ?? self.apiKey) : self.apiKey
finalHeaders.add(name: .authorization, value: "Bearer \(apiKey)")

let request = HTTPRequest(method: method, url: URL(string: "\(path)?\(query)") ?? .root, headers: finalHeaders, body: encodedHTTPBody)

return try httpClient.respond(to: Request(http: request, using: httpClient.container)).flatMap(to: SM.self) { (response) -> Future<SM> in
return try self.serializedResponse(response: response.http, worker: self.httpClient.container.eventLoop)
return httpClient.post("\(path)?\(query)", headers: finalHeaders) { (request) in
try request.content.encode(body)
}.flatMap(to: SM.self) { (response) -> Future<SM> in
return try self.serializedResponse(response: response.http, worker: self.httpClient.container.eventLoop)
}
}
}

0 comments on commit cdeb5da

Please sign in to comment.