module FidorApi::Client::DSL
Constants
- POSSIBLE_CONFIRMABLE_HEADERS
Public Class Methods
included(klass)
click to toggle source
# File lib/fidor_api/client/dsl.rb, line 16 def self.included(klass) # rubocop:disable Metrics/MethodLength klass.include Accounts klass.include Cards klass.include ConfirmableActions klass.include CoreData klass.include DebitReturns klass.include Messages klass.include Preauths klass.include ScheduledTransfers klass.include StandingOrders klass.include Transactions klass.include Transfers end
Private Instance Methods
create(klass, endpoint, attributes, options = {})
click to toggle source
# File lib/fidor_api/client/dsl.rb, line 45 def create(klass, endpoint, attributes, options = {}) headers = options.delete(:headers) || {} request_model(klass, endpoint, :post, attributes, headers) end
extract_confirmable_id(headers)
click to toggle source
# File lib/fidor_api/client/dsl.rb, line 76 def extract_confirmable_id(headers) return if (tuple = headers.detect { |key, value| POSSIBLE_CONFIRMABLE_HEADERS.include?(key) && value.present? }).nil? tuple.last.split('/').last end
fetch(type, klass, endpoint, options)
click to toggle source
# File lib/fidor_api/client/dsl.rb, line 32 def fetch(type, klass, endpoint, options) headers = options.delete(:headers) || {} case type when :single klass.new(connection.get(endpoint, query: options, headers: headers).body) when :collection Collection.new(klass: klass, raw: connection.get(endpoint, query: options, headers: headers).body) else raise ArgumentError end end
request(method, endpoint, attributes, headers = {})
click to toggle source
# File lib/fidor_api/client/dsl.rb, line 70 def request(method, endpoint, attributes, headers = {}) connection.public_send(method, endpoint, body: attributes, headers: headers) end
request_model(klass, endpoint, method, attributes, headers = {})
click to toggle source
# File lib/fidor_api/client/dsl.rb, line 57 def request_model(klass, endpoint, method, attributes, headers = {}) # rubocop:disable Metrics/AbcSize model = klass.new(attributes) model.tap do |m| response = request(method, endpoint, m.as_json, headers) m.set_attributes(response.body) if response.body.is_a?(Hash) m.confirmable_action_id = extract_confirmable_id(response.headers) end rescue Faraday::ClientError => e raise if e.response[:status] != 422 model.tap { |m| m.parse_errors(e.response[:body]) } end
update(klass, endpoint, id, attributes, options = {})
click to toggle source
# File lib/fidor_api/client/dsl.rb, line 51 def update(klass, endpoint, id, attributes, options = {}) headers = options.delete(:headers) || {} request_model(klass, endpoint, :put, attributes.merge(id: id), headers) end