Extensions for em-http so that we can use consumer.sign! with an EventMachine::HttpClient instance. This is purely syntactic sugar.
Add the OAuth information to an HTTP request. Depending on the options[:scheme] setting this may add a header, additional query string parameters, or additional POST body parameters. The default scheme is header, in which the OAuth parameters as put into the Authorization header.
http - Configured Net::HTTP instance, ignored in this scenario except for getting host.
consumer - OAuth::Consumer instance
token - OAuth::Token instance
options - Request-specific options (e.g. request_uri, consumer, token, scheme, signature_method, nonce, timestamp)
This method also modifies the User-Agent header to add the OAuth gem version.
See Also: OAuth core spec version 1.0, section 5.4.1
# File lib/oauth/client/em_http.rb, line 26 26: def oauth!(http, consumer = nil, token = nil, options = {}) 27: options = { :request_uri => normalized_oauth_uri(http), 28: :consumer => consumer, 29: :token => token, 30: :scheme => 'header', 31: :signature_method => nil, 32: :nonce => nil, 33: :timestamp => nil }.merge(options) 34: 35: @oauth_helper = OAuth::Client::Helper.new(self, options) 36: self.__send__(:"set_oauth_#{options[:scheme]}") 37: end
Create a string suitable for signing for an HTTP request. This process involves parameter normalization as specified in the OAuth specification. The exact normalization also depends on the options[:scheme] being used so this must match what will be used for the request itself. The default scheme is header, in which the OAuth parameters as put into the Authorization header.
http - Configured Net::HTTP instance
consumer - OAuth::Consumer instance
token - OAuth::Token instance
options - Request-specific options (e.g. request_uri, consumer, token, scheme, signature_method, nonce, timestamp)
See Also: OAuth core spec version 1.0, section 9.1.1
# File lib/oauth/client/em_http.rb, line 52 52: def signature_base_string(http, consumer = nil, token = nil, options = {}) 53: options = { :request_uri => normalized_oauth_uri(http), 54: :consumer => consumer, 55: :token => token, 56: :scheme => 'header', 57: :signature_method => nil, 58: :nonce => nil, 59: :timestamp => nil }.merge(options) 60: 61: OAuth::Client::Helper.new(self, options).signature_base_string 62: end
Since we expect to get the host etc details from the http instance (…), we create a fake url here. Surely this is a horrible, horrible idea?
# File lib/oauth/client/em_http.rb, line 68 68: def normalized_oauth_uri(http) 69: uri = URI.parse(normalize_uri.path) 70: uri.host = http.address 71: uri.port = http.port 72: 73: if http.respond_to?(:use_ssl?) && http.use_ssl? 74: uri.scheme = "https" 75: else 76: uri.scheme = "http" 77: end 78: uri.to_s 79: end
# File lib/oauth/client/em_http.rb, line 86 86: def set_oauth_body 87: raise NotImplementedError, 'please use the set_oauth_header method instead' 88: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.