Sha256: 071025e116725d196fd199c8ecef86c42a0a4e350bca82b96fda75051dbbf86a
Contents?: true
Size: 1.45 KB
Versions: 3
Compression:
Stored size: 1.45 KB
Contents
# frozen_string_literal: true require 'time' require 'base64' require 'json' require 'fractal_api/base_model' module FractalApi class Consent < BaseModel attributes :consent_id, :company_id, :bank_id, :permission, :date_created, :consent_type, :status, :type, :signin_url def self.create(bank_id, company_id, redirect_url) params = { redirect: redirect_url, permission: 'ReadAllBankData' } url = format_url( '/banking/v2/banks/:bank_id/consents', bank_id: bank_id.to_s ) result = post(url, params: params, headers: { 'X-Company-Id' => company_id }) build(json: result.body) end def self.build(json:) super.tap do |record| record.date_created = Time.parse(record.date_created) if record.date_created end end def self.build_from_state(state) decoded = JSON.parse(Base64.decode64(state), symbolize_names: true) new( consent_id: decoded[:accReq], company_id: decoded[:cId], bank_id: decoded[:bId] ) rescue JSON::ParserError nil end def update(code:, id_token:, state:) url = format_url( '/banking/v2/banks/:bank_id/consents/:consent_id', bank_id: bank_id.to_s, consent_id: consent_id ) result = put( url, params: { code: code, id_token: id_token, state: state }, headers: { 'X-Company-Id' => company_id } ) result.body end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
fractal_api-0.1.2 | lib/fractal_api/consent.rb |
fractal_api-0.1.1 | lib/fractal_api/consent.rb |
fractal_api-0.1.0 | lib/fractal_api/consent.rb |