keybase-unofficial 0.0.5 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c65d684f169a40ef888365599b327bc4fc33b087
4
- data.tar.gz: c621a15ee3e4af35db7ace294a3378452d947f6c
3
+ metadata.gz: 2edd9a6909fd527cc22f65bc1a4f3ba918179e80
4
+ data.tar.gz: d847cc38999955a7eb438b17a966f9e0b6f38b4b
5
5
  SHA512:
6
- metadata.gz: d0cbd85b2bf544a9374ef59c5840fb7a080a7c900d171a831b94b9308dfd3b031a5aa0888df4ac0af665f20f015e2a3f2439c737c4b18318646d8958c6792027
7
- data.tar.gz: cd3c1cc0857fc82059d5672347d76af3aecca6881bd2c6de0a3052da809bf45922b04417eacf67e60cd0cf0e12093f2c22160f170eb0de2554d82111e22ba2e4
6
+ metadata.gz: 94b656684f60c93c94e8ed1453c37231e3df3c3caf4c7a1314b32e0c4c133f0fe21033936c83fa1b59f9e3be18da3a1c8c0ad151764381dae027502eab9f616a
7
+ data.tar.gz: 00553731d8f691ab623328c2142f853c7c0162c498b6a6bb4ed27b2dd4c9532debb5f0795676658b5aa883e8c0bb5fbf89a11ee64224cfd513ca1cde7ecadef7
data/lib/keybase.rb CHANGED
@@ -1,13 +1,15 @@
1
1
  require_relative "keybase/exceptions"
2
2
  require_relative "keybase/configuration"
3
+ require_relative "keybase/u"
3
4
  require_relative "keybase/local_user"
4
5
  require_relative "keybase/kbfs"
5
6
  require_relative "keybase/api"
7
+ require_relative "keybase/chat"
6
8
 
7
9
  # The primary namespace for keybase-unofficial.
8
10
  module Keybase
9
11
  # keybase-unofficial's current version
10
- VERSION = "0.0.5".freeze
12
+ VERSION = "0.0.6".freeze
11
13
 
12
14
  extend Configuration
13
15
  end
data/lib/keybase/api.rb CHANGED
@@ -23,7 +23,7 @@ module Keybase
23
23
  # @see https://keybase.io/docs/api/1.0/call/user/lookup
24
24
  def lookup(**query)
25
25
  if query[:usernames]
26
- query[:usernames] = query[:usernames].join(",")
26
+ query[:usernames] = U[query[:usernames]]
27
27
  end
28
28
 
29
29
  response = Faraday.get "#{BASE_URL}/user/lookup.json", query
@@ -0,0 +1,182 @@
1
+ require "open3"
2
+ require "json"
3
+ require "ostruct"
4
+
5
+ module Keybase
6
+ # Represents Keybase's JSON chat API.
7
+ class Chat
8
+ # The initial arguments to pass when executing Keybase for chatting.
9
+ CHAT_EXEC_ARGS = ["keybase", "chat", "api"]
10
+
11
+ class << self
12
+ # @param meth [Symbol] the chat method
13
+ # @param options [Hash] the options hash
14
+ # @return [String] the JSON serialized envelope
15
+ # @api private
16
+ def envelope(meth, options: {})
17
+ {
18
+ method: meth,
19
+ params: {
20
+ options: options,
21
+ },
22
+ }.to_json
23
+ end
24
+
25
+ # @param payload [String]
26
+ # @return [OpenStruct] a struct mapping of the JSON response
27
+ # @api private
28
+ def chat_call(payload)
29
+ response = Open3.popen3(*CHAT_EXEC_ARGS) do |stdin, stdout, _, _|
30
+ stdin.write payload
31
+ stdin.close # close after writing to let keybase know we're done
32
+ stdout.read
33
+ end
34
+
35
+ JSON.parse response, object_class: OpenStruct
36
+ end
37
+
38
+ # List the user's inbox.
39
+ # @return [OpenStruct] a struct mapping of the JSON response
40
+ def list_inbox(topic_type: nil)
41
+ payload = envelope :list, options: {
42
+ topic_type: topic_type,
43
+ }
44
+
45
+ chat_call payload
46
+ end
47
+
48
+ # Read a conversation.
49
+ # @param users [Array<String>] a list of the users in the conversation
50
+ # @param peek [Boolean] whether to mark the conversation read
51
+ # @param unread_only [Boolean] whether to fetch unread messages only
52
+ # @return [OpenStruct] a struct mapping of the JSON response
53
+ def conversation(users, peek: false, unread_only: false)
54
+ payload = envelope :read, options: {
55
+ channel: {
56
+ name: U[*users],
57
+ },
58
+ peek: peek,
59
+ unread_only: unread_only,
60
+ }
61
+
62
+ chat_call payload
63
+ end
64
+
65
+ # Send a message to a conversation.
66
+ # @param users [Array<String>] a list of the users in the conversation
67
+ # @param message [String] the message to send
68
+ # @param public [Boolean] whether to send the message to a public channel
69
+ # @return [OpenStruct] a struct mapping of the JSON response
70
+ def send_message(users, message, public: false)
71
+ payload = envelope :send, options: {
72
+ channel: {
73
+ name: U[*users],
74
+ public: public,
75
+ },
76
+ message: {
77
+ body: message,
78
+ }
79
+ }
80
+
81
+ chat_call payload
82
+ end
83
+
84
+ # Delete a message from a conversation.
85
+ # @param users [Array<String>] a list of the users in the conversation
86
+ # @param id [Integer] the id of the message to delete
87
+ # @return [OpenStruct] a struct mapping of the JSON response
88
+ def delete_message(users, id)
89
+ payload = envelope :delete, options: {
90
+ channel: {
91
+ name: U[*users],
92
+ },
93
+ message_id: id,
94
+ }
95
+
96
+ chat_call payload
97
+ end
98
+
99
+ # Edit a message in a conversation.
100
+ # @param users [Array<String>] a list of the users in the conversation
101
+ # @param id [Integer] the id of the message to delete
102
+ # @param message [String] the message to send
103
+ # @return [OpenStruct] a struct mapping of the JSON response
104
+ def edit_message(users, id, message)
105
+ payload = envelope :edit, options: {
106
+ channel: {
107
+ name: U[*users],
108
+ },
109
+ message_id: id,
110
+ message: {
111
+ body: message,
112
+ }
113
+ }
114
+
115
+ chat_call payload
116
+ end
117
+
118
+ # Upload a file to a conversation.
119
+ # @param users [Array<String>] a list of the users in the conversation
120
+ # @param path [String] the pathname of the file to upload
121
+ # @param title [String] the uploaded file's title
122
+ # @return [OpenStruct] a struct mapping of the JSON response
123
+ def upload_attachment(users, path, title)
124
+ payload = envelope :attach, options: {
125
+ channel: {
126
+ name: U[*users],
127
+ },
128
+ filename: path,
129
+ title: title,
130
+ }
131
+
132
+ chat_call payload
133
+ end
134
+
135
+ # Download a file from a conversation.
136
+ # @param users [Array<String>] a list of the users in the conversation
137
+ # @param id [Integer] the id of the message to download from
138
+ # @param path [String] the pathname to download to
139
+ # @return [OpenStruct] a struct mapping of the JSON response
140
+ def download_attachment(users, id, path)
141
+ payload = envelope :download, options: {
142
+ channel: {
143
+ name: U[*users],
144
+ },
145
+ message_id: id,
146
+ output: path,
147
+ }
148
+
149
+ chat_call payload
150
+ end
151
+
152
+ # Make a conversation as read up to a specific ID.
153
+ # @param users [Array<String>] a list of the users in the conversation
154
+ # @param id [Integer] the id of the message to mark up to
155
+ # @return [OpenStruct] a struct mapping of the JSON response
156
+ def mark_conversation(users, id)
157
+ payload = envelope :mark, options: {
158
+ channel: {
159
+ name: U[*users],
160
+ },
161
+ message_id: id,
162
+ }
163
+
164
+ chat_call payload
165
+ end
166
+
167
+ # Mute a conversation.
168
+ # @param users [Array<String>] a list of the users in the conversation
169
+ # @return [OpenStruct] a struct mapping of the JSON response
170
+ def mute_conversation(users)
171
+ payload = envelope :setstatus, options: {
172
+ channel: {
173
+ name: U[*users],
174
+ },
175
+ status: "muted",
176
+ }
177
+
178
+ chat_call payload
179
+ end
180
+ end
181
+ end
182
+ end
data/lib/keybase/u.rb ADDED
@@ -0,0 +1,14 @@
1
+ module Keybase
2
+ # A class for converting arrays of users into Keybase-style strings.
3
+ class U
4
+ class << self
5
+ # @param args [Array<String>] the list of users to merge
6
+ # @return [String] the Keybase-style user string
7
+ # @example
8
+ # Keybase::U["a", "b"] # => "a,b"
9
+ def [](*args)
10
+ args.join(",")
11
+ end
12
+ end
13
+ end
14
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: keybase-unofficial
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - William Woodruff
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-02 00:00:00.000000000 Z
11
+ date: 2017-02-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -35,10 +35,12 @@ files:
35
35
  - README.md
36
36
  - lib/keybase.rb
37
37
  - lib/keybase/api.rb
38
+ - lib/keybase/chat.rb
38
39
  - lib/keybase/configuration.rb
39
40
  - lib/keybase/exceptions.rb
40
41
  - lib/keybase/kbfs.rb
41
42
  - lib/keybase/local_user.rb
43
+ - lib/keybase/u.rb
42
44
  homepage: https://github.com/woodruffw/keybase-unofficial
43
45
  licenses:
44
46
  - MIT