Class: NeetoCommonsBackend::Helpers::AuthServerApi

Inherits:
Object
  • Object
show all
Defined in:
lib/neeto_commons_backend/helpers/auth_server_api.rb

Constant Summary collapse

MAX_RETRIES =
5
REQUEST_CLASSES =
{
  get: Net::HTTP::Get,
  post: Net::HTTP::Post,
  put: Net::HTTP::Put,
  delete: Net::HTTP::Delete
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(custom_headers: {}) ⇒ AuthServerApi

Returns a new instance of AuthServerApi.



15
16
17
# File 'lib/neeto_commons_backend/helpers/auth_server_api.rb', line 15

def initialize(custom_headers: {})
  @custom_headers = custom_headers
end

Instance Attribute Details

#custom_headersObject (readonly)

Returns the value of attribute custom_headers.



13
14
15
# File 'lib/neeto_commons_backend/helpers/auth_server_api.rb', line 13

def custom_headers
  @custom_headers
end

#endpointObject (readonly)

Returns the value of attribute endpoint.



13
14
15
# File 'lib/neeto_commons_backend/helpers/auth_server_api.rb', line 13

def endpoint
  @endpoint
end

#request_bodyObject (readonly)

Returns the value of attribute request_body.



13
14
15
# File 'lib/neeto_commons_backend/helpers/auth_server_api.rb', line 13

def request_body
  @request_body
end

#request_classObject (readonly)

Returns the value of attribute request_class.



13
14
15
# File 'lib/neeto_commons_backend/helpers/auth_server_api.rb', line 13

def request_class
  @request_class
end

#request_paramsObject (readonly)

Returns the value of attribute request_params.



13
14
15
# File 'lib/neeto_commons_backend/helpers/auth_server_api.rb', line 13

def request_params
  @request_params
end

Instance Method Details

#delete(**args) ⇒ Object



31
32
33
# File 'lib/neeto_commons_backend/helpers/auth_server_api.rb', line 31

def delete(**args)
  request(type: :delete, **args)
end

#get(**args) ⇒ Object



19
20
21
# File 'lib/neeto_commons_backend/helpers/auth_server_api.rb', line 19

def get(**args)
  request(type: :get, **args)
end

#post(**args) ⇒ Object



27
28
29
# File 'lib/neeto_commons_backend/helpers/auth_server_api.rb', line 27

def post(**args)
  request(type: :post, **args)
end

#put(**args) ⇒ Object



23
24
25
# File 'lib/neeto_commons_backend/helpers/auth_server_api.rb', line 23

def put(**args)
  request(type: :put, **args)
end

#request(type:, **args) ⇒ Object



35
36
37
38
39
40
# File 'lib/neeto_commons_backend/helpers/auth_server_api.rb', line 35

def request(type:, **args)
  return if Rails.env.heroku?

  @request_class = REQUEST_CLASSES[type]
  process(**args)
end