Module: Keybase::Local::Chat
- Defined in:
- lib/keybase/local/chat.rb
Overview
Represents Keybase's JSON chat API.
Constant Summary collapse
- CHAT_EXEC_ARGS =
The initial arguments to pass when executing Keybase for chatting.
%w[keybase chat api].freeze
Class Method Summary collapse
-
.chat_call(meth, options: {}) ⇒ OpenStruct
private
Makes chat API calls.
-
.conversation(users, peek: false, unread_only: false) ⇒ OpenStruct
Read a conversation.
-
.delete_message(users, id) ⇒ OpenStruct
Delete a message from a conversation.
-
.download_attachment(users, id, path) ⇒ OpenStruct
Download a file from a conversation.
-
.edit_message(users, id, message) ⇒ OpenStruct
Edit a message in a conversation.
-
.envelope(meth, options: {}) ⇒ String
private
The JSON serialized envelope.
-
.list_inbox(topic_type: nil) ⇒ OpenStruct
List the current user's inbox.
-
.mark_conversation(users, id) ⇒ OpenStruct
Make a conversation as read up to a specific ID.
-
.mute_conversation(users) ⇒ OpenStruct
Mute a conversation.
-
.send_message(users, message, public: false) ⇒ OpenStruct
Send a message to a conversation.
-
.unwrap(struct) ⇒ OpenStruct
private
Cleans up the object returned by Chat.chat_call.
-
.upload_attachment(users, path, title) ⇒ OpenStruct
Upload a file to a conversation.
Class Method Details
.chat_call(meth, options: {}) ⇒ OpenStruct
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Makes chat API calls.
45 46 47 48 49 50 51 52 53 |
# File 'lib/keybase/local/chat.rb', line 45 def chat_call(meth, options: {}) response = Open3.popen3(*CHAT_EXEC_ARGS) do |stdin, stdout, _, _| stdin.write envelope meth, options: stdin.close stdout.read end unwrap JSON.parse response, object_class: OpenStruct end |
.conversation(users, peek: false, unread_only: false) ⇒ OpenStruct
Read a conversation.
71 72 73 74 75 76 77 78 79 |
# File 'lib/keybase/local/chat.rb', line 71 def conversation(users, peek: false, unread_only: false) chat_call :read, options: { channel: { name: Core::U[*users], }, peek: peek, unread_only: unread_only, } end |
.delete_message(users, id) ⇒ OpenStruct
Delete a message from a conversation.
104 105 106 107 108 109 110 111 |
# File 'lib/keybase/local/chat.rb', line 104 def (users, id) chat_call :delete, options: { channel: { name: Core::U[*users], }, message_id: id, } end |
.download_attachment(users, id, path) ⇒ OpenStruct
Download a file from a conversation.
153 154 155 156 157 158 159 160 161 |
# File 'lib/keybase/local/chat.rb', line 153 def (users, id, path) chat_call :download, options: { channel: { name: Core::U[*users], }, message_id: id, output: path, } end |
.edit_message(users, id, message) ⇒ OpenStruct
Edit a message in a conversation.
119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/keybase/local/chat.rb', line 119 def (users, id, ) chat_call :edit, options: { channel: { name: Core::U[*users], }, message_id: id, message: { body: , }, } end |
.envelope(meth, options: {}) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the JSON serialized envelope.
19 20 21 22 23 24 25 26 |
# File 'lib/keybase/local/chat.rb', line 19 def envelope(meth, options: {}) { method: meth, params: { options: , }, }.to_json end |
.list_inbox(topic_type: nil) ⇒ OpenStruct
List the current user's inbox.
59 60 61 62 63 |
# File 'lib/keybase/local/chat.rb', line 59 def list_inbox(topic_type: nil) chat_call :list, options: { topic_type: topic_type, } end |
.mark_conversation(users, id) ⇒ OpenStruct
Make a conversation as read up to a specific ID.
168 169 170 171 172 173 174 175 |
# File 'lib/keybase/local/chat.rb', line 168 def mark_conversation(users, id) chat_call :mark, options: { channel: { name: Core::U[*users], }, message_id: id, } end |
.mute_conversation(users) ⇒ OpenStruct
Mute a conversation.
181 182 183 184 185 186 187 188 |
# File 'lib/keybase/local/chat.rb', line 181 def mute_conversation(users) chat_call :setstatus, options: { channel: { name: Core::U[*users], }, status: "muted", } end |
.send_message(users, message, public: false) ⇒ OpenStruct
Send a message to a conversation.
87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/keybase/local/chat.rb', line 87 def (users, , public: false) chat_call :send, options: { channel: { name: Core::U[*users], public: public, }, message: { body: , }, } end |
.unwrap(struct) ⇒ OpenStruct
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Cleans up the object returned by chat_call.
33 34 35 36 37 |
# File 'lib/keybase/local/chat.rb', line 33 def unwrap(struct) raise Exceptions::ChatError, struct.error. if struct.error struct.result end |
.upload_attachment(users, path, title) ⇒ OpenStruct
Upload a file to a conversation.
137 138 139 140 141 142 143 144 145 |
# File 'lib/keybase/local/chat.rb', line 137 def (users, path, title) chat_call :attach, options: { channel: { name: Core::U[*users], }, filename: path, title: title, } end |