mixin_bot 0.3.3 → 0.3.8
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 +4 -4
- data/lib/mixin_bot.rb +8 -0
- data/lib/mixin_bot/api.rb +8 -2
- data/lib/mixin_bot/api/app.rb +2 -2
- data/lib/mixin_bot/api/asset.rb +36 -0
- data/lib/mixin_bot/api/auth.rb +1 -1
- data/lib/mixin_bot/api/conversation.rb +6 -3
- data/lib/mixin_bot/api/me.rb +4 -18
- data/lib/mixin_bot/api/multisig.rb +41 -35
- data/lib/mixin_bot/api/snapshot.rb +6 -3
- data/lib/mixin_bot/api/transfer.rb +7 -2
- data/lib/mixin_bot/client.rb +29 -4
- data/lib/mixin_bot/version.rb +1 -1
- metadata +17 -3
- data/lib/mixin_bot/errors.rb +0 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 59e234762e65de8e0858a88eaae1c25a8951076345728b20e65d2c15294fc831
|
4
|
+
data.tar.gz: 190b8385d4501ff7e603751670f160257f69651679cb4572f4037c4d7c955a67
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 92d6704e15ce02a56e5f3451c75689b27caf6b7a782597a5535e736926c0c6090cc75d7f40d2190c29ddb32858b910f4b3f0bbcf7f295d474298258ae60c73d6
|
7
|
+
data.tar.gz: 19b4de6e5645793750091cb311b38ecedf5e5ba5b6fd0ffaa1916d0be9f2c5fd53a33be658e21e992fdaffe01bbeee83c500b2cb0223ea04fdcd5fda1db87270
|
data/lib/mixin_bot.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# third-party dependencies
|
3
4
|
require 'English'
|
4
5
|
require 'base64'
|
5
6
|
require 'digest'
|
@@ -10,6 +11,7 @@ require 'msgpack'
|
|
10
11
|
require 'open3'
|
11
12
|
require 'openssl'
|
12
13
|
require 'rbnacl'
|
14
|
+
|
13
15
|
require_relative './mixin_bot/api'
|
14
16
|
require_relative './mixin_bot/cli'
|
15
17
|
require_relative './mixin_bot/version'
|
@@ -22,4 +24,10 @@ module MixinBot
|
|
22
24
|
def self.api
|
23
25
|
@api ||= MixinBot::API.new
|
24
26
|
end
|
27
|
+
|
28
|
+
class HttpError < StandardError; end
|
29
|
+
class RequestError < StandardError; end
|
30
|
+
class ResponseError < StandardError; end
|
31
|
+
class UnauthorizedError < StandardError; end
|
32
|
+
class ForbiddenError < StandardError; end
|
25
33
|
end
|
data/lib/mixin_bot/api.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative './client'
|
4
|
-
require_relative './errors'
|
5
4
|
require_relative './api/app'
|
5
|
+
require_relative './api/asset'
|
6
6
|
require_relative './api/attachment'
|
7
7
|
require_relative './api/auth'
|
8
8
|
require_relative './api/blaze'
|
@@ -25,9 +25,14 @@ module MixinBot
|
|
25
25
|
@client_id = options[:client_id] || MixinBot.client_id
|
26
26
|
@client_secret = options[:client_secret] || MixinBot.client_secret
|
27
27
|
@session_id = options[:session_id] || MixinBot.session_id
|
28
|
-
@pin_token = Base64.urlsafe_decode64 options[:pin_token] || MixinBot.pin_token
|
29
28
|
@client = Client.new(MixinBot.api_host || 'api.mixin.one')
|
30
29
|
@blaze_host = MixinBot.blaze_host || 'blaze.mixin.one'
|
30
|
+
@pin_token =
|
31
|
+
begin
|
32
|
+
Base64.urlsafe_decode64 options[:pin_token] || MixinBot.pin_token
|
33
|
+
rescue StandardError
|
34
|
+
''
|
35
|
+
end
|
31
36
|
_private_key = options[:private_key] || MixinBot.private_key
|
32
37
|
@private_key =
|
33
38
|
if /^-----BEGIN RSA PRIVATE KEY-----/.match? _private_key
|
@@ -49,6 +54,7 @@ module MixinBot
|
|
49
54
|
end
|
50
55
|
|
51
56
|
include MixinBot::API::App
|
57
|
+
include MixinBot::API::Asset
|
52
58
|
include MixinBot::API::Attachment
|
53
59
|
include MixinBot::API::Auth
|
54
60
|
include MixinBot::API::Blaze
|
data/lib/mixin_bot/api/app.rb
CHANGED
@@ -6,7 +6,7 @@ module MixinBot
|
|
6
6
|
def add_favorite_app(app_id, access_token: nil)
|
7
7
|
path = format('/apps/%<id>s/favorite', id: app_id)
|
8
8
|
|
9
|
-
access_token ||= access_token('POST', path
|
9
|
+
access_token ||= access_token('POST', path)
|
10
10
|
authorization = format('Bearer %<access_token>s', access_token: access_token)
|
11
11
|
client.post(path, headers: { 'Authorization': authorization })
|
12
12
|
end
|
@@ -14,7 +14,7 @@ module MixinBot
|
|
14
14
|
def remove_favorite_app(app_id, access_token: nil)
|
15
15
|
path = format('/apps/%<id>s/unfavorite', id: app_id)
|
16
16
|
|
17
|
-
access_token ||= access_token('POST', path
|
17
|
+
access_token ||= access_token('POST', path)
|
18
18
|
authorization = format('Bearer %<access_token>s', access_token: access_token)
|
19
19
|
client.post(path, headers: { 'Authorization': authorization })
|
20
20
|
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module MixinBot
|
4
|
+
class API
|
5
|
+
module Asset
|
6
|
+
# https://developers.mixin.one/api/alpha-mixin-network/read-assets/
|
7
|
+
def assets(access_token: nil)
|
8
|
+
path = '/assets'
|
9
|
+
access_token ||= access_token('GET', path, '')
|
10
|
+
authorization = format('Bearer %<access_token>s', access_token: access_token)
|
11
|
+
client.get(path, headers: { 'Authorization': authorization })
|
12
|
+
end
|
13
|
+
alias read_assets assets
|
14
|
+
|
15
|
+
# https://developers.mixin.one/api/alpha-mixin-network/read-asset/
|
16
|
+
def asset(asset_id, access_token: nil)
|
17
|
+
path = format('/assets/%<asset_id>s', asset_id: asset_id)
|
18
|
+
access_token ||= access_token('GET', path, '')
|
19
|
+
authorization = format('Bearer %<access_token>s', access_token: access_token)
|
20
|
+
client.get(path, headers: { 'Authorization': authorization })
|
21
|
+
end
|
22
|
+
alias read_asset asset
|
23
|
+
|
24
|
+
# https://developers.mixin.one/document/wallet/api/ticker
|
25
|
+
def ticker(asset_id, offset, access_token: nil)
|
26
|
+
offset = DateTime.rfc3339 offset if offset.is_a? String
|
27
|
+
offset = offset.rfc3339 if offset.is_a?(DateTime) || offset.is_a?(Time)
|
28
|
+
path = format('/ticker?asset=%<asset_id>s&offset=%<offset>s', asset_id: asset_id, offset: offset)
|
29
|
+
access_token ||= access_token('GET', path, '')
|
30
|
+
authorization = format('Bearer %<access_token>s', access_token: access_token)
|
31
|
+
client.get(path, headers: { 'Authorization': authorization })
|
32
|
+
end
|
33
|
+
alias read_ticker ticker
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/mixin_bot/api/auth.rb
CHANGED
@@ -4,7 +4,7 @@ module MixinBot
|
|
4
4
|
class API
|
5
5
|
module Auth
|
6
6
|
def access_token(method, uri, body = '', exp_in: 600, scp: 'FULL')
|
7
|
-
sig = Digest::SHA256.hexdigest(method + uri + body)
|
7
|
+
sig = Digest::SHA256.hexdigest(method + uri + body.to_s)
|
8
8
|
iat = Time.now.utc.to_i
|
9
9
|
exp = (Time.now.utc + exp_in).to_i
|
10
10
|
jti = SecureRandom.uuid
|
@@ -3,17 +3,19 @@
|
|
3
3
|
module MixinBot
|
4
4
|
class API
|
5
5
|
module Conversation
|
6
|
-
def
|
6
|
+
def conversation(conversation_id)
|
7
7
|
path = format('/conversations/%<conversation_id>s', conversation_id: conversation_id)
|
8
8
|
access_token ||= access_token('GET', path, '')
|
9
9
|
authorization = format('Bearer %<access_token>s', access_token: access_token)
|
10
10
|
client.get(path, headers: { 'Authorization': authorization })
|
11
11
|
end
|
12
|
+
alias read_conversation conversation
|
12
13
|
|
13
|
-
def
|
14
|
+
def conversation_by_user_id(user_id)
|
14
15
|
conversation_id = unique_conversation_id(user_id)
|
15
16
|
read_conversation(conversation_id)
|
16
17
|
end
|
18
|
+
alias read_conversation_by_user_id conversation_by_user_id
|
17
19
|
|
18
20
|
def create_contact_conversation(user_id)
|
19
21
|
path = '/conversations'
|
@@ -33,7 +35,7 @@ module MixinBot
|
|
33
35
|
client.post(path, headers: { 'Authorization': authorization }, json: payload)
|
34
36
|
end
|
35
37
|
|
36
|
-
def
|
38
|
+
def unique_uuid(user_id, opponent_id = nil)
|
37
39
|
opponent_id ||= client_id
|
38
40
|
md5 = Digest::MD5.new
|
39
41
|
md5 << [user_id, opponent_id].min
|
@@ -53,6 +55,7 @@ module MixinBot
|
|
53
55
|
fifth: hex[20..]
|
54
56
|
)
|
55
57
|
end
|
58
|
+
alias unique_conversation_id unique_uuid
|
56
59
|
end
|
57
60
|
end
|
58
61
|
end
|
data/lib/mixin_bot/api/me.rb
CHANGED
@@ -4,12 +4,13 @@ module MixinBot
|
|
4
4
|
class API
|
5
5
|
module Me
|
6
6
|
# https://developers.mixin.one/api/beta-mixin-message/read-profile/
|
7
|
-
def
|
7
|
+
def me(access_token: nil)
|
8
8
|
path = '/me'
|
9
9
|
access_token ||= access_token('GET', path, '')
|
10
10
|
authorization = format('Bearer %<access_token>s', access_token: access_token)
|
11
11
|
client.get(path, headers: { 'Authorization': authorization })
|
12
12
|
end
|
13
|
+
alias read_me me
|
13
14
|
|
14
15
|
# https://developers.mixin.one/api/beta-mixin-message/update-profile/
|
15
16
|
# avatar_base64:
|
@@ -25,29 +26,14 @@ module MixinBot
|
|
25
26
|
client.post(path, headers: { 'Authorization': authorization }, json: payload)
|
26
27
|
end
|
27
28
|
|
28
|
-
# https://developers.mixin.one/api/alpha-mixin-network/read-assets/
|
29
|
-
def read_assets(access_token: nil)
|
30
|
-
path = '/assets'
|
31
|
-
access_token ||= access_token('GET', path, '')
|
32
|
-
authorization = format('Bearer %<access_token>s', access_token: access_token)
|
33
|
-
client.get(path, headers: { 'Authorization': authorization })
|
34
|
-
end
|
35
|
-
|
36
|
-
# https://developers.mixin.one/api/alpha-mixin-network/read-asset/
|
37
|
-
def read_asset(asset_id, access_token: nil)
|
38
|
-
path = format('/assets/%<asset_id>s', asset_id: asset_id)
|
39
|
-
access_token ||= access_token('GET', path, '')
|
40
|
-
authorization = format('Bearer %<access_token>s', access_token: access_token)
|
41
|
-
client.get(path, headers: { 'Authorization': authorization })
|
42
|
-
end
|
43
|
-
|
44
29
|
# https://developers.mixin.one/api/beta-mixin-message/friends/
|
45
|
-
def
|
30
|
+
def friends(access_token: nil)
|
46
31
|
path = '/friends'
|
47
32
|
access_token ||= access_token('GET', path, '')
|
48
33
|
authorization = format('Bearer %<access_token>s', access_token: access_token)
|
49
34
|
client.get(path, headers: { 'Authorization': authorization })
|
50
35
|
end
|
36
|
+
alias read_friends friends
|
51
37
|
end
|
52
38
|
end
|
53
39
|
end
|
@@ -119,19 +119,19 @@ module MixinBot
|
|
119
119
|
|
120
120
|
# pay to the multisig address
|
121
121
|
# used for create multisig payment code_id
|
122
|
-
def create_multisig_payment(
|
122
|
+
def create_multisig_payment(**kwargs)
|
123
123
|
path = '/payments'
|
124
124
|
payload = {
|
125
|
-
asset_id:
|
126
|
-
amount:
|
127
|
-
trace_id:
|
128
|
-
memo:
|
125
|
+
asset_id: kwargs[:asset_id],
|
126
|
+
amount: kwargs[:amount].to_s,
|
127
|
+
trace_id: kwargs[:trace_id] || SecureRandom.uuid,
|
128
|
+
memo: kwargs[:memo],
|
129
129
|
opponent_multisig: {
|
130
|
-
receivers:
|
131
|
-
threshold:
|
130
|
+
receivers: kwargs[:receivers],
|
131
|
+
threshold: kwargs[:threshold]
|
132
132
|
}
|
133
133
|
}
|
134
|
-
access_token =
|
134
|
+
access_token = kwargs[:access_token]
|
135
135
|
access_token ||= access_token('POST', path, payload.to_json)
|
136
136
|
authorization = format('Bearer %<access_token>s', access_token: access_token)
|
137
137
|
client.post(path, headers: { 'Authorization': authorization }, json: payload)
|
@@ -166,37 +166,37 @@ module MixinBot
|
|
166
166
|
end
|
167
167
|
|
168
168
|
# filter utxo by members, asset_id and threshold
|
169
|
-
def filter_utxos(
|
170
|
-
utxos = all_multisigs(access_token:
|
169
|
+
def filter_utxos(**kwargs)
|
170
|
+
utxos = all_multisigs(access_token: kwargs[:access_token])
|
171
171
|
|
172
|
-
unless
|
172
|
+
unless kwargs[:members].nil?
|
173
173
|
utxos = utxos.filter(
|
174
174
|
&lambda { |utxo|
|
175
|
-
utxo['members'].sort ==
|
175
|
+
utxo['members'].sort == kwargs[:members].sort
|
176
176
|
}
|
177
177
|
)
|
178
178
|
end
|
179
179
|
|
180
|
-
unless
|
180
|
+
unless kwargs[:asset_id].nil?
|
181
181
|
utxos = utxos.filter(
|
182
182
|
&lambda { |utxo|
|
183
|
-
utxo['asset_id'] ==
|
183
|
+
utxo['asset_id'] == kwargs[:asset_id]
|
184
184
|
}
|
185
185
|
)
|
186
186
|
end
|
187
187
|
|
188
|
-
unless
|
188
|
+
unless kwargs[:threshold].nil?
|
189
189
|
utxos = utxos.filter(
|
190
190
|
&lambda { |utxo|
|
191
|
-
utxo['threshold'] ==
|
191
|
+
utxo['threshold'] == kwargs[:threshold]
|
192
192
|
}
|
193
193
|
)
|
194
194
|
end
|
195
195
|
|
196
|
-
unless
|
196
|
+
unless kwargs[:state].nil?
|
197
197
|
utxos = utxos.filter(
|
198
198
|
&lambda { |utxo|
|
199
|
-
utxo['state'] ==
|
199
|
+
utxo['state'] == kwargs[:state]
|
200
200
|
}
|
201
201
|
)
|
202
202
|
end
|
@@ -204,7 +204,7 @@ module MixinBot
|
|
204
204
|
utxos
|
205
205
|
end
|
206
206
|
|
207
|
-
#
|
207
|
+
# kwargs:
|
208
208
|
# {
|
209
209
|
# senders: [ uuid ],
|
210
210
|
# receivers: [ uuid ],
|
@@ -214,16 +214,16 @@ module MixinBot
|
|
214
214
|
# amount: string / float,
|
215
215
|
# memo: string,
|
216
216
|
# }
|
217
|
-
def build_raw_transaction(
|
218
|
-
senders =
|
219
|
-
receivers =
|
220
|
-
asset_id =
|
221
|
-
asset_mixin_id =
|
222
|
-
amount =
|
223
|
-
memo =
|
224
|
-
threshold =
|
225
|
-
access_token =
|
226
|
-
utxos =
|
217
|
+
def build_raw_transaction(kwargs)
|
218
|
+
senders = kwargs[:senders]
|
219
|
+
receivers = kwargs[:receivers]
|
220
|
+
asset_id = kwargs[:asset_id]
|
221
|
+
asset_mixin_id = kwargs[:asset_mixin_id]
|
222
|
+
amount = kwargs[:amount]
|
223
|
+
memo = kwargs[:memo]
|
224
|
+
threshold = kwargs[:threshold]
|
225
|
+
access_token = kwargs[:access_token]
|
226
|
+
utxos = kwargs[:utxos]
|
227
227
|
|
228
228
|
raise 'access_token required!' if access_token.nil? && !senders.include?(client_id)
|
229
229
|
|
@@ -261,15 +261,21 @@ module MixinBot
|
|
261
261
|
|
262
262
|
outputs = []
|
263
263
|
output0 = create_output(receivers: receivers, index: 0)['data']
|
264
|
-
|
265
|
-
|
266
|
-
|
264
|
+
outputs << {
|
265
|
+
'amount': format('%<amount>.8f', amount: amount),
|
266
|
+
'script': build_threshold_script(receivers.length),
|
267
|
+
'mask': output0['mask'],
|
268
|
+
'keys': output0['keys']
|
269
|
+
}
|
267
270
|
|
268
271
|
if input_amount > amount
|
269
272
|
output1 = create_output(receivers: senders, index: 1)['data']
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
+
outputs << {
|
274
|
+
'amount': format('%<amount>.8f', amount: input_amount - amount),
|
275
|
+
'script': build_threshold_script(threshold.to_i),
|
276
|
+
'mask': output1['mask'],
|
277
|
+
'keys': output1['keys']
|
278
|
+
}
|
273
279
|
end
|
274
280
|
|
275
281
|
extra = Digest.hexencode memo.to_s.slice(0, 140)
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module MixinBot
|
4
4
|
class API
|
5
5
|
module Snapshot
|
6
|
-
def
|
6
|
+
def network_snapshots(options = {})
|
7
7
|
path = format(
|
8
8
|
'/network/snapshots?limit=%<limit>s&offset=%<offset>s&asset=%<asset>s&order=%<order>s',
|
9
9
|
limit: options[:limit],
|
@@ -16,8 +16,9 @@ module MixinBot
|
|
16
16
|
authorization = format('Bearer %<access_token>s', access_token: access_token)
|
17
17
|
client.get(path, headers: { 'Authorization': authorization })
|
18
18
|
end
|
19
|
+
alias read_network_snapshots network_snapshots
|
19
20
|
|
20
|
-
def
|
21
|
+
def snapshots(options = {})
|
21
22
|
path = format(
|
22
23
|
'/snapshots?limit=%<limit>s&offset=%<offset>s&asset=%<asset>s',
|
23
24
|
limit: options[:limit],
|
@@ -29,14 +30,16 @@ module MixinBot
|
|
29
30
|
authorization = format('Bearer %<access_token>s', access_token: access_token)
|
30
31
|
client.get(path, headers: { 'Authorization': authorization })
|
31
32
|
end
|
33
|
+
alias read_snapshots snapshots
|
32
34
|
|
33
|
-
def
|
35
|
+
def network_snapshot(snapshot_id, options = {})
|
34
36
|
path = format('/network/snapshots/%<snapshot_id>s', snapshot_id: snapshot_id)
|
35
37
|
|
36
38
|
access_token = options[:access_token] || access_token('GET', path)
|
37
39
|
authorization = format('Bearer %<access_token>s', access_token: access_token)
|
38
40
|
client.get(path, headers: { 'Authorization': authorization })
|
39
41
|
end
|
42
|
+
alias read_network_snapshot network_snapshot
|
40
43
|
end
|
41
44
|
end
|
42
45
|
end
|
@@ -3,7 +3,10 @@
|
|
3
3
|
module MixinBot
|
4
4
|
class API
|
5
5
|
module Transfer
|
6
|
-
|
6
|
+
TRANSFER_ARGUMENTS = %i[asset_id opponent_id amount].freeze
|
7
|
+
def create_transfer(pin, options = {})
|
8
|
+
raise ArgumentError, "#{TRANSFER_ARGUMENTS.join(', ')} are needed for create transfer" unless TRANSFER_ARGUMENTS.all? { |param| options.keys.include? param }
|
9
|
+
|
7
10
|
asset_id = options[:asset_id]
|
8
11
|
opponent_id = options[:opponent_id]
|
9
12
|
amount = options[:amount]
|
@@ -21,17 +24,19 @@ module MixinBot
|
|
21
24
|
memo: memo
|
22
25
|
}
|
23
26
|
|
27
|
+
access_token = options[:access_token]
|
24
28
|
access_token ||= access_token('POST', path, payload.to_json)
|
25
29
|
authorization = format('Bearer %<access_token>s', access_token: access_token)
|
26
30
|
client.post(path, headers: { 'Authorization': authorization }, json: payload)
|
27
31
|
end
|
28
32
|
|
29
|
-
def
|
33
|
+
def transfer(trace_id, access_token: nil)
|
30
34
|
path = format('/transfers/trace/%<trace_id>s', trace_id: trace_id)
|
31
35
|
access_token ||= access_token('GET', path, '')
|
32
36
|
authorization = format('Bearer %<access_token>s', access_token: access_token)
|
33
37
|
client.get(path, headers: { 'Authorization': authorization })
|
34
38
|
end
|
39
|
+
alias read_transfer transfer
|
35
40
|
end
|
36
41
|
end
|
37
42
|
end
|
data/lib/mixin_bot/client.rb
CHANGED
@@ -29,17 +29,42 @@ module MixinBot
|
|
29
29
|
begin
|
30
30
|
response = HTTP.timeout(connect: 5, write: 5, read: 5).request(verb, uri, options)
|
31
31
|
rescue HTTP::Error => e
|
32
|
-
raise
|
32
|
+
raise HttpError, e.message
|
33
33
|
end
|
34
34
|
|
35
|
-
raise
|
35
|
+
raise RequestError.new(nil, response.to_s) unless response.status.success?
|
36
36
|
|
37
37
|
parse_response(response) do |parse_as, result|
|
38
38
|
case parse_as
|
39
39
|
when :json
|
40
|
-
|
40
|
+
if result['error'].nil?
|
41
|
+
result.merge! result['data'] if result['data'].is_a? Hash
|
42
|
+
break result
|
43
|
+
end
|
41
44
|
|
42
|
-
|
45
|
+
errmsg = "errcode: #{result['error']['code']}, errmsg: #{result['error']['description']}"
|
46
|
+
|
47
|
+
# status code description
|
48
|
+
# 202 400 The request body can’t be pasred as valid data.
|
49
|
+
# 202 401 Unauthorized.
|
50
|
+
# 202 403 Forbidden.
|
51
|
+
# 202 404 The endpoint is not found.
|
52
|
+
# 202 429 Too Many Requests.
|
53
|
+
# 202 10006 App update required.
|
54
|
+
# 202 20116 The group chat is full.
|
55
|
+
# 500 500 Internal Server Error.
|
56
|
+
# 500 7000 Blaze server error.
|
57
|
+
# 500 7001 The blaze operation timeout.
|
58
|
+
case result['error']['code']
|
59
|
+
when 401
|
60
|
+
raise UnauthorizedError, errmsg
|
61
|
+
when 403, 20116
|
62
|
+
raise ForbiddenError, errmsg
|
63
|
+
when 400, 404, 429, 10006, 20133, 500, 7000, 7001
|
64
|
+
raise ResponseError, errmsg
|
65
|
+
else
|
66
|
+
raise ResponseError, errmsg
|
67
|
+
end
|
43
68
|
else
|
44
69
|
result
|
45
70
|
end
|
data/lib/mixin_bot/version.rb
CHANGED
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.
|
4
|
+
version: 0.3.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- an-lee
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-02-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: awesome_print
|
@@ -136,6 +136,20 @@ dependencies:
|
|
136
136
|
- - "~>"
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: '1.0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: pry
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - "~>"
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: 0.13.1
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - "~>"
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: 0.13.1
|
139
153
|
- !ruby/object:Gem::Dependency
|
140
154
|
name: rake
|
141
155
|
requirement: !ruby/object:Gem::Requirement
|
@@ -219,6 +233,7 @@ files:
|
|
219
233
|
- lib/mixin_bot.rb
|
220
234
|
- lib/mixin_bot/api.rb
|
221
235
|
- lib/mixin_bot/api/app.rb
|
236
|
+
- lib/mixin_bot/api/asset.rb
|
222
237
|
- lib/mixin_bot/api/attachment.rb
|
223
238
|
- lib/mixin_bot/api/auth.rb
|
224
239
|
- lib/mixin_bot/api/blaze.rb
|
@@ -237,7 +252,6 @@ files:
|
|
237
252
|
- lib/mixin_bot/cli/multisig.rb
|
238
253
|
- lib/mixin_bot/cli/node.rb
|
239
254
|
- lib/mixin_bot/client.rb
|
240
|
-
- lib/mixin_bot/errors.rb
|
241
255
|
- lib/mixin_bot/version.rb
|
242
256
|
homepage: https://github.com/an-lee/mixin_bot
|
243
257
|
licenses:
|
data/lib/mixin_bot/errors.rb
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module MixinBot
|
4
|
-
module Errors
|
5
|
-
# 通用异常
|
6
|
-
Error = Class.new(StandardError)
|
7
|
-
|
8
|
-
# HTTP 异常,比如请求超时等
|
9
|
-
HttpError = Class.new(Error)
|
10
|
-
|
11
|
-
# API 异常,比如返回失败状态码
|
12
|
-
class APIError < Error
|
13
|
-
attr_reader :errcode, :errmsg
|
14
|
-
|
15
|
-
def initialize(errcode, errmsg)
|
16
|
-
@errcode = errcode
|
17
|
-
@errmsg = errmsg
|
18
|
-
|
19
|
-
super(format('[%<errcode>s]: %<errmsg>s', errcode: @errcode, errmsg: @errmsg))
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|