Class: Flipper::Adapters::Http::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/flipper/adapters/http/client.rb

Constant Summary collapse

DEFAULT_HEADERS =
{
  'Content-Type' => 'application/json',
  'Accept' => 'application/json',
  'User-Agent' => "Flipper HTTP Adapter v#{VERSION}",
}.freeze
HTTPS_SCHEME =
"https".freeze

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



17
18
19
20
21
22
23
24
25
# File 'lib/flipper/adapters/http/client.rb', line 17

def initialize(options = {})
  @uri = URI(options.fetch(:url))
  @headers = DEFAULT_HEADERS.merge(options[:headers] || {})
  @basic_auth_username = options[:basic_auth_username]
  @basic_auth_password = options[:basic_auth_password]
  @read_timeout = options[:read_timeout]
  @open_timeout = options[:open_timeout]
  @debug_output = options[:debug_output]
end

Instance Method Details

#delete(path, body = nil) ⇒ Object



35
36
37
# File 'lib/flipper/adapters/http/client.rb', line 35

def delete(path, body = nil)
  perform Net::HTTP::Delete, path, @headers, body: body
end

#get(path) ⇒ Object



27
28
29
# File 'lib/flipper/adapters/http/client.rb', line 27

def get(path)
  perform Net::HTTP::Get, path, @headers
end

#post(path, body = nil) ⇒ Object



31
32
33
# File 'lib/flipper/adapters/http/client.rb', line 31

def post(path, body = nil)
  perform Net::HTTP::Post, path, @headers, body: body
end