Module: Payout

Defined in:
lib/payout/response.rb,
lib/payout.rb,
lib/payout/v1/card.rb,
lib/payout/version.rb,
lib/payout/v1/balance.rb,
lib/payout/v1/payment.rb,
lib/payout/v1/bank_account.rb

Overview

Wraps a RestClient response to provide the Payout SDK interface.

Defined Under Namespace

Modules: V1 Classes: AuthenticationError, ConnectionError, Error, Response, TimeoutError, VersionError

Constant Summary collapse

DEFAULT_API_VERSION =
1
DEFAULT_OPEN_TIMEOUT =
30
DEFAULT_READ_TIMEOUT =
80
SSL_CA_FILE =
File.expand_path('../../data/ca-file.crt', __FILE__).freeze
VERSION =
'0.2.0'

Class Method Summary collapse

Class Method Details

.api_secretObject



44
45
46
47
# File 'lib/payout.rb', line 44

def api_secret
  @api_secret || fail(AuthenticationError,
    'Payout.api_secret must be defined')
end

.api_secret=(secret) ⇒ Object



77
78
79
# File 'lib/payout.rb', line 77

def api_secret=(secret)
  @api_secret = secret.dup.freeze
end

.api_tokenObject



39
40
41
42
# File 'lib/payout.rb', line 39

def api_token
  @api_token || fail(AuthenticationError,
    'Payout.api_token must be defined')
end

.api_token=(token) ⇒ Object



73
74
75
# File 'lib/payout.rb', line 73

def api_token=(token)
  @api_token = token.dup.freeze
end

.api_urlObject



35
36
37
# File 'lib/payout.rb', line 35

def api_url
  @api_url || 'https://live.payout.com'
end

.api_url=(api_url) ⇒ Object



64
65
66
67
68
69
70
71
# File 'lib/payout.rb', line 64

def api_url=(api_url)
  if api_url
    api_url = api_url.dup
    api_url = api_url[0..-2] if api_url[-1] == '/'
  end

  @api_url = api_url.freeze
end

.api_versionObject



27
28
29
30
31
32
33
# File 'lib/payout.rb', line 27

def api_version
  if const_defined?(:API_VERSION)
    API_VERSION
  else
    self.api_version = DEFAULT_API_VERSION
  end
end

.api_version=(version) ⇒ Object



57
58
59
60
61
62
# File 'lib/payout.rb', line 57

def api_version=(version)
  fail ArgumentError, 'must be an integer' unless version.is_a?(Integer)
  fail ArgumentError, 'must be a positive integer' unless version > 0

  _include_version(version)
end

.open_timeoutObject



49
50
51
# File 'lib/payout.rb', line 49

def open_timeout
  @open_timeout || DEFAULT_OPEN_TIMEOUT
end

.open_timeout=(timeout) ⇒ Object



81
82
83
84
# File 'lib/payout.rb', line 81

def open_timeout=(timeout)
  fail ArgumentError, 'must be an integer' unless timeout.is_a?(Integer)
  @open_timeout = timeout
end

.read_timeoutObject



53
54
55
# File 'lib/payout.rb', line 53

def read_timeout
  @read_timeout || DEFAULT_READ_TIMEOUT
end

.read_timeout=(timeout) ⇒ Object



86
87
88
89
# File 'lib/payout.rb', line 86

def read_timeout=(timeout)
  fail ArgumentError, 'must be an integer' unless timeout.is_a?(Integer)
  @read_timeout = timeout
end

.request(verb, path, params = {}) ⇒ Object



91
92
93
# File 'lib/payout.rb', line 91

def request(verb, path, params = {})
  Response.handle { request!(verb, path, params) }
end

.request!(verb, path, params) ⇒ Object



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/payout.rb', line 95

def request!(verb, path, params)
  url = _build_request_url(path)
  headers = _default_headers
  body = nil

  case verb
  when :get, :delete
    headers[:params] = params if params && params.any?
  when :post, :put
    headers[:content_type] = 'application/json'
    body = params.to_json if params && params.any?
  else
    fail ArgumentError, "invalid request verb: #{verb.inspect}"
  end

  _request(
    verify_ssl:   OpenSSL::SSL::VERIFY_PEER,
    ssl_ca_file:  SSL_CA_FILE,
    open_timeout: open_timeout,
    read_timeout: read_timeout,
    method:       verb,
    url:          url,
    headers:      headers,
    payload:      body
  )
end

.versionObject



23
24
25
# File 'lib/payout.rb', line 23

def version
  VERSION
end