Module: Lexdrill::HTTPClient

Defined in:
lib/lexdrill/http_client.rb

Overview

The only place lexdrill talks to Net::HTTP directly. Lexdrill::GoogleAuth (form-encoded OAuth endpoints) and Lexdrill::SheetsClient (JSON REST) both go through here, so every low-level connectivity failure (DNS, timeout, TLS, connection refused) is normalized to a single NetworkError for callers to handle, instead of each caller needing to know every possible Net::HTTP/OpenSSL/socket exception class.

Defined Under Namespace

Classes: NetworkError, Response

Constant Summary collapse

OPEN_TIMEOUT =
10
READ_TIMEOUT =
15

Class Method Summary collapse

Class Method Details

.json_get(url, headers: {}) ⇒ Object



34
35
36
37
38
# File 'lib/lexdrill/http_client.rb', line 34

def self.json_get(url, headers: {})
  uri = URI(url)
  request = build_get_request(uri, headers)
  perform(uri) { |http| http.request(request) }
end

.json_post(url, body:, headers: {}) ⇒ Object



26
27
28
# File 'lib/lexdrill/http_client.rb', line 26

def self.json_post(url, body:, headers: {})
  json_request(Net::HTTP::Post, url, body, headers)
end

.json_put(url, body:, headers: {}) ⇒ Object



30
31
32
# File 'lib/lexdrill/http_client.rb', line 30

def self.json_put(url, body:, headers: {})
  json_request(Net::HTTP::Put, url, body, headers)
end

.post_form(url, params) ⇒ Object



21
22
23
24
# File 'lib/lexdrill/http_client.rb', line 21

def self.post_form(url, params)
  uri = URI(url)
  perform(uri) { |http| http.post(uri.path, URI.encode_www_form(params)) }
end