class GoCardlessPro::Services::BaseService

Base Service that all services inherit from.

Public Class Methods

new(api_service) click to toggle source

Create a new service instance to make requests against

@param api_service [GoCardlessPro::ApiService}}] an instance of the ApiService

# File lib/gocardless_pro/services/base_service.rb, line 11
def initialize(api_service)
  @api_service = api_service
end

Public Instance Methods

envelope_key() click to toggle source

Get the envelope key for the given service. Children are expected to implement this method.

# File lib/gocardless_pro/services/base_service.rb, line 25
def envelope_key
  raise NotImplementedError
end
make_request(method, path, options = {}) click to toggle source

Make a request to the API using the API service instance

@param method [Symbol] the method to use to make the request @param path [String] the URL (without the base domain) to make the request to @param options [Hash] the options hash - either the query parameters for a GET, or the body if POST/PUT

# File lib/gocardless_pro/services/base_service.rb, line 20
def make_request(method, path, options = {})
  @api_service.make_request(method, path, options.merge(envelope_key: envelope_key))
end
sub_url(url, param_map) click to toggle source

take a URL with placeholder params and substitute them out for the actual value @param url [String] the URL with placeholders in @param param_map [Hash] a hash of placeholders and their actual values (which will be escaped)

# File lib/gocardless_pro/services/base_service.rb, line 32
def sub_url(url, param_map)
  param_map.reduce(url) do |new_url, (param, value)|
    new_url.gsub(":#{param}", CGI.escape(value))
  end
end