Class: Plivo::Resources::MessagesInterface
- Inherits:
-
Base::ResourceInterface
- Object
- Base::ResourceInterface
- Plivo::Resources::MessagesInterface
- Defined in:
- lib/plivo/resources/messages.rb
Instance Method Summary collapse
- #create(src, dst, text, 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.
31 32 33 34 35 36 |
# File 'lib/plivo/resources/messages.rb', line 31 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, options = nil, powerpack_uuid = nil) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 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 |
# File 'lib/plivo/resources/messages.rb', line 63 def create(src, dst, text, = nil, powerpack_uuid = nil) valid_param?(:src, src, [Integer, String, Symbol], false) valid_param?(:text, text, [String, Symbol], true) 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') 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 perform_create(params) end |
#each ⇒ Object
177 178 179 180 181 182 183 184 185 |
# File 'lib/plivo/resources/messages.rb', line 177 def each offset = 0 loop do = list(offset: offset) [:objects].each { || yield } offset += 20 return unless .length == 20 end end |
#get(message_uuid) ⇒ Object
39 40 41 |
# File 'lib/plivo/resources/messages.rb', line 39 def get() perform_get() end |
#list(options = nil) ⇒ Object
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/plivo/resources/messages.rb', line 130 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 |