Sha256: 0e57fe8e50db91df505505a6108558a408768944c57cdd767e085ef3ea6aaf24

Contents?: true

Size: 1.26 KB

Versions: 1

Compression:

Stored size: 1.26 KB

Contents

module Banks
  class Csas
    # 7777777777
    # https://help.salesforce.com/apex/HTViewHelpDoc?id=remoteaccess_oauth_refresh_token_flow.htm&language=en_US

    def initialize(token, config)
      @config = config
      @token = get_token(token)
    end

    def accounts
      JSON.parse(RestClient.get(@config[:base_uri] + '/netbanking/my/accounts', headers), symbolize_names: true)[:accounts]
    end

    def ibans
      accounts.collect{|ac| ac[:accountno][:iban]}
    end

    def transactions(time_start = nil, time_end = nil, iban = nil)
      url = @config[:base_uri] + '/netbanking/my/accounts/' + iban.to_s + '/transactions'
      url += "?dateStart=#{time_start.iso8601}" if time_start.present?
      url += "#{url =~ /\?/ ? '&' : '?'}dateEnd=#{time_end.iso8601}" if time_end.present?

      JSON.parse RestClient.get(url, headers), symbolize_names: true
    end

    private

    def headers
      {'WEB-API-key' => @config[:web_api_key], 'Authorization' => "Bearer #{@token}", accept: :json}
    end

    def get_token(token)
      response = RestClient.post @config[:token_uri], {grant_type: 'refresh_token', client_id: @config[:client_id], client_secret: @config[:secret], refresh_token: token}
      JSON.parse(response, symbolize_names: true)[:access_token]
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
czech_banks_parser-0.0.1 lib/banks/csas.rb