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 Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/flipper/adapters/http/client.rb', line 21

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]
  @write_timeout = options[:write_timeout]
  @max_retries = options.key?(:max_retries) ? options[:max_retries] : 0
  @debug_output = options[:debug_output]
end

Instance Attribute Details

#basic_auth_passwordObject (readonly)

Returns the value of attribute basic_auth_password.



18
19
20
# File 'lib/flipper/adapters/http/client.rb', line 18

def basic_auth_password
  @basic_auth_password
end

#basic_auth_usernameObject (readonly)

Returns the value of attribute basic_auth_username.



18
19
20
# File 'lib/flipper/adapters/http/client.rb', line 18

def basic_auth_username
  @basic_auth_username
end

#debug_outputObject (readonly)

Returns the value of attribute debug_output.



19
20
21
# File 'lib/flipper/adapters/http/client.rb', line 19

def debug_output
  @debug_output
end

#headersObject (readonly)

Returns the value of attribute headers.



17
18
19
# File 'lib/flipper/adapters/http/client.rb', line 17

def headers
  @headers
end

#max_retriesObject (readonly)

Returns the value of attribute max_retries.



19
20
21
# File 'lib/flipper/adapters/http/client.rb', line 19

def max_retries
  @max_retries
end

#open_timeoutObject (readonly)

Returns the value of attribute open_timeout.



19
20
21
# File 'lib/flipper/adapters/http/client.rb', line 19

def open_timeout
  @open_timeout
end

#read_timeoutObject (readonly)

Returns the value of attribute read_timeout.



19
20
21
# File 'lib/flipper/adapters/http/client.rb', line 19

def read_timeout
  @read_timeout
end

#uriObject (readonly)

Returns the value of attribute uri.



17
18
19
# File 'lib/flipper/adapters/http/client.rb', line 17

def uri
  @uri
end

#write_timeoutObject (readonly)

Returns the value of attribute write_timeout.



19
20
21
# File 'lib/flipper/adapters/http/client.rb', line 19

def write_timeout
  @write_timeout
end

Instance Method Details

#delete(path, body = nil) ⇒ Object



41
42
43
# File 'lib/flipper/adapters/http/client.rb', line 41

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

#get(path) ⇒ Object



33
34
35
# File 'lib/flipper/adapters/http/client.rb', line 33

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

#post(path, body = nil) ⇒ Object



37
38
39
# File 'lib/flipper/adapters/http/client.rb', line 37

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