class GoCardlessPro::Client

A class for working with and talking to the GoCardless API

Public Class Methods

new(options) click to toggle source

Get a Client configured to use HTTP Basic authentication with the GC Api

@param options [Hash<Symbol,String>] configuration for creating the client @option options [Symbol] :environment the environment to connect to - one of `:live` or `:sandbox`. @option options [Symbol] :access_token the API token @option options [Symbol] :url the full URL used to make requests to. If you specify this, it will be used over the `environment` option. @option options [Symbol] :connection_options `Faraday` connection options hash, e.g. `{ request: { timeout: 3 } }`. @return [Client] A client configured to use the API with HTTP Basic

authentication.
# File lib/gocardless_pro/client.rb, line 156
def initialize(options)
  access_token = options.delete(:access_token) || raise('No Access Token given to GoCardless Client')
  environment = options.delete(:environment) || :live
  url = options.delete(:url) || url_for_environment(environment)
  options = custom_options(options)
  @api_service = ApiService.new(url, access_token, options)
end

Public Instance Methods

bank_authorisations() click to toggle source

Access to the service for bank_authorisation to make API calls

# File lib/gocardless_pro/client.rb, line 7
def bank_authorisations
  @bank_authorisations ||= Services::BankAuthorisationsService.new(@api_service)
end
bank_details_lookups() click to toggle source

Access to the service for bank_details_lookup to make API calls

# File lib/gocardless_pro/client.rb, line 12
def bank_details_lookups
  @bank_details_lookups ||= Services::BankDetailsLookupsService.new(@api_service)
end
billing_request_flows() click to toggle source

Access to the service for billing_request_flow to make API calls

# File lib/gocardless_pro/client.rb, line 22
def billing_request_flows
  @billing_request_flows ||= Services::BillingRequestFlowsService.new(@api_service)
end
billing_request_templates() click to toggle source

Access to the service for billing_request_template to make API calls

# File lib/gocardless_pro/client.rb, line 27
def billing_request_templates
  @billing_request_templates ||= Services::BillingRequestTemplatesService.new(@api_service)
end
billing_requests() click to toggle source

Access to the service for billing_request to make API calls

# File lib/gocardless_pro/client.rb, line 17
def billing_requests
  @billing_requests ||= Services::BillingRequestsService.new(@api_service)
end
creditor_bank_accounts() click to toggle source

Access to the service for creditor_bank_account to make API calls

# File lib/gocardless_pro/client.rb, line 37
def creditor_bank_accounts
  @creditor_bank_accounts ||= Services::CreditorBankAccountsService.new(@api_service)
end
creditors() click to toggle source

Access to the service for creditor to make API calls

# File lib/gocardless_pro/client.rb, line 32
def creditors
  @creditors ||= Services::CreditorsService.new(@api_service)
end
currency_exchange_rates() click to toggle source

Access to the service for currency_exchange_rate to make API calls

# File lib/gocardless_pro/client.rb, line 42
def currency_exchange_rates
  @currency_exchange_rates ||= Services::CurrencyExchangeRatesService.new(@api_service)
end
customer_bank_accounts() click to toggle source

Access to the service for customer_bank_account to make API calls

# File lib/gocardless_pro/client.rb, line 52
def customer_bank_accounts
  @customer_bank_accounts ||= Services::CustomerBankAccountsService.new(@api_service)
end
customer_notifications() click to toggle source

Access to the service for customer_notification to make API calls

# File lib/gocardless_pro/client.rb, line 57
def customer_notifications
  @customer_notifications ||= Services::CustomerNotificationsService.new(@api_service)
end
customers() click to toggle source

Access to the service for customer to make API calls

# File lib/gocardless_pro/client.rb, line 47
def customers
  @customers ||= Services::CustomersService.new(@api_service)
end
events() click to toggle source

Access to the service for event to make API calls

# File lib/gocardless_pro/client.rb, line 62
def events
  @events ||= Services::EventsService.new(@api_service)
end
instalment_schedules() click to toggle source

Access to the service for instalment_schedule to make API calls

# File lib/gocardless_pro/client.rb, line 67
def instalment_schedules
  @instalment_schedules ||= Services::InstalmentSchedulesService.new(@api_service)
end
institutions() click to toggle source

Access to the service for institution to make API calls

# File lib/gocardless_pro/client.rb, line 72
def institutions
  @institutions ||= Services::InstitutionsService.new(@api_service)
end
mandate_import_entries() click to toggle source

Access to the service for mandate_import_entry to make API calls

# File lib/gocardless_pro/client.rb, line 87
def mandate_import_entries
  @mandate_import_entries ||= Services::MandateImportEntriesService.new(@api_service)
end
mandate_imports() click to toggle source

Access to the service for mandate_import to make API calls

# File lib/gocardless_pro/client.rb, line 82
def mandate_imports
  @mandate_imports ||= Services::MandateImportsService.new(@api_service)
end
mandate_pdfs() click to toggle source

Access to the service for mandate_pdf to make API calls

# File lib/gocardless_pro/client.rb, line 92
def mandate_pdfs
  @mandate_pdfs ||= Services::MandatePdfsService.new(@api_service)
end
mandates() click to toggle source

Access to the service for mandate to make API calls

# File lib/gocardless_pro/client.rb, line 77
def mandates
  @mandates ||= Services::MandatesService.new(@api_service)
end
payer_authorisations() click to toggle source

Access to the service for payer_authorisation to make API calls

# File lib/gocardless_pro/client.rb, line 97
def payer_authorisations
  @payer_authorisations ||= Services::PayerAuthorisationsService.new(@api_service)
end
payments() click to toggle source

Access to the service for payment to make API calls

# File lib/gocardless_pro/client.rb, line 102
def payments
  @payments ||= Services::PaymentsService.new(@api_service)
end
payout_items() click to toggle source

Access to the service for payout_item to make API calls

# File lib/gocardless_pro/client.rb, line 112
def payout_items
  @payout_items ||= Services::PayoutItemsService.new(@api_service)
end
payouts() click to toggle source

Access to the service for payout to make API calls

# File lib/gocardless_pro/client.rb, line 107
def payouts
  @payouts ||= Services::PayoutsService.new(@api_service)
end
redirect_flows() click to toggle source

Access to the service for redirect_flow to make API calls

# File lib/gocardless_pro/client.rb, line 117
def redirect_flows
  @redirect_flows ||= Services::RedirectFlowsService.new(@api_service)
end
refunds() click to toggle source

Access to the service for refund to make API calls

# File lib/gocardless_pro/client.rb, line 122
def refunds
  @refunds ||= Services::RefundsService.new(@api_service)
end
scenario_simulators() click to toggle source

Access to the service for scenario_simulator to make API calls

# File lib/gocardless_pro/client.rb, line 127
def scenario_simulators
  @scenario_simulators ||= Services::ScenarioSimulatorsService.new(@api_service)
end
subscriptions() click to toggle source

Access to the service for subscription to make API calls

# File lib/gocardless_pro/client.rb, line 132
def subscriptions
  @subscriptions ||= Services::SubscriptionsService.new(@api_service)
end
tax_rates() click to toggle source

Access to the service for tax_rate to make API calls

# File lib/gocardless_pro/client.rb, line 137
def tax_rates
  @tax_rates ||= Services::TaxRatesService.new(@api_service)
end
webhooks() click to toggle source

Access to the service for webhook to make API calls

# File lib/gocardless_pro/client.rb, line 142
def webhooks
  @webhooks ||= Services::WebhooksService.new(@api_service)
end

Private Instance Methods

custom_options(options) click to toggle source

Get customized options.

# File lib/gocardless_pro/client.rb, line 177
def custom_options(options)
  return default_options if options.nil?

  return default_options.merge(options) unless options[:default_headers]

  opts = default_options.merge(options)
  opts[:default_headers] = default_options[:default_headers].merge(options[:default_headers])

  opts
end
default_options() click to toggle source

Get the default options.

# File lib/gocardless_pro/client.rb, line 189
def default_options
  {
    default_headers: {
      'GoCardless-Version' => '2015-07-06',
      'User-Agent' => user_agent.to_s,
      'Content-Type' => 'application/json',
      'GoCardless-Client-Library' => 'gocardless-pro-ruby',
      'GoCardless-Client-Version' => '2.28.0',
    },
  }
end
url_for_environment(environment) click to toggle source
# File lib/gocardless_pro/client.rb, line 166
def url_for_environment(environment)
  if environment === :live
    'https://api.gocardless.com'
  elsif environment === :sandbox
    'https://api-sandbox.gocardless.com'
  else
    raise "Unknown environment key: #{environment}"
  end
end
user_agent() click to toggle source
# File lib/gocardless_pro/client.rb, line 201
def user_agent
  @user_agent ||=
    begin
      gem_info = 'gocardless-pro-ruby'
      gem_info += "/v#{GoCardlessPro::VERSION}" if defined?(GoCardlessPro::VERSION)

      ruby_engine = defined?(RUBY_ENGINE) ? RUBY_ENGINE : 'ruby'

      ruby_version = RUBY_VERSION
      ruby_version += "p#{RUBY_PATCHLEVEL}" if defined?(RUBY_PATCHLEVEL)

      interpreter_version = defined?(JRUBY_VERSION) ? JRUBY_VERSION : RUBY_VERSION

      comment = [
        "#{ruby_engine}/#{ruby_version}",
        "#{RUBY_ENGINE}/#{interpreter_version}",
        RUBY_PLATFORM.to_s,
      ]
      comment << "faraday/#{Faraday::VERSION}"
      "#{gem_info} #{comment.join(' ')}"
    end
end