Sha256: 06e9a6a6c02bab9e3b15f96fd91b1f9d2b24b020345137b368ef6e0925600385

Contents?: true

Size: 1.12 KB

Versions: 15

Compression:

Stored size: 1.12 KB

Contents

module TwitterAuth
  module Dispatcher
    module Shared
      def post!(status)
        self.post('/statuses/update.json', :status => status)
      end

      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
        when Net::HTTPUnauthorized
          raise TwitterAuth::Dispatcher::Unauthorized, 'The credentials provided did not authorize the user.'
        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

15 entries across 15 versions & 5 rubygems

Version Path
mbleigh-twitter-auth-0.1.16 lib/twitter_auth/dispatcher/shared.rb
mbleigh-twitter-auth-0.1.18 lib/twitter_auth/dispatcher/shared.rb
mbleigh-twitter-auth-0.1.20 lib/twitter_auth/dispatcher/shared.rb
mbleigh-twitter-auth-0.1.21 lib/twitter_auth/dispatcher/shared.rb
mbleigh-twitter-auth-0.1.22 lib/twitter_auth/dispatcher/shared.rb
millsb-twitter-auth-0.1.16 lib/twitter_auth/dispatcher/shared.rb
xaviershay-twitter-auth-0.1.19 lib/twitter_auth/dispatcher/shared.rb
twitter-auth-with-mongo-mapper-0.1.1 lib/twitter_auth/dispatcher/shared.rb
twitter-auth-with-mongo-mapper-0.1.0 lib/twitter_auth/dispatcher/shared.rb
twitter-auth-with-mongo-mapper-0.0.9 lib/twitter_auth/dispatcher/shared.rb
twitter-auth-0.1.22 lib/twitter_auth/dispatcher/shared.rb
twitter-auth-0.1.16 lib/twitter_auth/dispatcher/shared.rb
twitter-auth-0.1.17 lib/twitter_auth/dispatcher/shared.rb
twitter-auth-0.1.20 lib/twitter_auth/dispatcher/shared.rb
twitter-auth-0.1.21 lib/twitter_auth/dispatcher/shared.rb