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,9 @@
1
+ require 'spec_helper'
2
+
3
+ describe BetfairApiNgRails::StatementItem do
4
+ include_examples 'data model', DataModelsYamlLoader.new.fetch('statementItem') do
5
+ describe 'legacy data association' do
6
+ its(:legacy_data) { is_expected.to be_kind_of BetfairApiNgRails::StatementLegacyData }
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,6 @@
1
+ require 'spec_helper'
2
+
3
+ describe BetfairApiNgRails::StatementLegacyData do
4
+ include_examples 'data model', DataModelsYamlLoader.new.fetch('statementLegacyData')
5
+ end
6
+
@@ -1,7 +1,5 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe BetfairApiNgRails::TimeRange do
4
-
5
4
  include_examples 'data model', DataModelsYamlLoader.new.fetch('timeRange')
6
-
7
- end
5
+ end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe BetfairApiNgRails::Api::EndpointFactory do
4
+ subject(:factory) { described_class }
5
+
6
+ context 'when passed value associated with existing endpoint' do
7
+ context 'when symbol is passed' do
8
+ subject(:endpoint) { factory.call(:uk) }
9
+
10
+ it { is_expected.to be_kind_of(BetfairApiNgRails::Api::Endpoints::Uk) }
11
+ end
12
+
13
+ context 'when class is passed' do
14
+ subject(:endpoint) { factory.call(BetfairApiNgRails::Api::Endpoints::Italian) }
15
+
16
+ it { is_expected.to be_kind_of(BetfairApiNgRails::Api::Endpoints::Italian) }
17
+ end
18
+ end
19
+
20
+ context 'when passed value associated with unexisting endpoint' do
21
+ it 'raises InvalidEndpointError' do
22
+ expect{
23
+ factory.call(:unxisted_endpoint)
24
+ }.to raise_error(BetfairApiNgRails::Api::InvalidEndpointError)
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,6 @@
1
+ require 'spec_helper'
2
+
3
+ describe BetfairApiNgRails::Api::Endpoints::Australian do
4
+ include_examples 'base endpoint'
5
+ include_examples 'concrete endpoint', 'api-au.betfair.com', 'identitysso.betfair.com'
6
+ end
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+
3
+ describe BetfairApiNgRails::Api::Endpoints::Base do
4
+ include_examples 'base endpoint'
5
+ end
@@ -0,0 +1,6 @@
1
+ require 'spec_helper'
2
+
3
+ describe BetfairApiNgRails::Api::Endpoints::Italian do
4
+ include_examples 'base endpoint'
5
+ include_examples 'concrete endpoint', 'api.betfair.com', 'identitysso.betfair.it'
6
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe BetfairApiNgRails::Api::Endpoints::Spanish do
4
+ include_examples 'base endpoint'
5
+ include_examples 'concrete endpoint', 'api.betfair.com', 'identitysso.betfair.es'
6
+ end
7
+
@@ -0,0 +1,6 @@
1
+ require 'spec_helper'
2
+
3
+ describe BetfairApiNgRails::Api::Endpoints::Uk do
4
+ include_examples 'base endpoint'
5
+ include_examples 'concrete endpoint', "api.betfair.com", "identitysso.betfair.com"
6
+ end
@@ -1,17 +1,16 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe BetfairApiNgRails::Api::Hashalator do
4
-
5
4
  let(:hashable) { { some_key: :some_value } }
6
5
 
7
- subject { described_class.new(hashable) }
6
+ subject { described_class.new(hashable, for_param) }
7
+
8
+ let(:for_param) { false }
8
9
 
9
10
  its(:hashable) { is_expected.to eq hashable }
10
11
 
11
12
  describe "#to_hash" do
12
-
13
13
  context 'when value isn\'t blank or nil' do
14
-
15
14
  it "iterates though elements and process they" do
16
15
  expect(subject).to receive(:hash_key).at_least(:once)
17
16
  expect(subject).to receive(:hash_value).at_least(:once).and_return double
@@ -19,158 +18,140 @@ describe BetfairApiNgRails::Api::Hashalator do
19
18
  end
20
19
 
21
20
  end
22
-
23
- context 'when else' do
24
21
 
22
+ context 'when else' do
25
23
  it "does include it result hash" do
26
24
  expect(subject).to receive(:hash_key).exactly(0).times
27
25
  expect(subject).to receive(:hash_value).at_least(:once)
28
26
  subject.to_hash
29
27
  end
30
-
31
28
  end
32
-
33
29
  end
34
30
 
35
31
  describe "private method" do
36
-
37
32
  describe "#hashing_val" do
38
-
39
33
  let(:el) { double(:el) }
40
34
 
41
35
  context 'when array passed' do
42
-
43
36
  let(:array) { [el] }
44
37
 
45
38
  it "calls hash_value on each element" do
46
39
  expect(subject).to receive(:hash_value).with(el)
47
40
  subject.send :hashing_val, array
48
41
  end
49
-
50
42
  end
51
43
 
52
44
  context 'when single value passed' do
53
-
54
45
  it "calls to_hash on it" do
55
46
  expect(el).to receive(:to_hash)
56
47
  subject.send :hashing_val, el
57
48
  end
58
-
59
49
  end
60
-
61
50
  end
62
51
 
63
52
  describe "#hash_key" do
64
-
65
- it "returns key for api request hash" do
66
- expect(subject.send(:hash_key, :some_key)).to eq 'someKey'
53
+ context 'when not for param' do
54
+ it "returns key for api request hash" do
55
+ expect(subject.send(:hash_key, :some_key)).to eq 'someKey'
56
+ end
67
57
  end
68
58
 
59
+ context 'when for param' do
60
+ let(:for_param) { true }
61
+
62
+ it "returns key for api request hash" do
63
+ expect(subject.send(:hash_key, :some_key)).to eq :some_key
64
+ end
65
+ end
69
66
  end
70
67
 
71
68
  describe "#need_to_hash?" do
72
-
73
69
  before { stub_const("BetfairApiNgRails::Api::Data::Constants::ATTRS_AS_IS", classes) }
74
70
 
75
71
  context 'when ATTRS_AS_IS include value class' do
76
-
77
72
  let(:classes) { [String] }
78
73
 
79
74
  it "returns false" do
80
75
  expect(subject.send(:need_to_hash?, 'value')).to eq false
81
76
  end
82
-
83
77
  end
84
78
 
85
79
  context 'when ATTRS_AS_IS not include value class' do
86
-
87
80
  let(:classes) { [String] }
88
81
 
89
82
  it "returns true" do
90
83
  expect(subject.send(:need_to_hash?, 1)).to eq true
91
84
  end
92
-
93
85
  end
94
-
95
86
  end
96
87
 
97
88
  describe "#hash_value" do
98
-
99
89
  let(:value) { double(:value) }
100
90
 
101
91
  context 'when need to hashing value' do
102
-
103
92
  before { expect(subject).to receive(:need_to_hash?).with(value).and_return(true) }
104
93
 
105
94
  it "calls to_hash on value" do
106
95
  expect(subject).to receive(:hashing_val).with(value)
107
96
  subject.send :hash_value, value
108
97
  end
109
-
110
98
  end
111
99
 
112
100
  context 'when dont need to hashing value' do
113
-
114
101
  before { expect(subject).to receive(:need_to_hash?).with(value).and_return(false) }
115
102
 
116
103
  it "returns value" do
117
104
  expect(subject).to receive(:hashing_val).with(value).exactly(0).times
118
105
  subject.send :hash_value, value
119
106
  end
120
-
121
107
  end
122
-
123
108
  end
124
-
125
109
  end
126
110
 
127
111
  context 'integration tests' do
128
-
129
- subject { described_class.new(hashable).to_hash }
112
+ subject { described_class.new(hashable, for_param).to_hash }
113
+
114
+ let(:for_param) { false }
130
115
 
131
116
  context 'when only simple values passed' do
132
-
133
117
  let(:hashable) { { some_key: :some_value } }
134
118
 
135
- it { is_expected.to eq({'someKey' => :some_value}) }
119
+ context 'when not for param' do
120
+ it { is_expected.to eq({'someKey' => :some_value}) }
121
+ end
122
+
123
+ context 'when for param' do
124
+ let(:for_param) { true }
136
125
 
126
+ it { is_expected.to eq({:some_key => :some_value}) }
127
+ end
137
128
  end
138
129
 
139
130
  context 'when array with simple values passes' do
140
-
141
131
  let(:hashable) { {some_key: [1, 2, 3]} }
142
132
 
143
133
  it { is_expected.to eq({'someKey' => [1, 2, 3]}) }
144
-
145
134
  end
146
135
 
147
136
  context 'when array with at least one complex value passes' do
148
-
149
137
  let(:el) { double(:el) }
150
138
  let(:hashable) { {some_key: [el]} }
151
139
 
152
140
  before { expect(el).to receive(:to_hash).and_return(el) }
153
141
 
154
142
  it { is_expected.to eq({'someKey' => [el]}) }
155
-
156
143
  end
157
144
 
158
145
  context 'when one of values is blank' do
159
-
160
146
  let(:hashable) { {some_key: ""} }
161
147
 
162
148
  it { is_expected.to eq({}) }
163
-
164
149
  end
165
150
 
166
151
  context 'when one of values is nil' do
167
-
168
152
  let(:hashable) { {some_key: nil} }
169
153
 
170
154
  it { is_expected.to eq({}) }
171
-
172
155
  end
173
-
174
156
  end
175
-
176
- end
157
+ end
@@ -0,0 +1,40 @@
1
+ require 'spec_helper'
2
+
3
+ describe BetfairApiNgRails::Api::Http::Factory do
4
+ let(:account) do
5
+ BetfairApiNgRails::Account.new(
6
+ 'user001',
7
+ 'password',
8
+ 'app_key',
9
+ 'crt_filepath',
10
+ 'key_filepath'
11
+ )
12
+ end
13
+ let(:requester) { double(:requester) }
14
+
15
+ subject(:factory) { described_class }
16
+
17
+ before do
18
+ expect(factory).to receive(:create_http_requester)
19
+ .and_return(requester)
20
+ end
21
+
22
+ describe '.session_requester' do
23
+ it 'settings up requester for session' do
24
+ expect(requester).to receive(:set_ssl_files).with 'crt_filepath', 'key_filepath'
25
+ expect(requester).to receive(:set_request_headers)
26
+ expect(requester).to receive(:set_auth_headers).with 'app_key'
27
+ expect(requester).to receive(:set_form_data)
28
+ .with('username' => 'user001', 'password' => 'password')
29
+ factory.session_requester "https://login.url.com", account
30
+ end
31
+ end
32
+
33
+ describe '.provider_requester' do
34
+ it 'settings up requester for provider' do
35
+ expect(requester).to receive(:set_request_headers)
36
+ expect(requester).to receive(:set_auth_headers).with('app_key', 'some_ssoid')
37
+ factory.provider_requester 'api_url', 'some_ssoid', 'app_key'
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ describe BetfairApiNgRails::Api::Logs::ConsoleLogger do
4
+
5
+ subject(:object) { described_class.new }
6
+
7
+ describe "#write" do
8
+
9
+ let(:string) { "some content" }
10
+
11
+ it "puts content to console" do
12
+ expect(object).to receive(:puts).with "\e[0;32;49msome content\e[0m"
13
+ object.write string
14
+ end
15
+
16
+ end
17
+
18
+ end
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ describe BetfairApiNgRails::Api::Logs::FileLogger do
4
+ subject(:logger) { described_class.new(root, env) }
5
+
6
+ let(:root) { 'root_path_of_rails_app' }
7
+ let(:env) { 'some_env' }
8
+
9
+ describe "#write" do
10
+ let(:file) { double(:file) }
11
+ let(:string) { "some text" }
12
+
13
+ before do
14
+ expect(File).to receive(:open).and_yield file
15
+ expect(logger).to receive(:now_date).and_return 'now_date'
16
+ end
17
+
18
+ it "writes passed string to log file" do
19
+ expect(file).to receive(:puts).with("[now_date] - #{string}")
20
+ logger.write string
21
+ end
22
+ end
23
+
24
+ describe "private method" do
25
+ describe "#file_path" do
26
+ subject { logger.send(:file_path) }
27
+
28
+ it { is_expected.to include root }
29
+ it { is_expected.to include env }
30
+ it { is_expected.to eq "#{root}/log/betfair_api_ng_rails.#{env}.log" }
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,53 @@
1
+ require 'spec_helper'
2
+
3
+ describe BetfairApiNgRails::Api::Provider do
4
+ let(:ssoid) { double(:ssoid) }
5
+ let(:application_key) { '2ef8783ofno34fn' }
6
+
7
+ subject { described_class.new(ssoid, application_key) }
8
+
9
+ its(:ssoid) { is_expected.to eq ssoid }
10
+
11
+ describe "#fetch" do
12
+ let(:method) { double(:method, allowed?: method_allowed, name: 'someMethod') }
13
+
14
+ context 'when method isn\'t allowed' do
15
+ let(:method_allowed) { false }
16
+
17
+ it "raises error" do
18
+ expect{ subject.fetch(method: method) }.to raise_error
19
+ end
20
+ end
21
+
22
+ context 'when requested method is allowed' do
23
+ let(:method_allowed) { true }
24
+
25
+ it "calls run_request" do
26
+ expect(subject).to receive(:run_request).with(for_method: method, params: {})
27
+ subject.fetch method: method
28
+ end
29
+ end
30
+ end
31
+
32
+ describe "private method" do
33
+ describe "#run_request" do
34
+ let(:http_requester) { double(:http_requester) }
35
+ let(:method) { double(:method, api_url: 'api_url') }
36
+
37
+ before { expect(subject).to receive(:http_requester).at_least(:once).and_return(http_requester) }
38
+
39
+ it "runs http requster" do
40
+ expect(http_requester).to receive(:set_api_req_body).with(method, {})
41
+ expect(http_requester).to receive(:do_request)
42
+ subject.send :run_request, for_method: method, params: {}
43
+ end
44
+ end
45
+
46
+ describe "#http_requester" do
47
+ it "initalizes provider http request" do
48
+ expect(BetfairApiNgRails::Api::Http::Factory).to receive(:provider_requester).with 'api_url', ssoid, application_key
49
+ subject.send :http_requester, 'api_url'
50
+ end
51
+ end
52
+ end
53
+ end