Commit 53ff8227 authored by Sergey Gernyak's avatar Sergey Gernyak

Small request methods refactor

parent 6f80f09e
...@@ -13,8 +13,8 @@ module BetfairApiNgRails ...@@ -13,8 +13,8 @@ module BetfairApiNgRails
private private
def run_request(method, params, data = {}) def run_request(method, params, account_name = '')
BetfairApiNgRails.connection.request build_request_type(method), params.merge(data) BetfairApiNgRails.connection.request build_request_type(method), params#, account_name
end end
def build_request_type(name) def build_request_type(name)
......
...@@ -6,21 +6,21 @@ module BetfairApiNgRails ...@@ -6,21 +6,21 @@ module BetfairApiNgRails
SIMPLE_LISTING_FILTERED.each do |method| SIMPLE_LISTING_FILTERED.each do |method|
eval <<-CODE eval <<-CODE
def #{method.underscore}(filter: Api::Data::MarketFilter.new, locale: BetfairApiNgRails.config.locale) def #{method.underscore}(filter: BetfairApiNgRails::MarketFilter.new, locale: BetfairApiNgRails.config.locale)
run_request __method__, { filter: filter }, { locale: locale } run_request __method__, { filter: filter, locale: locale }
end end
CODE CODE
end end
def list_market_catalogue(filter: BetfairApiNgRails::MarketFilter.new, market_projection: [], sort: "", max_results: '1', locale: BetfairApiNgRails.config.locale) def list_market_catalogue(filter: BetfairApiNgRails::MarketFilter.new, market_projection: [], sort: "", max_results: '1', locale: BetfairApiNgRails.config.locale)
run_request __method__, { filter: filter, market_projection: market_projection, sort: sort, max_results: max_results }, { locale: locale } run_request __method__, { filter: filter, market_projection: market_projection, sort: sort, max_results: max_results, locale: locale }
end end
def list_market_book(market_ids: [], price_projection: BetfairApiNgRails::PriceProjection.new, order_projection: '', match_projection: '', currency_code: 'USD', locale: BetfairApiNgRails.config.locale) def list_market_book(market_ids: [], price_projection: BetfairApiNgRails::PriceProjection.new, order_projection: '', match_projection: '', currency_code: 'USD', locale: BetfairApiNgRails.config.locale)
run_request __method__, { market_ids: market_ids, price_projection: price_projection, order_projection: order_projection, match_projection: match_projection }, { currency_code: currency_code, locale: locale } run_request __method__, { market_ids: market_ids, price_projection: price_projection, order_projection: order_projection, match_projection: match_projection, currency_code: currency_code, locale: locale }
end end
def place_orders(market_id: "", instructions: [], customer_ref: "") def place_orders(market_id: "", instructions: [], customer_ref: "", account_name: '')
run_request __method__, { market_id: market_id, instructions: instructions, customer_ref: customer_ref } run_request __method__, { market_id: market_id, instructions: instructions, customer_ref: customer_ref }
end end
end end
......
...@@ -7,7 +7,7 @@ describe BetfairApiNgRails::Api::RequestMethods do ...@@ -7,7 +7,7 @@ describe BetfairApiNgRails::Api::RequestMethods do
BetfairApiNgRails::Api::Constants::SIMPLE_LISTING_FILTERED.each do |method| BetfairApiNgRails::Api::Constants::SIMPLE_LISTING_FILTERED.each do |method|
describe "##{method}" do describe "##{method}" do
it "calls run_request with proper params" do it "calls run_request with proper params" do
expect(TestModule).to receive(:run_request).with(method.underscore.to_sym, {filter: :filter}, {locale: :en}) expect(TestModule).to receive(:run_request).with(method.underscore.to_sym, {filter: :filter, locale: :en})
TestModule.send method.underscore.to_sym, filter: :filter TestModule.send method.underscore.to_sym, filter: :filter
end end
end end
...@@ -15,14 +15,14 @@ describe BetfairApiNgRails::Api::RequestMethods do ...@@ -15,14 +15,14 @@ describe BetfairApiNgRails::Api::RequestMethods do
describe "#list_market_catalogue" do describe "#list_market_catalogue" do
it "calls run_request with proper params" do it "calls run_request with proper params" do
expect(TestModule).to receive(:run_request).with(:list_market_catalogue, {filter: :filter, market_projection: [], sort: "", max_results: '1'}, {locale: :en}) expect(TestModule).to receive(:run_request).with(:list_market_catalogue, {filter: :filter, market_projection: [], sort: "", max_results: '1', locale: :en})
TestModule.list_market_catalogue filter: :filter TestModule.list_market_catalogue filter: :filter
end end
end end
describe "#list_market_book" do describe "#list_market_book" do
it "calls run_request with proper params" do it "calls run_request with proper params" do
expect(TestModule).to receive(:run_request).with(:list_market_book, {market_ids: ['1'], price_projection: :priceProjection, order_projection: '', match_projection: ''}, {currency_code: 'USD', locale: :en}) expect(TestModule).to receive(:run_request).with(:list_market_book, {market_ids: ['1'], price_projection: :priceProjection, order_projection: '', match_projection: '', currency_code: 'USD', locale: :en})
TestModule.list_market_book market_ids: ['1'], price_projection: :priceProjection TestModule.list_market_book market_ids: ['1'], price_projection: :priceProjection
end end
end end
...@@ -43,15 +43,14 @@ describe BetfairApiNgRails::Api::RequestMethods do ...@@ -43,15 +43,14 @@ describe BetfairApiNgRails::Api::RequestMethods do
describe "#run_request" do describe "#run_request" do
let(:params) { {key1: 'value'} } let(:params) { {key1: 'value'} }
let(:data) { {key2: 'value'} }
let(:connection) { double(:connection) } let(:connection) { double(:connection) }
before(:each) { BetfairApiNgRails.connection = connection } before(:each) { BetfairApiNgRails.connection = connection }
after(:each) { TestModule.send(:run_request, 'some_method', params, data) } after(:each) { TestModule.send(:run_request, 'some_method', params) }
it "calls request method with proper params" do it "calls request method with proper params" do
expect(connection).to receive(:request).with('someMethod', params.merge(data)) expect(connection).to receive(:request).with('someMethod', params)
end end
end end
end end
......
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