Skip to content
This repository has been archived by the owner on Jun 7, 2020. It is now read-only.

Commit

Permalink
Add PostMessageRequest
Browse files Browse the repository at this point in the history
  • Loading branch information
cardoso committed Nov 14, 2017
1 parent ce206a6 commit 0f88576
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Rocket.Chat.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@
806401311FB09DE800990572 /* Permission.swift in Sources */ = {isa = PBXBuildFile; fileRef = 806401301FB09DE800990572 /* Permission.swift */; };
806401331FB09EC400990572 /* PermissionModelMapping.swift in Sources */ = {isa = PBXBuildFile; fileRef = 806401321FB09EC400990572 /* PermissionModelMapping.swift */; };
806401351FB09F8A00990572 /* PermissionManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 806401341FB09F8A00990572 /* PermissionManager.swift */; };
806C59A21FBB0BD600C32D0A /* PostMessageRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 806C59A11FBB0BD600C32D0A /* PostMessageRequest.swift */; };
8073719A1F94E83600D53ADF /* SocketError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 807371991F94E83600D53ADF /* SocketError.swift */; };
8073719C1F963FA400D53ADF /* APITestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8073719B1F963FA400D53ADF /* APITestCase.swift */; };
8073719E1F9688B200D53ADF /* LoginServiceManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8073719D1F9688B200D53ADF /* LoginServiceManager.swift */; };
Expand Down Expand Up @@ -500,6 +501,7 @@
806401301FB09DE800990572 /* Permission.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = Permission.swift; path = Models/Permission.swift; sourceTree = "<group>"; };
806401321FB09EC400990572 /* PermissionModelMapping.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = PermissionModelMapping.swift; path = Models/Mapping/PermissionModelMapping.swift; sourceTree = "<group>"; };
806401341FB09F8A00990572 /* PermissionManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = PermissionManager.swift; path = Managers/Model/PermissionManager.swift; sourceTree = "<group>"; };
806C59A11FBB0BD600C32D0A /* PostMessageRequest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PostMessageRequest.swift; sourceTree = "<group>"; };
807371991F94E83600D53ADF /* SocketError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = SocketError.swift; path = Managers/Socket/Response/SocketError.swift; sourceTree = "<group>"; };
8073719B1F963FA400D53ADF /* APITestCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = APITestCase.swift; sourceTree = "<group>"; };
8073719D1F9688B200D53ADF /* LoginServiceManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = LoginServiceManager.swift; path = Managers/Model/LoginServiceManager.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1237,6 +1239,14 @@
path = Authentication;
sourceTree = "<group>";
};
806C59A01FBB0BA700C32D0A /* Message */ = {
isa = PBXGroup;
children = (
806C59A11FBB0BD600C32D0A /* PostMessageRequest.swift */,
);
path = Message;
sourceTree = "<group>";
};
897083CC1F8CF08100233561 /* Form */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -1301,6 +1311,7 @@
D1D535EF1F70863C006625D2 /* Requests */ = {
isa = PBXGroup;
children = (
806C59A01FBB0BA700C32D0A /* Message */,
802498EC1F7A82CD005477EC /* Authentication */,
80235D1C1F740AAC00A56CA5 /* Subscription */,
D1D535F01F70864C006625D2 /* InfoRequest.swift */,
Expand Down Expand Up @@ -1878,6 +1889,7 @@
806401311FB09DE800990572 /* Permission.swift in Sources */,
4159720C1D3DB854002258F4 /* Email.swift in Sources */,
412719461E6B403700461FEE /* RegisterUsernameViewController.swift in Sources */,
806C59A21FBB0BD600C32D0A /* PostMessageRequest.swift in Sources */,
41BAE3E71D71B26C00C2445A /* URLExtension.swift in Sources */,
4174CB0D1D2D994A0086DAC8 /* ConnectServerViewController.swift in Sources */,
4199A9891DABCC570035F820 /* Emojione.swift in Sources */,
Expand Down
46 changes: 46 additions & 0 deletions Rocket.Chat/API/Requests/Message/PostMessageRequest.swift
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
}
}

0 comments on commit 0f88576

Please sign in to comment.