Class: Safire::HTTPClient
- Inherits:
-
Object
- Object
- Safire::HTTPClient
- Includes:
- URIValidation
- Defined in:
- lib/safire/http_client.rb
Overview
HTTP client wrapper for Safire
Instance Method Summary collapse
- #delete(path = '', params: {}, headers: {}) ⇒ Object
- #get(path = '', params: {}, headers: {}) ⇒ Object
-
#initialize(base_url: nil, adapter: nil, request_format: :url_encoded, ssl_options: {}, allow_insecure_localhost: false) ⇒ HTTPClient
constructor
A new instance of HTTPClient.
- #post(path = '', body: nil, params: {}, headers: {}) ⇒ Object
- #put(path = '', body: nil, params: {}, headers: {}) ⇒ Object
Constructor Details
#initialize(base_url: nil, adapter: nil, request_format: :url_encoded, ssl_options: {}, allow_insecure_localhost: false) ⇒ HTTPClient
Returns a new instance of HTTPClient.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/safire/http_client.rb', line 11 def initialize(base_url: nil, adapter: nil, request_format: :url_encoded, ssl_options: {}, allow_insecure_localhost: false) @options = { url: normalize_base_url(base_url), ssl: , headers: { 'User-Agent' => Safire.configuration&.user_agent || "Safire v#{Safire::VERSION}", 'Accept' => 'application/json' } } @adapter = adapter || Faraday.default_adapter @request_format = request_format.to_sym @allow_insecure_localhost = validate_localhost_policy(allow_insecure_localhost) warn_if_ssl_verification_disabled() @connection = build_connection end |
Instance Method Details
#delete(path = '', params: {}, headers: {}) ⇒ Object
40 41 42 |
# File 'lib/safire/http_client.rb', line 40 def delete(path = '', params: {}, headers: {}) request(:delete, path, params:, headers:) end |
#get(path = '', params: {}, headers: {}) ⇒ Object
28 29 30 |
# File 'lib/safire/http_client.rb', line 28 def get(path = '', params: {}, headers: {}) request(:get, path, params:, headers:) end |
#post(path = '', body: nil, params: {}, headers: {}) ⇒ Object
32 33 34 |
# File 'lib/safire/http_client.rb', line 32 def post(path = '', body: nil, params: {}, headers: {}) request(:post, path, body:, params:, headers:) end |
#put(path = '', body: nil, params: {}, headers: {}) ⇒ Object
36 37 38 |
# File 'lib/safire/http_client.rb', line 36 def put(path = '', body: nil, params: {}, headers: {}) request(:put, path, body:, params:, headers:) end |