Sha256: 5c3f741880050674e395862825cfc580fe105dbacccf82ba67aaa4fe256d021f

Contents?: true

Size: 1.18 KB

Versions: 19

Compression:

Stored size: 1.18 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 = TwitterAuth.path_prefix + path
        path = append_extension_to(path)

        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

19 entries across 19 versions & 5 rubygems

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