sms_broker 1.0.3 → 1.0.4

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
  SHA1:
3
- metadata.gz: 6a4b480fcb3af10834e7dcceab54bb7a11a638fa
4
- data.tar.gz: c092ef5cc010867c9defb38a62c4597546d057da
3
+ metadata.gz: ea414f2b1fa82dce9c8c0d1d3e4ecf6fe3ea992c
4
+ data.tar.gz: c32329c461796e15dbcc731b41d41663ae2cc144
5
5
  SHA512:
6
- metadata.gz: 8572edd992371e259eac5aec974a67b346c6f231fd9ca9965b8f9dfe529837b744fbe3981f3ded4de331b6fa4b75e5c92cd478f372a62718620ecee02a7292ff
7
- data.tar.gz: 1d32ba4504a1c751ec8e341a57f945166080116459209aecfb8df1435466e9ddb03b6c66521be5111b8b9e5748af45f68103ddcef79f63960eed2cf588f8aa64
6
+ metadata.gz: 93756cbd914e72958c4f6b4956582582640627b248d645aab289854a0ea7f8f4aacc08e18779d447584291711ae0a24b7ff600d19ae3e38bb54f1abbd707dcaa
7
+ data.tar.gz: 99121ad5099a3505d825b2db0b33f184c3197fc97bacb4e793c509a9d06f7dc3d58269ce876e81f52a0fad50c4da87fd451e8b9c74903bcc6f0053f59770c40d
@@ -24,7 +24,7 @@ module SmsBroker
24
24
  def send_voice_message(message)
25
25
  response = client.initiate_tts_call \
26
26
  text: message[:text],
27
- from: message[:from],
27
+ from: message[:from],
28
28
  to: serialize_to_number(message[:to]),
29
29
  lg: message[:lang]
30
30
 
@@ -1,3 +1,3 @@
1
1
  module SmsBroker
2
- VERSION = '1.0.3'.freeze
2
+ VERSION = '1.0.4'.freeze
3
3
  end
@@ -1,7 +1,8 @@
1
1
  module SmsBroker
2
2
  class VoiceMessageSender
3
3
  attr_reader :client,
4
- :errors
4
+ :errors,
5
+ :voice_message_text
5
6
 
6
7
  def initialize(client)
7
8
  @client = client
@@ -45,13 +46,17 @@ module SmsBroker
45
46
  schema = {
46
47
  message: Compel.string.required.max_length(140),
47
48
  to: Compel.string.required,
48
- lang: Compel.string
49
+ lang: Compel.string,
50
+ rate: Compel.integer,
51
+ repeat: Compel.integer
49
52
  }
50
53
 
51
54
  object = {
52
55
  message: @voice_message_text,
53
56
  to: @voice_message_to,
54
- lang: options[:lang]
57
+ lang: options[:lang],
58
+ rate: options[:rate],
59
+ repeat: options[:repeat]
55
60
  }
56
61
 
57
62
  result = Compel.hash.keys(schema).validate(object)
@@ -61,9 +66,9 @@ module SmsBroker
61
66
  result.valid?
62
67
  end
63
68
 
64
- private
65
-
66
69
  def build_message(from = :sender_id)
70
+ client.is_a?(SmsBroker::Client::Nexmo) && tag_message
71
+
67
72
  {
68
73
  text: @voice_message_text,
69
74
  from: get_sender(from),
@@ -71,6 +76,8 @@ module SmsBroker
71
76
  }.merge!(@voice_message_options || {})
72
77
  end
73
78
 
79
+ private
80
+
74
81
  def get_sender(from)
75
82
  if client.sender_id && from == :sender_id
76
83
  client.sender_id
@@ -86,5 +93,23 @@ module SmsBroker
86
93
  response.invalid_sender_id? &&
87
94
  client.sender_id
88
95
  end
96
+
97
+ def tag_message
98
+ return unless @voice_message_options
99
+
100
+ @voice_message_options[:rate] && inject_rate
101
+ @voice_message_options[:repeat] && inject_repeat
102
+ end
103
+
104
+ def inject_rate
105
+ rate = @voice_message_options[:rate]
106
+ @voice_message_text = \
107
+ "<prosody rate='#{rate}%'>" + @voice_message_text + '</prosody>'
108
+ end
109
+
110
+ def inject_repeat
111
+ @voice_message_text += "<break time='1s'/>"
112
+ @voice_message_text *= @voice_message_options[:repeat]
113
+ end
89
114
  end
90
115
  end
@@ -39,6 +39,32 @@ describe SmsBroker do
39
39
  end
40
40
  end
41
41
 
42
+ context 'with rate and repeat set', :focus do
43
+ it 'should send voice message with success' do
44
+ SmsBroker.setup do |config|
45
+ config.nexmo_setup \
46
+ phone_number: from_phone,
47
+ sender_id: sender_id,
48
+ secret: api_secret,
49
+ key: api_key
50
+ end
51
+
52
+ sms_broker = SmsBroker
53
+ .voice_message(voice_message)
54
+ .to(to_phone)
55
+ .with(lang: lang, rate: 20, repeat: 3)
56
+ sms_broker.build_message
57
+ messages = \
58
+ sms_broker.voice_message_text.split("<break time='1s'/>")
59
+
60
+ expect(messages.count).to eq(3)
61
+ messages.each do |message|
62
+ expect(message).to eq("<prosody rate='20%'>Hello World</prosody>")
63
+ end
64
+ end
65
+ end
66
+
67
+
42
68
  context 'invalid' do
43
69
  it 'should return error for invalid credentials' do
44
70
  SmsBroker.setup do |config|
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sms_broker
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Streetbees Dev Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-11-07 00:00:00.000000000 Z
11
+ date: 2016-11-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nexmo