istox 0.1.115 → 0.1.116

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: cf656e8345ac7129697ea2a2366a417de683989f09b627fb4d71b062678fce32
4
- data.tar.gz: 959ca575d5ffa3044965cbd1224e7174cd961db3d5f6f5eb5892441cc9db124f
3
+ metadata.gz: f29d1b7e68de95eeefa9c2b9b6360d12df362c84c4c237157e57bda9bd93b582
4
+ data.tar.gz: a9f0a6349a081d0b3628cc200a5dd44e50b4a4908af8b1de8f1ee3b3f71f9d6f
5
5
  SHA512:
6
- metadata.gz: 471dd7ceef7f24b765837cd0a9144c22b00cd22a422df83002890ab4706d22b502b681f161fbe1350faca263a7f95e2965438f2381142d183bc46b5cbe7e7c66
7
- data.tar.gz: 695beb8e1b6b9d2de1a5c57ef6022e6d52d41bd1f890a12598fe9ef3a28df24cbbae6ce56d9dc9799c2dd4fa122d344a3d13966c36a0b0db96eac6d25b8d8e44
6
+ metadata.gz: aa32e45a7a16f59f6f2d65851eb403f277ff30d27bf39aaa574550725f811360f18e0fb40b5c4702bb6bce7b5762b9e6e73dffd8c89e97c9f757a7fc3e11c61e
7
+ data.tar.gz: 6b8cb8ab35f24ff0bb9701c8215ffefc6ed098127ed71434fec663488cc2debba2f72fb2d2331fa3fcbc24ad16c1619585ace9ca805fbc5d7cbd85b4631208fb
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- istox (0.1.114)
4
+ istox (0.1.115)
5
5
  awesome_print
6
6
  binding_of_caller
7
7
  bunny (>= 2.12.0)
@@ -95,7 +95,7 @@ GEM
95
95
  ffi (1.11.3)
96
96
  globalid (0.4.2)
97
97
  activesupport (>= 4.2.0)
98
- google-protobuf (3.11.2-universal-darwin)
98
+ google-protobuf (3.11.2)
99
99
  googleapis-common-protos-types (1.0.4)
100
100
  google-protobuf (~> 3.0)
101
101
  graphlient (0.3.7)
@@ -106,7 +106,7 @@ GEM
106
106
  graphql-client (0.16.0)
107
107
  activesupport (>= 3.0)
108
108
  graphql (~> 1.8)
109
- grpc (1.26.0-universal-darwin)
109
+ grpc (1.26.0)
110
110
  google-protobuf (~> 3.8)
111
111
  googleapis-common-protos-types (~> 1.0)
112
112
  grpc-tools (1.26.0)
@@ -24,7 +24,7 @@ module Istox
24
24
  require 'istox/helpers/grpc_client'
25
25
  require 'istox/helpers/graphql_client'
26
26
  require 'istox/helpers/gruf_listener_hook'
27
- require 'istox/helpers/message_service'
27
+ require 'istox/helpers/messaging'
28
28
  require 'istox/helpers/blockchain_service'
29
29
  require 'istox/helpers/f_math'
30
30
  require 'istox/helpers/my_open_struct'
@@ -0,0 +1,111 @@
1
+ module Istox
2
+ class Messaging
3
+ class << self
4
+ # sms, numbers can be an array of multiple phone numbers or just string of single phone number
5
+ def sms(numbers, content, subject: nil)
6
+ targets = []
7
+ if numbers.is_a?(Array)
8
+ targets = numbers
9
+ else
10
+ targets << numbers
11
+ end
12
+
13
+ targets = targets.compact
14
+
15
+ raise ArgumentError, 'Target numbers cannot be empty or nil' if targets.empty?
16
+ raise ArgumentError, 'SMS message content cannot be empty' if content.blank?
17
+
18
+ ::Istox::Publisher.manual_publish(
19
+ exchange: 'message',
20
+ exchange_type: 'direct',
21
+ routing_key: 'sms.message',
22
+ message: {
23
+ type: 'SEND_SMS',
24
+ data: {
25
+ to: targets,
26
+ subject: subject || 'Message from iSTOX',
27
+ body: content
28
+ }
29
+ }
30
+ )
31
+ end
32
+
33
+ # sample template data, it should be an array
34
+ # [{
35
+ # mobile: mobile,
36
+ # istoxP1: auth.first_name,
37
+ # <more other sample template attributes>: <other sample template data>,
38
+ # }]
39
+ def sms_template(template_name, template_data_arr)
40
+ raise ArgumentError, 'Template name and template data arr cannot be empty' if template_name.blank? || template_data_arr.nil? ||
41
+ template_data_arr.empty?
42
+
43
+ ::Istox::Publisher.manual_publish(
44
+ exchange: 'message',
45
+ exchange_type: 'direct',
46
+ routing_key: 'sms.message',
47
+ message: {
48
+ type: 'SEND_SMS_TEMPLATE',
49
+ data: {
50
+ template_name: template_name,
51
+ template_data_arr: template_data_arr
52
+ }
53
+ }
54
+ )
55
+ end
56
+
57
+ # email, email can be an array of multiple emails or just string of single email address
58
+ def email(emails, subject:, content:)
59
+ targets = []
60
+ if emails.is_a?(Array)
61
+ targets = emails
62
+ else
63
+ targets << emails
64
+ end
65
+
66
+ targets = targets.compact
67
+
68
+ raise ArgumentError, 'Target emails cannot be empty or nil' if targets.empty?
69
+ raise ArgumentError, 'Email subject and content cannot be empty' if content.blank? || subject.blank?
70
+
71
+ ::Istox::Publisher.manual_publish(
72
+ exchange: 'message',
73
+ exchange_type: 'direct',
74
+ routing_key: 'email.message',
75
+ message: {
76
+ type: 'SEND_EMAIL',
77
+ data: {
78
+ to: targets,
79
+ subject: subject,
80
+ body: content
81
+ }
82
+ }
83
+ )
84
+ end
85
+
86
+ # sample template data, it should be an array
87
+ # [{
88
+ # email: email,
89
+ # istoxP1: auth.first_name,
90
+ # <more other sample template attributes>: <other sample template data>,
91
+ # }]
92
+ def email_template(template_name, template_data_arr)
93
+ raise ArgumentError, 'Template name and template data arr cannot be empty' if template_name.blank? || template_data_arr.nil? ||
94
+ template_data_arr.empty?
95
+
96
+ ::Istox::Publisher.manual_publish(
97
+ exchange: 'message',
98
+ exchange_type: 'direct',
99
+ routing_key: 'email.message',
100
+ message: {
101
+ type: 'SEND_EMAIL_TEMPLATE',
102
+ data: {
103
+ template_name: template_name,
104
+ template_data_arr: template_data_arr
105
+ }
106
+ }
107
+ )
108
+ end
109
+ end
110
+ end
111
+ end
@@ -85,7 +85,7 @@ module Istox
85
85
  !exceeded?(subject, options)
86
86
  end
87
87
 
88
- # Check if next execution will cause the rate limit to be exceeded, raise error if exceeded
88
+ # Raise error if exceeded the limit
89
89
  #
90
90
  # @param [String] subject Subject to check
91
91
  # @param [Hash] options Options hash
@@ -97,7 +97,7 @@ module Istox
97
97
  add(subject)
98
98
  end
99
99
 
100
- # Check if next execution will cause the rate limit to be exceeded, return false if exceeded, else return true
100
+ # Return false if exceeded the limit, else return true
101
101
  #
102
102
  # @param [String] subject Subject to check
103
103
  # @param [Hash] options Options hash
@@ -1,3 +1,3 @@
1
1
  module Istox
2
- VERSION = '0.1.115'.freeze
2
+ VERSION = '0.1.116'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: istox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.115
4
+ version: 0.1.116
5
5
  platform: ruby
6
6
  authors:
7
7
  - Siong Leng
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-01-06 00:00:00.000000000 Z
11
+ date: 2020-01-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: awesome_print
@@ -383,7 +383,7 @@ files:
383
383
  - lib/istox/helpers/grpc_client.rb
384
384
  - lib/istox/helpers/gruf_listener_hook.rb
385
385
  - lib/istox/helpers/logger.rb
386
- - lib/istox/helpers/message_service.rb
386
+ - lib/istox/helpers/messaging.rb
387
387
  - lib/istox/helpers/my_open_struct.rb
388
388
  - lib/istox/helpers/order_book_price_time.rb
389
389
  - lib/istox/helpers/order_book_prorate.rb
@@ -1,51 +0,0 @@
1
- module Istox
2
- class MessageService
3
- class << self
4
- def send_sms(number, subject, content)
5
- publish('sms', data: {
6
- to: number,
7
- subject: subject,
8
- body: content
9
- },
10
- type: __method__.to_s.upcase!)
11
- end
12
-
13
- def send_sms_template(number, template)
14
- publish('sms', data: {
15
- to: number,
16
- template: template
17
- },
18
- type: __method__.to_s.upcase!)
19
- end
20
-
21
- def send_email(email, subject, content)
22
- publish('email', data: {
23
- to: email,
24
- subject: subject,
25
- type: 'text/plain',
26
- body: content
27
- },
28
- type: __method__.to_s.upcase!)
29
- end
30
-
31
- def send_email_template(email, template)
32
- publish('email', data: {
33
- to: email,
34
- template: template
35
- },
36
- type: __method__.to_s.upcase!)
37
- end
38
-
39
- private
40
-
41
- def publish(type, payload)
42
- ::Istox::Publisher.manual_publish(
43
- exchange: 'message',
44
- exchange_type: 'direct',
45
- routing_key: "#{type}.message",
46
- message: payload
47
- )
48
- end
49
- end
50
- end
51
- end