class ActionTexter::TwilioResponse
Twilio response
Attributes
cost[R]
TODO: Some of these should be moved to Response if they are common enough.
original[R]
TODO: Some of these should be moved to Response if they are common enough.
parts_count[R]
TODO: Some of these should be moved to Response if they are common enough.
reference[R]
TODO: Some of these should be moved to Response if they are common enough.
Private Instance Methods
process_response(raw)
click to toggle source
# File lib/action_texter/twilio.rb, line 17 def process_response(raw) @original = JSON.parse(raw) if @original["error_code"].blank? && @original["code"].blank? @success = true @reference = @original["sid"] @parts_count = @original["num_segments"] # The cost is nil because the message is, as of now, queued. To get the cost we need to GET @original["uri"] # for message details, but that assumes that the message is sent by that time. # The proper way, a callback, is way out of the scope of this gem. @cost = nil else @success = false # Responses take two shapes. Either they have a status like "queued", and they have an "error_code" field # (which I've never seen filled), or they return a status like "400", with a "code" and a "message" if @original.has_key?("code") @error_message = @original["message"] elsif @original.has_key?("error_message") @error_message = @original["error_message"] end end end