class GoCardless::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] :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. @return [Client] A client configured to use the API with HTTP Basic

authentication.
# File lib/gocardless-pro/client.rb, line 75
def initialize(options)
  access_token = options.delete(:token) || fail('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

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 12
def creditor_bank_accounts
  @creditor_bank_accounts ||= Services::CreditorBankAccountService.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 7
def creditors
  @creditors ||= Services::CreditorService.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 22
def customer_bank_accounts
  @customer_bank_accounts ||= Services::CustomerBankAccountService.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 17
def customers
  @customers ||= Services::CustomerService.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 27
def events
  @events ||= Services::EventService.new(@api_service)
end
helpers() click to toggle source

Access to the service for helper to make API calls

# File lib/gocardless-pro/client.rb, line 32
def helpers
  @helpers ||= Services::HelperService.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 37
def mandates
  @mandates ||= Services::MandateService.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 42
def payments
  @payments ||= Services::PaymentService.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 47
def payouts
  @payouts ||= Services::PayoutService.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 52
def redirect_flows
  @redirect_flows ||= Services::RedirectFlowService.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 57
def refunds
  @refunds ||= Services::RefundService.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 62
def subscriptions
  @subscriptions ||= Services::SubscriptionService.new(@api_service)
end

Private Instance Methods

custom_options(options) click to toggle source

Get customized options.

# File lib/gocardless-pro/client.rb, line 96
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 108
def default_options
  {
    default_headers: {
      'GoCardless-Version' => '2015-04-07',
      'User-Agent' => "#{user_agent}",
      'Content-Type' => 'application/json'
    }
  }
end
url_for_environment(environment) click to toggle source
# File lib/gocardless-pro/client.rb, line 85
def url_for_environment(environment)
  if environment === :live
    'https://api.gocardless.com'
  elsif environment === :sandbox
    'https://api-sandbox.gocardless.com'
  else
    fail "Unknown environment key: #{environment}"
  end
end
user_agent() click to toggle source
# File lib/gocardless-pro/client.rb, line 118
def user_agent
  @user_agent ||=
    begin
      gem_name = 'gocardless-pro'
      gem_info = "#{gem_name}"
      gem_info += "/v#{ GoCardless::VERSION}" if defined?(GoCardless::VERSION)
      ruby_engine = defined?(RUBY_ENGINE) ? RUBY_ENGINE : 'ruby'
      ruby_version = RUBY_VERSION
      ruby_version += " p#{RUBY_PATCHLEVEL}" if defined?(RUBY_PATCHLEVEL)
      comment = ["#{ruby_engine} #{ruby_version}"]
      comment << "gocardless-pro v#{ GoCardless::VERSION}"
      comment << "faraday v#{Faraday::VERSION}"
      comment << RUBY_PLATFORM if defined?(RUBY_PLATFORM)
      "#{gem_info} (#{comment.join('; ')})"
    end
end