Class: Flipper::Adapters::Http::Client
- Inherits:
-
Object
- Object
- Flipper::Adapters::Http::Client
- 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
- CLIENT_FRAMEWORKS =
{ rails: -> { Rails.version if defined?(Rails) }, sinatra: -> { Sinatra::VERSION if defined?(Sinatra) }, hanami: -> { Hanami::VERSION if defined?(Hanami) }, sidekiq: -> { Sidekiq::VERSION if defined?(Sidekiq) }, good_job: -> { GoodJob::VERSION if defined?(GoodJob) }, }
Instance Attribute Summary collapse
-
#basic_auth_password ⇒ Object
readonly
Returns the value of attribute basic_auth_password.
-
#basic_auth_username ⇒ Object
readonly
Returns the value of attribute basic_auth_username.
-
#debug_output ⇒ Object
readonly
Returns the value of attribute debug_output.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#max_retries ⇒ Object
readonly
Returns the value of attribute max_retries.
-
#open_timeout ⇒ Object
readonly
Returns the value of attribute open_timeout.
-
#read_timeout ⇒ Object
readonly
Returns the value of attribute read_timeout.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
-
#write_timeout ⇒ Object
readonly
Returns the value of attribute write_timeout.
Instance Method Summary collapse
- #add_header(key, value) ⇒ Object
- #delete(path, body = nil) ⇒ Object
- #get(path) ⇒ Object
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #post(path, body = nil) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/flipper/adapters/http/client.rb', line 30 def initialize( = {}) @uri = URI(.fetch(:url)) @basic_auth_username = [:basic_auth_username] @basic_auth_password = [:basic_auth_password] @read_timeout = [:read_timeout] @open_timeout = [:open_timeout] @write_timeout = [:write_timeout] @max_retries = .key?(:max_retries) ? [:max_retries] : 0 @debug_output = [:debug_output] @headers = {} DEFAULT_HEADERS.each { |key, value| add_header key, value } if [:headers] [:headers].each { |key, value| add_header key, value } end end |
Instance Attribute Details
#basic_auth_password ⇒ Object (readonly)
Returns the value of attribute basic_auth_password.
26 27 28 |
# File 'lib/flipper/adapters/http/client.rb', line 26 def basic_auth_password @basic_auth_password end |
#basic_auth_username ⇒ Object (readonly)
Returns the value of attribute basic_auth_username.
26 27 28 |
# File 'lib/flipper/adapters/http/client.rb', line 26 def basic_auth_username @basic_auth_username end |
#debug_output ⇒ Object (readonly)
Returns the value of attribute debug_output.
28 29 30 |
# File 'lib/flipper/adapters/http/client.rb', line 28 def debug_output @debug_output end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
25 26 27 |
# File 'lib/flipper/adapters/http/client.rb', line 25 def headers @headers end |
#max_retries ⇒ Object (readonly)
Returns the value of attribute max_retries.
28 29 30 |
# File 'lib/flipper/adapters/http/client.rb', line 28 def max_retries @max_retries end |
#open_timeout ⇒ Object (readonly)
Returns the value of attribute open_timeout.
27 28 29 |
# File 'lib/flipper/adapters/http/client.rb', line 27 def open_timeout @open_timeout end |
#read_timeout ⇒ Object (readonly)
Returns the value of attribute read_timeout.
27 28 29 |
# File 'lib/flipper/adapters/http/client.rb', line 27 def read_timeout @read_timeout end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
25 26 27 |
# File 'lib/flipper/adapters/http/client.rb', line 25 def uri @uri end |
#write_timeout ⇒ Object (readonly)
Returns the value of attribute write_timeout.
27 28 29 |
# File 'lib/flipper/adapters/http/client.rb', line 27 def write_timeout @write_timeout end |
Instance Method Details
#add_header(key, value) ⇒ Object
47 48 49 50 |
# File 'lib/flipper/adapters/http/client.rb', line 47 def add_header(key, value) key = key.to_s.downcase.gsub('_'.freeze, '-'.freeze).freeze @headers[key] = value end |
#delete(path, body = nil) ⇒ Object
60 61 62 |
# File 'lib/flipper/adapters/http/client.rb', line 60 def delete(path, body = nil) perform Net::HTTP::Delete, path, @headers, body: body end |
#get(path) ⇒ Object
52 53 54 |
# File 'lib/flipper/adapters/http/client.rb', line 52 def get(path) perform Net::HTTP::Get, path, @headers end |
#post(path, body = nil) ⇒ Object
56 57 58 |
# File 'lib/flipper/adapters/http/client.rb', line 56 def post(path, body = nil) perform Net::HTTP::Post, path, @headers, body: body end |