Sha256: 0f2f0b8c345a65354cae2c23e0931e62b8f69b8ea3af53c9ba852ea2b54016cf

Contents?: true

Size: 905 Bytes

Versions: 4

Compression:

Stored size: 905 Bytes

Contents

module TwitterAuth
  module Dispatcher
    module Shared
      def append_extension_to(path)
        path, query_string = *(path.split("?"))
        path << '.json' unless path.match(/\.(:?xml|json)\z/i)
        "#{path}#{"?#{query_string}" if query_string}"
      end

      def handle_response(response)
        case response
        when Net::HTTPOK 
          begin
            JSON.parse(response.body)
          rescue JSON::ParserError
            response.body
          end
        else
          message = begin
            JSON.parse(response.body)['error']
          rescue JSON::ParserError
            if match = response.body.match(/<error>(.*)<\/error>/)
              match[1]
            else
              'An error occurred processing your Twitter request.'
            end
          end

          raise TwitterAuth::Dispatcher::Error, message
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
mbleigh-twitter-auth-0.1.12 lib/twitter_auth/dispatcher/shared.rb
mbleigh-twitter-auth-0.1.13 lib/twitter_auth/dispatcher/shared.rb
twitter-auth-0.1.13 lib/twitter_auth/dispatcher/shared.rb
twitter-auth-0.1.12 lib/twitter_auth/dispatcher/shared.rb