Class: Safire::HTTPClient

Inherits:
Object
  • Object
show all
Defined in:
lib/safire/http_client.rb

Overview

HTTP client wrapper for Safire

Instance Method Summary collapse

Constructor Details

#initialize(base_url: nil, adapter: nil, request_format: :url_encoded, ssl_options: {}) ⇒ HTTPClient

Returns a new instance of HTTPClient.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/safire/http_client.rb', line 8

def initialize(base_url: nil, adapter: nil, request_format: :url_encoded, ssl_options: {})
  @options = {
    url: normalize_base_url(base_url),
    ssl: ssl_options,
    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
  warn_if_ssl_verification_disabled(ssl_options)
  @connection = build_connection
end

Instance Method Details

#delete(path = '', params: {}, headers: {}) ⇒ Object



35
36
37
# File 'lib/safire/http_client.rb', line 35

def delete(path = '', params: {}, headers: {})
  request(:delete, path, params:, headers:)
end

#get(path = '', params: {}, headers: {}) ⇒ Object



23
24
25
# File 'lib/safire/http_client.rb', line 23

def get(path = '', params: {}, headers: {})
  request(:get, path, params:, headers:)
end

#post(path = '', body: nil, params: {}, headers: {}) ⇒ Object



27
28
29
# File 'lib/safire/http_client.rb', line 27

def post(path = '', body: nil, params: {}, headers: {})
  request(:post, path, body:, params:, headers:)
end

#put(path = '', body: nil, params: {}, headers: {}) ⇒ Object



31
32
33
# File 'lib/safire/http_client.rb', line 31

def put(path = '', body: nil, params: {}, headers: {})
  request(:put, path, body:, params:, headers:)
end