Class: Plivo::Resources::MessagesInterface
- Inherits:
-
Base::ResourceInterface
- Object
- Base::ResourceInterface
- Plivo::Resources::MessagesInterface
- Defined in:
- lib/plivo/resources/messages.rb
Constant Summary
Constants included from Utils
Instance Method Summary collapse
- #create(src, dst, text = nil, options = nil, powerpack_uuid = nil) ⇒ Object
- #each ⇒ Object
- #get(message_uuid) ⇒ Object
-
#initialize(client, resource_list_json = nil) ⇒ MessagesInterface
constructor
A new instance of MessagesInterface.
- #list(options = nil) ⇒ Object
Methods included from Utils
expected_type?, expected_value?, raise_invalid_request, valid_account?, valid_mainaccount?, valid_param?, valid_signature?, valid_subaccount?
Constructor Details
#initialize(client, resource_list_json = nil) ⇒ MessagesInterface
Returns a new instance of MessagesInterface.
42 43 44 45 46 47 |
# File 'lib/plivo/resources/messages.rb', line 42 def initialize(client, resource_list_json = nil) @_name = 'Message' @_resource_type = Message @_identifier_string = 'message_uuid' super end |
Instance Method Details
#create(src, dst, text = nil, options = nil, powerpack_uuid = nil) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/plivo/resources/messages.rb', line 77 def create(src, dst, text = nil, = nil, powerpack_uuid = nil) valid_param?(:src, src, [Integer, String, Symbol], false) valid_param?(:text, text, [String, Symbol], false) valid_param?(:dst, dst, Array, true) valid_param?(:powerpack_uuid, powerpack_uuid, [String, Symbol], false) dst.each do |dst_num| valid_param?(:dst_num, dst_num, [Integer, String, Symbol], true) end if dst.include? src raise InvalidRequestError, 'src and dst cannot be same' end if src.nil? && powerpack_uuid.nil? raise InvalidRequestError, 'src and powerpack uuid both cannot be nil' end if !src.nil? && !powerpack_uuid.nil? raise InvalidRequestError, 'src and powerpack uuid both cannot be present' end params = { src: src, dst: dst.join('<'), text: text, powerpack_uuid: powerpack_uuid } return perform_create(params) if .nil? valid_param?(:options, , Hash, true) if .key?(:type) && valid_param?(:type, [:type], String, true, ['sms', 'mms']) params[:type] = [:type] end if .key?(:url) && valid_param?(:url, [:url], String, true) params[:url] = [:url] if .key?(:method) && valid_param?(:method, [:method], String, true, %w[POST GET]) params[:method] = [:method] else params[:method] = 'POST' end end if .key?(:log) && valid_param?(:log, [:log], [TrueClass, FalseClass], true) params[:log] = [:log] end if .key?(:trackable) && valid_param?(:trackable, [:trackable], [TrueClass, FalseClass], true) params[:trackable] = [:trackable] end if .key?(:media_urls) && valid_param?(:media_urls, [:media_urls], Array, true) params[:media_urls] = [:media_urls] end perform_create(params) end |
#each ⇒ Object
202 203 204 205 206 207 208 209 210 |
# File 'lib/plivo/resources/messages.rb', line 202 def each offset = 0 loop do = list(offset: offset) [:objects].each { || yield } offset += 20 return unless .length == 20 end end |
#get(message_uuid) ⇒ Object
50 51 52 |
# File 'lib/plivo/resources/messages.rb', line 50 def get() perform_get() end |
#list(options = nil) ⇒ Object
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/plivo/resources/messages.rb', line 155 def list( = nil) return perform_list if .nil? valid_param?(:options, , Hash, true) params = {} params_expected = i[ subaccount error_code ] params_expected.each do |param| if .key?(param) && valid_param?(param, [param], [String, Symbol], true) params[param] = [param] end end i[offset limit].each do |param| if .key?(param) && valid_param?(param, [param], [Integer, Integer], true) params[param] = [param] end end if .key?(:message_direction) && valid_param?(:message_direction, [:message_direction], [String, Symbol], true, %w[inbound outbound]) params[:message_direction] = [:message_direction] end if .key?(:message_state) && valid_param?(:message_state, [:message_state], [String, Symbol], true, %w[queued sent failed delivered undelivered rejected]) params[:message_state] = [:message_state] end if .key?(:limit) && ([:limit] > 20 || [:limit] <= 0) raise_invalid_request('The maximum number of results that can be '\ "fetched is 20. limit can't be more than 20 or less than 1") end raise_invalid_request("Offset can't be negative") if .key?(:offset) && [:offset] < 0 perform_list(params) end |