Class: SimpleOAuth::OAuth2::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/simple_oauth/oauth2/request.rb,
sig/simple_oauth/oauth2.rbs

Overview

An HTTP request to an OAuth 2.0 endpoint, built but not sent

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(method:, url:, headers:, body:) ⇒ Request

Initialize a new request

Examples:

SimpleOAuth::OAuth2::Request.new(method: "POST", url: "https://example.com/token", headers: {}, body: "")

Parameters:

  • method (String)

    the HTTP method

  • url (String)

    the endpoint URL

  • headers (Hash{String => String})

    the request headers

  • body (String)

    the form-encoded request body

  • method: (String)
  • url: (String)
  • headers: (Hash[String, String])
  • body: (String)


52
53
54
55
56
57
58
# File 'lib/simple_oauth/oauth2/request.rb', line 52

def initialize(method:, url:, headers:, body:)
  @method = method
  @url = url
  @headers = headers.dup.freeze
  @body = body
  freeze
end

Instance Attribute Details

#bodyString (readonly)

The form-encoded request body

Examples:

request.body # => "grant_type=refresh_token&refresh_token=tGzv3JOkF0XG5Qx2TlKWIA"

Returns:

  • (String)

    the body



41
42
43
# File 'lib/simple_oauth/oauth2/request.rb', line 41

def body
  @body
end

#headersHash{String => String} (readonly)

The request headers

Examples:

request.headers["Content-Type"] # => "application/x-www-form-urlencoded"

Returns:

  • (Hash{String => String})

    the headers



33
34
35
# File 'lib/simple_oauth/oauth2/request.rb', line 33

def headers
  @headers
end

#methodString (readonly)

The HTTP method

Examples:

request.method # => "POST"

Returns:

  • (String)

    the HTTP method



17
18
19
# File 'lib/simple_oauth/oauth2/request.rb', line 17

def method
  @method
end

#urlString (readonly)

The endpoint URL

Examples:

request.url # => "https://example.com/token"

Returns:

  • (String)

    the URL



25
26
27
# File 'lib/simple_oauth/oauth2/request.rb', line 25

def url
  @url
end