Sha256: e1dc333d0c39f96e323280f32f8e39659c46376f82560f7dd056913379465c92

Contents?: true

Size: 1.89 KB

Versions: 5

Compression:

Stored size: 1.89 KB

Contents

# frozen_string_literal: true

require 'base64'
require 'json'
require 'faraday'
require 'fintecture/utils/validation'
require 'fintecture/exceptions'
require 'fintecture/utils/date'
require 'fintecture/utils/constants'

module Fintecture
  module Ais
    class Accounts
      class << self
        # ------------ PUBLIC METHOD ------------
        def get(client, customer_id, account_id, remove_nulls, withBalances)
          @client = client

          # Do the request
          _request customer_id, account_id, remove_nulls, withBalances
        end

        private

        # ------------ REQUEST ------------
        def _request(customer_id, account_id, remove_nulls, withBalances)
          # Get the url request
          url = _endpoint customer_id, account_id

          # Build uri params
          query_string = ''
          if remove_nulls || withBalances
            params = {}
            params['remove_nulls'] = remove_nulls if remove_nulls
            params['withBalances'] = withBalances if withBalances

            query_string = "?#{params.map { |key, value| "#{key}=#{value}" }.join('&')}"
          end

          # Do connect request
          Fintecture::Faraday::Authentication::Connection.get(
            url: url + query_string,
            client: @client,
            custom_content_type: 'application/json',
            bearer: "Bearer #{@client.token}",
            secure_headers: true
          )
        end

        # ------------ API ENDPOINT ------------
        def _endpoint(customer_id, account_id)
          "#{_api_base_url}/#{Fintecture::Api::Endpoints::Ais::ACCOUNTS}/#{customer_id}/accounts/#{account_id || ''}"
        end

        # ------------ BASE URL ------------
        def _api_base_url
          Fintecture::Api::BaseUrl::FINTECTURE_API_URL[@client.environment.to_sym]
        end

      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
fintecture-0.5.1 lib/fintecture/api/ais/accounts.rb
fintecture-0.5.0 lib/fintecture/api/ais/accounts.rb
fintecture-0.4.1 lib/fintecture/api/ais/accounts.rb
fintecture-0.3.1 lib/fintecture/api/ais/accounts.rb
fintecture-0.3.0 lib/fintecture/api/ais/accounts.rb