Commit ec7e8d97 authored by Sergey Gernyak's avatar Sergey Gernyak

Passing application key to provider

parent d2d42bae
require 'active_support/core_ext/module/delegation'
require "betfair_api_ng_rails/errors" require "betfair_api_ng_rails/errors"
module BetfairApiNgRails module BetfairApiNgRails
...@@ -5,6 +6,8 @@ module BetfairApiNgRails ...@@ -5,6 +6,8 @@ module BetfairApiNgRails
class Connection class Connection
attr_reader :account_name attr_reader :account_name
delegate :app_key, to: :account
def initialize(account_name) def initialize(account_name)
@account_name = account_name @account_name = account_name
end end
...@@ -27,7 +30,7 @@ module BetfairApiNgRails ...@@ -27,7 +30,7 @@ module BetfairApiNgRails
protected protected
def provider def provider
@_provider ||= BetfairApiNgRails::Api::Provider.new request_ssoid BetfairApiNgRails::Api::Provider.new request_ssoid, app_key
end end
def request_ssoid def request_ssoid
......
...@@ -7,10 +7,11 @@ module BetfairApiNgRails ...@@ -7,10 +7,11 @@ module BetfairApiNgRails
include Api::Concerns::Errorable include Api::Concerns::Errorable
include Api::Constants include Api::Constants
attr_reader :ssoid attr_reader :ssoid, :application_key
def initialize(ssoid) def initialize(ssoid, application_key)
@ssoid = ssoid @ssoid = ssoid
@application_key = application_key
end end
def fetch(method: "", params: {}) def fetch(method: "", params: {})
......
...@@ -35,9 +35,14 @@ describe BetfairApiNgRails::Api::Connection do ...@@ -35,9 +35,14 @@ describe BetfairApiNgRails::Api::Connection do
context "private method" do context "private method" do
describe "#provider" do describe "#provider" do
let(:ssoid) { double(:ssoid) } let(:ssoid) { double(:ssoid) }
let(:app_key) { 'af2f23f23' }
before do
allow(subject).to receive(:app_key).and_return app_key
end
it "inits new provider" do it "inits new provider" do
expect(BetfairApiNgRails::Api::Provider).to receive(:new).with ssoid expect(BetfairApiNgRails::Api::Provider).to receive(:new).with ssoid, app_key
expect(subject).to receive(:request_ssoid).and_return ssoid expect(subject).to receive(:request_ssoid).and_return ssoid
subject.send(:provider) subject.send(:provider)
end end
......
...@@ -2,8 +2,9 @@ require 'spec_helper' ...@@ -2,8 +2,9 @@ require 'spec_helper'
describe BetfairApiNgRails::Api::Provider do describe BetfairApiNgRails::Api::Provider do
let(:ssoid) { double(:ssoid) } let(:ssoid) { double(:ssoid) }
let(:application_key) { '2ef8783ofno34fn' }
subject { described_class.new(ssoid) } subject { described_class.new(ssoid, application_key) }
its(:ssoid) { is_expected.to eq ssoid } its(:ssoid) { is_expected.to eq ssoid }
......
...@@ -4,6 +4,7 @@ require 'pry-nav' ...@@ -4,6 +4,7 @@ require 'pry-nav'
describe "placeOrders request method" do describe "placeOrders request method" do
let(:method_name) { "place_orders" } let(:method_name) { "place_orders" }
let(:result_class) { BetfairApiNgRails::PlaceExecutionReport } let(:result_class) { BetfairApiNgRails::PlaceExecutionReport }
let(:account) { BetfairApiNgRails::Account.new('user001', 'password', '42f2f434f3g43') }
let(:result_hash) do let(:result_hash) do
<<-JSON <<-JSON
{"result": {"result":
...@@ -28,6 +29,7 @@ describe "placeOrders request method" do ...@@ -28,6 +29,7 @@ describe "placeOrders request method" do
BetfairApiNgRails.config.formatter = nil BetfairApiNgRails.config.formatter = nil
BetfairApiNgRails.log = logger BetfairApiNgRails.log = logger
allow(logger).to receive(:write) allow(logger).to receive(:write)
allow(BetfairApiNgRails).to receive_message_chain(:account_manager, :get).and_return account
end end
context 'when no error occured' do context 'when no error occured' do
......
...@@ -2,11 +2,13 @@ shared_examples 'simple list filtering request' do |method| ...@@ -2,11 +2,13 @@ shared_examples 'simple list filtering request' do |method|
let(:parameters) { {filter: filter} } let(:parameters) { {filter: filter} }
let(:logger) { double(:logger) } let(:logger) { double(:logger) }
let(:account) { BetfairApiNgRails::Account.new('user001', 'password', '42f2f434f3g43') }
before(:each) do before(:each) do
BetfairApiNgRails.config.formatter = nil BetfairApiNgRails.config.formatter = nil
BetfairApiNgRails.log = logger BetfairApiNgRails.log = logger
allow(logger).to receive(:write) allow(logger).to receive(:write)
allow(BetfairApiNgRails).to receive_message_chain(:account_manager, :get).and_return account
end end
context 'when no error occured' do context 'when no error occured' do
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment