Sha256: cc2be5b5399b048190e7f19c8191483543c2ee54e7b370bfb09bd5ed6a93d62c

Contents?: true

Size: 1.16 KB

Versions: 10

Compression:

Stored size: 1.16 KB

Contents

require 'net/http'

module TwitterAuth
  module Dispatcher
    class Basic
      include TwitterAuth::Dispatcher::Shared

      attr_accessor :user

      def initialize(user)
        raise TwitterAuth::Error, 'Dispatcher must be initialized with a User.' unless user.is_a?(TwitterAuth::BasicUser)
        self.user = user
      end

      def request(http_method, path, body=nil, *arguments)
        path << '.json' unless path.match(/\.(:?xml|json)\z/i)

        response = TwitterAuth.net.start{ |http|
          req = "Net::HTTP::#{http_method.to_s.capitalize}".constantize.new(path, *arguments)
          req.basic_auth user.login, user.password
          req.set_form_data(body) unless body.nil?
          http.request(req)
        }
        
        handle_response(response)      
      end

      def get(path, *arguments)
        request(:get, path, *arguments)
      end

      def post(path, body='', *arguments)
        request(:post, path, body, *arguments)
      end

      def put(path, body='', *arguments)
        request(:put, path, body, *arguments)
      end

      def delete(path, *arguments)
        request(:delete, path, *arguments)
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
mbleigh-twitter-auth-0.1.10 lib/twitter_auth/dispatcher/basic.rb
mbleigh-twitter-auth-0.1.11 lib/twitter_auth/dispatcher/basic.rb
mbleigh-twitter-auth-0.1.5 lib/twitter_auth/dispatcher/basic.rb
mbleigh-twitter-auth-0.1.8 lib/twitter_auth/dispatcher/basic.rb
twitter-auth-0.1.10 lib/twitter_auth/dispatcher/basic.rb
twitter-auth-0.1.11 lib/twitter_auth/dispatcher/basic.rb
twitter-auth-0.1.5 lib/twitter_auth/dispatcher/basic.rb
twitter-auth-0.1.7 lib/twitter_auth/dispatcher/basic.rb
twitter-auth-0.1.8 lib/twitter_auth/dispatcher/basic.rb
twitter-auth-0.1.9 lib/twitter_auth/dispatcher/basic.rb