plivo 0.3.19 → 4.20.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +14 -0
- data/.rspec +2 -0
- data/.travis.yml +11 -0
- data/AUTHORS.md +4 -0
- data/CHANGELOG.md +158 -0
- data/Gemfile +10 -0
- data/Jenkinsfile +7 -0
- data/LICENSE.txt +19 -0
- data/README.md +155 -24
- data/Rakefile +9 -0
- data/ci/config.yml +7 -0
- data/examples/conference_bridge.rb +108 -0
- data/examples/jwt.rb +32 -0
- data/examples/lookup.rb +24 -0
- data/examples/multi_party_call.rb +295 -0
- data/examples/phlos.rb +55 -0
- data/examples/regulatory_compliance.rb +167 -0
- data/lib/plivo/base/resource.rb +148 -0
- data/lib/plivo/base/resource_interface.rb +108 -0
- data/lib/plivo/base/response.rb +38 -0
- data/lib/plivo/base.rb +17 -0
- data/lib/plivo/base_client.rb +393 -0
- data/lib/plivo/exceptions.rb +50 -0
- data/lib/plivo/jwt.rb +120 -0
- data/lib/plivo/phlo_client.rb +29 -0
- data/lib/plivo/resources/accounts.rb +181 -0
- data/lib/plivo/resources/addresses.rb +302 -0
- data/lib/plivo/resources/applications.rb +258 -0
- data/lib/plivo/resources/call_feedback.rb +55 -0
- data/lib/plivo/resources/calls.rb +559 -0
- data/lib/plivo/resources/conferences.rb +367 -0
- data/lib/plivo/resources/endpoints.rb +132 -0
- data/lib/plivo/resources/identities.rb +319 -0
- data/lib/plivo/resources/lookup.rb +88 -0
- data/lib/plivo/resources/media.rb +97 -0
- data/lib/plivo/resources/messages.rb +215 -0
- data/lib/plivo/resources/multipartycalls.rb +554 -0
- data/lib/plivo/resources/nodes.rb +83 -0
- data/lib/plivo/resources/numbers.rb +319 -0
- data/lib/plivo/resources/phlo_member.rb +64 -0
- data/lib/plivo/resources/phlos.rb +55 -0
- data/lib/plivo/resources/powerpacks.rb +717 -0
- data/lib/plivo/resources/pricings.rb +43 -0
- data/lib/plivo/resources/recordings.rb +116 -0
- data/lib/plivo/resources/regulatory_compliance.rb +610 -0
- data/lib/plivo/resources.rb +25 -0
- data/lib/plivo/rest_client.rb +63 -0
- data/lib/plivo/utils.rb +294 -0
- data/lib/plivo/version.rb +3 -0
- data/lib/plivo/xml/break.rb +31 -0
- data/lib/plivo/xml/conference.rb +20 -0
- data/lib/plivo/xml/cont.rb +13 -0
- data/lib/plivo/xml/dial.rb +16 -0
- data/lib/plivo/xml/dtmf.rb +13 -0
- data/lib/plivo/xml/element.rb +106 -0
- data/lib/plivo/xml/emphasis.rb +17 -0
- data/lib/plivo/xml/get_digits.rb +15 -0
- data/lib/plivo/xml/get_input.rb +16 -0
- data/lib/plivo/xml/hangup.rb +12 -0
- data/lib/plivo/xml/lang.rb +29 -0
- data/lib/plivo/xml/message.rb +13 -0
- data/lib/plivo/xml/multipartycall.rb +188 -0
- data/lib/plivo/xml/number.rb +13 -0
- data/lib/plivo/xml/p.rb +12 -0
- data/lib/plivo/xml/phoneme.rb +20 -0
- data/lib/plivo/xml/play.rb +13 -0
- data/lib/plivo/xml/plivo_xml.rb +19 -0
- data/lib/plivo/xml/pre_answer.rb +12 -0
- data/lib/plivo/xml/prosody.rb +28 -0
- data/lib/plivo/xml/record.rb +17 -0
- data/lib/plivo/xml/redirect.rb +13 -0
- data/lib/plivo/xml/response.rb +21 -0
- data/lib/plivo/xml/s.rb +12 -0
- data/lib/plivo/xml/say_as.rb +24 -0
- data/lib/plivo/xml/speak.rb +28 -0
- data/lib/plivo/xml/sub.rb +16 -0
- data/lib/plivo/xml/user.rb +13 -0
- data/lib/plivo/xml/w.rb +17 -0
- data/lib/plivo/xml/wait.rb +12 -0
- data/lib/plivo/xml.rb +39 -0
- data/lib/plivo.rb +12 -815
- data/plivo.gemspec +44 -0
- metadata +181 -41
- data/ext/mkrf_conf.rb +0 -9
@@ -0,0 +1,215 @@
|
|
1
|
+
module Plivo
|
2
|
+
module Resources
|
3
|
+
include Plivo::Utils
|
4
|
+
class Message < Base::Resource
|
5
|
+
def initialize(client, options = nil)
|
6
|
+
@_name = 'Message'
|
7
|
+
@_identifier_string = 'message_uuid'
|
8
|
+
super
|
9
|
+
end
|
10
|
+
def listMedia()
|
11
|
+
perform_action_apiresponse('Media', 'GET')
|
12
|
+
end
|
13
|
+
|
14
|
+
def deleteMedia()
|
15
|
+
perform_action_apiresponse('Media', 'DELETE')
|
16
|
+
end
|
17
|
+
|
18
|
+
def to_s
|
19
|
+
{
|
20
|
+
api_id: @api_id,
|
21
|
+
error_code: @error_code,
|
22
|
+
from_number: @from_number,
|
23
|
+
message_direction: @message_direction,
|
24
|
+
message_state: @message_state,
|
25
|
+
message_time: @message_time,
|
26
|
+
message_type: @message_type,
|
27
|
+
message_uuid: @message_uuid,
|
28
|
+
resource_uri: @resource_uri,
|
29
|
+
to_number: @to_number,
|
30
|
+
total_amount: @total_amount,
|
31
|
+
total_rate: @total_rate,
|
32
|
+
powerpack_id: @powerpack_id,
|
33
|
+
units: @units
|
34
|
+
}.to_s
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
class MessagesInterface < Base::ResourceInterface
|
39
|
+
def initialize(client, resource_list_json = nil)
|
40
|
+
@_name = 'Message'
|
41
|
+
@_resource_type = Message
|
42
|
+
@_identifier_string = 'message_uuid'
|
43
|
+
super
|
44
|
+
end
|
45
|
+
|
46
|
+
# @param [String] message_uuid
|
47
|
+
def get(message_uuid)
|
48
|
+
perform_get(message_uuid)
|
49
|
+
end
|
50
|
+
|
51
|
+
# @param [String] src
|
52
|
+
# @param [Array] dst
|
53
|
+
# @param [String] text
|
54
|
+
# @param [Hash] options
|
55
|
+
# @option options [String] :type The type of message. Should be `sms` or `mms`. Defaults to `sms`.
|
56
|
+
# @option options [String] :url The URL to which with the status of the message is sent. The following parameters are sent to the URL:
|
57
|
+
# - To - Phone number of the recipient
|
58
|
+
# - From - Phone number of the sender
|
59
|
+
# - Status - Status of the message including "queued", "sent", "failed", "delivered", "undelivered" or "rejected"
|
60
|
+
# - MessageUUID - The unique ID for the message
|
61
|
+
# - ParentMessageUUID - ID of the parent message (see notes about long SMS below)
|
62
|
+
# - PartInfo - Specifies the sequence of the message (useful for long messages split into multiple text messages; see notes about long SMS below)
|
63
|
+
# - TotalRate - Total rate per sms
|
64
|
+
# - TotalAmount - Total cost of sending the sms (TotalRate * Units)
|
65
|
+
# - Units - Number of units into which a long SMS was split
|
66
|
+
# - MCC - Mobile Country Code (see here {https://en.wikipedia.org/wiki/Mobile_country_code} for more details)
|
67
|
+
# - MNC - Mobile Network Code (see here {https://en.wikipedia.org/wiki/Mobile_country_code} for more details)
|
68
|
+
# - ErrorCode - Delivery Response code returned by the carrier attempting the delivery. See Supported error codes {https://www.plivo.com/docs/api/message/#standard-plivo-error-codes}.
|
69
|
+
# @option options [String] :method The method used to call the url. Defaults to POST.
|
70
|
+
# @option options [String] :log If set to false, the content of this message will not be logged on the Plivo infrastructure and the dst value will be masked (e.g., 141XXXXX528). Default is set to true.
|
71
|
+
# @option options [String] :trackable set to false
|
72
|
+
#@option options[List]: media_urls Minimum one media url should be present in Media urls list to send mms. Maximum allowd 10 media urls inside the list (e.g, media_urls : ['https//example.com/test.jpg', 'https://example.com/abcd.gif'])
|
73
|
+
#@option options[List]: media_ids Minimum one media ids should be present in Media ids list to send mms. Maximum allowd 10 media ids inside the list (e.g, media_ids : ['1fs211ba-355b-11ea-bbc9-02121c1190q7'])
|
74
|
+
|
75
|
+
def create(src, dst, text = nil, options = nil, powerpack_uuid = nil)
|
76
|
+
valid_param?(:src, src, [Integer, String, Symbol], false)
|
77
|
+
valid_param?(:text, text, [String, Symbol], false)
|
78
|
+
valid_param?(:dst, dst, Array, true)
|
79
|
+
valid_param?(:powerpack_uuid, powerpack_uuid, [String, Symbol], false)
|
80
|
+
dst.each do |dst_num|
|
81
|
+
valid_param?(:dst_num, dst_num, [Integer, String, Symbol], true)
|
82
|
+
end
|
83
|
+
|
84
|
+
if dst.include? src
|
85
|
+
raise InvalidRequestError, 'src and dst cannot be same'
|
86
|
+
end
|
87
|
+
|
88
|
+
if src.nil? && powerpack_uuid.nil?
|
89
|
+
raise InvalidRequestError, 'src and powerpack uuid both cannot be nil'
|
90
|
+
end
|
91
|
+
|
92
|
+
if !src.nil? && !powerpack_uuid.nil?
|
93
|
+
raise InvalidRequestError, 'src and powerpack uuid both cannot be present'
|
94
|
+
end
|
95
|
+
|
96
|
+
params = {
|
97
|
+
src: src,
|
98
|
+
dst: dst.join('<'),
|
99
|
+
text: text,
|
100
|
+
powerpack_uuid: powerpack_uuid
|
101
|
+
}
|
102
|
+
|
103
|
+
return perform_create(params) if options.nil?
|
104
|
+
valid_param?(:options, options, Hash, true)
|
105
|
+
|
106
|
+
if options.key?(:type) &&
|
107
|
+
valid_param?(:type, options[:type], String, true, ['sms', 'mms'])
|
108
|
+
params[:type] = options[:type]
|
109
|
+
end
|
110
|
+
|
111
|
+
if options.key?(:url) && valid_param?(:url, options[:url], String, true)
|
112
|
+
params[:url] = options[:url]
|
113
|
+
if options.key?(:method) &&
|
114
|
+
valid_param?(:method, options[:method], String, true, %w[POST GET])
|
115
|
+
params[:method] = options[:method]
|
116
|
+
else
|
117
|
+
params[:method] = 'POST'
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
if options.key?(:log) &&
|
122
|
+
valid_param?(:log, options[:log], [TrueClass, FalseClass], true)
|
123
|
+
params[:log] = options[:log]
|
124
|
+
end
|
125
|
+
|
126
|
+
if options.key?(:trackable) &&
|
127
|
+
valid_param?(:trackable, options[:trackable], [TrueClass, FalseClass], true)
|
128
|
+
params[:trackable] = options[:trackable]
|
129
|
+
end
|
130
|
+
|
131
|
+
if options.key?(:media_urls) &&
|
132
|
+
valid_param?(:media_urls, options[:media_urls], Array, true)
|
133
|
+
params[:media_urls] = options[:media_urls]
|
134
|
+
end
|
135
|
+
if options.key?(:media_ids) &&
|
136
|
+
valid_param?(:media_ids, options[:media_ids], Array, true)
|
137
|
+
params[:media_ids] = options[:media_ids]
|
138
|
+
end
|
139
|
+
perform_create(params)
|
140
|
+
end
|
141
|
+
|
142
|
+
# @param [Hash] options
|
143
|
+
# @option options [String] :subaccount The id of the subaccount, if message details of the subaccount is needed.
|
144
|
+
# @option options [String] :message_direction Filter the results by message direction. The valid inputs are inbound and outbound.
|
145
|
+
# @option options [String] :message_time Filter out messages according to the time of completion. The filter can be used in the following five forms:
|
146
|
+
# - message_time: The format expected is YYYY-MM-DD HH:MM[:ss[.uuuuuu]]. Eg:- To get all messages that were sent/received at 2012-03-21 11:47[:30], use message_time=2012-03-21 11:47[:30]
|
147
|
+
# - message_time\__gt: gt stands for greater than. The format expected is YYYY-MM-DD HH:MM[:ss[.uuuuuu]]. Eg:- To get all messages that were sent/received after 2012-03-21 11:47, use message_time\__gt=2012-03-21 11:47
|
148
|
+
# - message_time\__gte: gte stands for greater than or equal. The format expected is YYYY-MM-DD HH:MM[:ss[.uuuuuu]]. Eg:- To get all messages that were sent/received after or exactly at 2012-03-21 11:47[:30], use message_time\__gte=2012-03-21 11:47[:30]
|
149
|
+
# - message_time\__lt: lt stands for lesser than. The format expected is YYYY-MM-DD HH:MM[:ss[.uuuuuu]]. Eg:- To get all messages that were sent/received before 2012-03-21 11:47, use message_time\__lt=2012-03-21 11:47
|
150
|
+
# - message_time\__lte: lte stands for lesser than or equal. The format expected is YYYY-MM-DD HH:MM[:ss[.uuuuuu]]. Eg:- To get all messages that were sent/received before or exactly at 2012-03-21 11:47[:30], use message_time\__lte=2012-03-21 11:47[:30]
|
151
|
+
# - Note: The above filters can be combined to get messages that were sent/received in a particular time range. The timestamps need to be UTC timestamps.
|
152
|
+
# @option options [String] :message_state Status value of the message, is one of "queued", "sent", "failed", "delivered", "undelivered" or "rejected"
|
153
|
+
# @option options [Int] :limit Used to display the number of results per page. The maximum number of results that can be fetched is 20.
|
154
|
+
# @option options [Int] :offset Denotes the number of value items by which the results should be offset. Eg:- If the result contains a 1000 values and limit is set to 10 and offset is set to 705, then values 706 through 715 are displayed in the results. This parameter is also used for pagination of the results.
|
155
|
+
# @option options [String] :error_code Delivery Response code returned by the carrier attempting the delivery. See Supported error codes {https://www.plivo.com/docs/api/message/#standard-plivo-error-codes}.
|
156
|
+
# @option options [String] :powerpack_id Filter the results by powerpack id.
|
157
|
+
def list(options = nil)
|
158
|
+
return perform_list if options.nil?
|
159
|
+
valid_param?(:options, options, Hash, true)
|
160
|
+
|
161
|
+
params = {}
|
162
|
+
params_expected = %i[
|
163
|
+
subaccount message_time message_time__gt message_time__gte
|
164
|
+
message_time__lt message_time__lte error_code powerpack_id
|
165
|
+
]
|
166
|
+
params_expected.each do |param|
|
167
|
+
if options.key?(param) &&
|
168
|
+
valid_param?(param, options[param], [String, Symbol], true)
|
169
|
+
params[param] = options[param]
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
%i[offset limit].each do |param|
|
174
|
+
if options.key?(param) &&
|
175
|
+
valid_param?(param, options[param], [Integer, Integer], true)
|
176
|
+
params[param] = options[param]
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
if options.key?(:message_direction) &&
|
181
|
+
valid_param?(:message_direction, options[:message_direction],
|
182
|
+
[String, Symbol], true, %w[inbound outbound])
|
183
|
+
params[:message_direction] = options[:message_direction]
|
184
|
+
end
|
185
|
+
|
186
|
+
if options.key?(:message_state) &&
|
187
|
+
valid_param?(:message_state, options[:message_state],
|
188
|
+
[String, Symbol], true, %w[queued sent failed delivered
|
189
|
+
undelivered rejected])
|
190
|
+
params[:message_state] = options[:message_state]
|
191
|
+
end
|
192
|
+
|
193
|
+
if options.key?(:limit) &&
|
194
|
+
(options[:limit] > 20 || options[:limit] <= 0)
|
195
|
+
raise_invalid_request('The maximum number of results that can be '\
|
196
|
+
"fetched is 20. limit can't be more than 20 or less than 1")
|
197
|
+
end
|
198
|
+
|
199
|
+
raise_invalid_request("Offset can't be negative") if options.key?(:offset) && options[:offset] < 0
|
200
|
+
|
201
|
+
perform_list(params)
|
202
|
+
end
|
203
|
+
|
204
|
+
def each
|
205
|
+
offset = 0
|
206
|
+
loop do
|
207
|
+
message_list = list(offset: offset)
|
208
|
+
message_list[:objects].each { |message| yield message }
|
209
|
+
offset += 20
|
210
|
+
return unless message_list.length == 20
|
211
|
+
end
|
212
|
+
end
|
213
|
+
end
|
214
|
+
end
|
215
|
+
end
|