Class: EventMachine::Twitter::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/em-twitter/request.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Request

Returns a new instance of Request.



10
11
12
13
# File 'lib/em-twitter/request.rb', line 10

def initialize(options = {})
  @options = options
  @proxy = Proxy.new(@options.delete(:proxy)) if @options[:proxy]
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



8
9
10
# File 'lib/em-twitter/request.rb', line 8

def options
  @options
end

#proxyObject (readonly)

Returns the value of attribute proxy.



8
9
10
# File 'lib/em-twitter/request.rb', line 8

def proxy
  @proxy
end

Instance Method Details

#proxy?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/em-twitter/request.rb', line 48

def proxy?
  @proxy
end

#to_sObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/em-twitter/request.rb', line 15

def to_s
  content = query

  data = []
  data << "#{request_method} #{request_uri} HTTP/1.1"
  data << "Host: #{@options[:host]}"

  if gzip?
    data << 'Connection: Keep-Alive'
    data << 'Accept-Encoding: deflate, gzip'
  else
    data << 'Accept: */*'
  end

  data << "User-Agent: #{@options[:user_agent]}" if @options[:user_agent]
  if put_or_post?
    data << "Content-Type: #{@options[:content_type]}"
    data << "Content-Length: #{content.bytesize}"
  end
  data << "Authorization: #{oauth_header}" if oauth?
  data << "Authorization: #{basic_auth_header}" if basic_auth?
  data << "Proxy-Authorization: Basic #{proxy.header}" if proxy?

  @options[:headers].each do |name, value|
    data << "#{name}: #{value}"
  end

  data << "\r\n"
  data = data.join("\r\n")
  data << content if post? || put?
  data
end