Class: EventMachine::Middleware::OAuth

### Home Classes Methods

### In Files

- lib/em-http/middleware/oauth.rb

### Parent

Object

### Methods

- ::new
- #request

### Included Modules

- EventMachine::HttpEncoding

### Class/Module Index

Quicksearch

- EventMachine
- EventMachine::HTTPMethods
- EventMachine::HttpClient
- EventMachine::HttpClient::CookieJar
- EventMachine::HttpConnection
- EventMachine::HttpDecoders
- EventMachine::HttpDecoders::Base
- EventMachine::HttpDecoders::DecoderError
- EventMachine::HttpDecoders::Deflate
- EventMachine::HttpDecoders::GZip
- EventMachine::HttpDecoders::GZipHeader
- EventMachine::HttpEncoding
- EventMachine::HttpRequest
- EventMachine::HttpResponseHeader
- EventMachine::HttpStatus
- EventMachine::HttpStubConnection
- EventMachine::Middleware
- EventMachine::Middleware::DigestAuth
- EventMachine::Middleware::JSONResponse
- EventMachine::Middleware::OAuth
- EventMachine::Middleware::OAuth2
- EventMachine::MultiRequest
- HttpClientOptions
- HttpConnectionOptions
- String

No matching classes.

# EventMachine::Middleware::OAuth

### Public Class Methods

new(opts = {}) click to toggle source

    # File lib/em-http/middleware/oauth.rb, line 9
    def initialize(opts = {})
      @opts = opts.dup
      # Allow both `oauth` gem and `simple_oauth` gem opts formats
      @opts[:token] ||= @opts.delete(:access_token)
      @opts[:token_secret] ||= @opts.delete(:access_token_secret)
    end

### Public Instance Methods

request(client, head, body) click to toggle source

    # File lib/em-http/middleware/oauth.rb, line 16
    def request(client, head, body)
      request = client.req
      uri     = request.uri.join(encode_query(request.uri, request.query))
      params  = {}

      # from https://github.com/oauth/oauth-ruby/blob/master/lib/oauth/request_proxy/em_http_request.rb
      if ["POST", "PUT"].include?(request.method)
        head["content-type"] ||= "application/x-www-form-urlencoded" if body.is_a? Hash
        form_encoded = head["content-type"].to_s.downcase.start_with?("application/x-www-form-urlencoded")

        if form_encoded
          CGI.parse(client.normalize_body(body)).each do |k,v|
            # Since `CGI.parse` always returns values as an array
            params[k] = v.size == 1 ? v.first : v
          end
        end
      end

      head["Authorization"] = SimpleOAuth::Header.new(request.method, uri, params, @opts)

      [head,body]
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.