Skip to content

Commit

Permalink
Return GorushResponse instead of HTTPResponse
Browse files Browse the repository at this point in the history
  • Loading branch information
code28 committed Feb 21, 2019
1 parent 63d2585 commit 2ab6701
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
8 changes: 5 additions & 3 deletions Sources/Gorush/Gorush.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,21 @@ public final class Gorush: Service {
self.url = url
}

public func dispatch(_ gorushMessage: GorushMessage, on worker: Worker) -> Future<HTTPResponse> {
public func dispatch(_ gorushMessage: GorushMessage, on worker: Worker) -> Future<GorushResponse> {
return HTTPClient.connect(scheme: httpScheme, hostname: hostname, port: port, on: worker).flatMap { client in
let headers = [("Content-Type", "application/json")]
let body = try JSONEncoder().encode(gorushMessage)
let request = HTTPRequest(method: .POST, url: self.url, headers: HTTPHeaders(headers), body: body)

return client.send(request)
return client.send(request).map { response in
return try JSONDecoder().decode(GorushResponse.self, from: response.body.data!)
}
}
}

// MARK: Convenience method

public func dispatch(_ gorushNotification: GorushNotification, on worker: Worker) -> Future<HTTPResponse> {
public func dispatch(_ gorushNotification: GorushNotification, on worker: Worker) -> Future<GorushResponse> {
return dispatch(GorushMessage(notifications: [gorushNotification]), on: worker)
}
}
23 changes: 23 additions & 0 deletions Sources/Gorush/GorushResponse.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// GorushNotification.swift
// Gorush
//
// Created by Simon Kempendorf on 15.01.19.
//

import Foundation
import Vapor

public struct GorushResponse: Content {
public let counts: Int
public let success: String
public let logs: [Log]

public struct Log: Content {
public let type: String
public let platform: String
public let token: String
public let message: String
public let error: String
}
}

0 comments on commit 2ab6701

Please sign in to comment.