Sha256: 9ae69c9db6623ef8bdcfa3f2b7901f81531a2b0926a2bc045cb362164a823f71

Contents?: true

Size: 1.24 KB

Versions: 1

Compression:

Stored size: 1.24 KB

Contents

# frozen_string_literal: true

module NubankSdk
  #
  # Returns the account statement
  #
  class Account
    #
    # Returns the account statement
    #
    # @param [NubankSdk::Client::HTTPS] connection
    # @param [NubankSdk::ApiRoutes] api_routes
    def initialize(connection:, api_routes:)
      @connection = connection
      @api_routes = api_routes
    end

    #
    # Returns the account balance
    #
    # @return [Float]
    def balance
      query_url = @api_routes.entrypoint(path: :ssl, entrypoint: :query)

      response = @connection.post(
        query_url, {
          'variables': {},
          'query': '{viewer {savingsAccount {currentSavingsBalance {netAmount}}}}'
        }
      )

      data = Client.get_body(response)
      data[:data][:viewer][:savingsAccount][:currentSavingsBalance][:netAmount]
    end

    #
    # Returns the account feed
    #
    # @return [Array<Hash>]
    def feed
      query_url = @api_routes.entrypoint(path: :ssl, entrypoint: :query)

      response = @connection.post(
        query_url, {
          'variables': {},
          'query': Utils.read_graphql_query('account', 'feed')
        }
      )

      data = Client.get_body(response)
      data[:data][:viewer][:savingsAccount][:feed]
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
nubank_sdk-0.7.0 lib/nubank_sdk/account.rb