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,20 @@
1
+ module BetfairApiNgRails
2
+ module Api
3
+ module Enums
4
+ # Which wallet to return statementItems for
5
+ #
6
+ # Includes:
7
+ # UK - The UK Exchange wallet
8
+ # AUSTRALIAN - The Australian Exchange wallet
9
+ #
10
+ class Wallet
11
+ extend Api::Enums::Concerns::Enumable
12
+
13
+ enumify "UK",
14
+ "AUSTRALIAN"
15
+ end
16
+ end
17
+ end
18
+ end
19
+
20
+
@@ -4,18 +4,16 @@ module BetfairApiNgRails
4
4
  module Api
5
5
  class FormatterFactory
6
6
  class << self
7
-
8
7
  def initialize_formatter(name)
9
8
  name.is_a?(Symbol) ? initialize_formatter_by(name: name) : name.try(:new)
10
9
  end
11
10
 
12
- private
11
+ private
13
12
 
14
13
  def initialize_formatter_by(name: "")
15
14
  "BetfairApiNgRails::Api::Formatters::#{name.to_s.camelize}Formatter".constantize.new
16
15
  end
17
-
18
16
  end
19
17
  end
20
18
  end
21
- end
19
+ end
@@ -5,14 +5,13 @@ module BetfairApiNgRails
5
5
  module Api
6
6
  module Formatters
7
7
  class JsTreeFormatter
8
-
9
8
  ALLOW_CHILDREN = [:event_types, :competitions]
10
9
 
11
10
  def process(result, as: '')
12
11
  result.map { |r| format_record(r, resource_from_method(as)) }
13
12
  end
14
13
 
15
- private
14
+ private
16
15
 
17
16
  def resource_from_method(method)
18
17
  method.underscore.gsub(/^list_/, '').to_sym
@@ -31,8 +30,7 @@ module BetfairApiNgRails
31
30
  }
32
31
  }
33
32
  end
34
-
35
33
  end
36
34
  end
37
35
  end
38
- end
36
+ end
@@ -3,10 +3,11 @@ module BetfairApiNgRails
3
3
  class Hashalator
4
4
  include Api::Data::Constants
5
5
 
6
- attr_reader :hashable
6
+ attr_reader :hashable, :for_param
7
7
 
8
- def initialize(object)
8
+ def initialize(object, for_param = false)
9
9
  @hashable = object
10
+ @for_param = for_param
10
11
  end
11
12
 
12
13
  def to_hash
@@ -17,7 +18,7 @@ module BetfairApiNgRails
17
18
  end
18
19
  end
19
20
 
20
- private
21
+ private
21
22
 
22
23
  def hash_value(val)
23
24
  need_to_hash?(val) ? hashing_val(val) : val
@@ -32,9 +33,8 @@ module BetfairApiNgRails
32
33
  end
33
34
 
34
35
  def hash_key(key)
35
- key.to_s.camelize(:lower)
36
+ for_param ? key : key.to_s.camelize(:lower)
36
37
  end
37
-
38
38
  end
39
39
  end
40
- end
40
+ end
@@ -1,7 +1,6 @@
1
1
  module BetfairApiNgRails
2
2
  module Api
3
3
  module Helper
4
-
5
4
  def read_certificate_file(path)
6
5
  OpenSSL::X509::Certificate.new read_file(path)
7
6
  end
@@ -19,11 +18,10 @@ module BetfairApiNgRails
19
18
  def prepare_api_req_json(method, params)
20
19
  {
21
20
  "jsonrpc" => "2.0",
22
- "method" => "SportsAPING/v1.0/#{method}",
21
+ "method" => "#{method.json_method}/v1.0/#{method.name}",
23
22
  "params" => params
24
23
  }.to_json
25
24
  end
26
-
27
25
  end
28
26
  end
29
- end
27
+ end
@@ -5,37 +5,42 @@ module BetfairApiNgRails
5
5
  class << self
6
6
  include Api::Constants
7
7
 
8
- def provider_requester(ssoid = nil)
9
- create_http_requester(Api::Config.api_url).tap do |req|
8
+ def provider_requester(api_url, ssoid = nil, app_key)
9
+ create_http_requester(api_url).tap do |req|
10
10
  req.set_request_headers API_REQUEST_HEADERS
11
- req.set_auth_headers Api::Config.application_key, ssoid
11
+ req.set_auth_headers app_key, ssoid
12
12
  end
13
13
  end
14
14
 
15
- def session_requester
16
- create_http_requester(Api::Config.login_url).tap do |req|
17
- req.set_ssl_files Api::Config.ssl_crt_filepath, Api::Config.ssl_key_filepath
15
+ def session_requester(login_url, account)
16
+ create_http_requester(login_url, false).tap do |req|
17
+ req.set_ssl_files account.crt_filepath, account.key_filepath
18
18
  req.set_request_headers SESSION_REQUEST_HEADERS
19
- req.set_auth_headers Api::Config.application_key
20
- req.set_form_data "username" => Api::Config.username, "password" => Api::Config.password
19
+ req.set_auth_headers account.app_key
20
+ req.set_form_data "username" => account.username, "password" => account.password
21
21
  end
22
22
  end
23
23
 
24
+ # TODO: Looks like this method does not used anywhere.
25
+ # So this means that keep alive feature does not implemented.
24
26
  def keep_alive_requester(ssoid)
25
- create_http_requester(Api::Config.keep_alive_url).tap do |req|
27
+ create_http_requester(KEEP_ALIVE_URL, false).tap do |req|
26
28
  req.set_accept_header 'application/json'
27
29
  req.set_auth_headers Api::Config.application_key, ssoid
28
30
  end
29
31
  end
30
32
 
31
- private
33
+ private
32
34
 
33
- def create_http_requester(url = "")
34
- Api::Http::Requester.new url
35
+ def create_http_requester(url = '', provider = true)
36
+ if !Api::Config.proxy_enable
37
+ Api::Http::Requester.new url
38
+ else
39
+ Api::Http::ProxyRequester.new url, provider
40
+ end
35
41
  end
36
-
37
42
  end
38
43
  end
39
44
  end
40
45
  end
41
- end
46
+ end
@@ -3,7 +3,6 @@ module BetfairApiNgRails
3
3
  module Http
4
4
  module Helpers
5
5
  module InformationResponse
6
-
7
6
  def self.included(base)
8
7
  base.send :class_eval, <<-CODE
9
8
  def has_error_with_info_response?
@@ -18,7 +17,7 @@ module BetfairApiNgRails
18
17
  result['result']
19
18
  end
20
19
 
21
- protected
20
+ protected
22
21
 
23
22
  def info_response_error?
24
23
  set_error_info(:API, result['error']) if check_info_response_status
@@ -27,9 +26,8 @@ module BetfairApiNgRails
27
26
  def check_info_response_status
28
27
  result.has_key?('error')
29
28
  end
30
-
31
29
  end
32
30
  end
33
31
  end
34
32
  end
35
- end
33
+ end
@@ -4,7 +4,7 @@ module BetfairApiNgRails
4
4
  module Helpers
5
5
  module KeepAliveResponse
6
6
  include BetfairApiNgRails::Api::Constants
7
-
7
+
8
8
  def self.included(base)
9
9
  base.send :class_eval, <<-CODE
10
10
  def has_error_with_keep_alive_response?
@@ -15,7 +15,7 @@ module BetfairApiNgRails
15
15
  CODE
16
16
  end
17
17
 
18
- protected
18
+ protected
19
19
 
20
20
  def keep_alive_res_error?
21
21
  set_error_info(:KEEP_ALIVE, result['status']) if check_keep_alive_status
@@ -24,9 +24,8 @@ module BetfairApiNgRails
24
24
  def check_keep_alive_status
25
25
  result.fetch('status', SUCCESS_LOGIN) != SUCCESS_LOGIN
26
26
  end
27
-
28
27
  end
29
28
  end
30
29
  end
31
30
  end
32
- end
31
+ end
@@ -4,7 +4,7 @@ module BetfairApiNgRails
4
4
  module Helpers
5
5
  module SessionResponse
6
6
  include BetfairApiNgRails::Api::Constants
7
-
7
+
8
8
  def self.included(base)
9
9
  base.send :class_eval, <<-CODE
10
10
  def has_error_with_session_response?
@@ -19,7 +19,7 @@ module BetfairApiNgRails
19
19
  result['sessionToken']
20
20
  end
21
21
 
22
- protected
22
+ protected
23
23
 
24
24
  def session_res_error?
25
25
  set_error_info(:SESSION, result['loginStatus']) if check_login_status
@@ -28,9 +28,8 @@ module BetfairApiNgRails
28
28
  def check_login_status
29
29
  result.fetch('loginStatus', SUCCESS_LOGIN) != SUCCESS_LOGIN
30
30
  end
31
-
32
31
  end
33
32
  end
34
33
  end
35
34
  end
36
- end
35
+ end
@@ -0,0 +1,87 @@
1
+ require "net/https"
2
+ require "uri"
3
+ require 'json'
4
+ require 'betfair_api_ng_rails/api/helper'
5
+
6
+ module BetfairApiNgRails
7
+ module Api
8
+ module Http
9
+ class ProxyRequester
10
+ include BetfairApiNgRails::Api::Helper
11
+
12
+ attr_reader :http, :request, :uri,
13
+ :app_key, :session_key, :username,
14
+ :password, :body, :is_provider, :api_url
15
+
16
+ def initialize(url, provider = true, use_ssl = true)
17
+ @is_provider = provider
18
+ @api_url = url
19
+ end
20
+
21
+ def do_request
22
+ create_http
23
+ prepare_form_data
24
+ Api::Http::Responser.new http.request(request)
25
+ end
26
+
27
+ def set_auth_headers(app_key, session_key = nil)
28
+ @app_key = app_key
29
+ @session_key = session_key
30
+ end
31
+
32
+ def set_form_data(values)
33
+ @username = values['username']
34
+ @password = values['password']
35
+ end
36
+
37
+ def set_request_body(body)
38
+ @body = body
39
+ end
40
+
41
+ def set_api_req_body(method, params = {})
42
+ set_request_body prepare_api_req_json(method, params)
43
+ end
44
+
45
+ def set_crt_file(_path); end
46
+ def set_key_file(_path); end
47
+ def set_verify_mode(_value); end
48
+ def set_ssl_files(_crt_path, _key_path, _verify = OpenSSL::SSL::VERIFY_PEER); end
49
+ def set_accept_header(_value); end
50
+ def set_request_headers(_headers); end
51
+ def set_header(_name, _value); end
52
+
53
+ private
54
+
55
+ def create_http
56
+ @uri = URI.parse prepare_url
57
+ BetfairApiNgRails.log.write("==> Using url #{prepare_url}")
58
+ @http = Net::HTTP.new uri.host, uri.port
59
+ @request = Net::HTTP::Post.new uri.request_uri
60
+ end
61
+
62
+ def prepare_url
63
+ is_provider ? prepare_api_url : prepare_auth_url
64
+ end
65
+
66
+ def prepare_auth_url
67
+ "#{Api::Config.proxy_url}/auth/en/#{username}/#{password}/#{app_key}/#{Api::Config.go_localuser}/#{Api::Config.go_filename}"
68
+ end
69
+
70
+ def prepare_api_url
71
+ "#{Api::Config.proxy_url}/api"
72
+ end
73
+
74
+ def prepare_form_data
75
+ return unless is_provider
76
+ BetfairApiNgRails.log.write("==> Setting request body #{body}")
77
+ request.set_form_data({
78
+ app_key: app_key,
79
+ api_url: api_url,
80
+ session_token: session_key,
81
+ body: body
82
+ })
83
+ end
84
+ end
85
+ end
86
+ end
87
+ end
@@ -1,5 +1,5 @@
1
1
  require "net/https"
2
- require "uri"
2
+ require 'uri'
3
3
  require 'json'
4
4
  require 'betfair_api_ng_rails/api/helper'
5
5
 
@@ -58,6 +58,7 @@ module BetfairApiNgRails
58
58
  end
59
59
 
60
60
  def set_request_body(body)
61
+ BetfairApiNgRails.log.write("==> Setting request body #{body}")
61
62
  request.body = body
62
63
  end
63
64
 
@@ -68,8 +69,7 @@ module BetfairApiNgRails
68
69
  def set_header(name, value)
69
70
  request[name] = value
70
71
  end
71
-
72
72
  end
73
73
  end
74
74
  end
75
- end
75
+ end
@@ -17,6 +17,8 @@ module BetfairApiNgRails
17
17
 
18
18
  def result
19
19
  JSON.parse response.body
20
+ rescue
21
+ raise BetfairApiNgRails::BadResponseError
20
22
  end
21
23
 
22
24
  def has_error?
@@ -27,7 +29,7 @@ module BetfairApiNgRails
27
29
  include Api::Http::Helpers::KeepAliveResponse
28
30
  include Api::Http::Helpers::SessionResponse
29
31
 
30
- protected
32
+ protected
31
33
 
32
34
  def http_error?
33
35
  set_error_info(:HTTP, response.code) if check_response_code
@@ -40,8 +42,7 @@ module BetfairApiNgRails
40
42
  def set_error_info(type, info)
41
43
  @error_info = { type: type, info: info }
42
44
  end
43
-
44
45
  end
45
46
  end
46
47
  end
47
- end
48
+ end
@@ -0,0 +1,6 @@
1
+ module BetfairApiNgRails
2
+ module Api
3
+ class InvalidEndpointError < StandardError
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,13 @@
1
+ require 'colorize'
2
+
3
+ module BetfairApiNgRails
4
+ module Api
5
+ module Logs
6
+ class ConsoleLogger
7
+ def write(content)
8
+ puts content.green
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,23 @@
1
+ module BetfairApiNgRails
2
+ module Api
3
+ module Logs
4
+ class FileLogger < Struct.new(:root, :env)
5
+ def write(content)
6
+ File.open(file_path, 'a') do |file|
7
+ file.puts "[#{now_date}] - #{content}"
8
+ end
9
+ end
10
+
11
+ private
12
+
13
+ def now_date
14
+ DateTime.now.strftime '%Y-%m-%d %H:%M:%S.%L'
15
+ end
16
+
17
+ def file_path
18
+ @_log_file_path ||= "#{root}/log/betfair_api_ng_rails.#{env}.log"
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end