lib/action_texter/twilio.rb
# TODO: Some of these should be moved to Response if they are common enough.
Some of these should be moved to Response if they are common enough.
Some of these should be moved to Response if they are common enough .
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"]
      @cost = nil
    else
      @success = false
      if @original.has_key?("code")
        @error_message = @original["message"]
      elsif @original.has_key?("error_message")
        @error_message = @original["error_message"]
      end
    end
  end
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" ] @cost = nil else @success = false if @original . has_key? ( "code" ) @error_message = @original [ "message" ] elsif @original . has_key? ( "error_message" ) @error_message = @original [ "error_message" ] end end end
TODO: Some of these should be moved to Response if they are common enough.
TODO : Some of these should be moved to Response if they are common enough .
# 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. # 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"
raw