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
@@ -2,7 +2,6 @@ module BetfairApiNgRails
2
2
  module Api
3
3
  module Parsers
4
4
  class Base
5
-
6
5
  attr_reader :responser
7
6
 
8
7
  def initialize(responser)
@@ -10,20 +9,29 @@ module BetfairApiNgRails
10
9
  end
11
10
 
12
11
  def process
13
- fetch_result_json.map { |json_row| process_row json_row }
12
+ raise 'Must be reimplemented!'
14
13
  end
15
14
 
16
- private
15
+ private
17
16
 
18
17
  def fetch_result_json
19
- responser.has_error? ? [] : responser.api_result
18
+ responser.has_error? ? default_value : responser.api_result
19
+ rescue
20
+ raise BetfairApiNgRails::BadResponseError
20
21
  end
21
22
 
22
- def process_row(json_row)
23
+ def default_value
23
24
  raise 'Must be reimplemented!'
24
25
  end
25
26
 
27
+ def process_row(json_row)
28
+ data_class.from_json json_row
29
+ end
30
+
31
+ def data_class
32
+ raise 'Must be reimplemented!'
33
+ end
26
34
  end
27
35
  end
28
36
  end
29
- end
37
+ end
@@ -0,0 +1,13 @@
1
+ module BetfairApiNgRails
2
+ module Api
3
+ module Parsers
4
+ class GetAccountDetails < Api::Parsers::SingleBase
5
+ private
6
+
7
+ def data_class
8
+ Api::Data::AccountDetailsResponse
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,14 @@
1
+ module BetfairApiNgRails
2
+ module Api
3
+ module Parsers
4
+ class GetAccountFunds < Api::Parsers::SingleBase
5
+ private
6
+
7
+ def data_class
8
+ Api::Data::AccountFundsResponse
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
14
+
@@ -0,0 +1,15 @@
1
+ module BetfairApiNgRails
2
+ module Api
3
+ module Parsers
4
+ class GetAccountStatement < Api::Parsers::SingleBase
5
+ private
6
+
7
+ def data_class
8
+ Api::Data::AccountStatementReport
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
14
+
15
+
@@ -0,0 +1,18 @@
1
+ module BetfairApiNgRails
2
+ module Api
3
+ module Parsers
4
+ class ListBase < Api::Parsers::Base
5
+ def process
6
+ fetch_result_json.map { |json_row| process_row json_row }
7
+ end
8
+
9
+ private
10
+
11
+ def default_value
12
+ []
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+
@@ -1,15 +1,13 @@
1
1
  module BetfairApiNgRails
2
2
  module Api
3
3
  module Parsers
4
- class ListCompetitions < Api::Parsers::Base
4
+ class ListCompetitions < Api::Parsers::ListBase
5
+ private
5
6
 
6
- private
7
-
8
- def process_row(json_row)
9
- Api::Data::CompetitionResult.from_json json_row
7
+ def data_class
8
+ Api::Data::CompetitionResult
10
9
  end
11
-
12
10
  end
13
11
  end
14
12
  end
15
- end
13
+ end
@@ -1,15 +1,13 @@
1
1
  module BetfairApiNgRails
2
2
  module Api
3
3
  module Parsers
4
- class ListCountries < Api::Parsers::Base
4
+ class ListCountries < Api::Parsers::ListBase
5
+ private
5
6
 
6
- private
7
-
8
- def process_row(json_row)
9
- Api::Data::CountryCodeResult.from_json json_row
7
+ def data_class
8
+ Api::Data::CountryCodeResult
10
9
  end
11
-
12
10
  end
13
11
  end
14
12
  end
15
- end
13
+ end
@@ -1,15 +1,13 @@
1
1
  module BetfairApiNgRails
2
2
  module Api
3
3
  module Parsers
4
- class ListEventTypes < Api::Parsers::Base
4
+ class ListEventTypes < Api::Parsers::ListBase
5
+ private
5
6
 
6
- private
7
-
8
- def process_row(json_row)
9
- Api::Data::EventTypeResult.from_json json_row
7
+ def data_class
8
+ Api::Data::EventTypeResult
10
9
  end
11
-
12
10
  end
13
11
  end
14
12
  end
15
- end
13
+ end
@@ -1,15 +1,13 @@
1
1
  module BetfairApiNgRails
2
2
  module Api
3
3
  module Parsers
4
- class ListEvents < Api::Parsers::Base
4
+ class ListEvents < Api::Parsers::ListBase
5
+ private
5
6
 
6
- private
7
-
8
- def process_row(json_row)
9
- Api::Data::EventResult.from_json json_row
7
+ def data_class
8
+ Api::Data::EventResult
10
9
  end
11
-
12
10
  end
13
11
  end
14
12
  end
15
- end
13
+ end
@@ -1,15 +1,13 @@
1
1
  module BetfairApiNgRails
2
2
  module Api
3
3
  module Parsers
4
- class ListMarketBook < Api::Parsers::Base
4
+ class ListMarketBook < Api::Parsers::ListBase
5
+ private
5
6
 
6
- private
7
-
8
- def process_row(json_row)
9
- BetfairApiNgRails::MarketBook.from_json json_row
7
+ def data_class
8
+ BetfairApiNgRails::MarketBook
10
9
  end
11
-
12
10
  end
13
11
  end
14
12
  end
15
- end
13
+ end
@@ -1,15 +1,13 @@
1
1
  module BetfairApiNgRails
2
2
  module Api
3
3
  module Parsers
4
- class ListMarketCatalogue < Api::Parsers::Base
4
+ class ListMarketCatalogue < Api::Parsers::ListBase
5
+ private
5
6
 
6
- private
7
-
8
- def process_row(json_row)
9
- BetfairApiNgRails::MarketCatalogue.from_json json_row
7
+ def data_class
8
+ BetfairApiNgRails::MarketCatalogue
10
9
  end
11
-
12
10
  end
13
11
  end
14
12
  end
15
- end
13
+ end
@@ -1,15 +1,13 @@
1
1
  module BetfairApiNgRails
2
2
  module Api
3
3
  module Parsers
4
- class ListMarketTypes < Api::Parsers::Base
4
+ class ListMarketTypes < Api::Parsers::ListBase
5
+ private
5
6
 
6
- private
7
-
8
- def process_row(json_row)
9
- Api::Data::MarketTypeResult.from_json json_row
7
+ def data_class
8
+ Api::Data::MarketTypeResult
10
9
  end
11
-
12
10
  end
13
11
  end
14
12
  end
15
- end
13
+ end
@@ -1,15 +1,13 @@
1
1
  module BetfairApiNgRails
2
2
  module Api
3
3
  module Parsers
4
- class ListTimeRanges < Api::Parsers::Base
4
+ class ListTimeRanges < Api::Parsers::ListBase
5
+ private
5
6
 
6
- private
7
-
8
- def process_row(json_row)
9
- Api::Data::TimeRangeResult.from_json json_row
7
+ def data_class
8
+ Api::Data::TimeRangeResult
10
9
  end
11
-
12
10
  end
13
11
  end
14
12
  end
15
- end
13
+ end
@@ -1,15 +1,13 @@
1
1
  module BetfairApiNgRails
2
2
  module Api
3
3
  module Parsers
4
- class ListVenues < Api::Parsers::Base
4
+ class ListVenues < Api::Parsers::ListBase
5
+ private
5
6
 
6
- private
7
-
8
- def process_row(json_row)
9
- Api::Data::VenueResult.from_json json_row
7
+ def data_class
8
+ Api::Data::VenueResult
10
9
  end
11
-
12
10
  end
13
11
  end
14
12
  end
15
- end
13
+ end
@@ -0,0 +1,14 @@
1
+ module BetfairApiNgRails
2
+ module Api
3
+ module Parsers
4
+ class PlaceOrders < Api::Parsers::SingleBase
5
+ private
6
+
7
+ def data_class
8
+ Api::Data::PlaceExecutionReport
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
14
+
@@ -0,0 +1,19 @@
1
+ module BetfairApiNgRails
2
+ module Api
3
+ module Parsers
4
+ class SingleBase < Api::Parsers::Base
5
+ def process
6
+ process_row fetch_result_json
7
+ end
8
+
9
+ private
10
+
11
+ def default_value
12
+ "{}"
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+
19
+
@@ -7,32 +7,29 @@ module BetfairApiNgRails
7
7
  include Api::Concerns::Errorable
8
8
  include Api::Constants
9
9
 
10
- attr_reader :ssoid
10
+ attr_reader :ssoid, :application_key
11
11
 
12
- def initialize(ssoid)
12
+ def initialize(ssoid, application_key)
13
13
  @ssoid = ssoid
14
+ @application_key = application_key
14
15
  end
15
16
 
16
17
  def fetch(method: "", params: {})
17
- raise "Not allowed method #{method.to_s}" unless is_method_allowed?(method)
18
+ raise "Not allowed method #{method.name}" unless method.allowed?
18
19
  run_request for_method: method, params: params
19
20
  end
20
21
 
21
- private
22
+ private
22
23
 
23
24
  def run_request(for_method: "", params: {})
24
- http_requester.set_api_req_body for_method, params
25
- http_requester.do_request
25
+ requester = http_requester(for_method.api_url)
26
+ requester.set_api_req_body for_method, params
27
+ requester.do_request
26
28
  end
27
29
 
28
- def is_method_allowed?(method)
29
- ALLOWED_RESOURCES.include? method.to_s
30
+ def http_requester(api_url)
31
+ Api::Http::Factory.provider_requester api_url, ssoid, application_key
30
32
  end
31
-
32
- def http_requester
33
- @_http_requester ||= Api::Http::Factory.provider_requester ssoid
34
- end
35
-
36
33
  end
37
34
  end
38
- end
35
+ end
@@ -0,0 +1,43 @@
1
+ module BetfairApiNgRails
2
+ module Api
3
+ class RequestMethod
4
+ include Api::Constants
5
+
6
+ attr_reader :name, :endpoint
7
+
8
+ def initialize(name, endpoint)
9
+ @name = name
10
+ @endpoint = endpoint
11
+ BetfairApiNgRails.log.write("==> Creating request method for #{name}")
12
+ end
13
+
14
+ def allowed?
15
+ allow_data.any?
16
+ end
17
+
18
+ def type
19
+ fetch_type
20
+ end
21
+
22
+ def api_url
23
+ endpoint.api_url(type)
24
+ end
25
+
26
+ def json_method
27
+ JSON_METHOD[type]
28
+ end
29
+
30
+ private
31
+
32
+ def fetch_type
33
+ allow_data.keys.first.to_s.to_sym
34
+ end
35
+
36
+ def allow_data
37
+ @_allow_data ||= ALLOWED_RESOURCES.select do |k, v|
38
+ v.include? name
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,51 @@
1
+ module BetfairApiNgRails
2
+ module Api
3
+ module RequestMethods
4
+ module Account
5
+ #
6
+ # Returns the details relating your account, including your discount rate and Betfair point balance.
7
+ #
8
+ def get_account_details(account: '')
9
+ run_request __method__, {}, account
10
+ end
11
+
12
+ #
13
+ # Get available to bet amount. The getAccounts service will return the UK wallet balance by default
14
+ # from either the UK or AUS Accounts API endpoint if the wallet parameter is not specified.
15
+ #
16
+ def get_account_funds(account: '')
17
+ run_request __method__, {}, account
18
+ end
19
+
20
+ #
21
+ # Get account statement
22
+ #
23
+ # Parameters:
24
+ # locale - The language to be used where applicable. If not specified, the customer account default is returned.
25
+ # from_record - Specifies the first record that will be returned. Records start at index zero.
26
+ # If not specified then it will default to 0.
27
+ # record_count - Specifies the maximum number of records to be returned.
28
+ # Note that there is a page size limit of 100.
29
+ # item_date_range - Return items with an itemDate within this date range. Both from and to date times are inclusive.
30
+ # If from is not specified then the oldest available items will be in range. If to is not specified
31
+ # then the latest items will be in range. nb. This itemDataRange is currently only applied when
32
+ # includeItem is set to ALL or not specified, else items are NOT bound by itemDate.
33
+ # include_item - Which items to include, if not specified then defaults to ALL.
34
+ # wallet - Which wallet to return statementItems for. If unspecified then the UK wallet will be selected
35
+ # account - account username
36
+ #
37
+ # Returns:
38
+ # List of statement items chronologically ordered plus moreAvailable boolean to facilitate paging
39
+ #
40
+ def get_account_statement(args)
41
+ raise 'Must be a hash passed!' unless args.is_a? Hash
42
+ args[:locale] = args[:locale] || BetfairApiNgRails.config.locale
43
+ account = args[:account]
44
+ run_request __method__, args.except(:account), account
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
50
+
51
+