betfair_api_ng_rails 0.0.6 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +28 -10
  3. data/lib/betfair_api_ng_rails/api/base_provider.rb +1 -11
  4. data/lib/betfair_api_ng_rails/api/bf/config.rb +1 -2
  5. data/lib/betfair_api_ng_rails/api/bf/constants.rb +14 -4
  6. data/lib/betfair_api_ng_rails/api/bf/data/attributes.rb +52 -0
  7. data/lib/betfair_api_ng_rails/api/bf/data/base.rb +17 -0
  8. data/lib/betfair_api_ng_rails/api/bf/data/competition.rb +26 -0
  9. data/lib/betfair_api_ng_rails/api/bf/data/competition_result.rb +23 -0
  10. data/lib/betfair_api_ng_rails/api/bf/data/concerns/hashable.rb +40 -0
  11. data/lib/betfair_api_ng_rails/api/bf/data/concerns/querable.rb +46 -0
  12. data/lib/betfair_api_ng_rails/api/bf/data/constants.rb +13 -0
  13. data/lib/betfair_api_ng_rails/api/bf/data/event.rb +26 -0
  14. data/lib/betfair_api_ng_rails/api/bf/data/event_result.rb +21 -0
  15. data/lib/betfair_api_ng_rails/api/bf/data/event_type.rb +26 -0
  16. data/lib/betfair_api_ng_rails/api/bf/data/event_type_result.rb +21 -0
  17. data/lib/betfair_api_ng_rails/api/bf/data/market_filter.rb +19 -0
  18. data/lib/betfair_api_ng_rails/api/bf/data/time_range.rb +18 -0
  19. data/lib/betfair_api_ng_rails/api/bf/data/time_range_result.rb +21 -0
  20. data/lib/betfair_api_ng_rails/api/bf/enums/bet_status.rb +17 -0
  21. data/lib/betfair_api_ng_rails/api/bf/enums/concerns/enumable.rb +17 -0
  22. data/lib/betfair_api_ng_rails/api/bf/enums/execution_report_error_code.rb +30 -0
  23. data/lib/betfair_api_ng_rails/api/bf/enums/execution_report_status.rb +17 -0
  24. data/lib/betfair_api_ng_rails/api/bf/enums/group_by.rb +19 -0
  25. data/lib/betfair_api_ng_rails/api/bf/enums/instruction_report_error_code.rb +33 -0
  26. data/lib/betfair_api_ng_rails/api/bf/enums/instruction_report_status.rb +16 -0
  27. data/lib/betfair_api_ng_rails/api/bf/enums/market_betting_type.rb +19 -0
  28. data/lib/betfair_api_ng_rails/api/bf/enums/market_projection.rb +20 -0
  29. data/lib/betfair_api_ng_rails/api/bf/enums/market_sort.rb +19 -0
  30. data/lib/betfair_api_ng_rails/api/bf/enums/market_status.rb +17 -0
  31. data/lib/betfair_api_ng_rails/api/bf/enums/match_projection.rb +16 -0
  32. data/lib/betfair_api_ng_rails/api/bf/enums/order_by.rb +16 -0
  33. data/lib/betfair_api_ng_rails/api/bf/enums/order_projection.rb +16 -0
  34. data/lib/betfair_api_ng_rails/api/bf/enums/order_status.rb +15 -0
  35. data/lib/betfair_api_ng_rails/api/bf/enums/order_type.rb +16 -0
  36. data/lib/betfair_api_ng_rails/api/bf/enums/persistence_type.rb +16 -0
  37. data/lib/betfair_api_ng_rails/api/bf/enums/price_data.rb +18 -0
  38. data/lib/betfair_api_ng_rails/api/bf/enums/rollup_model.rb +17 -0
  39. data/lib/betfair_api_ng_rails/api/bf/enums/runner_status.rb +19 -0
  40. data/lib/betfair_api_ng_rails/api/bf/enums/side.rb +15 -0
  41. data/lib/betfair_api_ng_rails/api/bf/enums/sort_dir.rb +15 -0
  42. data/lib/betfair_api_ng_rails/api/bf/enums/time_granularity.rb +16 -0
  43. data/lib/betfair_api_ng_rails/api/bf/formatters/js_tree_formatter.rb +7 -11
  44. data/lib/betfair_api_ng_rails/api/bf/helper.rb +33 -0
  45. data/lib/betfair_api_ng_rails/api/bf/http/factory.rb +37 -0
  46. data/lib/betfair_api_ng_rails/api/bf/http/requester.rb +69 -0
  47. data/lib/betfair_api_ng_rails/api/bf/http/responser.rb +58 -0
  48. data/lib/betfair_api_ng_rails/api/bf/orm/parsers/base.rb +33 -0
  49. data/lib/betfair_api_ng_rails/api/bf/orm/parsers/list_competitions.rb +19 -0
  50. data/lib/betfair_api_ng_rails/api/bf/orm/parsers/list_event_types.rb +19 -0
  51. data/lib/betfair_api_ng_rails/api/bf/orm/parsers/list_events.rb +19 -0
  52. data/lib/betfair_api_ng_rails/api/bf/orm/requester.rb +52 -0
  53. data/lib/betfair_api_ng_rails/api/bf/provider.rb +11 -28
  54. data/lib/betfair_api_ng_rails/api/bf/session_manager.rb +26 -37
  55. data/lib/betfair_api_ng_rails/version.rb +1 -1
  56. data/lib/betfair_api_ng_rails.rb +80 -9
  57. data/lib/generators/betfair_api_ng_rails/install/templates/betfair_api_ng_rails.rb +2 -3
  58. metadata +48 -9
  59. data/lib/betfair_api_ng_rails/api/base_formatter.rb +0 -11
  60. data/lib/betfair_api_ng_rails/api/base_parser.rb +0 -25
  61. data/lib/betfair_api_ng_rails/api/base_requester.rb +0 -25
  62. data/lib/betfair_api_ng_rails/api/bf/http_requester.rb +0 -73
  63. data/lib/betfair_api_ng_rails/api/bf/http_responser.rb +0 -44
  64. data/lib/betfair_api_ng_rails/api/bf/parser.rb +0 -31
  65. data/lib/betfair_api_ng_rails/api/soccer/requester.rb +0 -25
@@ -7,46 +7,29 @@ module BetfairApiNgRails
7
7
  include Api::BF::Concerns::Errorable
8
8
  include Api::BF::Constants
9
9
 
10
- attr_reader :session_manager
10
+ attr_reader :session_manager, :http_requester
11
11
 
12
12
  def initialize
13
13
  @session_manager = Api::BF::SessionManager.new
14
14
  @provider_name = "BF"
15
+ @http_requester = Api::BF::Http::Factory.provider_requester
15
16
  end
16
17
 
17
- def fetch(data: "", parameters: {}, sport: "")
18
- return [] unless session_manager.request_ssoid
19
- raise "Not allowed method #{data.to_s} for sport #{sport.to_s}" unless is_method_allowed?(data, sport)
20
- setup_http_requester with_method: data, params: parameters
21
- do_request data, parameters, sport
18
+ def fetch(method: "", filter: {}, params: {})
19
+ return [] unless BetfairApiNgRails::Api::BF::SessionManager.request_ssoid
20
+ raise "Not allowed method #{method.to_s}" unless is_method_allowed?(method)
21
+ do_request with_method: method, filter: filter, params: params
22
22
  end
23
23
 
24
24
  private
25
25
 
26
- def do_request(data, parameters, sport)
27
- @http_responser = @http_requester.do_request
28
- process_response data, @http_responser.result, build_parser(data)
26
+ def do_request(with_method: "", filter: {}, params: {})
27
+ http_requester.set_api_req_body with_method, filter, params
28
+ http_requester.do_request
29
29
  end
30
30
 
31
- def process_response(data, response, parser)
32
- format_response data, parser.parse(response: response)
33
- end
34
-
35
- def format_response(data, response)
36
- return response unless Api::BF::Config.formatter
37
- response.map { |r| Api::BF::Config.formatter.format(record: r, resource: data) }
38
- end
39
-
40
- def setup_http_requester(with_method: "", params: {})
41
- @http_requester = Api::BF::HttpRequester.new(Api::BF::Config.api_url).tap do |req|
42
- req.set_request_headers API_REQUEST_HEADERS
43
- req.set_auth_headers Api::BF::Config.application_key, session_manager.ssoid
44
- req.set_api_req_body build_function(with_method), params
45
- end
46
- end
47
-
48
- def is_method_allowed?(data, sport)
49
- ALLOWED_RESOURCES[sport.to_sym].include? data.to_sym
31
+ def is_method_allowed?(method)
32
+ ALLOWED_RESOURCES.include? method.to_s
50
33
  end
51
34
 
52
35
  end
@@ -1,56 +1,45 @@
1
- require "net/https"
2
- require "uri"
3
- require 'json'
4
1
  require 'betfair_api_ng_rails/api/bf/concerns/errorable'
5
2
 
6
3
  module BetfairApiNgRails
7
4
  module Api
8
5
  module BF
9
6
  class SessionManager
10
- include Api::BF::Concerns::Errorable
11
- include Api::BF::Constants
7
+ class << self
8
+ include Api::BF::Concerns::Errorable
9
+ include Api::BF::Constants
12
10
 
13
- def initialize
14
- setup_http_requester
15
- end
16
-
17
- def ssoid
18
- @ssoid ||= fetch_ssoid
19
- end
11
+ def ssoid
12
+ @ssoid ||= fetch_ssoid
13
+ end
20
14
 
21
- def request_ssoid
22
- ssoid
23
- !has_errors?
24
- end
15
+ def request_ssoid
16
+ ssoid
17
+ !has_errors?
18
+ end
25
19
 
26
- def expire_ssoid
27
- @ssoid = nil
28
- end
20
+ def expire_ssoid
21
+ @ssoid = nil
22
+ end
29
23
 
30
- private
24
+ private
31
25
 
32
- def fetch_ssoid
33
- process_response get_login_response
34
- end
26
+ def fetch_ssoid
27
+ process_response get_login_response
28
+ end
35
29
 
36
- def process_response(response)
37
- response['sessionToken']
38
- end
30
+ def process_response(response)
31
+ response['sessionToken']
32
+ end
39
33
 
40
- def get_login_response
41
- @http_responser = @http_requester.do_request
42
- @http_responser.result
43
- end
34
+ def get_login_response
35
+ http_requester.do_request.result
36
+ end
44
37
 
45
- def setup_http_requester
46
- @http_requester = Api::BF::HttpRequester.new(Api::BF::Config.login_url).tap do |req|
47
- req.set_ssl_files Api::BF::Config.ssl_crt_filepath, Api::BF::Config.ssl_key_filepath
48
- req.set_request_headers SESSION_REQUEST_HEADERS
49
- req.set_auth_headers Api::BF::Config.application_key
50
- req.set_form_data "username" => Api::BF::Config.username, "password" => Api::BF::Config.password
38
+ def http_requester
39
+ @_http_requester ||= Api::BF::Http::Factory.session_requester
51
40
  end
52
- end
53
41
 
42
+ end
54
43
  end
55
44
  end
56
45
  end
@@ -1,3 +1,3 @@
1
1
  module BetfairApiNgRails
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.8"
3
3
  end
@@ -4,38 +4,109 @@ module BetfairApiNgRails
4
4
 
5
5
  module Api
6
6
 
7
- autoload :BaseParser, 'betfair_api_ng_rails/api/base_parser'
8
7
  autoload :BaseProvider, 'betfair_api_ng_rails/api/base_provider'
9
8
  autoload :BaseRequester, 'betfair_api_ng_rails/api/base_requester'
10
- autoload :BaseFormatter, 'betfair_api_ng_rails/api/base_formatter'
11
9
  autoload :FormatterFactory, 'betfair_api_ng_rails/api/formatter_factory'
12
10
 
13
11
  module BF
14
12
 
15
13
  autoload :Config, 'betfair_api_ng_rails/api/bf/config'
16
14
  autoload :Constants, 'betfair_api_ng_rails/api/bf/constants'
17
- autoload :HttpRequester, 'betfair_api_ng_rails/api/bf/http_requester'
18
- autoload :HttpResponser, 'betfair_api_ng_rails/api/bf/http_responser'
19
15
  autoload :Provider, 'betfair_api_ng_rails/api/bf/provider'
20
- autoload :Parser, 'betfair_api_ng_rails/api/bf/parser'
21
16
  autoload :SessionManager, 'betfair_api_ng_rails/api/bf/session_manager'
22
17
 
23
18
  module Formatters
24
19
 
25
- autoload :JsTreeFromatter, 'betfair_api_ng_rails/api/bf/formatters/js_tree_formatter'
20
+ autoload :JsTreeFormatter, 'betfair_api_ng_rails/api/bf/formatters/js_tree_formatter'
26
21
 
27
22
  end
28
23
 
29
- end
24
+ module Data
25
+
26
+ autoload :Base, 'betfair_api_ng_rails/api/bf/data/base'
27
+ autoload :Attributes, 'betfair_api_ng_rails/api/bf/data/attributes'
28
+ autoload :Constants, 'betfair_api_ng_rails/api/bf/data/constants'
29
+ autoload :Competition, 'betfair_api_ng_rails/api/bf/data/competition'
30
+ autoload :CompetitionResult, 'betfair_api_ng_rails/api/bf/data/competition_result'
31
+ autoload :MarketFilter, 'betfair_api_ng_rails/api/bf/data/market_filter'
32
+ autoload :TimeRange, 'betfair_api_ng_rails/api/bf/data/time_range'
33
+ autoload :TimeRangeResult, 'betfair_api_ng_rails/api/bf/data/time_range_result'
34
+ autoload :EventType, 'betfair_api_ng_rails/api/bf/data/event_type'
35
+ autoload :EventTypeResult, 'betfair_api_ng_rails/api/bf/data/event_type_result'
36
+ autoload :Event, 'betfair_api_ng_rails/api/bf/data/event'
37
+ autoload :EventResult, 'betfair_api_ng_rails/api/bf/data/event_result'
38
+
39
+ module Concerns
40
+
41
+ autoload :Hashable, 'betfair_api_ng_rails/api/bf/data/concerns/hashable'
42
+ autoload :Querable, 'betfair_api_ng_rails/api/bf/data/concerns/querable'
43
+
44
+ end
45
+
46
+ end
47
+
48
+ module Enums
49
+
50
+ autoload :MarketProjection, 'betfair_api_ng_rails/api/bf/enums/market_projection'
51
+ autoload :PriceData, 'betfair_api_ng_rails/api/bf/enums/price_data'
52
+ autoload :MatchProjection, 'betfair_api_ng_rails/api/bf/enums/match_projection'
53
+ autoload :OrderProjection, 'betfair_api_ng_rails/api/bf/enums/order_projection'
54
+ autoload :MarketStatus, 'betfair_api_ng_rails/api/bf/enums/market_status'
55
+ autoload :RunnerStatus, 'betfair_api_ng_rails/api/bf/enums/runner_status'
56
+ autoload :TimeGranularity, 'betfair_api_ng_rails/api/bf/enums/time_granularity'
57
+ autoload :Side, 'betfair_api_ng_rails/api/bf/enums/side'
58
+ autoload :OrderStatus, 'betfair_api_ng_rails/api/bf/enums/order_status'
59
+ autoload :OrderBy, 'betfair_api_ng_rails/api/bf/enums/order_by'
60
+ autoload :SortDir, 'betfair_api_ng_rails/api/bf/enums/sort_dir'
61
+ autoload :OrderType, 'betfair_api_ng_rails/api/bf/enums/order_type'
62
+ autoload :MarketSort, 'betfair_api_ng_rails/api/bf/enums/market_sort'
63
+ autoload :MarketBettingType, 'betfair_api_ng_rails/api/bf/enums/market_betting_type'
64
+ autoload :ExecutionReportStatus, 'betfair_api_ng_rails/api/bf/enums/execution_report_status'
65
+ autoload :ExecutionReportErrorCode, 'betfair_api_ng_rails/api/bf/enums/execution_report_error_code'
66
+ autoload :PersistenceType, 'betfair_api_ng_rails/api/bf/enums/perisstence_type'
67
+ autoload :InstrictionReportStatus, 'betfair_api_ng_rails/api/bf/enums/instruction_report_status'
68
+ autoload :InstructionReportErrorCode, 'betfair_api_ng_rails/api/bf/enums/instruction_report_error_code'
69
+ autoload :RollupModel, 'betfair_api_ng_rails/api/bf/enums/rollup_model'
70
+ autoload :GroupBy, 'betfair_api_ng_rails/api/bf/enums/group_by'
71
+ autoload :BetStatus, 'betfair_api_ng_rails/api/bf/enums/bet_status'
72
+
73
+ module Concerns
74
+
75
+ autoload :Enumable, 'betfair_api_ng_rails/api/bf/enums/concerns/enumable'
76
+
77
+ end
30
78
 
31
- module Soccer
79
+ end
80
+
81
+ module Http
82
+
83
+ autoload :Requester, 'betfair_api_ng_rails/api/bf/http/requester'
84
+ autoload :Responser, 'betfair_api_ng_rails/api/bf/http/responser'
85
+ autoload :Factory, 'betfair_api_ng_rails/api/bf/http/factory'
86
+
87
+ end
88
+
89
+ module ORM
32
90
 
33
- autoload :Requester, 'betfair_api_ng_rails/api/soccer/requester'
91
+ autoload :Requester, 'betfair_api_ng_rails/api/bf/orm/requester'
92
+
93
+ module Parsers
94
+
95
+ autoload :Base, 'betfair_api_ng_rails/api/bf/orm/parsers/base'
96
+ autoload :ListCompetitions, 'betfair_api_ng_rails/api/bf/orm/parsers/list_competitions'
97
+ autoload :ListEventTypes, 'betfair_api_ng_rails/api/bf/orm/parsers/list_event_types'
98
+ autoload :ListEvents, 'betfair_api_ng_rails/api/bf/orm/parsers/list_events'
99
+
100
+ end
101
+
102
+ end
34
103
 
35
104
  end
36
105
 
37
106
  end
38
107
 
108
+ include Api::BF::Data
109
+
39
110
  def self.config(&block)
40
111
  @_config ||= BetfairApiNgRails::Api::BF::Config
41
112
  block_given? ? yield(@_config) : @_config
@@ -10,8 +10,7 @@ BetfairApiNgRails.config do |config|
10
10
  config.api_url = load_config['api_url']
11
11
  config.username = load_config['username']
12
12
  config.password = load_config['password']
13
-
14
- # Uncomment and set needed formatter or nil if you want plain response
15
- # config.formatter = :js_tree
13
+ config.locale = :ru
14
+ config.formatter = nil #out of box available formatter for JsTree
16
15
 
17
16
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: betfair_api_ng_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - sergio1990
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-17 00:00:00.000000000 Z
11
+ date: 2014-03-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -66,21 +66,60 @@ files:
66
66
  - Rakefile
67
67
  - betfair_api_ng_rails.gemspec
68
68
  - lib/betfair_api_ng_rails.rb
69
- - lib/betfair_api_ng_rails/api/base_formatter.rb
70
- - lib/betfair_api_ng_rails/api/base_parser.rb
71
69
  - lib/betfair_api_ng_rails/api/base_provider.rb
72
- - lib/betfair_api_ng_rails/api/base_requester.rb
73
70
  - lib/betfair_api_ng_rails/api/bf/concerns/errorable.rb
74
71
  - lib/betfair_api_ng_rails/api/bf/config.rb
75
72
  - lib/betfair_api_ng_rails/api/bf/constants.rb
73
+ - lib/betfair_api_ng_rails/api/bf/data/attributes.rb
74
+ - lib/betfair_api_ng_rails/api/bf/data/base.rb
75
+ - lib/betfair_api_ng_rails/api/bf/data/competition.rb
76
+ - lib/betfair_api_ng_rails/api/bf/data/competition_result.rb
77
+ - lib/betfair_api_ng_rails/api/bf/data/concerns/hashable.rb
78
+ - lib/betfair_api_ng_rails/api/bf/data/concerns/querable.rb
79
+ - lib/betfair_api_ng_rails/api/bf/data/constants.rb
80
+ - lib/betfair_api_ng_rails/api/bf/data/event.rb
81
+ - lib/betfair_api_ng_rails/api/bf/data/event_result.rb
82
+ - lib/betfair_api_ng_rails/api/bf/data/event_type.rb
83
+ - lib/betfair_api_ng_rails/api/bf/data/event_type_result.rb
84
+ - lib/betfair_api_ng_rails/api/bf/data/market_filter.rb
85
+ - lib/betfair_api_ng_rails/api/bf/data/time_range.rb
86
+ - lib/betfair_api_ng_rails/api/bf/data/time_range_result.rb
87
+ - lib/betfair_api_ng_rails/api/bf/enums/bet_status.rb
88
+ - lib/betfair_api_ng_rails/api/bf/enums/concerns/enumable.rb
89
+ - lib/betfair_api_ng_rails/api/bf/enums/execution_report_error_code.rb
90
+ - lib/betfair_api_ng_rails/api/bf/enums/execution_report_status.rb
91
+ - lib/betfair_api_ng_rails/api/bf/enums/group_by.rb
92
+ - lib/betfair_api_ng_rails/api/bf/enums/instruction_report_error_code.rb
93
+ - lib/betfair_api_ng_rails/api/bf/enums/instruction_report_status.rb
94
+ - lib/betfair_api_ng_rails/api/bf/enums/market_betting_type.rb
95
+ - lib/betfair_api_ng_rails/api/bf/enums/market_projection.rb
96
+ - lib/betfair_api_ng_rails/api/bf/enums/market_sort.rb
97
+ - lib/betfair_api_ng_rails/api/bf/enums/market_status.rb
98
+ - lib/betfair_api_ng_rails/api/bf/enums/match_projection.rb
99
+ - lib/betfair_api_ng_rails/api/bf/enums/order_by.rb
100
+ - lib/betfair_api_ng_rails/api/bf/enums/order_projection.rb
101
+ - lib/betfair_api_ng_rails/api/bf/enums/order_status.rb
102
+ - lib/betfair_api_ng_rails/api/bf/enums/order_type.rb
103
+ - lib/betfair_api_ng_rails/api/bf/enums/persistence_type.rb
104
+ - lib/betfair_api_ng_rails/api/bf/enums/price_data.rb
105
+ - lib/betfair_api_ng_rails/api/bf/enums/rollup_model.rb
106
+ - lib/betfair_api_ng_rails/api/bf/enums/runner_status.rb
107
+ - lib/betfair_api_ng_rails/api/bf/enums/side.rb
108
+ - lib/betfair_api_ng_rails/api/bf/enums/sort_dir.rb
109
+ - lib/betfair_api_ng_rails/api/bf/enums/time_granularity.rb
76
110
  - lib/betfair_api_ng_rails/api/bf/formatters/js_tree_formatter.rb
77
- - lib/betfair_api_ng_rails/api/bf/http_requester.rb
78
- - lib/betfair_api_ng_rails/api/bf/http_responser.rb
79
- - lib/betfair_api_ng_rails/api/bf/parser.rb
111
+ - lib/betfair_api_ng_rails/api/bf/helper.rb
112
+ - lib/betfair_api_ng_rails/api/bf/http/factory.rb
113
+ - lib/betfair_api_ng_rails/api/bf/http/requester.rb
114
+ - lib/betfair_api_ng_rails/api/bf/http/responser.rb
115
+ - lib/betfair_api_ng_rails/api/bf/orm/parsers/base.rb
116
+ - lib/betfair_api_ng_rails/api/bf/orm/parsers/list_competitions.rb
117
+ - lib/betfair_api_ng_rails/api/bf/orm/parsers/list_event_types.rb
118
+ - lib/betfair_api_ng_rails/api/bf/orm/parsers/list_events.rb
119
+ - lib/betfair_api_ng_rails/api/bf/orm/requester.rb
80
120
  - lib/betfair_api_ng_rails/api/bf/provider.rb
81
121
  - lib/betfair_api_ng_rails/api/bf/session_manager.rb
82
122
  - lib/betfair_api_ng_rails/api/formatter_factory.rb
83
- - lib/betfair_api_ng_rails/api/soccer/requester.rb
84
123
  - lib/betfair_api_ng_rails/version.rb
85
124
  - lib/generators/betfair_api_ng_rails/install/install_generator.rb
86
125
  - lib/generators/betfair_api_ng_rails/install/templates/betfair_api_ng_rails.rb
@@ -1,11 +0,0 @@
1
- module BetfairApiNgRails
2
- module Api
3
- class BaseFormatter
4
-
5
- def format(record: {}, resource: "")
6
- raise 'Must be reimplemented!'
7
- end
8
-
9
- end
10
- end
11
- end
@@ -1,25 +0,0 @@
1
- require 'json'
2
-
3
- module BetfairApiNgRails
4
- module Api
5
- class BaseParser
6
-
7
- def parse(response: {})
8
- raise 'Must be reimplemented!'
9
- end
10
-
11
- private
12
-
13
- def jsonify(response)
14
- JSON.parse response
15
- rescue
16
- {}
17
- end
18
-
19
- def process_record(h)
20
- h
21
- end
22
-
23
- end
24
- end
25
- end
@@ -1,25 +0,0 @@
1
- require 'active_support/inflector'
2
-
3
- module BetfairApiNgRails
4
- module Api
5
- class BaseRequester
6
-
7
- attr_reader :provider_name, :sport, :data
8
-
9
- def initialize(provider)
10
- @provider_name = provider
11
- end
12
-
13
- def load(resource: "", parameters: {})
14
- raise "Must be reimplemented!"
15
- end
16
-
17
- private
18
-
19
- def current_provider
20
- @_current_provider ||= "BetfairApiNgRails::Api::#{provider_name.to_s.upcase}::Provider".constantize.new
21
- end
22
-
23
- end
24
- end
25
- end
@@ -1,73 +0,0 @@
1
- require "net/https"
2
- require "uri"
3
- require 'json'
4
-
5
- module BetfairApiNgRails
6
- module Api
7
- module BF
8
- class HttpRequester
9
-
10
- attr_reader :http, :request, :uri
11
-
12
- def initialize(url, use_ssl = true)
13
- @uri = URI.parse url
14
- @http = Net::HTTP.new uri.host, uri.port
15
- http.use_ssl = use_ssl
16
- @request = Net::HTTP::Post.new uri.request_uri
17
- end
18
-
19
- def do_request
20
- Api::BF::HttpResponser.new http.request(request)
21
- end
22
-
23
- def set_crt_file(path)
24
- http.cert = OpenSSL::X509::Certificate.new(read_file(path))
25
- end
26
-
27
- def set_key_file(path)
28
- http.key = OpenSSL::PKey::RSA.new(read_file(path))
29
- end
30
-
31
- def set_verify_mode(value)
32
- http.verify_mode = value
33
- end
34
-
35
- def set_ssl_files(crt_path, key_path, verify = OpenSSL::SSL::VERIFY_PEER)
36
- set_crt_file crt_path
37
- set_key_file key_path
38
- set_verify_mode verify
39
- end
40
-
41
- def set_auth_headers(app_key, session_key = nil)
42
- request["X-Application"] = app_key
43
- request["X-Authentication"] = session_key if session_key
44
- end
45
-
46
- def set_request_headers(headers)
47
- headers.each { |name, value| request[name] = value }
48
- end
49
-
50
- def set_form_data(values)
51
- request.set_form_data values
52
- end
53
-
54
- def set_request_body(body)
55
- request.body = body
56
- end
57
-
58
- def set_api_req_body(method, filter = {})
59
- set_request_body "{\"jsonrpc\": \"2.0\", \"method\": \"SportsAPING/v1.0/#{method}\", \"params\": {\"filter\": #{filter.to_json}}}"
60
- end
61
-
62
- private
63
-
64
- def read_file(path)
65
- File.read path
66
- rescue
67
- ""
68
- end
69
-
70
- end
71
- end
72
- end
73
- end
@@ -1,44 +0,0 @@
1
- require 'json'
2
-
3
- module BetfairApiNgRails
4
- module Api
5
- module BF
6
- class HttpResponser
7
- include Api::BF::Constants
8
-
9
- attr_reader :response, :error_info
10
-
11
- def initialize(response)
12
- @response = response
13
- end
14
-
15
- def result
16
- JSON.parse response.body
17
- end
18
-
19
- def has_error?
20
- http_error? || api_req_error? || session_req_error?
21
- end
22
-
23
- private
24
-
25
- def http_error?
26
- (response.code != '200').tap { |val| set_error_info(:HTTP, response.code) if val }
27
- end
28
-
29
- def session_req_error?
30
- (result.fetch('loginStatus', SUCCESS_LOGIN) != SUCCESS_LOGIN).tap { |val| set_error_info(:SESSION, result['loginStatus']) if val }
31
- end
32
-
33
- def api_req_error?
34
- (result.has_key?('error')).tap { |val| set_error_info(:API, result['error']) if val }
35
- end
36
-
37
- def set_error_info(type, info)
38
- @error_info = { type: type, info: info }
39
- end
40
-
41
- end
42
- end
43
- end
44
- end
@@ -1,31 +0,0 @@
1
- require 'active_support/inflector'
2
-
3
- module BetfairApiNgRails
4
- module Api
5
- module BF
6
- class Parser < Api::BaseParser
7
-
8
- attr_reader :data
9
-
10
- def initialize(data)
11
- @data = data
12
- end
13
-
14
- def parse(response: {})
15
- response.fetch('result', []).map { |r| process_record(r) }
16
- end
17
-
18
- private
19
-
20
- def resource_key
21
- data.camelize :lower
22
- end
23
-
24
- def process_record(h)
25
- h.merge!(h[resource_key]).except resource_key
26
- end
27
-
28
- end
29
- end
30
- end
31
- end
@@ -1,25 +0,0 @@
1
- module BetfairApiNgRails
2
- module Api
3
- module Soccer
4
- class Requester < BetfairApiNgRails::Api::BaseRequester
5
-
6
- def initialize(provider: "")
7
- @sport = :soccer
8
- super provider
9
- end
10
-
11
- def load(resource: "", parameters: {})
12
- @data = resource
13
- make_fetch parameters: parameters
14
- end
15
-
16
- private
17
-
18
- def make_fetch(parameters: {})
19
- current_provider.fetch data: data, parameters: parameters, sport: sport
20
- end
21
-
22
- end
23
- end
24
- end
25
- end