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.
Files changed (181) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +26 -1
  3. data/Rakefile +8 -8
  4. data/betfair_api_ng_rails.gemspec +12 -7
  5. data/lib/betfair_api_ng_rails.rb +162 -98
  6. data/lib/betfair_api_ng_rails/account.rb +4 -0
  7. data/lib/betfair_api_ng_rails/account_manager.rb +36 -0
  8. data/lib/betfair_api_ng_rails/account_session.rb +5 -0
  9. data/lib/betfair_api_ng_rails/account_session_manager.rb +29 -0
  10. data/lib/betfair_api_ng_rails/api/caching/helper.rb +34 -0
  11. data/lib/betfair_api_ng_rails/api/caching/response_cache.rb +57 -0
  12. data/lib/betfair_api_ng_rails/api/concerns/errorable.rb +1 -3
  13. data/lib/betfair_api_ng_rails/api/config.rb +20 -8
  14. data/lib/betfair_api_ng_rails/api/connection.rb +28 -10
  15. data/lib/betfair_api_ng_rails/api/connection_ext/caching.rb +60 -0
  16. data/lib/betfair_api_ng_rails/api/connection_ext/error_handling.rb +5 -1
  17. data/lib/betfair_api_ng_rails/api/connection_ext/logging.rb +34 -0
  18. data/lib/betfair_api_ng_rails/api/connection_ext/parsing.rb +2 -4
  19. data/lib/betfair_api_ng_rails/api/connection_ext/ssoid_refreshing.rb +40 -0
  20. data/lib/betfair_api_ng_rails/api/constants.rb +39 -18
  21. data/lib/betfair_api_ng_rails/api/data/account_details_response.rb +27 -0
  22. data/lib/betfair_api_ng_rails/api/data/account_funds_response.rb +26 -0
  23. data/lib/betfair_api_ng_rails/api/data/account_statement_report.rb +17 -0
  24. data/lib/betfair_api_ng_rails/api/data/competition.rb +3 -4
  25. data/lib/betfair_api_ng_rails/api/data/competition_result.rb +1 -3
  26. data/lib/betfair_api_ng_rails/api/data/concerns/attributable.rb +2 -6
  27. data/lib/betfair_api_ng_rails/api/data/concerns/hashable.rb +11 -4
  28. data/lib/betfair_api_ng_rails/api/data/constants.rb +2 -4
  29. data/lib/betfair_api_ng_rails/api/data/country_code_result.rb +1 -3
  30. data/lib/betfair_api_ng_rails/api/data/event.rb +1 -2
  31. data/lib/betfair_api_ng_rails/api/data/event_result.rb +1 -3
  32. data/lib/betfair_api_ng_rails/api/data/limit_on_close_order.rb +22 -0
  33. data/lib/betfair_api_ng_rails/api/data/limit_order.rb +23 -0
  34. data/lib/betfair_api_ng_rails/api/data/market_book.rb +2 -4
  35. data/lib/betfair_api_ng_rails/api/data/market_filter.rb +3 -2
  36. data/lib/betfair_api_ng_rails/api/data/market_on_close_order.rb +20 -0
  37. data/lib/betfair_api_ng_rails/api/data/order.rb +1 -3
  38. data/lib/betfair_api_ng_rails/api/data/place_execution_report.rb +24 -0
  39. data/lib/betfair_api_ng_rails/api/data/place_instruction.rb +25 -0
  40. data/lib/betfair_api_ng_rails/api/data/place_instruction_report.rb +27 -0
  41. data/lib/betfair_api_ng_rails/api/data/statement_item.rb +30 -0
  42. data/lib/betfair_api_ng_rails/api/data/statement_legacy_data.rb +40 -0
  43. data/lib/betfair_api_ng_rails/api/endpoint_factory.rb +21 -0
  44. data/lib/betfair_api_ng_rails/api/endpoints/australian.rb +17 -0
  45. data/lib/betfair_api_ng_rails/api/endpoints/base.rb +42 -0
  46. data/lib/betfair_api_ng_rails/api/endpoints/italian.rb +17 -0
  47. data/lib/betfair_api_ng_rails/api/endpoints/spanish.rb +17 -0
  48. data/lib/betfair_api_ng_rails/api/endpoints/uk.rb +17 -0
  49. data/lib/betfair_api_ng_rails/api/enums/execution_report_error_code.rb +22 -1
  50. data/lib/betfair_api_ng_rails/api/enums/execution_report_status.rb +12 -1
  51. data/lib/betfair_api_ng_rails/api/enums/include_item.rb +23 -0
  52. data/lib/betfair_api_ng_rails/api/enums/instruction_report_error_code.rb +25 -1
  53. data/lib/betfair_api_ng_rails/api/enums/instruction_report_status.rb +8 -1
  54. data/lib/betfair_api_ng_rails/api/enums/item_class.rb +19 -0
  55. data/lib/betfair_api_ng_rails/api/enums/order_status.rb +7 -1
  56. data/lib/betfair_api_ng_rails/api/enums/order_type.rb +11 -2
  57. data/lib/betfair_api_ng_rails/api/enums/persistence_type.rb +8 -1
  58. data/lib/betfair_api_ng_rails/api/enums/side.rb +7 -2
  59. data/lib/betfair_api_ng_rails/api/enums/wallet.rb +20 -0
  60. data/lib/betfair_api_ng_rails/api/formatter_factory.rb +2 -4
  61. data/lib/betfair_api_ng_rails/api/formatters/js_tree_formatter.rb +2 -4
  62. data/lib/betfair_api_ng_rails/api/hashalator.rb +6 -6
  63. data/lib/betfair_api_ng_rails/api/helper.rb +2 -4
  64. data/lib/betfair_api_ng_rails/api/http/factory.rb +19 -14
  65. data/lib/betfair_api_ng_rails/api/http/helpers/information_response.rb +2 -4
  66. data/lib/betfair_api_ng_rails/api/http/helpers/keep_alive_response.rb +3 -4
  67. data/lib/betfair_api_ng_rails/api/http/helpers/session_response.rb +3 -4
  68. data/lib/betfair_api_ng_rails/api/http/proxy_requester.rb +87 -0
  69. data/lib/betfair_api_ng_rails/api/http/requester.rb +3 -3
  70. data/lib/betfair_api_ng_rails/api/http/responser.rb +4 -3
  71. data/lib/betfair_api_ng_rails/api/invalid_endpoint_error.rb +6 -0
  72. data/lib/betfair_api_ng_rails/api/logs/console_logger.rb +13 -0
  73. data/lib/betfair_api_ng_rails/api/logs/file_logger.rb +23 -0
  74. data/lib/betfair_api_ng_rails/api/parsers/base.rb +14 -6
  75. data/lib/betfair_api_ng_rails/api/parsers/get_account_details.rb +13 -0
  76. data/lib/betfair_api_ng_rails/api/parsers/get_account_funds.rb +14 -0
  77. data/lib/betfair_api_ng_rails/api/parsers/get_account_statement.rb +15 -0
  78. data/lib/betfair_api_ng_rails/api/parsers/list_base.rb +18 -0
  79. data/lib/betfair_api_ng_rails/api/parsers/list_competitions.rb +5 -7
  80. data/lib/betfair_api_ng_rails/api/parsers/list_countries.rb +5 -7
  81. data/lib/betfair_api_ng_rails/api/parsers/list_event_types.rb +5 -7
  82. data/lib/betfair_api_ng_rails/api/parsers/list_events.rb +5 -7
  83. data/lib/betfair_api_ng_rails/api/parsers/list_market_book.rb +5 -7
  84. data/lib/betfair_api_ng_rails/api/parsers/list_market_catalogue.rb +5 -7
  85. data/lib/betfair_api_ng_rails/api/parsers/list_market_types.rb +5 -7
  86. data/lib/betfair_api_ng_rails/api/parsers/list_time_ranges.rb +5 -7
  87. data/lib/betfair_api_ng_rails/api/parsers/list_venues.rb +5 -7
  88. data/lib/betfair_api_ng_rails/api/parsers/place_orders.rb +14 -0
  89. data/lib/betfair_api_ng_rails/api/parsers/single_base.rb +19 -0
  90. data/lib/betfair_api_ng_rails/api/provider.rb +11 -14
  91. data/lib/betfair_api_ng_rails/api/request_method.rb +43 -0
  92. data/lib/betfair_api_ng_rails/api/request_methods/account.rb +51 -0
  93. data/lib/betfair_api_ng_rails/api/request_methods/all.rb +26 -0
  94. data/lib/betfair_api_ng_rails/api/request_methods/betting.rb +30 -0
  95. data/lib/betfair_api_ng_rails/api/session_manager.rb +34 -31
  96. data/lib/betfair_api_ng_rails/bad_response_error.rb +4 -0
  97. data/lib/betfair_api_ng_rails/errors.rb +3 -2
  98. data/lib/betfair_api_ng_rails/railtie.rb +7 -2
  99. data/lib/betfair_api_ng_rails/version.rb +1 -1
  100. data/lib/generators/betfair_api_ng_rails/install/templates/betfair_api_ng_rails.rb +20 -11
  101. data/lib/generators/betfair_api_ng_rails/install/templates/betfair_api_ng_rails.yml +5 -7
  102. data/spec/lib/betfair_api_ng_rails/account_manager_spec.rb +76 -0
  103. data/spec/lib/betfair_api_ng_rails/account_session_manager_spec.rb +59 -0
  104. data/spec/lib/betfair_api_ng_rails/account_session_spec.rb +13 -0
  105. data/spec/lib/betfair_api_ng_rails/account_spec.rb +18 -0
  106. data/spec/lib/betfair_api_ng_rails/api/caching/helper_spec.rb +89 -0
  107. data/spec/lib/betfair_api_ng_rails/api/caching/response_cache_spec.rb +131 -0
  108. data/spec/lib/betfair_api_ng_rails/api/config_spec.rb +37 -0
  109. data/spec/lib/betfair_api_ng_rails/api/connection_spec.rb +99 -0
  110. data/spec/lib/betfair_api_ng_rails/api/data/account_statement_report_spec.rb +11 -0
  111. data/spec/{betfair_api_ng_rails → lib/betfair_api_ng_rails}/api/data/competition_result_spec.rb +0 -0
  112. data/spec/{betfair_api_ng_rails → lib/betfair_api_ng_rails}/api/data/competition_spec.rb +0 -0
  113. data/spec/{betfair_api_ng_rails → lib/betfair_api_ng_rails}/api/data/concerns/attributable_spec.rb +0 -0
  114. data/spec/{betfair_api_ng_rails → lib/betfair_api_ng_rails}/api/data/concerns/hashable_spec.rb +16 -32
  115. data/spec/{betfair_api_ng_rails → lib/betfair_api_ng_rails}/api/data/concerns/jsonable_spec.rb +0 -0
  116. data/spec/{betfair_api_ng_rails → lib/betfair_api_ng_rails}/api/data/country_code_result_spec.rb +0 -0
  117. data/spec/{betfair_api_ng_rails → lib/betfair_api_ng_rails}/api/data/event_result_spec.rb +0 -0
  118. data/spec/{betfair_api_ng_rails → lib/betfair_api_ng_rails}/api/data/event_spec.rb +0 -0
  119. data/spec/{betfair_api_ng_rails → lib/betfair_api_ng_rails}/api/data/event_type_result_spec.rb +0 -0
  120. data/spec/{betfair_api_ng_rails → lib/betfair_api_ng_rails}/api/data/event_type_spec.rb +0 -0
  121. data/spec/{betfair_api_ng_rails → lib/betfair_api_ng_rails}/api/data/ex_best_offers_overrides_spec.rb +0 -0
  122. data/spec/{betfair_api_ng_rails → lib/betfair_api_ng_rails}/api/data/exchange_prices_spec.rb +0 -0
  123. data/spec/{betfair_api_ng_rails → lib/betfair_api_ng_rails}/api/data/market_book_spec.rb +1 -6
  124. data/spec/{betfair_api_ng_rails → lib/betfair_api_ng_rails}/api/data/market_catalogue_spec.rb +0 -0
  125. data/spec/{betfair_api_ng_rails → lib/betfair_api_ng_rails}/api/data/market_description_spec.rb +0 -0
  126. data/spec/{betfair_api_ng_rails → lib/betfair_api_ng_rails}/api/data/market_filter_spec.rb +0 -0
  127. data/spec/{betfair_api_ng_rails → lib/betfair_api_ng_rails}/api/data/market_type_result_spec.rb +0 -0
  128. data/spec/{betfair_api_ng_rails → lib/betfair_api_ng_rails}/api/data/match_spec.rb +0 -0
  129. data/spec/{betfair_api_ng_rails → lib/betfair_api_ng_rails}/api/data/order_spec.rb +0 -0
  130. data/spec/{betfair_api_ng_rails → lib/betfair_api_ng_rails}/api/data/price_projection_spec.rb +0 -0
  131. data/spec/{betfair_api_ng_rails → lib/betfair_api_ng_rails}/api/data/price_size_spec.rb +0 -0
  132. data/spec/{betfair_api_ng_rails → lib/betfair_api_ng_rails}/api/data/runner_catalog_spec.rb +0 -0
  133. data/spec/{betfair_api_ng_rails → lib/betfair_api_ng_rails}/api/data/runner_spec.rb +0 -0
  134. data/spec/{betfair_api_ng_rails → lib/betfair_api_ng_rails}/api/data/starting_prices_spec.rb +0 -0
  135. data/spec/lib/betfair_api_ng_rails/api/data/statement_item_spec.rb +9 -0
  136. data/spec/lib/betfair_api_ng_rails/api/data/statement_legacy_data_spec.rb +6 -0
  137. data/spec/{betfair_api_ng_rails → lib/betfair_api_ng_rails}/api/data/time_range_result_spec.rb +0 -0
  138. data/spec/{betfair_api_ng_rails → lib/betfair_api_ng_rails}/api/data/time_range_spec.rb +1 -3
  139. data/spec/{betfair_api_ng_rails → lib/betfair_api_ng_rails}/api/data/venue_result_spec.rb +0 -0
  140. data/spec/lib/betfair_api_ng_rails/api/endpoint_factory_spec.rb +27 -0
  141. data/spec/lib/betfair_api_ng_rails/api/endpoints/australian_spec.rb +6 -0
  142. data/spec/lib/betfair_api_ng_rails/api/endpoints/base_spec.rb +5 -0
  143. data/spec/lib/betfair_api_ng_rails/api/endpoints/italian_spec.rb +6 -0
  144. data/spec/lib/betfair_api_ng_rails/api/endpoints/spanish_spec.rb +7 -0
  145. data/spec/lib/betfair_api_ng_rails/api/endpoints/uk_spec.rb +6 -0
  146. data/spec/{betfair_api_ng_rails → lib/betfair_api_ng_rails}/api/formatters/js_tree_formatter_spec.rb +0 -0
  147. data/spec/{betfair_api_ng_rails → lib/betfair_api_ng_rails}/api/hashalator_spec.rb +27 -46
  148. data/spec/lib/betfair_api_ng_rails/api/http/factory_spec.rb +40 -0
  149. data/spec/lib/betfair_api_ng_rails/api/logs/console_logger_spec.rb +18 -0
  150. data/spec/lib/betfair_api_ng_rails/api/logs/file_logger_spec.rb +33 -0
  151. data/spec/lib/betfair_api_ng_rails/api/provider_spec.rb +53 -0
  152. data/spec/lib/betfair_api_ng_rails/api/request_method_spec.rb +38 -0
  153. data/spec/{betfair_api_ng_rails → lib/betfair_api_ng_rails}/api/request_methods_spec.rb +47 -32
  154. data/spec/lib/betfair_api_ng_rails/api/session_manager_spec.rb +77 -0
  155. data/spec/lib/betfair_api_ng_rails/integration/get_account_statement_spec.rb +57 -0
  156. data/spec/{betfair_api_ng_rails → lib/betfair_api_ng_rails}/integration/list_competitions_spec.rb +7 -9
  157. data/spec/{betfair_api_ng_rails → lib/betfair_api_ng_rails}/integration/list_countries_spec.rb +7 -9
  158. data/spec/{betfair_api_ng_rails → lib/betfair_api_ng_rails}/integration/list_event_types_spec.rb +7 -9
  159. data/spec/{betfair_api_ng_rails → lib/betfair_api_ng_rails}/integration/list_events_spec.rb +7 -9
  160. data/spec/{betfair_api_ng_rails → lib/betfair_api_ng_rails}/integration/list_market_book_spec.rb +7 -9
  161. data/spec/{betfair_api_ng_rails → lib/betfair_api_ng_rails}/integration/list_market_catalogue_spec.rb +7 -16
  162. data/spec/{betfair_api_ng_rails → lib/betfair_api_ng_rails}/integration/list_market_types_spec.rb +7 -9
  163. data/spec/{betfair_api_ng_rails → lib/betfair_api_ng_rails}/integration/list_time_ranges_spec.rb +7 -9
  164. data/spec/{betfair_api_ng_rails → lib/betfair_api_ng_rails}/integration/list_venues_spec.rb +7 -9
  165. data/spec/lib/betfair_api_ng_rails/integration/place_orders_spec.rb +55 -0
  166. data/spec/spec_helper.rb +9 -1
  167. data/spec/support/base_yaml_loader.rb +2 -4
  168. data/spec/support/data/models.yml +37 -1
  169. data/spec/support/data_models_yaml_loader.rb +1 -3
  170. data/spec/support/have_attr_accessor.rb +18 -0
  171. data/spec/support/helper.rb +1 -3
  172. data/spec/support/shared_examples/base_endpoint.rb +5 -0
  173. data/spec/support/shared_examples/concrete_endpoint.rb +28 -0
  174. data/spec/support/shared_examples/data_model.rb +2 -11
  175. data/spec/support/shared_examples/request_method.rb +5 -8
  176. data/spec/support/shared_examples/simple_list_filtering_request.rb +10 -19
  177. metadata +252 -117
  178. data/lib/betfair_api_ng_rails/api/request_methods.rb +0 -41
  179. data/spec/betfair_api_ng_rails/api/connection_spec.rb +0 -76
  180. data/spec/betfair_api_ng_rails/api/provider_spec.rb +0 -91
  181. data/spec/betfair_api_ng_rails/api/session_manager_spec.rb +0 -59
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+
3
+ describe BetfairApiNgRails::Api::RequestMethod do
4
+ let(:method_name) { 'someMethod' }
5
+ let(:logger) { double(:logger) }
6
+ let(:endpoint) { BetfairApiNgRails.config.endpoint }
7
+
8
+ subject(:method) { described_class.new(method_name, endpoint) }
9
+
10
+ before do
11
+ BetfairApiNgRails.log = logger
12
+ allow(logger).to receive(:write)
13
+ end
14
+
15
+ context 'has attributes' do
16
+ its(:name) { is_expected.to eq(method_name) }
17
+ end
18
+
19
+ context 'when method is exists in allowed' do
20
+ before do
21
+ stub_const('BetfairApiNgRails::Api::Constants::ALLOWED_RESOURCES', {betting: [method_name]})
22
+ stub_const('BetfairApiNgRails::Api::Constants::JSON_METHOD', {betting: 'json_method'})
23
+ end
24
+
25
+ its(:type) { is_expected.to eq(:betting) }
26
+ its(:allowed?) { is_expected.to be_truthy }
27
+ its(:api_url) { is_expected.to_not eq :no_api_url }
28
+ its(:json_method) { is_expected.to eq('json_method') }
29
+ end
30
+
31
+ context 'when method is not exists in allowed' do
32
+ before do
33
+ stub_const('BetfairApiNgRails::Api::Constants::ALLOWED_RESOURCES', {betting: ['someMethod1']})
34
+ end
35
+
36
+ its(:allowed?) { is_expected.to be_falsey }
37
+ end
38
+ end
@@ -1,80 +1,95 @@
1
1
  require 'spec_helper'
2
2
  require 'betfair_api_ng_rails/api/constants'
3
3
 
4
- module TestModule
5
- extend BetfairApiNgRails::Api::RequestMethods
6
- end
7
-
8
4
  describe BetfairApiNgRails::Api::RequestMethods do
5
+ let(:logger) { double(:logger) }
6
+ before do
7
+ BetfairApiNgRails.config.locale = :en
8
+ BetfairApiNgRails.log = logger
9
+ allow(logger).to receive(:write)
10
+ end
9
11
 
10
- before { BetfairApiNgRails.config.locale = :en }
11
-
12
12
  BetfairApiNgRails::Api::Constants::SIMPLE_LISTING_FILTERED.each do |method|
13
-
14
13
  describe "##{method}" do
15
-
16
14
  it "calls run_request with proper params" do
17
- expect(TestModule).to receive(:run_request).with(method.underscore.to_sym, {filter: :filter}, {locale: :en})
15
+ expect(TestModule).to receive(:run_request).with(method.underscore.to_sym, {filter: :filter, locale: :en})
18
16
  TestModule.send method.underscore.to_sym, filter: :filter
19
17
  end
20
-
21
18
  end
22
-
23
19
  end
24
20
 
25
21
  describe "#list_market_catalogue" do
26
-
27
22
  it "calls run_request with proper params" do
28
- expect(TestModule).to receive(:run_request).with(:list_market_catalogue, {filter: :filter, market_projection: [], sort: "", max_results: '1'}, {locale: :en})
23
+ expect(TestModule).to receive(:run_request).with(:list_market_catalogue, {filter: :filter, market_projection: [], sort: "", max_results: '1', locale: :en})
29
24
  TestModule.list_market_catalogue filter: :filter
30
25
  end
31
-
32
26
  end
33
27
 
34
28
  describe "#list_market_book" do
35
-
36
29
  it "calls run_request with proper params" do
37
- 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})
30
+ 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})
38
31
  TestModule.list_market_book market_ids: ['1'], price_projection: :priceProjection
39
32
  end
40
-
41
33
  end
42
34
 
43
35
  describe "#place_orders" do
44
-
45
36
  it "calls run_request with proper params" do
46
- expect(TestModule).to receive(:run_request).with(:place_orders, {market_id: "", instructions: [], customer_ref: ""})
37
+ expect(TestModule).to receive(:run_request).with(:place_orders, {market_id: "", instructions: [], customer_ref: ""}, "")
47
38
  TestModule.place_orders
48
39
  end
40
+ end
49
41
 
42
+ describe '#get_account_details' do
43
+ it 'calls run request with proper params' do
44
+ expect(TestModule).to receive(:run_request).with(:get_account_details, {}, "")
45
+ TestModule.get_account_details
46
+ end
47
+ end
48
+
49
+ describe '#get_account_funds' do
50
+ it 'calls run request with proper params' do
51
+ expect(TestModule).to receive(:run_request).with(:get_account_funds, {}, "")
52
+ TestModule.get_account_funds
53
+ end
54
+ end
55
+
56
+ describe '#get_account_statement' do
57
+ context 'when valid params passed' do
58
+ let(:params) { {locale: :en} }
59
+
60
+ it 'runs success' do
61
+ expect(TestModule).to receive(:run_request).with(:get_account_statement, params, nil)
62
+ TestModule.get_account_statement params
63
+ end
64
+ end
65
+
66
+ context 'when invalid params passed' do
67
+ let(:params) { [1, 2] }
68
+
69
+ it 'raises exception' do
70
+ expect{
71
+ TestModule.get_account_statement params
72
+ }.to raise_error
73
+ end
74
+ end
50
75
  end
51
76
 
52
77
  describe "private method" do
53
-
54
78
  describe "#build_request_type" do
55
-
56
79
  it "returns proper api method name" do
57
80
  expect(TestModule.send(:build_request_type, 'some_value')).to eq 'someValue'
58
81
  end
59
-
60
82
  end
61
83
 
62
84
  describe "#run_request" do
63
-
64
85
  let(:params) { {key1: 'value'} }
65
- let(:data) { {key2: 'value'} }
66
86
  let(:connection) { double(:connection) }
67
87
 
68
- before(:each) { BetfairApiNgRails.connection = connection }
69
-
70
- after(:each) { TestModule.send(:run_request, 'some_method', params, data) }
88
+ after(:each) { TestModule.send(:run_request, 'some_method', params) }
71
89
 
72
90
  it "calls request method with proper params" do
73
- expect(connection).to receive(:request).with('someMethod', params.merge(data))
91
+ expect_any_instance_of(BetfairApiNgRails::Api::Connection).to receive(:request).with('someMethod', params)
74
92
  end
75
-
76
93
  end
77
-
78
94
  end
79
-
80
- end
95
+ end
@@ -0,0 +1,77 @@
1
+ require 'spec_helper'
2
+
3
+ describe BetfairApiNgRails::Api::SessionManager do
4
+ subject(:session_manager) { described_class.new(endpoint) }
5
+
6
+ let(:endpoint) { BetfairApiNgRails.config.endpoint }
7
+ let(:username) { 'user001' }
8
+ let(:asm) { double(:account_session_manager) }
9
+ let(:account) { BetfairApiNgRails::Account.new(username, 'password', '3cnt4ngt8oh3co', 'crt', 'key') }
10
+
11
+ before do
12
+ allow(BetfairApiNgRails).to receive(:account_session_manager).and_return asm
13
+ end
14
+
15
+ describe '.get_ssoid' do
16
+ before do
17
+ allow(BetfairApiNgRails).to receive_message_chain(:account_session_manager, :get).and_return ssoid
18
+ end
19
+
20
+ context 'when ASM has ssoid for passed account' do
21
+ let(:ssoid) { '2mf348f3fm3f3' }
22
+
23
+ it 'returns this one' do
24
+ expect(session_manager.get_ssoid(account)).to eq ssoid
25
+ end
26
+ end
27
+
28
+ context 'when ASM has not ssoid' do
29
+ let(:ssoid) { nil }
30
+
31
+ it 'requests new ssoid and returns it' do
32
+ expect_any_instance_of(BetfairApiNgRails::Api::SessionManager::SsoidRequester).to receive(:session_token).and_return ssoid
33
+ expect(asm).to receive(:store)
34
+ expect(session_manager.get_ssoid(account)).to eq ssoid
35
+ end
36
+ end
37
+ end
38
+
39
+ describe '.expire_ssoid' do
40
+ it 'expires ssoid for passed account' do
41
+ expect(asm).to receive(:expire).with username
42
+ session_manager.expire_ssoid account
43
+ end
44
+ end
45
+
46
+ end
47
+
48
+ describe BetfairApiNgRails::Api::SessionManager::SsoidRequester do
49
+ subject(:requester) { described_class.new(account, endpoint) }
50
+
51
+ let(:endpoint) { BetfairApiNgRails.config.endpoint }
52
+ let(:username) { 'user001' }
53
+ let(:account) { BetfairApiNgRails::Account.new(username, 'password', '3cnt4ngt8oh3co', 'crt', 'key') }
54
+
55
+ let(:http_requester) { double(:http_requester, do_request: login_response) }
56
+ let(:login_response) do
57
+ double(:login_response, session_token: session_token)
58
+ end
59
+ let(:session_token) { 'some_session_token_str' }
60
+
61
+ before do
62
+ allow(BetfairApiNgRails::Api::Http::Factory).to receive(:session_requester)
63
+ .with(instance_of(String), account)
64
+ .and_return http_requester
65
+ end
66
+
67
+ describe '#get' do
68
+ it 'returns fetched ssoid' do
69
+ expect(requester.get).to eq session_token
70
+ end
71
+
72
+ it 'stores fetched ssoid in registry' do
73
+ requester.get
74
+ expect(BetfairApiNgRails.account_session_manager.sessions.count).to eq 1
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,57 @@
1
+ require 'spec_helper'
2
+ require 'pry-nav'
3
+
4
+ describe 'getAccountStatement request method' do
5
+ let(:method_name) { "get_account_statement" }
6
+ let(:result_class) { BetfairApiNgRails::AccountStatementReport }
7
+ let(:account) { BetfairApiNgRails::Account.new('user001', 'password', '42f2f434f3g43') }
8
+ let(:result_hash) do
9
+ <<-'JSON'
10
+ {"result":
11
+ {
12
+ "accountStatement":[
13
+ {
14
+ "refId":"0",
15
+ "itemDate":"2015-01-02T20:32:51.000Z",
16
+ "amount":-100.0,
17
+ "balance":318.58,
18
+ "itemClassData":{"unknownStatementItem":"{\"avgPrice\":1.68,\"betSize\":100.0,\"betType\":\"B\",\"betCategoryType\":\"E\",\"commissionRate\":null,\"eventId\":116857220,\"eventTypeId\":7524,\"fullMarketName\":\"Games 08 January / Florida @ Vancouver/ Moneyline\",\"grossBetAmount\":0.0,\"marketName\":\"Ставки вкл. ОТ\",\"marketType\":\"O\",\"placedDate\":\"2015-01-08T22:09:26.000Z\",\"selectionId\":2109691,\"selectionName\":\"Ванкувер\",\"startDate\":\"0001-01-01T00:00:00.000Z\",\"transactionType\":\"ACCOUNT_DEBIT\",\"transactionId\":0,\"winLose\":\"RESULT_LOST\"}"},
19
+ "legacyData": {"avgPrice":1.68,"betSize":100.0,"betType":"B","betCategoryType":"E","eventId":116857220,"eventTypeId":7524,"fullMarketName":"Games 08 January / Florida @ Vancouver/ Moneyline","grossBetAmount":0.0,"marketName":"Ставки вкл. ОТ","marketType":"O","placedDate":"2015-01-08T22:09:26.000Z","selectionId":2109691,"selectionName":"Ванкувер","startDate":"0001-01-01T00:00:00.000Z","transactionType":"ACCOUNT_DEBIT","transactionId":0,"winLose":"RESULT_LOST"},
20
+ "itemClass":"UNKNOWN"
21
+ }
22
+ ],
23
+ "moreAvailable":false
24
+ },
25
+ "id":1}
26
+ JSON
27
+ end
28
+ let(:parameters) do
29
+ { }
30
+ end
31
+ let(:logger) { double(:logger) }
32
+
33
+ before(:each) do
34
+ BetfairApiNgRails.config.formatter = nil
35
+ BetfairApiNgRails.log = logger
36
+ allow(logger).to receive(:write)
37
+ allow(BetfairApiNgRails).to receive_message_chain(:account_manager, :get).and_return account
38
+ end
39
+
40
+ context 'when no error occured' do
41
+ it_behaves_like 'request method' do
42
+ it { is_expected.to_not be_nil }
43
+ its(:more_available) { is_expected.to be_nil }
44
+ its(:account_statement) { is_expected.to_not be_empty }
45
+ end
46
+ end
47
+
48
+ context 'when api error occured' do
49
+ it_behaves_like 'request method' do
50
+ let(:result_hash) { "{\"error\":{\"code\":-32700,\"message\":\"DSC-3000\"}}" }
51
+
52
+ it "raise APINGException" do
53
+ expect{ subject }.to raise_error
54
+ end
55
+ end
56
+ end
57
+ end
@@ -1,18 +1,16 @@
1
1
  require 'spec_helper'
2
2
 
3
- module TestModule
4
- extend BetfairApiNgRails::Api::RequestMethods
5
- end
6
-
7
3
  describe "listCompetitions request method" do
8
-
9
4
  it_behaves_like 'simple list filtering request', 'listCompetitions' do
10
-
11
5
  let(:method_name) { "list_competitions" }
12
6
  let(:result_class) { BetfairApiNgRails::CompetitionResult }
13
- let(:result_hash) { "{\"result\": [{\"marketCount\": 1, \"competition\": { \"id\": 1, \"name\": \"World Cup 2014\" }, \"competitionRegion\": \"BR\"}]}" }
14
-
7
+ let(:result_hash) do
8
+ <<-JSON
9
+ {"result":
10
+ [{"marketCount": 1, "competition": { "id": 1, "name": "World Cup 2014" }, "competitionRegion": "BR"}
11
+ ]}
12
+ JSON
13
+ end
15
14
  end
16
-
17
15
  end
18
16
 
@@ -1,18 +1,16 @@
1
1
  require 'spec_helper'
2
2
 
3
- module TestModule
4
- extend BetfairApiNgRails::Api::RequestMethods
5
- end
6
-
7
3
  describe "listCountries request method" do
8
-
9
4
  it_behaves_like 'simple list filtering request', 'listCountries' do
10
-
11
5
  let(:method_name) { "list_countries" }
12
6
  let(:result_class) { BetfairApiNgRails::CountryCodeResult }
13
- let(:result_hash) { "{\"result\": [{\"marketCount\": 1, \"event\": \"UA\"}]}" }
14
-
7
+ let(:result_hash) do
8
+ <<-JSON
9
+ {"result":
10
+ [{"marketCount": 1, "event": "UA"}
11
+ ]}
12
+ JSON
13
+ end
15
14
  end
16
-
17
15
  end
18
16
 
@@ -1,18 +1,16 @@
1
1
  require 'spec_helper'
2
2
 
3
- module TestModule
4
- extend BetfairApiNgRails::Api::RequestMethods
5
- end
6
-
7
3
  describe "listEventTypes request method" do
8
-
9
4
  it_behaves_like 'simple list filtering request', 'listEventTypes' do
10
-
11
5
  let(:method_name) { "list_event_types" }
12
6
  let(:result_class) { BetfairApiNgRails::EventTypeResult }
13
- let(:result_hash) { "{\"result\": [{\"marketCount\": 1, \"eventType\": { \"id\": 1, \"name\": \"Soccer\" }}]}" }
14
-
7
+ let(:result_hash) do
8
+ <<-JSON
9
+ {"result":
10
+ [{"marketCount": 1, "eventType": { "id": 1, "name": "Soccer" }}
11
+ ]}
12
+ JSON
13
+ end
15
14
  end
16
-
17
15
  end
18
16
 
@@ -1,18 +1,16 @@
1
1
  require 'spec_helper'
2
2
 
3
- module TestModule
4
- extend BetfairApiNgRails::Api::RequestMethods
5
- end
6
-
7
3
  describe "listEvents request method" do
8
-
9
4
  it_behaves_like 'simple list filtering request', 'listEvents' do
10
-
11
5
  let(:method_name) { "list_events" }
12
6
  let(:result_class) { BetfairApiNgRails::EventResult }
13
- let(:result_hash) { "{\"result\": [{\"marketCount\": 1, \"event\": { \"id\": 1, \"name\": \"Chelsea - PSG\" }}]}" }
14
-
7
+ let(:result_hash) do
8
+ <<-JSON
9
+ {"result":
10
+ [{"marketCount": 1, "event": { "id": 1, "name": "Chelsea - PSG" }}
11
+ ]}
12
+ JSON
13
+ end
15
14
  end
16
-
17
15
  end
18
16
 
@@ -1,19 +1,17 @@
1
1
  require 'spec_helper'
2
2
 
3
- module TestModule
4
- extend BetfairApiNgRails::Api::RequestMethods
5
- end
6
-
7
3
  describe "listMarketBook request method" do
8
-
9
4
  it_behaves_like 'simple list filtering request', 'listMarketBook' do
10
-
11
5
  let(:parameters) { {market_ids: [1]} }
12
6
  let(:method_name) { "list_market_book" }
13
7
  let(:result_class) { BetfairApiNgRails::MarketBook }
14
- let(:result_hash) { "{\"result\": [{\"marketId\": 1, \"isMarketDataDelayed\": \"true\"}]}" }
15
-
8
+ let(:result_hash) do
9
+ <<-JSON
10
+ {"result":
11
+ [{"marketId": 1, "isMarketDataDelayed": "true"}
12
+ ]}
13
+ JSON
14
+ end
16
15
  end
17
-
18
16
  end
19
17
 
@@ -1,36 +1,27 @@
1
1
  require 'spec_helper'
2
2
 
3
- module TestModule
4
- extend BetfairApiNgRails::Api::RequestMethods
5
- end
6
-
7
3
  describe "listMarketCatalogue request method" do
8
-
9
4
  it_behaves_like 'simple list filtering request', 'listMarketCatalogue' do
10
-
11
5
  let(:method_name) { "list_market_catalogue" }
12
6
  let(:result_class) { BetfairApiNgRails::MarketCatalogue }
13
- let(:result_hash) { "{\"result\": [{\"marketId\": 1, \"marketName\": \"Madrid\", \"marketStartTime\": \"23-04-2014\", \"description\": \"Madrid\", \"totalMatched\": \"1\", \"competition\": {\"id\": 1, \"name\": \"name\"}}]}" }
7
+ let(:result_hash) do
8
+ <<-JSON
9
+ {"result":
10
+ [{"marketId": 1, "marketName": "Madrid", "marketStartTime": "23-04-2014", "description": "Madrid", "totalMatched": "1", "competition": {"id": 1, "name": "name"}}
11
+ ]}
12
+ JSON
13
+ end
14
14
 
15
15
  describe 'checking attribute' do
16
-
17
16
  context 'competition' do
18
-
19
17
  it_behaves_like 'request method' do
20
-
21
18
  subject { TestModule.send(method_name, parameters).first }
22
19
 
23
20
  its(:competition) { is_expected.not_to be_nil }
24
-
25
21
  its('competition.name') { is_expected.to eq 'name' }
26
-
27
22
  end
28
-
29
23
  end
30
-
31
24
  end
32
-
33
25
  end
34
-
35
26
  end
36
27