Class: EventMachine::HttpClient — Documentation by YARD 0.9.45

# Class: EventMachine::HttpClient

Inherits:
  Object
  - Object
  - EventMachine::HttpClient
  show all

Defined in:
  lib/oauth/client/em_http.rb

## Instance Attribute Summary collapse

- #oauth_helper ⇒ Object readonly

  Returns the value of attribute oauth_helper.

## Instance Method Summary collapse

- #normalize_uri ⇒ Object

  This code was lifted from the em-http-request because it was removed from the gem June 19, 2010 see: http://github.com/igrigorik/em-http-request/commit/d536fc17d56dbe55c487eab01e2ff9382a62598b.

- #oauth!(http, consumer = nil, token = nil, options = {}) ⇒ Object

  Add the OAuth information to an HTTP request.

- #signature_base_string(http, consumer = nil, token = nil, options = {}) ⇒ Object

  Create a string suitable for signing for an HTTP request.

## Instance Attribute Details

### #oauth_helper ⇒ `Object` (readonly)

Returns the value of attribute oauth_helper.

    13
    14
    15
    # File 'lib/oauth/client/em_http.rb', line 13

    def oauth_helper
      @oauth_helper
    end

## Instance Method Details

### #normalize_uri ⇒ `Object`

This code was lifted from the em-http-request because it was removed from
the gem June 19, 2010
see: http://github.com/igrigorik/em-http-request/commit/d536fc17d56dbe55c487eab01e2ff9382a62598b

    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    # File 'lib/oauth/client/em_http.rb', line 74

    def normalize_uri
      @normalized_uri ||= begin
        uri = @conn.dup
        encoded_query = encode_query(@conn, @req[:query])
        path, query = encoded_query.split("?", 2)
        uri.query = query unless encoded_query.empty?
        uri.path = path
        uri
      end
    end

### #oauth!(http, consumer = nil, token = nil, options = {}) ⇒ `Object`

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: core spec version 1.0, section 5.4.1[http://oauth.net/core/1.0#rfc.section.5.4.1]

    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    # File 'lib/oauth/client/em_http.rb', line 29

    def oauth!(http, consumer = nil, token = nil, options = {})
      options = {
        request_uri: normalized_oauth_uri(http),
        consumer: consumer,
        token: token,
        scheme: "header",
        signature_method: nil,
        nonce: nil,
        timestamp: nil
      }.merge(options)

      @oauth_helper = OAuth::Client::Helper.new(self, options)
      __send__(:"set_oauth_#{options[:scheme]}")
    end

### #signature_base_string(http, consumer = nil, token = nil, options = {}) ⇒ `Object`

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: core spec version 1.0, section 9.1.1[http://oauth.net/core/1.0#rfc.section.9.1.1]

    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    # File 'lib/oauth/client/em_http.rb', line 57

    def signature_base_string(http, consumer = nil, token = nil, options = {})
      options = {
        request_uri: normalized_oauth_uri(http),
        consumer: consumer,
        token: token,
        scheme: "header",
        signature_method: nil,
        nonce: nil,
        timestamp: nil
      }.merge(options)

      OAuth::Client::Helper.new(self, options).signature_base_string
    end