betfair_api_ng_rails 1.1.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +26 -1
- data/Rakefile +8 -8
- data/betfair_api_ng_rails.gemspec +12 -7
- data/lib/betfair_api_ng_rails.rb +162 -98
- data/lib/betfair_api_ng_rails/account.rb +4 -0
- data/lib/betfair_api_ng_rails/account_manager.rb +36 -0
- data/lib/betfair_api_ng_rails/account_session.rb +5 -0
- data/lib/betfair_api_ng_rails/account_session_manager.rb +29 -0
- data/lib/betfair_api_ng_rails/api/caching/helper.rb +34 -0
- data/lib/betfair_api_ng_rails/api/caching/response_cache.rb +57 -0
- data/lib/betfair_api_ng_rails/api/concerns/errorable.rb +1 -3
- data/lib/betfair_api_ng_rails/api/config.rb +20 -8
- data/lib/betfair_api_ng_rails/api/connection.rb +28 -10
- data/lib/betfair_api_ng_rails/api/connection_ext/caching.rb +60 -0
- data/lib/betfair_api_ng_rails/api/connection_ext/error_handling.rb +5 -1
- data/lib/betfair_api_ng_rails/api/connection_ext/logging.rb +34 -0
- data/lib/betfair_api_ng_rails/api/connection_ext/parsing.rb +2 -4
- data/lib/betfair_api_ng_rails/api/connection_ext/ssoid_refreshing.rb +40 -0
- data/lib/betfair_api_ng_rails/api/constants.rb +39 -18
- data/lib/betfair_api_ng_rails/api/data/account_details_response.rb +27 -0
- data/lib/betfair_api_ng_rails/api/data/account_funds_response.rb +26 -0
- data/lib/betfair_api_ng_rails/api/data/account_statement_report.rb +17 -0
- data/lib/betfair_api_ng_rails/api/data/competition.rb +3 -4
- data/lib/betfair_api_ng_rails/api/data/competition_result.rb +1 -3
- data/lib/betfair_api_ng_rails/api/data/concerns/attributable.rb +2 -6
- data/lib/betfair_api_ng_rails/api/data/concerns/hashable.rb +11 -4
- data/lib/betfair_api_ng_rails/api/data/constants.rb +2 -4
- data/lib/betfair_api_ng_rails/api/data/country_code_result.rb +1 -3
- data/lib/betfair_api_ng_rails/api/data/event.rb +1 -2
- data/lib/betfair_api_ng_rails/api/data/event_result.rb +1 -3
- data/lib/betfair_api_ng_rails/api/data/limit_on_close_order.rb +22 -0
- data/lib/betfair_api_ng_rails/api/data/limit_order.rb +23 -0
- data/lib/betfair_api_ng_rails/api/data/market_book.rb +2 -4
- data/lib/betfair_api_ng_rails/api/data/market_filter.rb +3 -2
- data/lib/betfair_api_ng_rails/api/data/market_on_close_order.rb +20 -0
- data/lib/betfair_api_ng_rails/api/data/order.rb +1 -3
- data/lib/betfair_api_ng_rails/api/data/place_execution_report.rb +24 -0
- data/lib/betfair_api_ng_rails/api/data/place_instruction.rb +25 -0
- data/lib/betfair_api_ng_rails/api/data/place_instruction_report.rb +27 -0
- data/lib/betfair_api_ng_rails/api/data/statement_item.rb +30 -0
- data/lib/betfair_api_ng_rails/api/data/statement_legacy_data.rb +40 -0
- data/lib/betfair_api_ng_rails/api/endpoint_factory.rb +21 -0
- data/lib/betfair_api_ng_rails/api/endpoints/australian.rb +17 -0
- data/lib/betfair_api_ng_rails/api/endpoints/base.rb +42 -0
- data/lib/betfair_api_ng_rails/api/endpoints/italian.rb +17 -0
- data/lib/betfair_api_ng_rails/api/endpoints/spanish.rb +17 -0
- data/lib/betfair_api_ng_rails/api/endpoints/uk.rb +17 -0
- data/lib/betfair_api_ng_rails/api/enums/execution_report_error_code.rb +22 -1
- data/lib/betfair_api_ng_rails/api/enums/execution_report_status.rb +12 -1
- data/lib/betfair_api_ng_rails/api/enums/include_item.rb +23 -0
- data/lib/betfair_api_ng_rails/api/enums/instruction_report_error_code.rb +25 -1
- data/lib/betfair_api_ng_rails/api/enums/instruction_report_status.rb +8 -1
- data/lib/betfair_api_ng_rails/api/enums/item_class.rb +19 -0
- data/lib/betfair_api_ng_rails/api/enums/order_status.rb +7 -1
- data/lib/betfair_api_ng_rails/api/enums/order_type.rb +11 -2
- data/lib/betfair_api_ng_rails/api/enums/persistence_type.rb +8 -1
- data/lib/betfair_api_ng_rails/api/enums/side.rb +7 -2
- data/lib/betfair_api_ng_rails/api/enums/wallet.rb +20 -0
- data/lib/betfair_api_ng_rails/api/formatter_factory.rb +2 -4
- data/lib/betfair_api_ng_rails/api/formatters/js_tree_formatter.rb +2 -4
- data/lib/betfair_api_ng_rails/api/hashalator.rb +6 -6
- data/lib/betfair_api_ng_rails/api/helper.rb +2 -4
- data/lib/betfair_api_ng_rails/api/http/factory.rb +19 -14
- data/lib/betfair_api_ng_rails/api/http/helpers/information_response.rb +2 -4
- data/lib/betfair_api_ng_rails/api/http/helpers/keep_alive_response.rb +3 -4
- data/lib/betfair_api_ng_rails/api/http/helpers/session_response.rb +3 -4
- data/lib/betfair_api_ng_rails/api/http/proxy_requester.rb +87 -0
- data/lib/betfair_api_ng_rails/api/http/requester.rb +3 -3
- data/lib/betfair_api_ng_rails/api/http/responser.rb +4 -3
- data/lib/betfair_api_ng_rails/api/invalid_endpoint_error.rb +6 -0
- data/lib/betfair_api_ng_rails/api/logs/console_logger.rb +13 -0
- data/lib/betfair_api_ng_rails/api/logs/file_logger.rb +23 -0
- data/lib/betfair_api_ng_rails/api/parsers/base.rb +14 -6
- data/lib/betfair_api_ng_rails/api/parsers/get_account_details.rb +13 -0
- data/lib/betfair_api_ng_rails/api/parsers/get_account_funds.rb +14 -0
- data/lib/betfair_api_ng_rails/api/parsers/get_account_statement.rb +15 -0
- data/lib/betfair_api_ng_rails/api/parsers/list_base.rb +18 -0
- data/lib/betfair_api_ng_rails/api/parsers/list_competitions.rb +5 -7
- data/lib/betfair_api_ng_rails/api/parsers/list_countries.rb +5 -7
- data/lib/betfair_api_ng_rails/api/parsers/list_event_types.rb +5 -7
- data/lib/betfair_api_ng_rails/api/parsers/list_events.rb +5 -7
- data/lib/betfair_api_ng_rails/api/parsers/list_market_book.rb +5 -7
- data/lib/betfair_api_ng_rails/api/parsers/list_market_catalogue.rb +5 -7
- data/lib/betfair_api_ng_rails/api/parsers/list_market_types.rb +5 -7
- data/lib/betfair_api_ng_rails/api/parsers/list_time_ranges.rb +5 -7
- data/lib/betfair_api_ng_rails/api/parsers/list_venues.rb +5 -7
- data/lib/betfair_api_ng_rails/api/parsers/place_orders.rb +14 -0
- data/lib/betfair_api_ng_rails/api/parsers/single_base.rb +19 -0
- data/lib/betfair_api_ng_rails/api/provider.rb +11 -14
- data/lib/betfair_api_ng_rails/api/request_method.rb +43 -0
- data/lib/betfair_api_ng_rails/api/request_methods/account.rb +51 -0
- data/lib/betfair_api_ng_rails/api/request_methods/all.rb +26 -0
- data/lib/betfair_api_ng_rails/api/request_methods/betting.rb +30 -0
- data/lib/betfair_api_ng_rails/api/session_manager.rb +34 -31
- data/lib/betfair_api_ng_rails/bad_response_error.rb +4 -0
- data/lib/betfair_api_ng_rails/errors.rb +3 -2
- data/lib/betfair_api_ng_rails/railtie.rb +7 -2
- data/lib/betfair_api_ng_rails/version.rb +1 -1
- data/lib/generators/betfair_api_ng_rails/install/templates/betfair_api_ng_rails.rb +20 -11
- data/lib/generators/betfair_api_ng_rails/install/templates/betfair_api_ng_rails.yml +5 -7
- data/spec/lib/betfair_api_ng_rails/account_manager_spec.rb +76 -0
- data/spec/lib/betfair_api_ng_rails/account_session_manager_spec.rb +59 -0
- data/spec/lib/betfair_api_ng_rails/account_session_spec.rb +13 -0
- data/spec/lib/betfair_api_ng_rails/account_spec.rb +18 -0
- data/spec/lib/betfair_api_ng_rails/api/caching/helper_spec.rb +89 -0
- data/spec/lib/betfair_api_ng_rails/api/caching/response_cache_spec.rb +131 -0
- data/spec/lib/betfair_api_ng_rails/api/config_spec.rb +37 -0
- data/spec/lib/betfair_api_ng_rails/api/connection_spec.rb +99 -0
- data/spec/lib/betfair_api_ng_rails/api/data/account_statement_report_spec.rb +11 -0
- data/spec/{betfair_api_ng_rails → lib/betfair_api_ng_rails}/api/data/competition_result_spec.rb +0 -0
- data/spec/{betfair_api_ng_rails → lib/betfair_api_ng_rails}/api/data/competition_spec.rb +0 -0
- data/spec/{betfair_api_ng_rails → lib/betfair_api_ng_rails}/api/data/concerns/attributable_spec.rb +0 -0
- data/spec/{betfair_api_ng_rails → lib/betfair_api_ng_rails}/api/data/concerns/hashable_spec.rb +16 -32
- data/spec/{betfair_api_ng_rails → lib/betfair_api_ng_rails}/api/data/concerns/jsonable_spec.rb +0 -0
- data/spec/{betfair_api_ng_rails → lib/betfair_api_ng_rails}/api/data/country_code_result_spec.rb +0 -0
- data/spec/{betfair_api_ng_rails → lib/betfair_api_ng_rails}/api/data/event_result_spec.rb +0 -0
- data/spec/{betfair_api_ng_rails → lib/betfair_api_ng_rails}/api/data/event_spec.rb +0 -0
- data/spec/{betfair_api_ng_rails → lib/betfair_api_ng_rails}/api/data/event_type_result_spec.rb +0 -0
- data/spec/{betfair_api_ng_rails → lib/betfair_api_ng_rails}/api/data/event_type_spec.rb +0 -0
- data/spec/{betfair_api_ng_rails → lib/betfair_api_ng_rails}/api/data/ex_best_offers_overrides_spec.rb +0 -0
- data/spec/{betfair_api_ng_rails → lib/betfair_api_ng_rails}/api/data/exchange_prices_spec.rb +0 -0
- data/spec/{betfair_api_ng_rails → lib/betfair_api_ng_rails}/api/data/market_book_spec.rb +1 -6
- data/spec/{betfair_api_ng_rails → lib/betfair_api_ng_rails}/api/data/market_catalogue_spec.rb +0 -0
- data/spec/{betfair_api_ng_rails → lib/betfair_api_ng_rails}/api/data/market_description_spec.rb +0 -0
- data/spec/{betfair_api_ng_rails → lib/betfair_api_ng_rails}/api/data/market_filter_spec.rb +0 -0
- data/spec/{betfair_api_ng_rails → lib/betfair_api_ng_rails}/api/data/market_type_result_spec.rb +0 -0
- data/spec/{betfair_api_ng_rails → lib/betfair_api_ng_rails}/api/data/match_spec.rb +0 -0
- data/spec/{betfair_api_ng_rails → lib/betfair_api_ng_rails}/api/data/order_spec.rb +0 -0
- data/spec/{betfair_api_ng_rails → lib/betfair_api_ng_rails}/api/data/price_projection_spec.rb +0 -0
- data/spec/{betfair_api_ng_rails → lib/betfair_api_ng_rails}/api/data/price_size_spec.rb +0 -0
- data/spec/{betfair_api_ng_rails → lib/betfair_api_ng_rails}/api/data/runner_catalog_spec.rb +0 -0
- data/spec/{betfair_api_ng_rails → lib/betfair_api_ng_rails}/api/data/runner_spec.rb +0 -0
- data/spec/{betfair_api_ng_rails → lib/betfair_api_ng_rails}/api/data/starting_prices_spec.rb +0 -0
- data/spec/lib/betfair_api_ng_rails/api/data/statement_item_spec.rb +9 -0
- data/spec/lib/betfair_api_ng_rails/api/data/statement_legacy_data_spec.rb +6 -0
- data/spec/{betfair_api_ng_rails → lib/betfair_api_ng_rails}/api/data/time_range_result_spec.rb +0 -0
- data/spec/{betfair_api_ng_rails → lib/betfair_api_ng_rails}/api/data/time_range_spec.rb +1 -3
- data/spec/{betfair_api_ng_rails → lib/betfair_api_ng_rails}/api/data/venue_result_spec.rb +0 -0
- data/spec/lib/betfair_api_ng_rails/api/endpoint_factory_spec.rb +27 -0
- data/spec/lib/betfair_api_ng_rails/api/endpoints/australian_spec.rb +6 -0
- data/spec/lib/betfair_api_ng_rails/api/endpoints/base_spec.rb +5 -0
- data/spec/lib/betfair_api_ng_rails/api/endpoints/italian_spec.rb +6 -0
- data/spec/lib/betfair_api_ng_rails/api/endpoints/spanish_spec.rb +7 -0
- data/spec/lib/betfair_api_ng_rails/api/endpoints/uk_spec.rb +6 -0
- data/spec/{betfair_api_ng_rails → lib/betfair_api_ng_rails}/api/formatters/js_tree_formatter_spec.rb +0 -0
- data/spec/{betfair_api_ng_rails → lib/betfair_api_ng_rails}/api/hashalator_spec.rb +27 -46
- data/spec/lib/betfair_api_ng_rails/api/http/factory_spec.rb +40 -0
- data/spec/lib/betfair_api_ng_rails/api/logs/console_logger_spec.rb +18 -0
- data/spec/lib/betfair_api_ng_rails/api/logs/file_logger_spec.rb +33 -0
- data/spec/lib/betfair_api_ng_rails/api/provider_spec.rb +53 -0
- data/spec/lib/betfair_api_ng_rails/api/request_method_spec.rb +38 -0
- data/spec/{betfair_api_ng_rails → lib/betfair_api_ng_rails}/api/request_methods_spec.rb +47 -32
- data/spec/lib/betfair_api_ng_rails/api/session_manager_spec.rb +77 -0
- data/spec/lib/betfair_api_ng_rails/integration/get_account_statement_spec.rb +57 -0
- data/spec/{betfair_api_ng_rails → lib/betfair_api_ng_rails}/integration/list_competitions_spec.rb +7 -9
- data/spec/{betfair_api_ng_rails → lib/betfair_api_ng_rails}/integration/list_countries_spec.rb +7 -9
- data/spec/{betfair_api_ng_rails → lib/betfair_api_ng_rails}/integration/list_event_types_spec.rb +7 -9
- data/spec/{betfair_api_ng_rails → lib/betfair_api_ng_rails}/integration/list_events_spec.rb +7 -9
- data/spec/{betfair_api_ng_rails → lib/betfair_api_ng_rails}/integration/list_market_book_spec.rb +7 -9
- data/spec/{betfair_api_ng_rails → lib/betfair_api_ng_rails}/integration/list_market_catalogue_spec.rb +7 -16
- data/spec/{betfair_api_ng_rails → lib/betfair_api_ng_rails}/integration/list_market_types_spec.rb +7 -9
- data/spec/{betfair_api_ng_rails → lib/betfair_api_ng_rails}/integration/list_time_ranges_spec.rb +7 -9
- data/spec/{betfair_api_ng_rails → lib/betfair_api_ng_rails}/integration/list_venues_spec.rb +7 -9
- data/spec/lib/betfair_api_ng_rails/integration/place_orders_spec.rb +55 -0
- data/spec/spec_helper.rb +9 -1
- data/spec/support/base_yaml_loader.rb +2 -4
- data/spec/support/data/models.yml +37 -1
- data/spec/support/data_models_yaml_loader.rb +1 -3
- data/spec/support/have_attr_accessor.rb +18 -0
- data/spec/support/helper.rb +1 -3
- data/spec/support/shared_examples/base_endpoint.rb +5 -0
- data/spec/support/shared_examples/concrete_endpoint.rb +28 -0
- data/spec/support/shared_examples/data_model.rb +2 -11
- data/spec/support/shared_examples/request_method.rb +5 -8
- data/spec/support/shared_examples/simple_list_filtering_request.rb +10 -19
- metadata +252 -117
- data/lib/betfair_api_ng_rails/api/request_methods.rb +0 -41
- data/spec/betfair_api_ng_rails/api/connection_spec.rb +0 -76
- data/spec/betfair_api_ng_rails/api/provider_spec.rb +0 -91
- data/spec/betfair_api_ng_rails/api/session_manager_spec.rb +0 -59
@@ -0,0 +1,131 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe BetfairApiNgRails::Api::Caching::ResponseCache do
|
4
|
+
|
5
|
+
let(:method) { :method }
|
6
|
+
let(:params) { :params }
|
7
|
+
|
8
|
+
subject(:cache) { described_class.new(method, params) }
|
9
|
+
|
10
|
+
before { allow_any_instance_of(described_class).to receive(:createsig).with(:params).and_return :sig_params }
|
11
|
+
|
12
|
+
describe ".redis_connection" do
|
13
|
+
|
14
|
+
it "initializes connection to redis" do
|
15
|
+
expect(Redis).to receive :new
|
16
|
+
described_class.redis_connection
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "#is_cached?" do
|
22
|
+
|
23
|
+
before { expect(cache).to receive(:cache_result).and_return(cache_result) }
|
24
|
+
|
25
|
+
context 'when cache result returns item' do
|
26
|
+
|
27
|
+
let(:cache_result) { double }
|
28
|
+
|
29
|
+
its(:is_cached?) { is_expected.to be_truthy }
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
context 'when cache result returns no item' do
|
34
|
+
|
35
|
+
let(:cache_result) { nil }
|
36
|
+
|
37
|
+
its(:is_cached?) { is_expected.to be_falsey }
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
describe "#responser" do
|
44
|
+
|
45
|
+
before { expect(cache).to receive(:prepare_response).and_return :response }
|
46
|
+
|
47
|
+
it "returns http responser with cached info" do
|
48
|
+
expect(BetfairApiNgRails::Api::Http::Responser).to receive(:new).with(:response)
|
49
|
+
cache.responser
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
describe "#cache!" do
|
55
|
+
|
56
|
+
let(:response) { { some: :key } }
|
57
|
+
let(:cache_adapter) { double(:cache_adapter) }
|
58
|
+
|
59
|
+
before do
|
60
|
+
allow(cache).to receive(:cache_adapter).and_return cache_adapter
|
61
|
+
expect(cache).to receive(:expire_time).and_return 5
|
62
|
+
end
|
63
|
+
|
64
|
+
it "saves response in cache" do
|
65
|
+
expect(cache_adapter).to receive(:set).with("betfair_api_ng_rails:method:sig_params", "{\"some\":\"key\"}")
|
66
|
+
expect(cache_adapter).to receive(:expire).with("betfair_api_ng_rails:method:sig_params", 5)
|
67
|
+
cache.cache! response
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
context 'private method' do
|
73
|
+
|
74
|
+
describe "#cache_result" do
|
75
|
+
|
76
|
+
let(:cache_adapter) { double(:cache_adapter) }
|
77
|
+
|
78
|
+
before { expect(cache).to receive(:cache_adapter).and_return cache_adapter }
|
79
|
+
|
80
|
+
it "returns result from cache" do
|
81
|
+
expect(cache_adapter).to receive(:get).with("betfair_api_ng_rails:method:sig_params")
|
82
|
+
cache.send :cache_result
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
86
|
+
|
87
|
+
describe "#prepare_response" do
|
88
|
+
|
89
|
+
before { allow(cache).to receive(:cache_result).and_return :result }
|
90
|
+
|
91
|
+
subject(:response) { cache.send(:prepare_response) }
|
92
|
+
|
93
|
+
it { is_expected.to respond_to(:body) }
|
94
|
+
|
95
|
+
it { is_expected.to respond_to(:code) }
|
96
|
+
|
97
|
+
its(:body) { is_expected.to eq :result }
|
98
|
+
|
99
|
+
its(:code) { is_expected.to eq '200' }
|
100
|
+
|
101
|
+
end
|
102
|
+
|
103
|
+
describe "#expire_time" do
|
104
|
+
|
105
|
+
it "returns time from config" do
|
106
|
+
expect(BetfairApiNgRails).to receive_message_chain(:config, :cache_expire).and_return 4
|
107
|
+
expect(cache.send(:expire_time)).to eq 4
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|
111
|
+
|
112
|
+
describe "#cache_adapter" do
|
113
|
+
|
114
|
+
#it "returns redis connection" do
|
115
|
+
#expect(cache).to receive_message_chain(:class, :redis_connection)
|
116
|
+
#cache.send :cache_adapter
|
117
|
+
#end
|
118
|
+
|
119
|
+
end
|
120
|
+
|
121
|
+
describe "#cache_key" do
|
122
|
+
|
123
|
+
it "returns proper key for cache" do
|
124
|
+
expect(cache.send(:cache_key)).to eq "betfair_api_ng_rails:method:sig_params"
|
125
|
+
end
|
126
|
+
|
127
|
+
end
|
128
|
+
|
129
|
+
end
|
130
|
+
|
131
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe BetfairApiNgRails::Api::Config do
|
4
|
+
subject(:config) { described_class }
|
5
|
+
|
6
|
+
it { is_expected.to have_attr_accessor :application_key }
|
7
|
+
it { is_expected.to have_attr_accessor :ssl_key_filepath }
|
8
|
+
it { is_expected.to have_attr_accessor :ssl_crt_filepath }
|
9
|
+
it { is_expected.to have_attr_accessor :username }
|
10
|
+
it { is_expected.to have_attr_accessor :password }
|
11
|
+
it { is_expected.to have_attr_accessor :locale }
|
12
|
+
it { is_expected.to have_attr_accessor :formatter }
|
13
|
+
it { is_expected.to have_attr_accessor :keep_alive_session }
|
14
|
+
it { is_expected.to have_attr_accessor :use_cache }
|
15
|
+
it { is_expected.to have_attr_accessor :cache_expire }
|
16
|
+
it { is_expected.to have_attr_accessor :proxy_url }
|
17
|
+
it { is_expected.to have_attr_accessor :proxy_enable }
|
18
|
+
it { is_expected.to have_attr_accessor :go_localuser }
|
19
|
+
it { is_expected.to have_attr_accessor :go_filename }
|
20
|
+
it { is_expected.to have_attr_accessor :endpoint }
|
21
|
+
|
22
|
+
describe ".load_for_environment" do
|
23
|
+
let(:path) { "path" }
|
24
|
+
let(:opts) { [:opt1] }
|
25
|
+
let(:config_hash) { {'env' => { 'opt1' => :val1 }} }
|
26
|
+
|
27
|
+
before do
|
28
|
+
stub_const("BetfairApiNgRails::Api::Constants::LOADABLE_CONFIG_OPTIONS", opts)
|
29
|
+
allow(YAML).to receive(:load_file).with(path).and_return config_hash
|
30
|
+
end
|
31
|
+
|
32
|
+
it "loads config from file and apply it" do
|
33
|
+
expect(config).to receive('opt1=').with(:val1)
|
34
|
+
config.load_for_environment path, 'env'
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe BetfairApiNgRails::Api::Connection do
|
4
|
+
subject(:connection) { described_class.new(acc_name) }
|
5
|
+
|
6
|
+
let(:acc_name) { 'user001' }
|
7
|
+
let(:asm) { double(:account_session_manager) }
|
8
|
+
let(:account) { BetfairApiNgRails::Account.new(acc_name, 'pass', 'nfl43n7fg834', 'crt', 'key') }
|
9
|
+
let(:logger) { double(:logger) }
|
10
|
+
|
11
|
+
before do
|
12
|
+
allow(BetfairApiNgRails).to receive(:account_session_manager).and_return asm
|
13
|
+
BetfairApiNgRails.log = logger
|
14
|
+
allow(logger).to receive(:write)
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "#request" do
|
18
|
+
let(:provider) { double(:provider) }
|
19
|
+
let(:parser) { double(:parser, process: true) }
|
20
|
+
let(:response) { double(:response, result: "") }
|
21
|
+
|
22
|
+
before(:each) do
|
23
|
+
expect(subject).to receive(:init_parser).and_return parser
|
24
|
+
end
|
25
|
+
|
26
|
+
it "calls provider's fetch method" do
|
27
|
+
expect(subject).to receive(:provider).and_return provider
|
28
|
+
expect(provider).to receive(:fetch).and_return response
|
29
|
+
expect(response).to receive(:has_error?).and_return false
|
30
|
+
allow(subject).to receive(:hashing).with({}).and_return({})
|
31
|
+
subject.request 'method'
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context "protected methods" do
|
36
|
+
describe "#expire_provider" do
|
37
|
+
it "resets account's ssoid" do
|
38
|
+
allow(connection).to receive(:account).and_return account
|
39
|
+
expect(connection.session_manager).to receive(:expire_ssoid).with(account)
|
40
|
+
connection.send :expire_provider
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "#provider" do
|
45
|
+
let(:ssoid) { double(:ssoid) }
|
46
|
+
let(:app_key) { 'af2f23f23' }
|
47
|
+
|
48
|
+
before do
|
49
|
+
allow(subject).to receive(:app_key).and_return app_key
|
50
|
+
end
|
51
|
+
|
52
|
+
it "inits new provider" do
|
53
|
+
expect(BetfairApiNgRails::Api::Provider).to receive(:new).with ssoid, app_key
|
54
|
+
expect(subject).to receive(:request_ssoid).and_return ssoid
|
55
|
+
subject.send(:provider)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe "#request_ssoid" do
|
60
|
+
before do
|
61
|
+
allow(connection).to receive(:account).and_return account
|
62
|
+
end
|
63
|
+
|
64
|
+
it "requests new ssoid for new connection" do
|
65
|
+
expect(connection.session_manager).to receive(:get_ssoid).with(account)
|
66
|
+
subject.send(:request_ssoid)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe "#hashing" do
|
71
|
+
let(:hashalator) { double(:hashalator) }
|
72
|
+
let(:params) { double(:params) }
|
73
|
+
|
74
|
+
it "hashalators params" do
|
75
|
+
expect(BetfairApiNgRails::Api::Hashalator).to receive(:new).with(params).and_return hashalator
|
76
|
+
expect(hashalator).to receive(:to_hash)
|
77
|
+
subject.send :hashing, params
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
describe '#account' do
|
82
|
+
context 'when it is found' do
|
83
|
+
it 'returns this one' do
|
84
|
+
expect(BetfairApiNgRails).to receive_message_chain(:account_manager, :get).and_return double(:acc, username: :user001)
|
85
|
+
connection.send :account
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
context 'when it is not found' do
|
90
|
+
it 'raises error' do
|
91
|
+
expect{
|
92
|
+
expect(BetfairApiNgRails).to receive_message_chain(:account_manager, :get).and_return(nil)
|
93
|
+
connection.send :account
|
94
|
+
}.to raise_error(BetfairApiNgRails::NoAccountProvided)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe BetfairApiNgRails::AccountStatementReport do
|
4
|
+
include_examples 'data model', DataModelsYamlLoader.new.fetch('accountStatementReport') do
|
5
|
+
|
6
|
+
describe "account statements association" do
|
7
|
+
its(:account_statement) { is_expected.to be_kind_of Array }
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
data/spec/{betfair_api_ng_rails → lib/betfair_api_ng_rails}/api/data/competition_result_spec.rb
RENAMED
File without changes
|
File without changes
|
data/spec/{betfair_api_ng_rails → lib/betfair_api_ng_rails}/api/data/concerns/attributable_spec.rb
RENAMED
File without changes
|
data/spec/{betfair_api_ng_rails → lib/betfair_api_ng_rails}/api/data/concerns/hashable_spec.rb
RENAMED
@@ -16,85 +16,72 @@ class TestClass
|
|
16
16
|
end
|
17
17
|
|
18
18
|
describe BetfairApiNgRails::Api::Data::Concerns::Hashable do
|
19
|
-
|
20
19
|
subject { TestClass.new }
|
21
20
|
|
22
21
|
describe "#to_hash" do
|
23
|
-
|
24
22
|
let(:attributes) { double(:attributes) }
|
25
23
|
let(:hashalator) { double(:hashalator) }
|
26
24
|
|
27
25
|
it "returns Hashalator's to_hash result" do
|
28
26
|
expect(subject).to receive(:attributes_hash).and_return attributes
|
29
|
-
expect(BetfairApiNgRails::Api::Hashalator).to receive(:new).with(attributes).and_return hashalator
|
27
|
+
expect(BetfairApiNgRails::Api::Hashalator).to receive(:new).with(attributes, false).and_return hashalator
|
30
28
|
expect(hashalator).to receive(:to_hash)
|
31
29
|
subject.to_hash
|
32
30
|
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "#to_param" do
|
34
|
+
let(:attributes) { double(:attributes) }
|
35
|
+
let(:hashalator) { double(:hashalator) }
|
33
36
|
|
37
|
+
it "returns Hashalator's to_hash result" do
|
38
|
+
expect(subject).to receive(:attributes_hash).and_return attributes
|
39
|
+
expect(BetfairApiNgRails::Api::Hashalator).to receive(:new).with(attributes, true).and_return hashalator
|
40
|
+
expect(hashalator).to receive(:to_hash)
|
41
|
+
subject.to_param
|
42
|
+
end
|
34
43
|
end
|
35
44
|
|
36
45
|
describe "private method" do
|
37
|
-
|
38
46
|
describe "#attributes_hash" do
|
39
|
-
|
40
47
|
context "returns hash represantation of attributes and its values" do
|
41
|
-
|
42
48
|
its(:attributes_hash) { is_expected.to eq({:name => 'Walli'}) }
|
43
|
-
|
44
49
|
end
|
45
|
-
|
46
50
|
end
|
47
51
|
|
48
52
|
describe "#get_attr_value" do
|
49
|
-
|
50
53
|
it "returns attribute value by its name" do
|
51
54
|
expect(subject.send(:get_attr_value, :name)).to eq 'Walli'
|
52
55
|
end
|
53
|
-
|
54
56
|
end
|
55
57
|
|
56
58
|
describe "#get_attr_key" do
|
57
|
-
|
58
59
|
subject { TestClass.new.send :get_attr_key, attrib }
|
59
60
|
|
60
61
|
context 'when passed Hash' do
|
61
|
-
|
62
62
|
let(:attrib) { {some_attr: { type: String }} }
|
63
63
|
|
64
64
|
context 'returns first key' do
|
65
|
-
|
66
65
|
it { is_expected.to eq :some_attr }
|
67
|
-
|
68
66
|
end
|
69
|
-
|
70
|
-
end
|
67
|
+
end
|
71
68
|
|
72
69
|
context 'when passed single value' do
|
73
|
-
|
74
70
|
let(:attrib) { :some_attr }
|
75
71
|
|
76
72
|
context 'returns it' do
|
77
|
-
|
78
73
|
it { is_expected.to eq :some_attr }
|
79
|
-
|
80
74
|
end
|
81
|
-
|
82
75
|
end
|
83
|
-
|
84
76
|
end
|
85
|
-
|
86
77
|
end
|
87
78
|
|
88
79
|
describe "integration tests" do
|
89
|
-
|
90
80
|
context "returns hash represention of TestClass instance" do
|
91
|
-
|
92
81
|
its(:to_hash) { is_expected.to eq({'name' => 'Walli'}) }
|
93
|
-
|
94
82
|
end
|
95
83
|
|
96
84
|
context 'dont include nil attributes in resulting hash' do
|
97
|
-
|
98
85
|
before(:each) do
|
99
86
|
subject.class.send :instance_eval, <<-CODE
|
100
87
|
attr_accessor :second_name
|
@@ -103,11 +90,10 @@ describe BetfairApiNgRails::Api::Data::Concerns::Hashable do
|
|
103
90
|
end
|
104
91
|
|
105
92
|
its(:to_hash) { is_expected.to eq({'name' => 'Walli'}) }
|
106
|
-
|
93
|
+
its(:to_param) { is_expected.to eq({name: 'Walli'}) }
|
107
94
|
end
|
108
95
|
|
109
96
|
context 'when exists attr with additional options' do
|
110
|
-
|
111
97
|
before(:each) do
|
112
98
|
subject.class.send :instance_eval, <<-CODE
|
113
99
|
attr_accessor :second_name
|
@@ -117,9 +103,7 @@ describe BetfairApiNgRails::Api::Data::Concerns::Hashable do
|
|
117
103
|
end
|
118
104
|
|
119
105
|
its(:to_hash) { is_expected.to eq({'name' => 'Walli', 'secondName' => 'Black'}) }
|
120
|
-
|
106
|
+
its(:to_param) { is_expected.to eq({name: 'Walli', second_name: 'Black'}) }
|
121
107
|
end
|
122
|
-
|
123
108
|
end
|
124
|
-
|
125
|
-
end
|
109
|
+
end
|
data/spec/{betfair_api_ng_rails → lib/betfair_api_ng_rails}/api/data/concerns/jsonable_spec.rb
RENAMED
File without changes
|
data/spec/{betfair_api_ng_rails → lib/betfair_api_ng_rails}/api/data/country_code_result_spec.rb
RENAMED
File without changes
|
File without changes
|
File without changes
|
data/spec/{betfair_api_ng_rails → lib/betfair_api_ng_rails}/api/data/event_type_result_spec.rb
RENAMED
File without changes
|
File without changes
|
File without changes
|
data/spec/{betfair_api_ng_rails → lib/betfair_api_ng_rails}/api/data/exchange_prices_spec.rb
RENAMED
File without changes
|
@@ -1,15 +1,10 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe BetfairApiNgRails::MarketBook do
|
4
|
-
|
5
4
|
include_examples 'data model', DataModelsYamlLoader.new.fetch('marketBook') do
|
6
5
|
|
7
6
|
describe "runners association" do
|
8
|
-
|
9
7
|
its(:runners) { is_expected.to be_kind_of Array }
|
10
|
-
|
11
8
|
end
|
12
|
-
|
13
9
|
end
|
14
|
-
|
15
|
-
end
|
10
|
+
end
|
data/spec/{betfair_api_ng_rails → lib/betfair_api_ng_rails}/api/data/market_catalogue_spec.rb
RENAMED
File without changes
|