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,26 @@
1
+ require 'active_support/inflector'
2
+ require 'betfair_api_ng_rails/api/constants'
3
+ require 'betfair_api_ng_rails/api/request_methods/betting'
4
+ require 'betfair_api_ng_rails/api/request_methods/account'
5
+
6
+ module BetfairApiNgRails
7
+ module Api
8
+ module RequestMethods
9
+ module All
10
+ include Api::Constants
11
+ include Api::RequestMethods::Betting
12
+ include Api::RequestMethods::Account
13
+
14
+ private
15
+
16
+ def run_request(method, params, account_name = '')
17
+ BetfairApiNgRails::Api::Connection.new(account_name).request build_request_type(method), params
18
+ end
19
+
20
+ def build_request_type(name)
21
+ name.to_s.camelize(:lower)
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,30 @@
1
+ module BetfairApiNgRails
2
+ module Api
3
+ module RequestMethods
4
+ module Betting
5
+ include Api::Constants
6
+
7
+ SIMPLE_LISTING_FILTERED.each do |method|
8
+ eval <<-CODE
9
+ def #{method.underscore}(filter: BetfairApiNgRails::MarketFilter.new, locale: BetfairApiNgRails.config.locale)
10
+ run_request __method__, { filter: filter, locale: locale }
11
+ end
12
+ CODE
13
+ end
14
+
15
+ def list_market_catalogue(filter: BetfairApiNgRails::MarketFilter.new, market_projection: [], sort: "", max_results: '1', locale: BetfairApiNgRails.config.locale)
16
+ run_request __method__, { filter: filter, market_projection: market_projection, sort: sort, max_results: max_results, locale: locale }
17
+ end
18
+
19
+ def list_market_book(market_ids: [], price_projection: BetfairApiNgRails::PriceProjection.new, order_projection: '', match_projection: '', currency_code: 'USD', locale: BetfairApiNgRails.config.locale)
20
+ 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 }
21
+ end
22
+
23
+ def place_orders(market_id: "", instructions: [], customer_ref: "", account_name: '')
24
+ run_request __method__, { market_id: market_id, instructions: instructions, customer_ref: customer_ref }, account_name
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+
@@ -1,54 +1,57 @@
1
1
  require 'betfair_api_ng_rails/api/concerns/errorable'
2
+ require 'active_support/core_ext/module/delegation'
2
3
 
3
4
  module BetfairApiNgRails
4
5
  module Api
5
- class SessionManager
6
- class << self
7
- include Api::Concerns::Errorable
8
- include Api::Constants
6
+ class SessionManager < Struct.new(:endpoint)
7
+ include Api::Concerns::Errorable
8
+ include Api::Constants
9
+
10
+ def get_ssoid(account)
11
+ username = account.username
12
+ ssoid = BetfairApiNgRails.account_session_manager.get username
13
+ ssoid || SsoidRequester.new(account, endpoint).get
14
+ end
9
15
 
10
- def ssoid
11
- @ssoid ||= fetch_ssoid
12
- end
16
+ def expire_ssoid(account)
17
+ username = account.username
18
+ BetfairApiNgRails.account_session_manager.expire username
19
+ end
13
20
 
14
- def request_ssoid
15
- ssoid
16
- !has_errors?
17
- end
21
+ private
18
22
 
19
- def expire_ssoid
20
- @ssoid = nil
21
- end
23
+ class SsoidRequester < Struct.new(:account, :endpoint)
24
+ delegate :username, to: :account
25
+ delegate :login_url, to: :endpoint
22
26
 
23
- def new_ssoid
24
- expire_ssoid
25
- ssoid
27
+ def get
28
+ session_token.tap do |token|
29
+ store_session token
30
+ end
26
31
  end
27
32
 
28
- private
33
+ private
29
34
 
30
- def fetch_ssoid
31
- get_login_response.session_token.tap { |sid| send_keep_alive(sid) }
35
+ def store_session(token)
36
+ BetfairApiNgRails.account_session_manager.store account_session(token)
32
37
  end
33
38
 
34
- def get_login_response
35
- http_requester.do_request
39
+ def account_session(token)
40
+ BetfairApiNgRails::AccountSession.new(username, token)
36
41
  end
37
42
 
38
- def send_keep_alive(sid)
39
- return unless Api::Config.keep_alive_session
40
- keep_alive_requester(sid).do_request
43
+ def session_token
44
+ get_login_response.session_token
41
45
  end
42
46
 
43
- def http_requester
44
- @_http_requester ||= Api::Http::Factory.session_requester
47
+ def get_login_response
48
+ http_requester.do_request
45
49
  end
46
50
 
47
- def keep_alive_requester(sid)
48
- Api::Http::Factory.keep_alive_requester sid
51
+ def http_requester
52
+ @_http_requester ||= Api::Http::Factory.session_requester(login_url, account)
49
53
  end
50
-
51
54
  end
52
55
  end
53
56
  end
54
- end
57
+ end
@@ -0,0 +1,4 @@
1
+ module BetfairApiNgRails
2
+ class BadResponseError < StandardError
3
+ end
4
+ end
@@ -1,5 +1,4 @@
1
1
  module BetfairApiNgRails
2
-
3
2
  class NoConnectionError < ::StandardError
4
3
  end
5
4
 
@@ -10,4 +9,6 @@ module BetfairApiNgRails
10
9
  end
11
10
  end
12
11
 
13
- end
12
+ class NoAccountProvided < ::StandardError
13
+ end
14
+ end
@@ -1,7 +1,12 @@
1
1
  module BetfairApiNgRails
2
2
  class Railtie < Rails::Railtie
3
3
  config.after_initialize do
4
- BetfairApiNgRails.connection = BetfairApiNgRails::Api::Connection.new
4
+ BetfairApiNgRails.log = BetfairApiNgRails::Api::Logs::FileLogger.new Rails.root, Rails.env
5
5
  end
6
+
7
+ console do
8
+ BetfairApiNgRails.log = BetfairApiNgRails::Api::Logs::ConsoleLogger.new
9
+ end
10
+
6
11
  end
7
- end
12
+ end
@@ -1,3 +1,3 @@
1
1
  module BetfairApiNgRails
2
- VERSION = "1.1.0"
2
+ VERSION = "2.1.0"
3
3
  end
@@ -1,18 +1,27 @@
1
1
  BetfairApiNgRails.config do |config|
2
- require 'yaml'
2
+ config.load_for_environment "#{Rails.root}/config/betfair_api_ng_rails.yml", Rails.env
3
3
 
4
- load_config = YAML.load_file("#{Rails.root}/config/betfair_api_ng_rails.yml")[Rails.env]
5
-
6
- config.application_key = load_config['application_key']
7
4
  config.ssl_key_filepath = "#{Rails.root}/public/client-2048.key"
8
5
  config.ssl_crt_filepath = "#{Rails.root}/public/client-2048.crt"
9
- config.login_url = load_config['login_url']
10
- config.api_url = load_config['api_url']
11
- config.keep_alive_url = load_config['keep_alive_url']
12
- config.username = load_config['username']
13
- config.password = load_config['password']
6
+
14
7
  config.locale = :ru
15
- config.formatter = nil #out of box available formatter for JsTree
8
+ config.formatter = nil
16
9
  config.keep_alive_session = true
17
10
 
18
- end
11
+ # Caching settings
12
+ config.use_cache = false
13
+ config.cache_expire = 5 # in seconds
14
+
15
+ # Proxy layer settings
16
+ config.proxy_enable = false
17
+ # Uncomment next line if you will use go layer and go_enable is set to true
18
+ # config.proxy_url = "http://127.0.0.1/"
19
+
20
+ # Setting up account
21
+ BetfairApiNgRails.account_manager.store BetfairApiNgRails::Account.new(config.username,
22
+ config.password,
23
+ config.application_key,
24
+ config.ssl_crt_filepath,
25
+ config.ssl_key_filepath)
26
+ BetfairApiNgRails.account_manager.default config.username
27
+ end
@@ -1,15 +1,13 @@
1
1
  development:
2
2
  application_key: YOUR_APP_KEY
3
- login_url: https://identitysso.betfair.com/api/certlogin
4
- api_url: https://api-ng.betstores.com/betting/betfair/services/api.betfair.com/exchange/betting/json-rpc/v1
5
- keep_alive_url: https://identitysso.betfair.com/api/keepAlive
6
3
  username: YOUR_ACCOUNT_USERNAME
7
4
  password: YOUR_ACCOUNT_PASSWORD
5
+ go_localuser: YOURUSERNAME
6
+ go_filename: betfair
8
7
 
9
8
  production:
10
9
  application_key: YOUR_APP_KEY
11
- login_url: https://identitysso.betfair.com/api/certlogin
12
- api_url: https://api-ng.betstores.com/betting/betfair/services/api.betfair.com/exchange/betting/json-rpc/v1
13
- keep_alive_url: https://identitysso.betfair.com/api/keepAlive
14
10
  username: YOUR_ACCOUNT_USERNAME
15
- password: YOUR_ACCOUNT_PASSWORD
11
+ password: YOUR_ACCOUNT_PASSWORD
12
+ go_localuser: YOURUSERNAME
13
+ go_filename: betfair
@@ -0,0 +1,76 @@
1
+ require 'spec_helper'
2
+
3
+ describe BetfairApiNgRails::AccountManager do
4
+ let(:account) { BetfairApiNgRails::Account.new('user001', 'password', 'cf23f23') }
5
+ subject(:manager) { described_class.instance }
6
+
7
+ it { is_expected.to respond_to :accounts }
8
+
9
+ describe '#store' do
10
+ before do
11
+ manager.clear
12
+ end
13
+
14
+ it 'stores account in global hash' do
15
+ expect{
16
+ manager.store account
17
+ }.to change(manager.accounts, :count).by 1
18
+ end
19
+ end
20
+
21
+ describe '#get' do
22
+ context 'gets account by username' do
23
+ context 'when it exists' do
24
+ before do
25
+ manager.store account
26
+ end
27
+
28
+ it 'returns this one' do
29
+ expect(manager.get('user001')).to eq account
30
+ end
31
+ end
32
+
33
+ context 'when it not exists' do
34
+ context 'and default exists' do
35
+ before do
36
+ manager.store account
37
+ manager.default 'user001'
38
+ end
39
+
40
+ it 'returns it' do
41
+ expect(manager.get('user002')).to eq account
42
+ end
43
+ end
44
+
45
+ context 'and no defaults' do
46
+ before do
47
+ manager.clear
48
+ end
49
+
50
+ it 'returns nil' do
51
+ expect(manager.get('user002')).to be_nil
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
57
+
58
+ describe '#clear' do
59
+ before do
60
+ manager.store account
61
+ end
62
+
63
+ it 'cleares account register' do
64
+ manager.clear
65
+ expect(manager.accounts.count).to eq 0
66
+ end
67
+ end
68
+
69
+ describe '#default' do
70
+ it 'sets default account' do
71
+ expect{
72
+ manager.default 'user001'
73
+ }.to_not raise_error
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,59 @@
1
+ require 'spec_helper'
2
+
3
+ describe BetfairApiNgRails::AccountSessionManager do
4
+ let(:session) { BetfairApiNgRails::AccountSession.new('user001', 'nwfh7348ofho3478fh') }
5
+ subject(:manager) { described_class.instance }
6
+
7
+ describe '#store' do
8
+ before do
9
+ manager.clear
10
+ end
11
+
12
+ it 'stores session in global hash' do
13
+ expect{
14
+ manager.store session
15
+ }.to change(manager.sessions, :count).by 1
16
+ end
17
+ end
18
+
19
+ describe '#get' do
20
+ context 'when information for user exists' do
21
+ before do
22
+ manager.store session
23
+ end
24
+
25
+ it 'returns it' do
26
+ expect(manager.get('user001')).to_not be_nil
27
+ end
28
+ end
29
+
30
+ context 'when information for user not exists' do
31
+ it 'returns nil' do
32
+ expect(manager.get('003')).to be_nil
33
+ end
34
+ end
35
+ end
36
+
37
+ describe '#expire' do
38
+ before do
39
+ manager.store session
40
+ end
41
+
42
+ it 'removes session of user' do
43
+ expect{
44
+ manager.expire 'user001'
45
+ }.to change(manager.sessions, :count).by -1
46
+ end
47
+ end
48
+
49
+ describe '#clear' do
50
+ before do
51
+ manager.store session
52
+ end
53
+
54
+ it 'cleares sessions register' do
55
+ manager.clear
56
+ expect(manager.sessions.count).to eq 0
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe BetfairApiNgRails::AccountSession do
4
+ let(:username) { 'user001' }
5
+ let(:ssoid) { 'wgj34g8h39p4hgp3j' }
6
+ let(:opts) { [username, ssoid] }
7
+
8
+ subject(:account_session) { described_class.new(*opts) }
9
+
10
+ its(:username) { is_expected.to eq username }
11
+ its(:ssoid) { is_expected.to eq ssoid }
12
+ end
13
+
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ describe BetfairApiNgRails::Account do
4
+ let(:username) { 'user001' }
5
+ let(:password) { 'some_password' }
6
+ let(:app_key) { 'n34f73o48fn' }
7
+ let(:crt_filepath) { 'cn2i3nc2f32' }
8
+ let(:key_filepath) { 'f23f23f23f' }
9
+ let(:opts) { [username, password, app_key, crt_filepath, key_filepath] }
10
+
11
+ subject(:account) { described_class.new(*opts) }
12
+
13
+ its(:username) { is_expected.to eq username }
14
+ its(:password) { is_expected.to eq password }
15
+ its(:app_key) { is_expected.to eq app_key }
16
+ its(:crt_filepath) { is_expected.to eq crt_filepath }
17
+ its(:key_filepath) { is_expected.to eq key_filepath }
18
+ end
@@ -0,0 +1,89 @@
1
+ require 'spec_helper'
2
+
3
+ class TestObject
4
+ include BetfairApiNgRails::Api::Caching::Helper
5
+ end
6
+
7
+ describe BetfairApiNgRails::Api::Caching::Helper do
8
+
9
+ subject(:helper) { TestObject.new }
10
+
11
+ describe ".createsig" do
12
+
13
+ it "creates hex from sigflat result" do
14
+ expect(helper).to receive(:sigflat).with("some").and_return "some-sigflat"
15
+ expect(Digest::MD5).to receive(:hexdigest).with "some-sigflat"
16
+ helper.createsig "some"
17
+ end
18
+
19
+ describe 'real tests' do
20
+
21
+ context 'sigs equal values' do
22
+
23
+ let(:value1) { {key1: :value2} }
24
+ let(:value2) { {key1: :value2} }
25
+
26
+ it 'expects to be equal' do
27
+ val1 = helper.createsig(value1)
28
+ val2 = helper.createsig(value2)
29
+ expect(val1).to eq val2
30
+ end
31
+
32
+ end
33
+
34
+ context 'sigs different values' do
35
+
36
+ let(:value1) { {key1: :value2} }
37
+ let(:value2) { {key1: :value3} }
38
+
39
+ it 'expects not to be equal' do
40
+ val1 = helper.createsig(value1)
41
+ val2 = helper.createsig(value2)
42
+ expect(val1).not_to eq val2
43
+ end
44
+
45
+ end
46
+
47
+ end
48
+
49
+ end
50
+
51
+ describe ".sigflat" do
52
+
53
+ subject { helper.sigflat(value) }
54
+
55
+ context "when String passed" do
56
+
57
+ let(:value) { 'some' }
58
+
59
+ it { is_expected.to eq("some") }
60
+
61
+ end
62
+
63
+ context "when Integer passed" do
64
+
65
+ let(:value) { 1 }
66
+
67
+ it { is_expected.to eq("1Fixnum") }
68
+
69
+ end
70
+
71
+ context "when Hash passed" do
72
+
73
+ let(:value) { { key: :value } }
74
+
75
+ it { is_expected.to eq("{:key=>:value}Hash") }
76
+
77
+ end
78
+
79
+ context "when Array passed" do
80
+
81
+ let(:value) { ["val1", "val2"] }
82
+
83
+ it { is_expected.to eq("[\"val1\", \"val2\"]Array") }
84
+
85
+ end
86
+
87
+ end
88
+
89
+ end