Sha256: 8e10444f49e8284f8935fd6246b99f6f9dfb2fe35d4f5ff38e79175cceb0926e

Contents?: true

Size: 1.13 KB

Versions: 1

Compression:

Stored size: 1.13 KB

Contents

require 'net/http'

module Stocktwits
  module Dispatcher
    class Plain
      include Stocktwits::Dispatcher::Shared

      attr_accessor :user

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

      def request(http_method, path, body=nil, *arguments)
        path = Stocktwits.path_prefix + path
        path = append_extension_to(path)
        response = Stocktwits.net.start{ |http|
          req = "Net::HTTP::#{http_method.to_s.capitalize}".constantize.new(path, *arguments)
          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

1 entries across 1 versions & 1 rubygems

Version Path
stocktwits-1.0.0 lib/stocktwits/dispatcher/plain.rb