Sha256: 2e147f529143a53405639adde41abcacd981ee628d68b83b7d14beb5992cae84

Contents?: true

Size: 1.21 KB

Versions: 9

Compression:

Stored size: 1.21 KB

Contents

# frozen_string_literal: true

require 'graphql/account'

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': Graphql::Account::BALANCE
        }
      )

      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': Graphql::Account::FEED
        }
      )

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

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
nubank_sdk-0.7.9 lib/nubank_sdk/account.rb
nubank_sdk-0.7.8 lib/nubank_sdk/account.rb
nubank_sdk-0.7.7 lib/nubank_sdk/account.rb
nubank_sdk-0.7.6 lib/nubank_sdk/account.rb
nubank_sdk-0.7.5 lib/nubank_sdk/account.rb
nubank_sdk-0.7.4 lib/nubank_sdk/account.rb
nubank_sdk-0.7.3 lib/nubank_sdk/account.rb
nubank_sdk-0.7.2 lib/nubank_sdk/account.rb
nubank_sdk-0.7.1 lib/nubank_sdk/account.rb