mixin_bot 0.3.8 → 0.3.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 59e234762e65de8e0858a88eaae1c25a8951076345728b20e65d2c15294fc831
4
- data.tar.gz: 190b8385d4501ff7e603751670f160257f69651679cb4572f4037c4d7c955a67
3
+ metadata.gz: d714edf6aef84c707774d04abf1b8016041d09160f82864966e2b09bf6845870
4
+ data.tar.gz: 7816eaf72dd92c841ed78e9bc315a562feb12b34d50f7c87c35a3c34d7fe1176
5
5
  SHA512:
6
- metadata.gz: 92d6704e15ce02a56e5f3451c75689b27caf6b7a782597a5535e736926c0c6090cc75d7f40d2190c29ddb32858b910f4b3f0bbcf7f295d474298258ae60c73d6
7
- data.tar.gz: 19b4de6e5645793750091cb311b38ecedf5e5ba5b6fd0ffaa1916d0be9f2c5fd53a33be658e21e992fdaffe01bbeee83c500b2cb0223ea04fdcd5fda1db87270
6
+ metadata.gz: 846f28a71824b964b68664538e2960f991dabf3ebbcf3f162cacc2ef4fd88713351d2949f639108d125cfd65dc33aebb9f6c4bfdc07d2fcf07f72d01a96c10b2
7
+ data.tar.gz: fc2939f80ba895921d45d5d29866d50696dab737b19f5234d1223d6f3cd5867879606ec3978ee502ae7532275cbd6172a6a780771c3d68965fa82f5e2ae446f7
@@ -17,19 +17,106 @@ module MixinBot
17
17
  end
18
18
  alias read_conversation_by_user_id conversation_by_user_id
19
19
 
20
- def create_contact_conversation(user_id)
20
+ def create_conversation(category:, conversation_id:, participants:, name: nil, access_token: nil)
21
21
  path = '/conversations'
22
22
  payload = {
23
+ category: category,
24
+ conversation_id: conversation_id || SecureRandom.uuid,
25
+ name: name,
26
+ participants: participants
27
+ }
28
+
29
+ access_token ||= access_token('POST', path, payload.to_json)
30
+ authorization = format('Bearer %<access_token>s', access_token: access_token)
31
+ client.post(path, headers: { 'Authorization': authorization }, json: payload)
32
+ end
33
+
34
+ def create_group_conversation(user_ids:, name:, conversation_id: nil, access_token: nil)
35
+ create_conversation(
36
+ category: 'GROUP',
37
+ conversation_id: conversation_id,
38
+ name: name,
39
+ participants: user_ids.map(&->(participant) { { user_id: participant } }),
40
+ access_token: access_token
41
+ )
42
+ end
43
+
44
+ def create_contact_conversation(user_id, access_token: nil)
45
+ create_conversation(
23
46
  category: 'CONTACT',
24
47
  conversation_id: unique_conversation_id(user_id),
25
48
  participants: [
26
49
  {
27
- action: 'ADD',
28
- role: '',
29
50
  user_id: user_id
30
51
  }
31
- ]
52
+ ],
53
+ access_token: access_token
54
+ )
55
+ end
56
+
57
+ def update_group_conversation_name(name:, conversation_id:, access_token: nil)
58
+ path = format('/conversations/%<id>s', id: conversation_id)
59
+ payload = {
60
+ name: name
61
+ }
62
+
63
+ access_token ||= access_token('POST', path, payload.to_json)
64
+ authorization = format('Bearer %<access_token>s', access_token: access_token)
65
+ client.post(path, headers: { 'Authorization': authorization }, json: payload)
66
+ end
67
+
68
+ def update_group_conversation_announcement(announcement:, conversation_id:, access_token: nil)
69
+ path = format('/conversations/%<id>s', id: conversation_id)
70
+ payload = {
71
+ announcement: announcement
32
72
  }
73
+
74
+ access_token ||= access_token('POST', path, payload.to_json)
75
+ authorization = format('Bearer %<access_token>s', access_token: access_token)
76
+ client.post(path, headers: { 'Authorization': authorization }, json: payload)
77
+ end
78
+
79
+ # participants = [{ user_id: "" }]
80
+ def add_conversation_participants(conversation_id:, user_ids:, access_token: nil)
81
+ path = format('/conversations/%<id>s/participants/ADD', id: conversation_id)
82
+ payload = user_ids.map(&->(participant) { { user_id: participant } })
83
+
84
+ access_token ||= access_token('POST', path, payload.to_json)
85
+ authorization = format('Bearer %<access_token>s', access_token: access_token)
86
+ client.post(path, headers: { 'Authorization': authorization }, json: payload)
87
+ end
88
+
89
+ # participants = [{ user_id: "" }]
90
+ def remove_conversation_participants(conversation_id:, user_ids:, access_token: nil)
91
+ path = format('/conversations/%<id>s/participants/REMOVE', id: conversation_id)
92
+ payload = user_ids.map(&->(participant) { { user_id: participant } })
93
+
94
+ access_token ||= access_token('POST', path, payload.to_json)
95
+ authorization = format('Bearer %<access_token>s', access_token: access_token)
96
+ client.post(path, headers: { 'Authorization': authorization }, json: payload)
97
+ end
98
+
99
+ def exit_conversation(conversation_id, access_token: nil)
100
+ path = format('/conversations/%<id>s/exit', id: conversation_id)
101
+
102
+ access_token ||= access_token('POST', path)
103
+ authorization = format('Bearer %<access_token>s', access_token: access_token)
104
+ client.post(path, headers: { 'Authorization': authorization })
105
+ end
106
+
107
+ def rotate_conversation(conversation_id, access_token: nil)
108
+ path = format('/conversations/%<id>s/rotate', id: conversation_id)
109
+
110
+ access_token ||= access_token('POST', path)
111
+ authorization = format('Bearer %<access_token>s', access_token: access_token)
112
+ client.post(path, headers: { 'Authorization': authorization })
113
+ end
114
+
115
+ # participants = [{ user_id: "", role: "ADMIN" }]
116
+ def update_conversation_participants_role(conversation_id:, participants:, access_token: nil)
117
+ path = format('/conversations/%<id>s/participants/ROLE', id: conversation_id)
118
+ payload = participants
119
+
33
120
  access_token ||= access_token('POST', path, payload.to_json)
34
121
  authorization = format('Bearer %<access_token>s', access_token: access_token)
35
122
  client.post(path, headers: { 'Authorization': authorization }, json: payload)
@@ -32,7 +32,7 @@ module MixinBot
32
32
  raise HttpError, e.message
33
33
  end
34
34
 
35
- raise RequestError.new(nil, response.to_s) unless response.status.success?
35
+ raise RequestError, response.to_s unless response.status.success?
36
36
 
37
37
  parse_response(response) do |parse_as, result|
38
38
  case parse_as
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MixinBot
4
- VERSION = '0.3.8'
4
+ VERSION = '0.3.9'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mixin_bot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.8
4
+ version: 0.3.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - an-lee
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-02-07 00:00:00.000000000 Z
11
+ date: 2021-02-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: awesome_print