Class: FlexOps::HttpClient

Inherits:
Object
  • Object
show all
Defined in:
lib/flexops/http.rb

Constant Summary collapse

DEFAULT_BASE_URL =
"https://gateway.flexops.io"
DEFAULT_TIMEOUT =
30
MAX_RETRIES =
3
RETRYABLE_STATUSES =
[429, 500, 502, 503, 504].freeze

Instance Method Summary collapse

Constructor Details

#initialize(base_url: DEFAULT_BASE_URL, api_key: nil, access_token: nil, timeout: DEFAULT_TIMEOUT) ⇒ HttpClient

Returns a new instance of HttpClient.



20
21
22
23
24
25
# File 'lib/flexops/http.rb', line 20

def initialize(base_url: DEFAULT_BASE_URL, api_key: nil, access_token: nil, timeout: DEFAULT_TIMEOUT)
  @base_url = base_url.chomp("/")
  @api_key = api_key
  @access_token = access_token
  @timeout = timeout
end

Instance Method Details

#delete(path) ⇒ Object



53
54
55
# File 'lib/flexops/http.rb', line 53

def delete(path)
  request(:delete, path)
end

#get(path, query: nil) ⇒ Object



37
38
39
# File 'lib/flexops/http.rb', line 37

def get(path, query: nil)
  request(:get, path, query: query)
end

#patch(path, body: nil) ⇒ Object



49
50
51
# File 'lib/flexops/http.rb', line 49

def patch(path, body: nil)
  request(:patch, path, body: body)
end

#post(path, body: nil, query: nil) ⇒ Object



41
42
43
# File 'lib/flexops/http.rb', line 41

def post(path, body: nil, query: nil)
  request(:post, path, body: body, query: query)
end

#put(path, body: nil) ⇒ Object



45
46
47
# File 'lib/flexops/http.rb', line 45

def put(path, body: nil)
  request(:put, path, body: body)
end

#set_access_token(token) ⇒ Object



27
28
29
30
# File 'lib/flexops/http.rb', line 27

def set_access_token(token)
  @access_token = token
  @api_key = nil
end

#set_api_key(key) ⇒ Object



32
33
34
35
# File 'lib/flexops/http.rb', line 32

def set_api_key(key)
  @api_key = key
  @access_token = nil
end