betfair_api_ng_rails 0.0.3 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (25) hide show
  1. checksums.yaml +4 -4
  2. data/lib/betfair_api_ng_rails.rb +4 -17
  3. data/lib/betfair_api_ng_rails/api/base_formatter.rb +11 -0
  4. data/lib/betfair_api_ng_rails/api/base_parser.rb +1 -1
  5. data/lib/betfair_api_ng_rails/api/base_provider.rb +4 -2
  6. data/lib/betfair_api_ng_rails/api/bf/config.rb +19 -1
  7. data/lib/betfair_api_ng_rails/api/bf/constants.rb +2 -0
  8. data/lib/betfair_api_ng_rails/api/bf/formatters/js_tree_formatter.rb +34 -0
  9. data/lib/betfair_api_ng_rails/api/bf/parser.rb +27 -0
  10. data/lib/betfair_api_ng_rails/api/bf/provider.rb +9 -3
  11. data/lib/betfair_api_ng_rails/version.rb +1 -1
  12. data/lib/generators/betfair_api_ng_rails/install/templates/betfair_api_ng_rails.rb +3 -0
  13. metadata +5 -14
  14. data/lib/betfair_api_ng_rails/api/bf/parsers/soccer/cleared_order_parser.rb +0 -13
  15. data/lib/betfair_api_ng_rails/api/bf/parsers/soccer/competition_parser.rb +0 -21
  16. data/lib/betfair_api_ng_rails/api/bf/parsers/soccer/country_parser.rb +0 -13
  17. data/lib/betfair_api_ng_rails/api/bf/parsers/soccer/current_order_parser.rb +0 -13
  18. data/lib/betfair_api_ng_rails/api/bf/parsers/soccer/event_parser.rb +0 -13
  19. data/lib/betfair_api_ng_rails/api/bf/parsers/soccer/event_type_parser.rb +0 -13
  20. data/lib/betfair_api_ng_rails/api/bf/parsers/soccer/market_book_parser.rb +0 -13
  21. data/lib/betfair_api_ng_rails/api/bf/parsers/soccer/market_catalogue_parser.rb +0 -13
  22. data/lib/betfair_api_ng_rails/api/bf/parsers/soccer/market_profit_and_loss_parser.rb +0 -13
  23. data/lib/betfair_api_ng_rails/api/bf/parsers/soccer/market_type_parser.rb +0 -13
  24. data/lib/betfair_api_ng_rails/api/bf/parsers/soccer/time_range_parser.rb +0 -13
  25. data/lib/betfair_api_ng_rails/api/bf/parsers/soccer/venue_parser.rb +0 -13
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a8ca4036f894f99635b1af2b2341de424a4412f8
4
- data.tar.gz: c4a8389caa862033ba128c2367f9f0a204c5ac51
3
+ metadata.gz: 3a4047856d17acd629735d0b1ed9cac87dbddb2a
4
+ data.tar.gz: 56acfabb6cb2b33e9b4bbed51c80128e58687b0e
5
5
  SHA512:
6
- metadata.gz: 5a5cf2adf3d26028237f488e2a2fbbbcb6b4601bca0270ed68c8d5905c31a3e99c0e4f89d7409b77980ab09e2c20522f759434f76e8cbb4413dad39444eec9af
7
- data.tar.gz: 8e0ddec22f0bd8a391d96d337d11ab63ebe65271f9841e0a3c40d305161116bd5e302597f3b8acfe49ea5fc156e5237d6ea21e648b7326e6ec9061f14d420dba
6
+ metadata.gz: 5fb004e76dfbda6bc66a624feb375ded194a6d4d6fdea445c54bc3a0e2a8313711bb16a5395b9a2097c2802c9e298144c0b3a1c8a38f420e93ba032fed7f6d57
7
+ data.tar.gz: a707fd5f1ef38d874a016ef385b07f1e828e6c86d13be0bc51f99cfd985dd72f783efcba60c2c8d2a384ff0a666768166102034eb8219e9d6e8094c0a94933eb
@@ -7,6 +7,7 @@ module BetfairApiNgRails
7
7
  autoload :BaseParser, 'betfair_api_ng_rails/api/base_parser'
8
8
  autoload :BaseProvider, 'betfair_api_ng_rails/api/base_provider'
9
9
  autoload :BaseRequester, 'betfair_api_ng_rails/api/base_requester'
10
+ autoload :BaseFormatter, 'betfair_api_ng_rails/api/base_formatter'
10
11
 
11
12
  module BF
12
13
 
@@ -15,26 +16,12 @@ module BetfairApiNgRails
15
16
  autoload :HttpRequester, 'betfair_api_ng_rails/api/bf/http_requester'
16
17
  autoload :HttpResponser, 'betfair_api_ng_rails/api/bf/http_responser'
17
18
  autoload :Provider, 'betfair_api_ng_rails/api/bf/provider'
19
+ autoload :Parser, 'betfair_api_ng_rails/api/bf/parser'
18
20
  autoload :SessionManager, 'betfair_api_ng_rails/api/bf/session_manager'
19
21
 
20
- module Parsers
22
+ module Formatters
21
23
 
22
- module Soccer
23
-
24
- autoload :CompetitionParser, 'betfair_api_ng_rails/api/bf/parsers/soccer/competition_parser'
25
- autoload :EventTypeParser, 'betfair_api_ng_rails/api/bf/parsers/soccer/event_type_parser'
26
- autoload :TimeRangeParser, 'betfair_api_ng_rails/api/bf/parsers/soccer/time_range_parser'
27
- autoload :EventParser, 'betfair_api_ng_rails/api/bf/parsers/soccer/event_parser'
28
- autoload :MarketTypeParser, 'betfair_api_ng_rails/api/bf/parsers/soccer/market_type_parser'
29
- autoload :CountryParser, 'betfair_api_ng_rails/api/bf/parsers/soccer/country_parser'
30
- autoload :VenueParser, 'betfair_api_ng_rails/api/bf/parsers/soccer/venue_parser'
31
- autoload :MarketCatalogueParser, 'betfair_api_ng_rails/api/bf/parsers/soccer/market_catalogue_parser'
32
- autoload :MarketBookParser, 'betfair_api_ng_rails/api/bf/parsers/soccer/market_book_parser'
33
- autoload :CurrentOrderParser, 'betfair_api_ng_rails/api/bf/parsers/soccer/current_order_parser'
34
- autoload :ClearedOrderParser, 'betfair_api_ng_rails/api/bf/parsers/soccer/cleared_order_parser'
35
- autoload :MarketProfitAndLossParser, 'betfair_api_ng_rails/api/bf/parsers/soccer/market_profit_and_loss_parser'
36
-
37
- end
24
+ autoload :JsTreeFromatter, 'betfair_api_ng_rails/api/bf/formatters/js_tree_formatter'
38
25
 
39
26
  end
40
27
 
@@ -0,0 +1,11 @@
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
@@ -5,7 +5,7 @@ module BetfairApiNgRails
5
5
  class BaseParser
6
6
 
7
7
  def parse(response: {})
8
- response.fetch('result', []).map { |r| process_record(r) }
8
+ raise 'Must be reimplemented!'
9
9
  end
10
10
 
11
11
  private
@@ -4,6 +4,8 @@ module BetfairApiNgRails
4
4
  module Api
5
5
  class BaseProvider
6
6
 
7
+ attr_reader :provider_name
8
+
7
9
  def fetch(data: "", parameters: {}, sport: "")
8
10
  raise "Must be reimplemented!"
9
11
  end
@@ -14,8 +16,8 @@ module BetfairApiNgRails
14
16
  "list#{method.to_s.camelize}"
15
17
  end
16
18
 
17
- def build_parser(data, sport)
18
- "BetfairApiNgRails::Api::BF::Parsers::#{sport.to_s.camelize}::#{data.to_s.singularize.camelize}Parser".constantize.new
19
+ def build_parser(data)
20
+ "BetfairApiNgRails::Api::#{provider_name}::Parser".constantize.new data.to_s.singularize
19
21
  end
20
22
 
21
23
  end
@@ -1,3 +1,6 @@
1
+ require 'active_support/core_ext/object'
2
+ require 'betfair_api_ng_rails/api/bf/formatters/js_tree_formatter'
3
+
1
4
  module BetfairApiNgRails
2
5
  module Api
3
6
  module BF
@@ -11,7 +14,22 @@ module BetfairApiNgRails
11
14
  :login_url,
12
15
  :api_url,
13
16
  :username,
14
- :password
17
+ :password,
18
+ :formatter
19
+
20
+ def formatter=(value)
21
+ @formatter = initialize_formatter value
22
+ end
23
+
24
+ private
25
+
26
+ def initialize_formatter(name)
27
+ name.is_a?(Symbol) ? initialize_formatter_by(name: name) : name.try(:new)
28
+ end
29
+
30
+ def initialize_formatter_by(name: "")
31
+ "BetfairApiNgRails::Api::BF::Formatters::#{name.to_s.camelize}Formatter".constantize.new
32
+ end
15
33
 
16
34
  end
17
35
 
@@ -5,6 +5,8 @@ module BetfairApiNgRails
5
5
 
6
6
  SUCCESS_LOGIN = "SUCCESS"
7
7
 
8
+ PROVIDER_NAME = "BF"
9
+
8
10
  SESSION_REQUEST_HEADERS = {
9
11
  "Content-Type" => "application/x-www-form-urlencoded"
10
12
  }
@@ -0,0 +1,34 @@
1
+ require 'json'
2
+ require 'active_support/inflector'
3
+
4
+ module BetfairApiNgRails
5
+ module Api
6
+ module BF
7
+ module Formatters
8
+ class JsTreeFormatter < BetfairApiNgRails::Api::BaseFormatter
9
+
10
+ attr_accessor :allow_children
11
+
12
+ ALLOW_CHILDREN = [:event_types, :competitions]
13
+
14
+ def initialize
15
+ @allow_children = false
16
+ end
17
+
18
+ def format(record: {}, resource: "")
19
+ {
20
+ id: record['id'],
21
+ text: record['name'],
22
+ chldren: ALLOW_CHILDREN.include?(resource),
23
+ data:{
24
+ type: resource.to_s.singularize,
25
+ fields: record
26
+ }
27
+ }
28
+ end
29
+
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,27 @@
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 process_record(h)
21
+ h.merge!(h[data]).except data
22
+ end
23
+
24
+ end
25
+ end
26
+ end
27
+ end
@@ -11,6 +11,7 @@ module BetfairApiNgRails
11
11
 
12
12
  def initialize
13
13
  @session_manager = Api::BF::SessionManager.new
14
+ @provider_name = "BF"
14
15
  end
15
16
 
16
17
  def fetch(data: "", parameters: {}, sport: "")
@@ -23,11 +24,16 @@ module BetfairApiNgRails
23
24
 
24
25
  def do_request(data, parameters, sport)
25
26
  @http_responser = @http_requester.do_request
26
- process_response @http_responser.result, build_parser(data, sport)
27
+ process_response data, @http_responser.result, build_parser(data)
27
28
  end
28
29
 
29
- def process_response(response, parser)
30
- parser.parse response: response
30
+ def process_response(data, response, parser)
31
+ format_response data, parser.parse(response: response)
32
+ end
33
+
34
+ def format_response(data, response)
35
+ return response unless Api::BF::Config.formatter
36
+ response.map { |r| Api::BF::Config.formatter.format(record: r, resource: data) }
31
37
  end
32
38
 
33
39
  def setup_http_requester(with_method: "")
@@ -1,3 +1,3 @@
1
1
  module BetfairApiNgRails
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -11,4 +11,7 @@ BetfairApiNgRails.config do |config|
11
11
  config.username = load_config['username']
12
12
  config.password = load_config['password']
13
13
 
14
+ # Uncomment and set needed formatter or nil if you want plain response
15
+ # config.formatter = :js_tree
16
+
14
17
  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.3
4
+ version: 0.0.5
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-15 00:00:00.000000000 Z
11
+ date: 2014-03-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -66,26 +66,17 @@ 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
69
70
  - lib/betfair_api_ng_rails/api/base_parser.rb
70
71
  - lib/betfair_api_ng_rails/api/base_provider.rb
71
72
  - lib/betfair_api_ng_rails/api/base_requester.rb
72
73
  - lib/betfair_api_ng_rails/api/bf/concerns/errorable.rb
73
74
  - lib/betfair_api_ng_rails/api/bf/config.rb
74
75
  - lib/betfair_api_ng_rails/api/bf/constants.rb
76
+ - lib/betfair_api_ng_rails/api/bf/formatters/js_tree_formatter.rb
75
77
  - lib/betfair_api_ng_rails/api/bf/http_requester.rb
76
78
  - lib/betfair_api_ng_rails/api/bf/http_responser.rb
77
- - lib/betfair_api_ng_rails/api/bf/parsers/soccer/cleared_order_parser.rb
78
- - lib/betfair_api_ng_rails/api/bf/parsers/soccer/competition_parser.rb
79
- - lib/betfair_api_ng_rails/api/bf/parsers/soccer/country_parser.rb
80
- - lib/betfair_api_ng_rails/api/bf/parsers/soccer/current_order_parser.rb
81
- - lib/betfair_api_ng_rails/api/bf/parsers/soccer/event_parser.rb
82
- - lib/betfair_api_ng_rails/api/bf/parsers/soccer/event_type_parser.rb
83
- - lib/betfair_api_ng_rails/api/bf/parsers/soccer/market_book_parser.rb
84
- - lib/betfair_api_ng_rails/api/bf/parsers/soccer/market_catalogue_parser.rb
85
- - lib/betfair_api_ng_rails/api/bf/parsers/soccer/market_profit_and_loss_parser.rb
86
- - lib/betfair_api_ng_rails/api/bf/parsers/soccer/market_type_parser.rb
87
- - lib/betfair_api_ng_rails/api/bf/parsers/soccer/time_range_parser.rb
88
- - lib/betfair_api_ng_rails/api/bf/parsers/soccer/venue_parser.rb
79
+ - lib/betfair_api_ng_rails/api/bf/parser.rb
89
80
  - lib/betfair_api_ng_rails/api/bf/provider.rb
90
81
  - lib/betfair_api_ng_rails/api/bf/session_manager.rb
91
82
  - lib/betfair_api_ng_rails/api/soccer/cleared_order_requester.rb
@@ -1,13 +0,0 @@
1
- module BetfairApiNgRails
2
- module Api
3
- module BF
4
- module Parsers
5
- module Soccer
6
- class ClearedOrderParser < Api::BaseParser
7
-
8
- end
9
- end
10
- end
11
- end
12
- end
13
- end
@@ -1,21 +0,0 @@
1
- module BetfairApiNgRails
2
- module Api
3
- module BF
4
- module Parsers
5
- module Soccer
6
- class CompetitionParser < Api::BaseParser
7
-
8
- private
9
-
10
- def process_record(h)
11
- h.merge! h['competition']
12
- h.except! 'competition'
13
- h
14
- end
15
-
16
- end
17
- end
18
- end
19
- end
20
- end
21
- end
@@ -1,13 +0,0 @@
1
- module BetfairApiNgRails
2
- module Api
3
- module BF
4
- module Parsers
5
- module Soccer
6
- class CountryParser < Api::BaseParser
7
-
8
- end
9
- end
10
- end
11
- end
12
- end
13
- end
@@ -1,13 +0,0 @@
1
- module BetfairApiNgRails
2
- module Api
3
- module BF
4
- module Parsers
5
- module Soccer
6
- class CurrentOrderParser < Api::BaseParser
7
-
8
- end
9
- end
10
- end
11
- end
12
- end
13
- end
@@ -1,13 +0,0 @@
1
- module BetfairApiNgRails
2
- module Api
3
- module BF
4
- module Parsers
5
- module Soccer
6
- class EventParser < Api::BaseParser
7
-
8
- end
9
- end
10
- end
11
- end
12
- end
13
- end
@@ -1,13 +0,0 @@
1
- module BetfairApiNgRails
2
- module Api
3
- module BF
4
- module Parsers
5
- module Soccer
6
- class EventTypeParser < Api::BaseParser
7
-
8
- end
9
- end
10
- end
11
- end
12
- end
13
- end
@@ -1,13 +0,0 @@
1
- module BetfairApiNgRails
2
- module Api
3
- module BF
4
- module Parsers
5
- module Soccer
6
- class MarketBookParser < Api::BaseParser
7
-
8
- end
9
- end
10
- end
11
- end
12
- end
13
- end
@@ -1,13 +0,0 @@
1
- module BetfairApiNgRails
2
- module Api
3
- module BF
4
- module Parsers
5
- module Soccer
6
- class MarketCatalogueParser < Api::BaseParser
7
-
8
- end
9
- end
10
- end
11
- end
12
- end
13
- end
@@ -1,13 +0,0 @@
1
- module BetfairApiNgRails
2
- module Api
3
- module BF
4
- module Parsers
5
- module Soccer
6
- class MarketProfitAndLossParser < Api::BaseParser
7
-
8
- end
9
- end
10
- end
11
- end
12
- end
13
- end
@@ -1,13 +0,0 @@
1
- module BetfairApiNgRails
2
- module Api
3
- module BF
4
- module Parsers
5
- module Soccer
6
- class MarketTypeParser < Api::BaseParser
7
-
8
- end
9
- end
10
- end
11
- end
12
- end
13
- end
@@ -1,13 +0,0 @@
1
- module BetfairApiNgRails
2
- module Api
3
- module BF
4
- module Parsers
5
- module Soccer
6
- class TimeRangeParser < Api::BaseParser
7
-
8
- end
9
- end
10
- end
11
- end
12
- end
13
- end
@@ -1,13 +0,0 @@
1
- module BetfairApiNgRails
2
- module Api
3
- module BF
4
- module Parsers
5
- module Soccer
6
- class VenueParser < Api::BaseParser
7
-
8
- end
9
- end
10
- end
11
- end
12
- end
13
- end