Class: SynapsePayments::Client
- Inherits:
-
Object
- Object
- SynapsePayments::Client
- 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
-
#api_base ⇒ Object
readonly
Returns the value of attribute api_base.
-
#client_id ⇒ Object
Returns the value of attribute client_id.
-
#client_secret ⇒ Object
Returns the value of attribute client_secret.
-
#sandbox_mode ⇒ Object
Returns the value of attribute sandbox_mode.
-
#subscriptions ⇒ Object
readonly
Returns the value of attribute subscriptions.
-
#timeout_options ⇒ Object
Returns the value of attribute timeout_options.
-
#users ⇒ Object
readonly
Returns the value of attribute users.
Instance Method Summary collapse
- #credentials ⇒ Hash
- #credentials? ⇒ Boolean
- #delete(path:, oauth_key: nil, fingerprint: nil) ⇒ Object
- #get(path:, oauth_key: nil, fingerprint: nil) ⇒ Object
-
#initialize(options = {}) {|_self| ... } ⇒ SynapsePayments::Client
constructor
Initializes a new Client object.
- #institutions ⇒ Array
- #patch(path:, json:, oauth_key: nil, fingerprint: nil) ⇒ Object
- #post(path:, json:, oauth_key: nil, fingerprint: nil, idempotency_key: nil) ⇒ Object
- #symbolize_keys!(object) ⇒ Object
Constructor Details
#initialize(options = {}) {|_self| ... } ⇒ SynapsePayments::Client
Initializes a new Client object
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(={}) @sandbox_mode = true @timeout_options = { write: 2, connect: 5, read: 10 } .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_base ⇒ Object (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_id ⇒ Object
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_secret ⇒ Object
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_mode ⇒ Object
Returns the value of attribute sandbox_mode.
9 10 11 |
# File 'lib/synapse_payments/client.rb', line 9 def sandbox_mode @sandbox_mode end |
#subscriptions ⇒ Object (readonly)
Returns the value of attribute subscriptions.
10 11 12 |
# File 'lib/synapse_payments/client.rb', line 10 def subscriptions @subscriptions end |
#timeout_options ⇒ Object
Returns the value of attribute timeout_options.
9 10 11 |
# File 'lib/synapse_payments/client.rb', line 9 def @timeout_options end |
#users ⇒ Object (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
#credentials ⇒ 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
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 |
#institutions ⇒ 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 |