This repository has been archived by the owner on Jun 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 438
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
2 changed files
with
58 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
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,46 @@ | ||
// | ||
// PostMessageRequest.swift | ||
// Rocket.Chat | ||
// | ||
// Created by Matheus Cardoso on 11/13/17. | ||
// Copyright © 2017 Rocket.Chat. All rights reserved. | ||
// | ||
// DOCS: https://docs.rocket.chat/developer-guides/rest-api/chat/postmessage | ||
|
||
import SwiftyJSON | ||
|
||
typealias PostMessageResult = APIResult<PostMessageRequest> | ||
|
||
class PostMessageRequest: APIRequest { | ||
let method: String = "POST" | ||
let path = "/api/v1/chat.postMessage" | ||
|
||
let message: Message | ||
|
||
init(message: Message) { | ||
self.message = message | ||
} | ||
|
||
func body() -> Data? { | ||
let body = JSON([ | ||
"roomId": message.subscription?.rid ?? "", | ||
"text": message.text | ||
]) | ||
|
||
return body.rawString()?.data(using: .utf8) | ||
} | ||
|
||
var contentType: String? { | ||
return "application/json" | ||
} | ||
} | ||
|
||
extension APIResult where T == PostMessageRequest { | ||
var message: Message? { | ||
guard let rawMessage = raw?["message"] else { return nil } | ||
|
||
let message = Message() | ||
message.map(rawMessage, realm: nil) | ||
return message | ||
} | ||
} |