Class: SynapsePayments::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/synapse_payments/client.rb

Constant Summary collapse

API_TEST =
'https://sandbox.synapsepay.com/api/3'
API_LIVE =
'https://synapsepay.com/api/3'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) {|_self| ... } ⇒ SynapsePayments::Client

Initializes a new Client object

Parameters:

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

Yields:

  • (_self)

Yield Parameters:



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/synapse_payments/client.rb', line 16

def initialize(options={})
  @sandbox_mode = true
  @timeout_options = { write: 2, connect: 5, read: 10 }

  options.each do |key, value|
    instance_variable_set("@#{key}", value)
  end

  yield(self) if block_given?

  @api_base = @sandbox_mode ? API_TEST : API_LIVE

  @users = Users.new(self)
  @subscriptions = Subscriptions.new(self)
end

Instance Attribute Details

#api_baseObject (readonly)

Returns the value of attribute api_base.



10
11
12
# File 'lib/synapse_payments/client.rb', line 10

def api_base
  @api_base
end

#client_idObject

Returns the value of attribute client_id.



9
10
11
# File 'lib/synapse_payments/client.rb', line 9

def client_id
  @client_id
end

#client_secretObject

Returns the value of attribute client_secret.



9
10
11
# File 'lib/synapse_payments/client.rb', line 9

def client_secret
  @client_secret
end

#sandbox_modeObject

Returns the value of attribute sandbox_mode.



9
10
11
# File 'lib/synapse_payments/client.rb', line 9

def sandbox_mode
  @sandbox_mode
end

#subscriptionsObject (readonly)

Returns the value of attribute subscriptions.



10
11
12
# File 'lib/synapse_payments/client.rb', line 10

def subscriptions
  @subscriptions
end

#timeout_optionsObject

Returns the value of attribute timeout_options.



9
10
11
# File 'lib/synapse_payments/client.rb', line 9

def timeout_options
  @timeout_options
end

#usersObject (readonly)

Returns the value of attribute users.



10
11
12
# File 'lib/synapse_payments/client.rb', line 10

def users
  @users
end

Instance Method Details

#credentialsHash

Returns:

  • (Hash)


33
34
35
36
37
38
# File 'lib/synapse_payments/client.rb', line 33

def credentials
  {
    client_id: client_id,
    client_secret: client_secret
  }
end

#credentials?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/synapse_payments/client.rb', line 41

def credentials?
  credentials.values.all?
end

#delete(path:, oauth_key: nil, fingerprint: nil) ⇒ Object



64
65
66
# File 'lib/synapse_payments/client.rb', line 64

def delete(path:, oauth_key: nil, fingerprint: nil)
  Request.new(client: self, method: :delete, path: path, oauth_key: oauth_key, fingerprint: fingerprint).perform
end

#get(path:, oauth_key: nil, fingerprint: nil) ⇒ Object



52
53
54
# File 'lib/synapse_payments/client.rb', line 52

def get(path:, oauth_key: nil, fingerprint: nil)
  Request.new(client: self, method: :get, path: path, oauth_key: oauth_key, fingerprint: fingerprint).perform
end

#institutionsArray

Returns:

  • (Array)


46
47
48
49
50
# File 'lib/synapse_payments/client.rb', line 46

def institutions
  institutions = HTTP.get('https://synapsepay.com/api/v3/institutions/show').parse
  symbolize_keys!(institutions)
  institutions[:banks]
end

#patch(path:, json:, oauth_key: nil, fingerprint: nil) ⇒ Object



60
61
62
# File 'lib/synapse_payments/client.rb', line 60

def patch(path:, json:, oauth_key: nil, fingerprint: nil)
  Request.new(client: self, method: :patch, path: path, oauth_key: oauth_key, fingerprint: fingerprint, json: json).perform
end

#post(path:, json:, oauth_key: nil, fingerprint: nil, idempotency_key: nil) ⇒ Object



56
57
58
# File 'lib/synapse_payments/client.rb', line 56

def post(path:, json:, oauth_key: nil, fingerprint: nil, idempotency_key: nil)
  Request.new(client: self, method: :post, path: path, oauth_key: oauth_key, fingerprint: fingerprint, json: json, idempotency_key: idempotency_key).perform
end

#symbolize_keys!(object) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/synapse_payments/client.rb', line 68

def symbolize_keys!(object)
  if object.is_a?(Array)
    object.each_with_index do |val, index|
      object[index] = symbolize_keys!(val)
    end
  elsif object.is_a?(Hash)
    object.keys.each do |key|
      object[key.to_sym] = symbolize_keys!(object.delete(key))
    end
  end
  object
end