Class: GoCardless::Services::BaseService

Inherits:
Object
  • Object
show all
Defined in:
lib/gocardless-pro/services/base_service.rb

Overview

Base Service that all services inherit from.

Instance Method Summary collapse

Constructor Details

#initialize(api_service) ⇒ BaseService

Create a new service instance to make requests against

Parameters:



9
10
11
# File 'lib/gocardless-pro/services/base_service.rb', line 9

def initialize(api_service)
  @api_service = api_service
end

Instance Method Details

#envelope_keyObject

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



24
25
26
# File 'lib/gocardless-pro/services/base_service.rb', line 24

def envelope_key
  fail NotImplementedError
end

#make_request(method, path, options = {}, custom_headers = {}) ⇒ Object

Make a request to the API using the API service instance

Parameters:

  • method (Symbol)

    the method to use to make the request

  • path (String)

    the URL (without the base domain) to make the request to

  • options (Hash) (defaults to: {})

    the options hash - either the query parameters for a GET, or the body if POST/PUT

  • custom_headers (Hash) (defaults to: {})

    a hash of custom headers to use in the request



19
20
21
# File 'lib/gocardless-pro/services/base_service.rb', line 19

def make_request(method, path, options = {}, custom_headers = {})
  @api_service.make_request(method, path, options.merge(envelope_key: envelope_key), custom_headers)
end