Class: Smartbill::Sdk::NetHttpAdapter
- Inherits:
-
Object
- Object
- Smartbill::Sdk::NetHttpAdapter
- Defined in:
- lib/smartbill/sdk/net_http_adapter.rb
Overview
Default HTTP adapter backed by stdlib Net::HTTP.
The SDK talks to the adapter through a single method, #call, which receives a Transport::Request and returns a Response. This keeps the transport logic decoupled from the HTTP library and makes it trivial to swap in another adapter (or stub one in tests).
Constant Summary collapse
- METHOD_CLASSES =
{ "GET" => Net::HTTP::Get, "POST" => Net::HTTP::Post, "PUT" => Net::HTTP::Put, "DELETE" => Net::HTTP::Delete, "PATCH" => Net::HTTP::Patch }.freeze
Instance Method Summary collapse
- #call(req) ⇒ Object
-
#initialize(timeout: 30) ⇒ NetHttpAdapter
constructor
A new instance of NetHttpAdapter.
Constructor Details
#initialize(timeout: 30) ⇒ NetHttpAdapter
Returns a new instance of NetHttpAdapter.
23 24 25 |
# File 'lib/smartbill/sdk/net_http_adapter.rb', line 23 def initialize(timeout: 30) @timeout = timeout end |
Instance Method Details
#call(req) ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/smartbill/sdk/net_http_adapter.rb', line 27 def call(req) uri = build_uri(req) request = build_request(req, uri) response = perform(uri, request) Response.new(status: response.code.to_i, body: response.body, content_type: response["content-type"]) rescue ArgumentError, Net::HTTPError => e raise TransportError, "Transport error: #{e.}" end |