-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
478 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
|
||
# Created by https://www.gitignore.io/api/xcode,swift,swiftpm | ||
# Edit at https://www.gitignore.io/?templates=xcode,swift,swiftpm | ||
|
||
### Swift ### | ||
# Xcode | ||
# | ||
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore | ||
|
||
## Build generated | ||
build/ | ||
DerivedData/ | ||
|
||
## Various settings | ||
*.pbxuser | ||
!default.pbxuser | ||
*.mode1v3 | ||
!default.mode1v3 | ||
*.mode2v3 | ||
!default.mode2v3 | ||
*.perspectivev3 | ||
!default.perspectivev3 | ||
xcuserdata/ | ||
|
||
## Other | ||
*.moved-aside | ||
*.xccheckout | ||
*.xcscmblueprint | ||
|
||
## Obj-C/Swift specific | ||
*.hmap | ||
*.ipa | ||
*.dSYM.zip | ||
*.dSYM | ||
|
||
## Playgrounds | ||
timeline.xctimeline | ||
playground.xcworkspace | ||
|
||
# Swift Package Manager | ||
# | ||
# Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. | ||
# Packages/ | ||
# Package.pins | ||
# Package.resolved | ||
.build/ | ||
|
||
# CocoaPods | ||
# | ||
# We recommend against adding the Pods directory to your .gitignore. However | ||
# you should judge for yourself, the pros and cons are mentioned at: | ||
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control | ||
# | ||
# Pods/ | ||
# | ||
# Add this line if you want to avoid checking in source code from the Xcode workspace | ||
# *.xcworkspace | ||
|
||
# Carthage | ||
# | ||
# Add this line if you want to avoid checking in source code from Carthage dependencies. | ||
# Carthage/Checkouts | ||
|
||
Carthage/Build | ||
|
||
# fastlane | ||
# | ||
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the | ||
# screenshots whenever they are needed. | ||
# For more information about the recommended setup visit: | ||
# https://docs.fastlane.tools/best-practices/source-control/#source-control | ||
|
||
fastlane/report.xml | ||
fastlane/Preview.html | ||
fastlane/screenshots/**/*.png | ||
fastlane/test_output | ||
|
||
# Code Injection | ||
# | ||
# After new code Injection tools there's a generated folder /iOSInjectionProject | ||
# https://github.com/johnno1962/injectionforxcode | ||
|
||
iOSInjectionProject/ | ||
|
||
### SwiftPM ### | ||
Packages | ||
xcuserdata | ||
*.xcodeproj | ||
|
||
### Xcode ### | ||
# Xcode | ||
# | ||
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore | ||
|
||
## User settings | ||
|
||
## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9) | ||
|
||
## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4) | ||
|
||
### Xcode Patch ### | ||
*.xcodeproj/* | ||
!*.xcodeproj/project.pbxproj | ||
!*.xcodeproj/xcshareddata/ | ||
!*.xcworkspace/contents.xcworkspacedata | ||
/*.gcno | ||
**/xcshareddata/WorkspaceSettings.xcsettings | ||
|
||
# End of https://www.gitignore.io/api/xcode,swift,swiftpm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
{ | ||
"object": { | ||
"pins": [ | ||
{ | ||
"package": "Console", | ||
"repositoryURL": "https://github.com/vapor/console.git", | ||
"state": { | ||
"branch": null, | ||
"revision": "5b9796d39f201b3dd06800437abd9d774a455e57", | ||
"version": "3.0.2" | ||
} | ||
}, | ||
{ | ||
"package": "Core", | ||
"repositoryURL": "https://github.com/vapor/core.git", | ||
"state": { | ||
"branch": null, | ||
"revision": "eb876a758733166a4fb20f3f0a17b480c5ea563e", | ||
"version": "3.4.3" | ||
} | ||
}, | ||
{ | ||
"package": "Crypto", | ||
"repositoryURL": "https://github.com/vapor/crypto.git", | ||
"state": { | ||
"branch": null, | ||
"revision": "5605334590affd4785a5839806b4504407e054ac", | ||
"version": "3.3.0" | ||
} | ||
}, | ||
{ | ||
"package": "DatabaseKit", | ||
"repositoryURL": "https://github.com/vapor/database-kit.git", | ||
"state": { | ||
"branch": null, | ||
"revision": "3a17dbbe9be5f8c37703e4b7982c1332ad6b00c4", | ||
"version": "1.3.1" | ||
} | ||
}, | ||
{ | ||
"package": "HTTP", | ||
"repositoryURL": "https://github.com/vapor/http.git", | ||
"state": { | ||
"branch": null, | ||
"revision": "9e3eff9dfa4df7fc282bf27f801c72b3ffbfd984", | ||
"version": "3.1.4" | ||
} | ||
}, | ||
{ | ||
"package": "Multipart", | ||
"repositoryURL": "https://github.com/vapor/multipart.git", | ||
"state": { | ||
"branch": null, | ||
"revision": "e57007c23a52b68e44ebdfc70cbe882a7c4f1ec3", | ||
"version": "3.0.2" | ||
} | ||
}, | ||
{ | ||
"package": "Routing", | ||
"repositoryURL": "https://github.com/vapor/routing.git", | ||
"state": { | ||
"branch": null, | ||
"revision": "3219e328491b0853b8554c5a694add344d2c6cfb", | ||
"version": "3.0.1" | ||
} | ||
}, | ||
{ | ||
"package": "Service", | ||
"repositoryURL": "https://github.com/vapor/service.git", | ||
"state": { | ||
"branch": null, | ||
"revision": "281a70b69783891900be31a9e70051b6fe19e146", | ||
"version": "1.0.0" | ||
} | ||
}, | ||
{ | ||
"package": "swift-nio", | ||
"repositoryURL": "https://github.com/apple/swift-nio.git", | ||
"state": { | ||
"branch": null, | ||
"revision": "5d8148c8b45dfb449276557f22120694567dd1d2", | ||
"version": "1.9.5" | ||
} | ||
}, | ||
{ | ||
"package": "swift-nio-ssl", | ||
"repositoryURL": "https://github.com/apple/swift-nio-ssl.git", | ||
"state": { | ||
"branch": null, | ||
"revision": "8380fa29a2af784b067d8ee01c956626ca29f172", | ||
"version": "1.3.1" | ||
} | ||
}, | ||
{ | ||
"package": "swift-nio-ssl-support", | ||
"repositoryURL": "https://github.com/apple/swift-nio-ssl-support.git", | ||
"state": { | ||
"branch": null, | ||
"revision": "c02eec4e0e6d351cd092938cf44195a8e669f555", | ||
"version": "1.0.0" | ||
} | ||
}, | ||
{ | ||
"package": "swift-nio-zlib-support", | ||
"repositoryURL": "https://github.com/apple/swift-nio-zlib-support.git", | ||
"state": { | ||
"branch": null, | ||
"revision": "37760e9a52030bb9011972c5213c3350fa9d41fd", | ||
"version": "1.0.0" | ||
} | ||
}, | ||
{ | ||
"package": "TemplateKit", | ||
"repositoryURL": "https://github.com/vapor/template-kit.git", | ||
"state": { | ||
"branch": null, | ||
"revision": "db35b1c35aabd0f5db3abca0cfda7becfe9c43e2", | ||
"version": "1.1.0" | ||
} | ||
}, | ||
{ | ||
"package": "URLEncodedForm", | ||
"repositoryURL": "https://github.com/vapor/url-encoded-form.git", | ||
"state": { | ||
"branch": null, | ||
"revision": "932024f363ee5ff59059cf7d67194a1c271d3d0c", | ||
"version": "1.0.5" | ||
} | ||
}, | ||
{ | ||
"package": "Validation", | ||
"repositoryURL": "https://github.com/vapor/validation.git", | ||
"state": { | ||
"branch": null, | ||
"revision": "156f8adeac3440e868da3757777884efbc6ec0cc", | ||
"version": "2.1.0" | ||
} | ||
}, | ||
{ | ||
"package": "Vapor", | ||
"repositoryURL": "https://github.com/vapor/vapor.git", | ||
"state": { | ||
"branch": null, | ||
"revision": "157d3b15336caa882662cc75024dd04b2e225246", | ||
"version": "3.1.0" | ||
} | ||
}, | ||
{ | ||
"package": "WebSocket", | ||
"repositoryURL": "https://github.com/vapor/websocket.git", | ||
"state": { | ||
"branch": null, | ||
"revision": "149af03348f60ac8b84defdf277112d62fd8c704", | ||
"version": "1.0.2" | ||
} | ||
} | ||
] | ||
}, | ||
"version": 1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// swift-tools-version:4.0 | ||
|
||
import PackageDescription | ||
|
||
let package = Package( | ||
name: "Gorush", | ||
products: [ | ||
.library(name: "Gorush", targets: ["Gorush"]) | ||
], | ||
dependencies: [ | ||
.package(url: "https://github.com/vapor/vapor.git", from: "3.0.0") | ||
], | ||
targets: [ | ||
.target(name: "Gorush", dependencies: ["Vapor"]), | ||
.testTarget(name: "GorushTests", dependencies: ["Gorush"]) | ||
] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Gorush Service for Vapor | ||
|
||
This service allows to easily integrate [Gorush](https://github.com/appleboy/gorush) into [Vapor](https://vapor.codes) to send push notifications. | ||
|
||
## Installation | ||
### Add the package to the `Package.swift` | ||
```swift | ||
.package(url: "https://github.com/code28/vapor-gorush.git", from: "0.1.0") | ||
// ... | ||
.target(name: "App", dependencies: ["Vapor", "Gorush"]) | ||
``` | ||
|
||
### Register Gorush in `configure.swift` | ||
```swift | ||
services.register(Gorush.self) { container in | ||
return Gorush(hostname: Environment.get("GORUSH_HOSTNAME"), port: Environment.get("GORUSH_PORT")) | ||
} | ||
``` | ||
Per default, HTTPS will be used. To use HTTP instead, just add `httpScheme: .http` into that initialization. | ||
|
||
## Usage | ||
```swift | ||
import Gorush | ||
// ... | ||
let notification = GorushNotification(tokens: ["deviceToken"], platform: .ios, message: "Push message", title: "Push title") | ||
|
||
let gorush = container.make(Gorush.self) | ||
gorush.dispatch(notification, on: worker) | ||
// ... | ||
``` | ||
|
||
## License | ||
This vapor-gorush package is released under an MIT license. See [License](LICENSE) for more information. | ||
|
||
## Todo | ||
|
||
- [ ] Parse Gorush response and answer with succeeded or failed future | ||
- [ ] Write further documentation | ||
- [ ] Complete fields for Gorush notification | ||
- [ ] Write tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// | ||
// GorushNotification.swift | ||
// Gorush | ||
// | ||
// Created by Simon Kempendorf on 15.01.19. | ||
// | ||
|
||
import Foundation | ||
import Vapor | ||
|
||
public final class Gorush: Service { | ||
let httpScheme: HTTPScheme | ||
let hostname: String | ||
let url: String | ||
let port: Int? | ||
|
||
public init(httpScheme: HTTPScheme = .https, hostname: String, port: Int? = nil, url: String = "/api/push") { | ||
self.httpScheme = httpScheme | ||
self.hostname = hostname | ||
self.port = port | ||
self.url = url | ||
} | ||
|
||
public func dispatch(_ gorushMessage: GorushMessage, on worker: Worker) -> Future<HTTPResponse> { | ||
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) | ||
} | ||
} | ||
|
||
// MARK: Convenience method | ||
|
||
public func dispatch(_ gorushNotification: GorushNotification, on worker: Worker) -> Future<HTTPResponse> { | ||
return dispatch(GorushMessage(notifications: [gorushNotification]), on: worker) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// | ||
// GorushMessage.swift | ||
// Gorush | ||
// | ||
// Created by Simon Kempendorf on 15.01.19. | ||
// | ||
|
||
import Foundation | ||
import Vapor | ||
|
||
public struct GorushMessage: Encodable { | ||
let notifications: [GorushNotification] | ||
|
||
public init(notifications: [GorushNotification]) { | ||
self.notifications = notifications | ||
} | ||
} |
Oops, something went wrong.