Module: Ask::Auth::OAuth::HTTP

Defined in:
lib/ask/auth/oauth/http.rb

Overview

Minimal form-encoded POST for token endpoints — stdlib only, so ask-auth stays dependency-free. Swappable in tests.

Constant Summary collapse

OPEN_TIMEOUT =
10
READ_TIMEOUT =
30

Class Method Summary collapse

Class Method Details

.post_form(url, params, headers: {}) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/ask/auth/oauth/http.rb', line 15

def self.post_form(url, params, headers: {})
  uri = URI(url)
  http = Net::HTTP.new(uri.host, uri.port)
  http.open_timeout = OPEN_TIMEOUT
  http.read_timeout = READ_TIMEOUT
  http.use_ssl = uri.scheme == "https"
  req = Net::HTTP::Post.new(uri)
  req.set_form_data(params)
  headers.each { |k, v| req[k] = v }
  res = http.request(req)
  [res.code.to_i, res.body.to_s]
end