This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def self.internal_api(*args) | |
| self.faraday(*args) do |f| | |
| f.headers['Content-Type'] = 'application/json' | |
| f.headers['InternalAPIPassword'] = ENV['INTERNAL_API_PASSWORD'] | |
| f.headers['UserRole'] = ENV['USER_ROLE'] | |
| f.headers['UserCode'] = ENV['USER_CODE'] | |
| f.options.open_timeout = 10 | |
| f.options.timeout = 20 | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def call | |
| # code omitted | |
| res = Connection.internal_api.post do |req| | |
| req.url "#{ENV['TRANSACTION_HOST']}/transactions" | |
| req.headers['UserCode'] = params[:user_serial] | |
| req.body = params.to_json | |
| end | |
| # code omitted |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def call | |
| # code omitted | |
| res = Connection.internal_api.get do |req| | |
| req.url "#{ENV['TRANSACTION_HOST']}/transactions?user_id=#{user_id}" | |
| req.headers['UserRole'] = 'new_value' | |
| req.headers['OtherHeader'] = 'other_value' | |
| end | |
| # code omitted |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def call | |
| # code omitted | |
| res = Connection.internal_api.get do |req| | |
| req.url "#{ENV['TRANSACTION_HOST']}/transactions?user_id=#{user_id}" | |
| end | |
| # code omitted | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Connection | |
| def self.internal_api(*args) | |
| self.faraday(*args) do |f| | |
| f.headers['Content-Type'] = 'application/json' | |
| f.headers['InternalAPIPassword'] = ENV['INTERNAL_API_PASSWORD'] | |
| f.headers['UserRole'] = ENV['USER_ROLE'] | |
| f.headers['UserCode'] = ENV['USER_CODE'] | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def call | |
| # code omitted | |
| conn = Faraday.new | |
| res = conn.get do |req| | |
| req.url "#{ENV['TRANSACTION_HOST']}/transactions?user_id=#{user_id}" | |
| req.headers['Content-Type'] = 'application/json' | |
| req.headers['InternalAPIPassword'] = ENV['INTERNAL_API_PASSWORD'] | |
| req.headers['UserCode'] = ENV['USER_CODE'] | |
| req.headers['UserRole'] = ENV['USER_ROLE'] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'rails_helper' | |
| RSpec.describe TransferMoneyService, type: :model do | |
| describe '#call' do | |
| let(:sender) { create(:user) } | |
| let!(:sender_account) { create(:account, balance: 1_000, user: sender) } | |
| let(:receiver) { create(:user) } | |
| let!(:receiver_account) { create(:account, balance: 0, user: receiver) } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'rails_helper' | |
| RSpec.describe TransferMoneyService, type: :model do | |
| describe '#call' do | |
| let(:sender) { create(:user) } | |
| let!(:sender_account) { create(:account, balance: 1_000, user: sender) } | |
| let(:receiver) { create(:user) } | |
| let!(:receiver_account) { create(:account, balance: 0, user: receiver) } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'rails_helper' | |
| RSpec.describe TransferMoneyService, type: :model do | |
| describe '#call' do | |
| let(:sender) { create(:user) } | |
| let!(:sender_account) { create(:account, balance: 1_000, user: sender) } | |
| let(:receiver) { create(:user) } | |
| let!(:receiver_account) { create(:account, balance: 0, user: receiver) } | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class TransferMoneyService | |
| def initialize(sender, receiver, amount) | |
| @sender = sender | |
| @receiver = receiver | |
| @amount = amount | |
| end | |
| def call | |
| sender_account = sender.account | |
| receiver_account = receiver.account |
NewerOlder