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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d9d49a7cde97a88c5c56c6233b964b72c66d9b046b2521cac189475646be55f2
4
- data.tar.gz: 600b68b342c99830aba799eb13da1650d02cecd4bd824aeb38f51c768c77a13a
3
+ metadata.gz: 0c59c2a25ba8f895e9a1820e6cf8072c219680ccfc763582f9b8761903ae0f3f
4
+ data.tar.gz: 9ca32b859e6f0feeddf5c5e87b38309e691f7459e60d3a9b281f1396dc4bc998
5
5
  SHA512:
6
- metadata.gz: 3c7989e1245b7b2993e4c5784373d05c25870a1e4e695da1a49571e5ada8d779fb90c5d5f37fd9174e3cef51b054655c9efdb8470f573a98bdfa10ea950d1d8c
7
- data.tar.gz: 8e30b0e94b496efdc80f6dc4d5bdb655e8236ff098880bf28f46bc8433f08182fe7bfca3942abe893cfd698f8be720ae598611ae24ea6c98b4adfac2db1c9c5b
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}:#{@to_device}",
50
- ciphertext: encrypt_message(@jwt.prepare(body), @to, @to_device))
45
+ recipient: "#{@to}:#{to_device}",
46
+ ciphertext: encrypt_message(@jwt.prepare(body), @to, to_device))
51
47
  end
52
48
 
53
49
  end
@@ -15,15 +15,24 @@ module SelfSDK
15
15
  end
16
16
 
17
17
  def request
18
- res = @messaging.send_and_wait_for_response(proto, self)
19
- SelfSDK.logger.info "synchronously messaging to #{@to}:#{@to_device}"
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
- res = @messaging.send_message proto
25
- SelfSDK.logger.info "asynchronously requested information to #{@to}:#{@to_device}"
26
- res
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
- app = @client.app(@jwt.id)
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)
@@ -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(msg, original)
146
- wait_for msg.id, original do
147
- send_message msg
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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: selfsdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.144
4
+ version: 0.0.145
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aldgate Ventures