Module: HTTP::Chainable

### Home Classes Methods

### In Files

- lib/http/chainable.rb

### Methods

- #accept
- #auth
- #basic_auth
- #cache
- #connect
- #cookies
- #default_headers
- #default_headers=
- #default_options
- #default_options=
- #delete
- #follow
- #get
- #head
- #headers
- #options
- #patch
- #persistent
- #post
- #put
- #request
- #through
- #timeout
- #trace
- #via
- #with
- #with_cache
- #with_follow
- #with_headers

### Class/Module Index

Quicksearch

- HTTP
- HTTP::Cache
- HTTP::Cache::Headers
- HTTP::Cache::NullCache
- HTTP::Cache::NullLogger
- HTTP::CacheError
- HTTP::Chainable
- HTTP::Client
- HTTP::Connection
- HTTP::Error
- HTTP::Headers
- HTTP::Headers::Mixin
- HTTP::InvalidHeaderNameError
- HTTP::MimeType
- HTTP::MimeType::Adapter
- HTTP::MimeType::JSON
- HTTP::Options
- HTTP::Redirector
- HTTP::Redirector::EndlessRedirectError
- HTTP::Redirector::TooManyRedirectsError
- HTTP::Request
- HTTP::Request::Caching
- HTTP::Request::UnsupportedMethodError
- HTTP::Request::UnsupportedSchemeError
- HTTP::Request::Writer
- HTTP::RequestError
- HTTP::Response
- HTTP::Response::Body
- HTTP::Response::Caching
- HTTP::Response::IoBody
- HTTP::Response::Parser
- HTTP::Response::Status
- HTTP::Response::StringBody
- HTTP::ResponseError
- HTTP::StateError
- HTTP::Timeout
- HTTP::Timeout::Global
- HTTP::Timeout::Null
- HTTP::Timeout::PerOperation
- HTTP::TimeoutError
- HTTP::URI
- Object

No matching classes.

# HTTP::Chainable

### Public Instance Methods

accept(type) click to toggle source

Accept the given MIME type(s) @param type

    # File lib/http/chainable.rb, line 202
    def accept(type)
      headers Headers::ACCEPT => MimeType.normalize(type)
    end

auth(value, opts = nil) click to toggle source

Make a request with the given Authorization header @param [to_s] value Authorization header value

    # File lib/http/chainable.rb, line 208
    def auth(value, opts = nil)
      # shim for deprecated auth(:basic, opts).
      # will be removed in 0.8.0
      return basic_auth(opts) if :basic == value
      headers Headers::AUTHORIZATION => value.to_s
    end

basic_auth(opts) click to toggle source

Make a request with the given Basic authorization header @see tools.ietf.org/html/rfc2617 @param [fetch] opts @option opts [to_s] :user @option opts [to_s] :pass

    # File lib/http/chainable.rb, line 220
    def basic_auth(opts)
      user = opts.fetch :user
      pass = opts.fetch :pass

      auth("Basic " << Base64.strict_encode64("#{user}:#{pass}"))
    end

cache(cache) click to toggle source

    # File lib/http/chainable.rb, line 173
    def cache(cache)
      branch default_options.with_cache(cache)
    end

Also aliased as: with_cache
connect(uri, options = {}) click to toggle source

Convert to a transparent TCP/IP tunnel @param uri @option options [Hash]

    # File lib/http/chainable.rb, line 59
    def connect(uri, options = {})
      request :connect, uri, options
    end

cookies(cookies) click to toggle source

Make a request with the given cookies

    # File lib/http/chainable.rb, line 196
    def cookies(cookies)
      branch default_options.with_cookies(cookies)
    end

default_headers() click to toggle source

@deprecated Will be removed in 1.0.0; Use `default_options#headers` Get headers of HTTP options

    # File lib/http/chainable.rb, line 242
    def default_headers
      default_options.headers
    end

default_headers=(headers) click to toggle source

Set headers of HTTP options @deprecated Will be removed in 1.0.0; Use `headers` @param headers

    # File lib/http/chainable.rb, line 249
    def default_headers=(headers)
      @default_options = default_options.dup do |opts|
        opts.headers = headers
      end
    end

default_options() click to toggle source

Get options for HTTP @return [HTTP::Options]

    # File lib/http/chainable.rb, line 229
    def default_options
      @default_options ||= HTTP::Options.new
    end

default_options=(opts) click to toggle source

Set options for HTTP @param opts @return [HTTP::Options]

    # File lib/http/chainable.rb, line 236
    def default_options=(opts)
      @default_options = HTTP::Options.new(opts)
    end

delete(uri, options = {}) click to toggle source

Delete a resource @param uri @option options [Hash]

    # File lib/http/chainable.rb, line 38
    def delete(uri, options = {})
      request :delete, uri, options
    end

follow(opts = {}) click to toggle source

Make client follow redirects. @param opts @return [HTTP::Client] @see Redirector#initialize

    # File lib/http/chainable.rb, line 165
    def follow(opts = {})
      branch default_options.with_follow opts
    end

Also aliased as: with_follow
get(uri, options = {}) click to toggle source

Get a resource @param uri @option options [Hash]

    # File lib/http/chainable.rb, line 17
    def get(uri, options = {})
      request :get, uri, options
    end

head(uri, options = {}) click to toggle source

Request a get sans response body @param uri @option options [Hash]

    # File lib/http/chainable.rb, line 10
    def head(uri, options = {})
      request :head, uri, options
    end

headers(headers) click to toggle source

Make a request with the given headers @param headers

    # File lib/http/chainable.rb, line 183
    def headers(headers)
      branch default_options.with_headers(headers)
    end

Also aliased as: with, with_headers
options(uri, options = {}) click to toggle source

Return the methods supported on the given URI @param uri @option options [Hash]

    # File lib/http/chainable.rb, line 52
    def options(uri, options = {})
      request :options, uri, options
    end

patch(uri, options = {}) click to toggle source

Apply partial modifications to a resource @param uri @option options [Hash]

    # File lib/http/chainable.rb, line 66
    def patch(uri, options = {})
      request :patch, uri, options
    end

persistent(host) click to toggle source

@overload persistent(host)

    Flags as persistent
    @param [String] host
    @raise [Request::Error] if Host is invalid
    @return [HTTP::Client] Persistent client

@overload persistent(host, &block)

    Executes given block with persistent client and automatically closes
    connection at the end of execution.

    @example

        def keys(users)
          HTTP.persistent("https://github.com") do |http|
            users.map { |u| http.get("/#{u}.keys").to_s }
          end
        end

        # same as

        def keys(users)
          http = HTTP.persistent "https://github.com"
          users.map { |u| http.get("/#{u}.keys").to_s }
        ensure
          http.close if http
        end

    @yieldparam [HTTP::Client] client Persistent client
    @return [Object] result of last expression in the block

    # File lib/http/chainable.rb, line 135
    def persistent(host)
      p_client = branch default_options.with_persistent host
      return p_client unless block_given?
      yield p_client
    ensure
      p_client.close
    end

post(uri, options = {}) click to toggle source

Post to a resource @param uri @option options [Hash]

    # File lib/http/chainable.rb, line 24
    def post(uri, options = {})
      request :post, uri, options
    end

put(uri, options = {}) click to toggle source

Put to a resource @param uri @option options [Hash]

    # File lib/http/chainable.rb, line 31
    def put(uri, options = {})
      request :put, uri, options
    end

request(verb, uri, options = {}) click to toggle source

Make an HTTP request with the given verb @param uri @option options [Hash]

    # File lib/http/chainable.rb, line 73
    def request(verb, uri, options = {})
      branch(options).request verb, uri
    end

through(*proxy) click to toggle source
Alias for: via
timeout(klass, options = {}) click to toggle source

@overload(options = {})

    Syntax sugar for `timeout(:per_operation, options)`

@overload(klass, options = {})

    @param [#to_sym] klass
    @param [Hash] options
    @option options [Float] :read Read timeout
    @option options [Float] :write Write timeout
    @option options [Float] :connect Connect timeout

    # File lib/http/chainable.rb, line 85
    def timeout(klass, options = {})
      klass, options = :per_operation, klass if klass.is_a? Hash

      klass = case klass.to_sym
              when :null          then HTTP::Timeout::Null
              when :global        then HTTP::Timeout::Global
              when :per_operation then HTTP::Timeout::PerOperation
              else fail ArgumentError, "Unsupported Timeout class: #{klass}"
              end

      [:read, :write, :connect].each do |k|
        next unless options.key? k
        options["#{k}_timeout".to_sym] = options.delete k
      end

      branch default_options.merge(
        :timeout_class => klass,
        :timeout_options => options
      )
    end

trace(uri, options = {}) click to toggle source

Echo the request back to the client @param uri @option options [Hash]

    # File lib/http/chainable.rb, line 45
    def trace(uri, options = {})
      request :trace, uri, options
    end

via(*proxy) click to toggle source

Make a request through an HTTP proxy @param [Array] proxy @raise [Request::Error] if HTTP proxy is invalid

    # File lib/http/chainable.rb, line 146
    def via(*proxy)
      proxy_hash = {}
      proxy_hash[:proxy_address]  = proxy[0] if proxy[0].is_a?(String)
      proxy_hash[:proxy_port]     = proxy[1] if proxy[1].is_a?(Integer)
      proxy_hash[:proxy_username] = proxy[2] if proxy[2].is_a?(String)
      proxy_hash[:proxy_password] = proxy[3] if proxy[3].is_a?(String)

      if [2, 4].include?(proxy_hash.keys.size)
        branch default_options.with_proxy(proxy_hash)
      else
        fail(RequestError, "invalid HTTP proxy: #{proxy_hash}")
      end
    end

Also aliased as: through
with(headers) click to toggle source

@deprecated will be removed in 1.0.0 @see headers

Alias for: headers
with_cache(cache) click to toggle source

@deprecated will be removed in 1.0.0 @see cache

Alias for: cache
with_follow(opts = {}) click to toggle source

@deprecated will be removed in 1.0.0 @see follow

Alias for: follow
with_headers(headers) click to toggle source

@deprecated will be removed in 1.0.0 @see headers

Alias for: headers

[Validate]

Generated with the Darkfish Rdoc Generator 2.