betfair_api_ng_rails 0.0.5 → 0.0.6

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/README.md +8 -4
  3. data/lib/betfair_api_ng_rails.rb +5 -16
  4. data/lib/betfair_api_ng_rails/api/base_requester.rb +1 -1
  5. data/lib/betfair_api_ng_rails/api/bf/config.rb +1 -12
  6. data/lib/betfair_api_ng_rails/api/bf/constants.rb +5 -0
  7. data/lib/betfair_api_ng_rails/api/bf/formatters/js_tree_formatter.rb +1 -1
  8. data/lib/betfair_api_ng_rails/api/bf/parser.rb +5 -1
  9. data/lib/betfair_api_ng_rails/api/bf/provider.rb +8 -3
  10. data/lib/betfair_api_ng_rails/api/formatter_factory.rb +21 -0
  11. data/lib/betfair_api_ng_rails/api/soccer/requester.rb +3 -2
  12. data/lib/betfair_api_ng_rails/version.rb +1 -1
  13. metadata +3 -14
  14. data/lib/betfair_api_ng_rails/api/soccer/cleared_order_requester.rb +0 -10
  15. data/lib/betfair_api_ng_rails/api/soccer/competition_requester.rb +0 -10
  16. data/lib/betfair_api_ng_rails/api/soccer/country_requester.rb +0 -10
  17. data/lib/betfair_api_ng_rails/api/soccer/current_order_requester.rb +0 -10
  18. data/lib/betfair_api_ng_rails/api/soccer/event_requester.rb +0 -10
  19. data/lib/betfair_api_ng_rails/api/soccer/event_type_requester.rb +0 -10
  20. data/lib/betfair_api_ng_rails/api/soccer/market_book_requester.rb +0 -10
  21. data/lib/betfair_api_ng_rails/api/soccer/market_catalogue_requester.rb +0 -10
  22. data/lib/betfair_api_ng_rails/api/soccer/market_profit_and_loss_requester.rb +0 -10
  23. data/lib/betfair_api_ng_rails/api/soccer/market_type_requester.rb +0 -10
  24. data/lib/betfair_api_ng_rails/api/soccer/time_range_requester.rb +0 -10
  25. data/lib/betfair_api_ng_rails/api/soccer/venue_requester.rb +0 -10
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3a4047856d17acd629735d0b1ed9cac87dbddb2a
4
- data.tar.gz: 56acfabb6cb2b33e9b4bbed51c80128e58687b0e
3
+ metadata.gz: 9d4331f320e5e91adc30dcca6364e44be4bc38ad
4
+ data.tar.gz: 32f2bb4dd3cf565ed282c9ddb1ba31e8a0538192
5
5
  SHA512:
6
- metadata.gz: 5fb004e76dfbda6bc66a624feb375ded194a6d4d6fdea445c54bc3a0e2a8313711bb16a5395b9a2097c2802c9e298144c0b3a1c8a38f420e93ba032fed7f6d57
7
- data.tar.gz: a707fd5f1ef38d874a016ef385b07f1e828e6c86d13be0bc51f99cfd985dd72f783efcba60c2c8d2a384ff0a666768166102034eb8219e9d6e8094c0a94933eb
6
+ metadata.gz: 09b7ff8a4028830d7addc66f5aabf22ed3a14bffe9d08bf071bccf5ec8634c5803dccb3873ebf036cdf396d1ca83fa74e4784e1e3f1fa79dabeadce7cf06e500
7
+ data.tar.gz: 00b898d7cbe81d336514bab145731cac7424fe8113429dbe118d902618cf8b24bf44825b345f7f7ba545eff1d9fc5f3e72b4ed1931b09974644c4e1bd765cf95
data/README.md CHANGED
@@ -20,6 +20,10 @@ Or install it yourself as:
20
20
 
21
21
  $ gem install betfair_api_ng_rails
22
22
 
23
+ Or if you want to stay on the edge:
24
+
25
+ gem 'betfair_api_ng_rails', github: 'alterego-labs/betfair_api_ng_rails'
26
+
23
27
  After this run next rake command:
24
28
 
25
29
  $ bundle exec rake betfair_api_ng_rails:install
@@ -38,8 +42,8 @@ In this files you must specify credentials to API-NG. Also you should notice tha
38
42
  Sample code for fetching competitions list:
39
43
 
40
44
  ```ruby
41
- requester = BetfairApiNgRails::Api::Soccer::CompetitionRequester.new provider: :bf
42
- res = requester.load
45
+ requester = BetfairApiNgRails::Api::Soccer::Requester.new provider: :bf
46
+ res = requester.load resource: :competitions
43
47
  ```
44
48
 
45
49
  For all available methods see [there](https://api.developer.betfair.com/services/webapps/docs/display/1smk3cen4v3lu3yomq5qye0ni/Betting+Operations).
@@ -47,8 +51,8 @@ For all available methods see [there](https://api.developer.betfair.com/services
47
51
  Also you may passing filering params in _load_:
48
52
 
49
53
  ```ruby
50
- requester = BetfairApiNgRails::Api::Soccer::CompetitionRequester.new provider: :bf
51
- res = requester.load parameters: { event_ids: [1, 2] }
54
+ requester = BetfairApiNgRails::Api::Soccer::Requester.new provider: :bf
55
+ res = requester.load resource: :competitions, parameters: { event_ids: [1, 2] }
52
56
  ```
53
57
 
54
58
  ## Contributing
@@ -4,10 +4,11 @@ module BetfairApiNgRails
4
4
 
5
5
  module Api
6
6
 
7
- autoload :BaseParser, 'betfair_api_ng_rails/api/base_parser'
8
- autoload :BaseProvider, 'betfair_api_ng_rails/api/base_provider'
9
- autoload :BaseRequester, 'betfair_api_ng_rails/api/base_requester'
10
- autoload :BaseFormatter, 'betfair_api_ng_rails/api/base_formatter'
7
+ autoload :BaseParser, 'betfair_api_ng_rails/api/base_parser'
8
+ autoload :BaseProvider, 'betfair_api_ng_rails/api/base_provider'
9
+ autoload :BaseRequester, 'betfair_api_ng_rails/api/base_requester'
10
+ autoload :BaseFormatter, 'betfair_api_ng_rails/api/base_formatter'
11
+ autoload :FormatterFactory, 'betfair_api_ng_rails/api/formatter_factory'
11
12
 
12
13
  module BF
13
14
 
@@ -30,18 +31,6 @@ module BetfairApiNgRails
30
31
  module Soccer
31
32
 
32
33
  autoload :Requester, 'betfair_api_ng_rails/api/soccer/requester'
33
- autoload :CompetitionRequester, 'betfair_api_ng_rails/api/soccer/competition_requester'
34
- autoload :EventTypeRequester, 'betfair_api_ng_rails/api/soccer/event_type_requester'
35
- autoload :TimeRangeRequester, 'betfair_api_ng_rails/api/soccer/time_range_requester'
36
- autoload :EventRequester, 'betfair_api_ng_rails/api/soccer/event_requester'
37
- autoload :MarketTypeRequester, 'betfair_api_ng_rails/api/soccer/market_type_requester'
38
- autoload :CountryRequester, 'betfair_api_ng_rails/api/soccer/country_requester'
39
- autoload :VenueRequester, 'betfair_api_ng_rails/api/soccer/venue_requester'
40
- autoload :MarketCatalogueRequester, 'betfair_api_ng_rails/api/soccer/market_catalogue_requester'
41
- autoload :MarketBookRequester, 'betfair_api_ng_rails/api/soccer/market_book_requester'
42
- autoload :CurrentOrderRequester, 'betfair_api_ng_rails/api/soccer/current_order_requester'
43
- autoload :ClearedOrderRequester, 'betfair_api_ng_rails/api/soccer/cleared_order_requester'
44
- autoload :MarketProfitAndLossRequester, 'betfair_api_ng_rails/api/soccer/market_profit_and_loss_requester'
45
34
 
46
35
  end
47
36
 
@@ -10,7 +10,7 @@ module BetfairApiNgRails
10
10
  @provider_name = provider
11
11
  end
12
12
 
13
- def load(parameters: {})
13
+ def load(resource: "", parameters: {})
14
14
  raise "Must be reimplemented!"
15
15
  end
16
16
 
@@ -1,4 +1,3 @@
1
- require 'active_support/core_ext/object'
2
1
  require 'betfair_api_ng_rails/api/bf/formatters/js_tree_formatter'
3
2
 
4
3
  module BetfairApiNgRails
@@ -18,17 +17,7 @@ module BetfairApiNgRails
18
17
  :formatter
19
18
 
20
19
  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
20
+ @formatter = BetfairApiNgRails::Api::FormatterFactory.initialize_formatter value
32
21
  end
33
22
 
34
23
  end
@@ -16,6 +16,11 @@ module BetfairApiNgRails
16
16
  "Accept" => "application/json"
17
17
  }
18
18
 
19
+ ALLOWED_RESOURCES = {
20
+ soccer: [:event_types, :competitions, :time_ranges, :events, :market_types, :countries, :venues, :market_catalogue,
21
+ :market_book, :current_orders, :cleared_orders, :market_profit_and_loss]
22
+ }
23
+
19
24
  end
20
25
  end
21
26
  end
@@ -19,7 +19,7 @@ module BetfairApiNgRails
19
19
  {
20
20
  id: record['id'],
21
21
  text: record['name'],
22
- chldren: ALLOW_CHILDREN.include?(resource),
22
+ children: ALLOW_CHILDREN.include?(resource.to_sym),
23
23
  data:{
24
24
  type: resource.to_s.singularize,
25
25
  fields: record
@@ -17,8 +17,12 @@ module BetfairApiNgRails
17
17
 
18
18
  private
19
19
 
20
+ def resource_key
21
+ data.camelize :lower
22
+ end
23
+
20
24
  def process_record(h)
21
- h.merge!(h[data]).except data
25
+ h.merge!(h[resource_key]).except resource_key
22
26
  end
23
27
 
24
28
  end
@@ -16,7 +16,8 @@ module BetfairApiNgRails
16
16
 
17
17
  def fetch(data: "", parameters: {}, sport: "")
18
18
  return [] unless session_manager.request_ssoid
19
- setup_http_requester with_method: data
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
20
21
  do_request data, parameters, sport
21
22
  end
22
23
 
@@ -36,14 +37,18 @@ module BetfairApiNgRails
36
37
  response.map { |r| Api::BF::Config.formatter.format(record: r, resource: data) }
37
38
  end
38
39
 
39
- def setup_http_requester(with_method: "")
40
+ def setup_http_requester(with_method: "", params: {})
40
41
  @http_requester = Api::BF::HttpRequester.new(Api::BF::Config.api_url).tap do |req|
41
42
  req.set_request_headers API_REQUEST_HEADERS
42
43
  req.set_auth_headers Api::BF::Config.application_key, session_manager.ssoid
43
- req.set_api_req_body build_function(with_method)
44
+ req.set_api_req_body build_function(with_method), params
44
45
  end
45
46
  end
46
47
 
48
+ def is_method_allowed?(data, sport)
49
+ ALLOWED_RESOURCES[sport.to_sym].include? data.to_sym
50
+ end
51
+
47
52
  end
48
53
  end
49
54
  end
@@ -0,0 +1,21 @@
1
+ require 'active_support/core_ext/object'
2
+
3
+ module BetfairApiNgRails
4
+ module Api
5
+ class FormatterFactory
6
+ class << self
7
+
8
+ def initialize_formatter(name)
9
+ name.is_a?(Symbol) ? initialize_formatter_by(name: name) : name.try(:new)
10
+ end
11
+
12
+ private
13
+
14
+ def initialize_formatter_by(name: "")
15
+ "BetfairApiNgRails::Api::BF::Formatters::#{name.to_s.camelize}Formatter".constantize.new
16
+ end
17
+
18
+ end
19
+ end
20
+ end
21
+ end
@@ -3,12 +3,13 @@ module BetfairApiNgRails
3
3
  module Soccer
4
4
  class Requester < BetfairApiNgRails::Api::BaseRequester
5
5
 
6
- def initialize(provider)
6
+ def initialize(provider: "")
7
7
  @sport = :soccer
8
8
  super provider
9
9
  end
10
10
 
11
- def load(parameters: {})
11
+ def load(resource: "", parameters: {})
12
+ @data = resource
12
13
  make_fetch parameters: parameters
13
14
  end
14
15
 
@@ -1,3 +1,3 @@
1
1
  module BetfairApiNgRails
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  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.5
4
+ version: 0.0.6
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-16 00:00:00.000000000 Z
11
+ date: 2014-03-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -79,19 +79,8 @@ files:
79
79
  - lib/betfair_api_ng_rails/api/bf/parser.rb
80
80
  - lib/betfair_api_ng_rails/api/bf/provider.rb
81
81
  - lib/betfair_api_ng_rails/api/bf/session_manager.rb
82
- - lib/betfair_api_ng_rails/api/soccer/cleared_order_requester.rb
83
- - lib/betfair_api_ng_rails/api/soccer/competition_requester.rb
84
- - lib/betfair_api_ng_rails/api/soccer/country_requester.rb
85
- - lib/betfair_api_ng_rails/api/soccer/current_order_requester.rb
86
- - lib/betfair_api_ng_rails/api/soccer/event_requester.rb
87
- - lib/betfair_api_ng_rails/api/soccer/event_type_requester.rb
88
- - lib/betfair_api_ng_rails/api/soccer/market_book_requester.rb
89
- - lib/betfair_api_ng_rails/api/soccer/market_catalogue_requester.rb
90
- - lib/betfair_api_ng_rails/api/soccer/market_profit_and_loss_requester.rb
91
- - lib/betfair_api_ng_rails/api/soccer/market_type_requester.rb
82
+ - lib/betfair_api_ng_rails/api/formatter_factory.rb
92
83
  - lib/betfair_api_ng_rails/api/soccer/requester.rb
93
- - lib/betfair_api_ng_rails/api/soccer/time_range_requester.rb
94
- - lib/betfair_api_ng_rails/api/soccer/venue_requester.rb
95
84
  - lib/betfair_api_ng_rails/version.rb
96
85
  - lib/generators/betfair_api_ng_rails/install/install_generator.rb
97
86
  - lib/generators/betfair_api_ng_rails/install/templates/betfair_api_ng_rails.rb
@@ -1,10 +0,0 @@
1
- module BetfairApiNgRails
2
- class Api::Soccer::ClearedOrderRequester < BetfairApiNgRails::Api::Soccer::Requester
3
-
4
- def initialize(provider: '')
5
- @data = :cleared_orders
6
- super provider
7
- end
8
-
9
- end
10
- end
@@ -1,10 +0,0 @@
1
- module BetfairApiNgRails
2
- class Api::Soccer::CompetitionRequester < BetfairApiNgRails::Api::Soccer::Requester
3
-
4
- def initialize(provider: '')
5
- @data = :competitions
6
- super provider
7
- end
8
-
9
- end
10
- end
@@ -1,10 +0,0 @@
1
- module BetfairApiNgRails
2
- class Api::Soccer::CountryRequester < BetfairApiNgRails::Api::Soccer::Requester
3
-
4
- def initialize(provider: '')
5
- @data = :countries
6
- super provider
7
- end
8
-
9
- end
10
- end
@@ -1,10 +0,0 @@
1
- module BetfairApiNgRails
2
- class Api::Soccer::CurrentOrderRequester < BetfairApiNgRails::Api::Soccer::Requester
3
-
4
- def initialize(provider: '')
5
- @data = :current_orders
6
- super provider
7
- end
8
-
9
- end
10
- end
@@ -1,10 +0,0 @@
1
- module BetfairApiNgRails
2
- class Api::Soccer::EventRequester < BetfairApiNgRails::Api::Soccer::Requester
3
-
4
- def initialize(provider: '')
5
- @data = :events
6
- super provider
7
- end
8
-
9
- end
10
- end
@@ -1,10 +0,0 @@
1
- module BetfairApiNgRails
2
- class Api::Soccer::EventTypeRequester < BetfairApiNgRails::Api::Soccer::Requester
3
-
4
- def initialize(provider: '')
5
- @data = :event_types
6
- super provider
7
- end
8
-
9
- end
10
- end
@@ -1,10 +0,0 @@
1
- module BetfairApiNgRails
2
- class Api::Soccer::MarketBookRequester < BetfairApiNgRails::Api::Soccer::Requester
3
-
4
- def initialize(provider: '')
5
- @data = :market_book
6
- super provider
7
- end
8
-
9
- end
10
- end
@@ -1,10 +0,0 @@
1
- module BetfairApiNgRails
2
- class Api::Soccer::MarketCatalogueRequester < BetfairApiNgRails::Api::Soccer::Requester
3
-
4
- def initialize(provider: '')
5
- @data = :market_catalogue
6
- super provider
7
- end
8
-
9
- end
10
- end
@@ -1,10 +0,0 @@
1
- module BetfairApiNgRails
2
- class Api::Soccer::MarketProfitAndLossRequester < BetfairApiNgRails::Api::Soccer::Requester
3
-
4
- def initialize(provider: '')
5
- @data = :market_profit_and_loss
6
- super provider
7
- end
8
-
9
- end
10
- end
@@ -1,10 +0,0 @@
1
- module BetfairApiNgRails
2
- class Api::Soccer::MarketTypeRequester < BetfairApiNgRails::Api::Soccer::Requester
3
-
4
- def initialize(provider: '')
5
- @data = :market_types
6
- super provider
7
- end
8
-
9
- end
10
- end
@@ -1,10 +0,0 @@
1
- module BetfairApiNgRails
2
- class Api::Soccer::TimeRangeRequester < BetfairApiNgRails::Api::Soccer::Requester
3
-
4
- def initialize(provider: '')
5
- @data = :time_ranges
6
- super provider
7
- end
8
-
9
- end
10
- end
@@ -1,10 +0,0 @@
1
- module BetfairApiNgRails
2
- class Api::Soccer::VenueRequester < BetfairApiNgRails::Api::Soccer::Requester
3
-
4
- def initialize(provider: '')
5
- @data = :venues
6
- super provider
7
- end
8
-
9
- end
10
- end