class EventMachine::Twitter::Request
Attributes
options[R]
proxy[R]
Public Class Methods
new(options = {})
click to toggle source
# File lib/em-twitter/request.rb, line 10 def initialize(options = {}) @options = options @proxy = Proxy.new(@options.delete(:proxy)) if @options[:proxy] end
Public Instance Methods
proxy?()
click to toggle source
# File lib/em-twitter/request.rb, line 48 def proxy? @proxy end
to_s()
click to toggle source
# 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
Private Instance Methods
basic_auth?()
click to toggle source
# File lib/em-twitter/request.rb, line 110 def basic_auth? @options[:basic] && !@options[:basic].empty? end
basic_auth_header()
click to toggle source
# File lib/em-twitter/request.rb, line 114 def basic_auth_header auth_string = "#{@options[:basic][:username]}:#{@options[:basic][:password]}" 'Basic ' + [auth_string].pack('m').delete("\r\n") end
full_uri()
click to toggle source
# File lib/em-twitter/request.rb, line 139 def full_uri proxy? ? proxy_uri : "#{uri_base}#{request_uri}" end
get?()
click to toggle source
# File lib/em-twitter/request.rb, line 54 def get? request_method == 'GET' end
gzip?()
click to toggle source
# File lib/em-twitter/request.rb, line 70 def gzip? @options[:encoding] && @options[:encoding] == 'gzip' end
oauth?()
click to toggle source
# File lib/em-twitter/request.rb, line 94 def oauth? @options[:oauth] && !@options[:oauth].empty? end
oauth_header()
click to toggle source
# File lib/em-twitter/request.rb, line 98 def oauth_header SimpleOAuth::Header.new(@options[:method], full_uri, oauth_url_params, oauth_params) end
oauth_params()
click to toggle source
# File lib/em-twitter/request.rb, line 106 def oauth_params @options[:oauth].merge(:ignore_extra_keys => true) end
oauth_url_params()
click to toggle source
# File lib/em-twitter/request.rb, line 102 def oauth_url_params get? ? {} : params end
params()
click to toggle source
# File lib/em-twitter/request.rb, line 78 def params flat = {} @options[:params].each do |param, val| next if val.to_s.empty? || (val.respond_to?(:empty?) && val.empty?) val = val.join(",") if val.respond_to?(:join) flat[param.to_s] = val.to_s end flat end
path()
click to toggle source
# File lib/em-twitter/request.rb, line 127 def path get? ? "#{@options[:path]}?#{query}" : @options[:path] end
post?()
click to toggle source
# File lib/em-twitter/request.rb, line 58 def post? request_method == 'POST' end
protocol()
click to toggle source
# File lib/em-twitter/request.rb, line 135 def protocol @options[:ssl] ? 'https' : 'http' end
proxy_uri()
click to toggle source
# File lib/em-twitter/request.rb, line 119 def proxy_uri "#{uri_base}:#{@options[:port]}#{path}" end
put?()
click to toggle source
# File lib/em-twitter/request.rb, line 62 def put? request_method == 'PUT' end
put_or_post?()
click to toggle source
# File lib/em-twitter/request.rb, line 66 def put_or_post? put? || post? end
query()
click to toggle source
# File lib/em-twitter/request.rb, line 88 def query params.map do |param, value| [param, SimpleOAuth::Header.encode(value)].join("=") end.sort.join("&") end
request_method()
click to toggle source
# File lib/em-twitter/request.rb, line 74 def request_method @options[:method].to_s.upcase end
request_uri()
click to toggle source
# File lib/em-twitter/request.rb, line 123 def request_uri proxy? ? proxy_uri : path end
uri_base()
click to toggle source
# File lib/em-twitter/request.rb, line 131 def uri_base "#{protocol}://#{@options[:host]}" end