Sha256: 77120457f89f3c622e5b62dadaf16b7bd6376742f26d6c8becfde3bcb968f576

Contents?: true

Size: 589 Bytes

Versions: 1

Compression:

Stored size: 589 Bytes

Contents

require 'yaml'

module Clickatell
  
  # Used to parse HTTP responses returned from Clickatell API calls.
  class Response

    class << self
      PARSE_REGEX = /[A-Za-z0-9]+:.*?(?:(?=[A-Za-z0-9]+:)|$)/
      
      # Returns the HTTP response body data as a hash.
      def parse(http_response)
        return { 'OK' => 'session_id' } if API.test_mode
        
        if http_response.body.scan(/ERR/).any?
          raise Clickatell::API::Error.parse(http_response.body)
        end
        YAML.load(http_response.body.scan(PARSE_REGEX).join("\n"))
      end
      
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
clickatell-0.6.0 lib/clickatell/response.rb