Sha256: 5fbfdd7357b58bad108741394fd2170d2b07cef4b8107ab2a7af8109384ab5f7

Contents?: true

Size: 1.18 KB

Versions: 1

Compression:

Stored size: 1.18 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)
    end

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

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

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
twitter-5.6.0 lib/twitter/request.rb