Sha256: 1a510277bd4ea70f74b77df05252337025341d8757907b88e83dff4f04bec1ff

Contents?: true

Size: 1.16 KB

Versions: 7

Compression:

Stored size: 1.16 KB

Contents

require 'twitter/cursor'

module Twitter
  class Request
    attr_accessor :client, :request_method, :path, :options
    alias_method :verb, :request_method

    # @param client [Twitter::Client]
    # @param request_method [String, Symbol]
    # @param path [String]
    # @param options [Hash]
    # @return [Twitter::Request]
    def initialize(client, request_method, path, options = {})
      @client = client
      @request_method = request_method.to_sym
      @path = path
      @options = options
    end

    # @return [Hash]
    def perform
      @client.send(@request_method, @path, @options).body
    end

    # @param klass [Class]
    # @param request [Twitter::Request]
    # @return [Object]
    def perform_with_object(klass)
      klass.new(perform)
    end

    # @param collection_name [Symbol]
    # @param klass [Class]
    # @return [Twitter::Cursor]
    def perform_with_cursor(collection_name, klass = nil)
      Twitter::Cursor.new(perform, collection_name.to_sym, klass, self)
    end

    # @param klass [Class]
    # @return [Array]
    def perform_with_objects(klass)
      perform.collect do |element|
        klass.new(element)
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
twitter-5.12.0 lib/twitter/request.rb
twitter-5.11.0 lib/twitter/request.rb
twitter-5.10.0 lib/twitter/request.rb
twitter-5.9.0 lib/twitter/request.rb
twitter-5.8.0 lib/twitter/request.rb
twitter-5.7.1 lib/twitter/request.rb
twitter-5.7.0 lib/twitter/request.rb