class SvcParty::Client

Attributes

base_uri[R]

Public Class Methods

new(base_uri, verify_ssl = true) click to toggle source
# File lib/svc_party.rb, line 15
def initialize(base_uri, verify_ssl = true)
  @base_uri = base_uri
  @verify_ssl = verify_ssl
end

Public Instance Methods

get_headers(_header_data = {}) click to toggle source

Extend this in your base class

# File lib/svc_party.rb, line 67
def get_headers(_header_data = {})
  raise NotImplementedError
end
with_delete(url, header_data = {}) { |api_response_handler.call| ... } click to toggle source
# File lib/svc_party.rb, line 56
def with_delete(url, header_data = {})
  response = self.class.delete(construct_url(url),
                               verify: @verify_ssl,
                               headers: get_headers(header_data))
  yield ApiResponseHandler.new(response).call

rescue StandardError => ex
  yield ApiResponseHandler.error(ex)
end
with_get(uri_endpoint, header_data = {}) { |api_response_handler.call| ... } click to toggle source
# File lib/svc_party.rb, line 20
def with_get(uri_endpoint, header_data = {})
  response = self.class.get(construct_url(uri_endpoint),
                            verify: @verify_ssl,
                            headers: get_headers(header_data))
  yield ApiResponseHandler.new(response).call

rescue StandardError => ex
  yield ApiResponseHandler.error(ex)
end
with_patch(url, params, header_data = {}) { |api_response_handler.call| ... } click to toggle source
# File lib/svc_party.rb, line 43
def with_patch(url, params, header_data = {})
  params = (params.class == String ? params : params.to_json)

  response = self.class.patch(construct_url(url),
                              verify: @verify_ssl,
                              body: params,
                              headers: get_headers(header_data))
  yield ApiResponseHandler.new(response).call

rescue StandardError => ex
  yield ApiResponseHandler.error(ex)
end
with_post(url, params, header_data = {}) { |api_response_handler.call| ... } click to toggle source
# File lib/svc_party.rb, line 30
def with_post(url, params, header_data = {})
  params = (params.class == String ? params : params.to_json)

  response = self.class.post(construct_url(url),
                             verify: @verify_ssl,
                             body: params,
                             headers: get_headers(header_data))
  yield ApiResponseHandler.new(response).call

rescue StandardError => ex
  yield ApiResponseHandler.error(ex)
end

Private Instance Methods

construct_url(uri_endpoint) click to toggle source
# File lib/svc_party.rb, line 73
def construct_url(uri_endpoint)
  # Support APIs that define a follow on url
  return uri_endpoint if uri_endpoint.start_with? 'http'
  URI.join(@base_uri, uri_endpoint)
end