selfsdk 0.0.144 → 0.0.145
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/messages/authentication_req.rb +3 -7
- data/lib/messages/base.rb +25 -5
- data/lib/messages/fact_request.rb +2 -11
- data/lib/messaging.rb +6 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0c59c2a25ba8f895e9a1820e6cf8072c219680ccfc763582f9b8761903ae0f3f
|
4
|
+
data.tar.gz: 9ca32b859e6f0feeddf5c5e87b38309e691f7459e60d3a9b281f1396dc4bc998
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 65b73466d77d25bfa80dfa9c191f19bb6d525c739754753e653652ebbb59eecb3b3c8936d3205c8b41dd7a71376bef6aa18367fb8f275fe60ef18888633e0a8d
|
7
|
+
data.tar.gz: c39e65926ddb0923673b5e1109ae54dcc01adfa2408a560182acd8cc3160adb8f7085e9a0f22545078108f2efc1f9d432363255086400833ad5bdd5947091867
|
@@ -38,16 +38,12 @@ module SelfSDK
|
|
38
38
|
|
39
39
|
protected
|
40
40
|
|
41
|
-
def proto
|
42
|
-
app = @client.app(@jwt.id)
|
43
|
-
raise "Your credits have expired, please log in to the developer portal and top up your account." if app[:paid_actions] == false
|
44
|
-
|
45
|
-
@to_device = @client.devices(@to).first
|
41
|
+
def proto(to_device)
|
46
42
|
Msgproto::Message.new(type: Msgproto::MsgType::MSG,
|
47
43
|
sender: "#{@jwt.id}:#{@messaging.device_id}",
|
48
44
|
id: @id,
|
49
|
-
recipient: "#{@to}:#{
|
50
|
-
ciphertext: encrypt_message(@jwt.prepare(body), @to,
|
45
|
+
recipient: "#{@to}:#{to_device}",
|
46
|
+
ciphertext: encrypt_message(@jwt.prepare(body), @to, to_device))
|
51
47
|
end
|
52
48
|
|
53
49
|
end
|
data/lib/messages/base.rb
CHANGED
@@ -15,15 +15,24 @@ module SelfSDK
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def request
|
18
|
-
|
19
|
-
|
18
|
+
check_credits!
|
19
|
+
msgs = []
|
20
|
+
devices.each do |d|
|
21
|
+
msgs << proto(d)
|
22
|
+
end
|
23
|
+
res = @messaging.send_and_wait_for_response(msgs, self)
|
24
|
+
SelfSDK.logger.info "synchronously messaging to #{@to}:#{@d}"
|
20
25
|
res
|
21
26
|
end
|
22
27
|
|
23
28
|
def send_message
|
24
|
-
|
25
|
-
|
26
|
-
|
29
|
+
check_credits!
|
30
|
+
res = []
|
31
|
+
devices.each do |d|
|
32
|
+
res << @messaging.send_message(proto(d))
|
33
|
+
SelfSDK.logger.info "asynchronously requested information to #{@to}:#{@d}"
|
34
|
+
end
|
35
|
+
res.first
|
27
36
|
end
|
28
37
|
|
29
38
|
def encrypt_message(message, recipient, recipient_device)
|
@@ -65,6 +74,17 @@ module SelfSDK
|
|
65
74
|
raise ::StandardError.new("must define this method")
|
66
75
|
end
|
67
76
|
|
77
|
+
def devices
|
78
|
+
return @client.devices(@to) if @intermediary.nil?
|
79
|
+
|
80
|
+
@client.devices(@intermediary)
|
81
|
+
end
|
82
|
+
|
83
|
+
def check_credits!
|
84
|
+
app = @client.app(@jwt.id)
|
85
|
+
raise "Your credits have expired, please log in to the developer portal and top up your account." if app[:paid_actions] == false
|
86
|
+
end
|
87
|
+
|
68
88
|
private
|
69
89
|
|
70
90
|
def get_payload(input)
|
@@ -85,17 +85,8 @@ module SelfSDK
|
|
85
85
|
|
86
86
|
protected
|
87
87
|
|
88
|
-
def proto
|
89
|
-
|
90
|
-
raise "Your credits have expired, please log in to the developer portal and top up your account." if app[:paid_actions] == false
|
91
|
-
|
92
|
-
devices = if @intermediary.nil?
|
93
|
-
@client.devices(@to)
|
94
|
-
else
|
95
|
-
@client.devices(@intermediary)
|
96
|
-
end
|
97
|
-
@to_device = devices.first
|
98
|
-
|
88
|
+
def proto(to_device)
|
89
|
+
@to_device = to_device
|
99
90
|
if @intermediary.nil?
|
100
91
|
recipient = "#{@to}:#{@to_device}"
|
101
92
|
ciphertext = encrypt_message(@jwt.prepare(body), @to, @to_device)
|
data/lib/messaging.rb
CHANGED
@@ -94,6 +94,7 @@ module SelfSDK
|
|
94
94
|
# @param type [string] message type
|
95
95
|
# @param request [hash] original message requesing information
|
96
96
|
def send_custom(recipient, request_body)
|
97
|
+
# TODO (adriacidre) this is sending the message to the first device only
|
97
98
|
@to_device = @client.devices(recipient).first
|
98
99
|
send_message msg = Msgproto::Message.new(
|
99
100
|
type: Msgproto::MsgType::MSG,
|
@@ -142,9 +143,11 @@ module SelfSDK
|
|
142
143
|
# Sends a message and waits for the response
|
143
144
|
#
|
144
145
|
# @params msg [Msgproto::Message] message object to be sent
|
145
|
-
def send_and_wait_for_response(
|
146
|
-
wait_for msg.id, original do
|
147
|
-
|
146
|
+
def send_and_wait_for_response(msgs, original)
|
147
|
+
wait_for msg.first.id, original do
|
148
|
+
msgs.each do |msg|
|
149
|
+
send_message msg
|
150
|
+
end
|
148
151
|
end
|
149
152
|
end
|
150
153
|
|