betfair_api_ng_rails 0.0.8 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -28
- data/Rakefile +10 -1
- data/betfair_api_ng_rails.gemspec +3 -0
- data/lib/betfair_api_ng_rails.rb +92 -73
- data/lib/betfair_api_ng_rails/api/concerns/errorable.rb +19 -0
- data/lib/betfair_api_ng_rails/api/config.rb +27 -0
- data/lib/betfair_api_ng_rails/api/connection.rb +34 -0
- data/lib/betfair_api_ng_rails/api/connection_ext/formatting.rb +34 -0
- data/lib/betfair_api_ng_rails/api/connection_ext/parsing.rb +29 -0
- data/lib/betfair_api_ng_rails/api/constants.rb +51 -0
- data/lib/betfair_api_ng_rails/api/data/attributes.rb +50 -0
- data/lib/betfair_api_ng_rails/api/data/base.rb +16 -0
- data/lib/betfair_api_ng_rails/api/data/competition.rb +20 -0
- data/lib/betfair_api_ng_rails/api/data/competition_result.rb +21 -0
- data/lib/betfair_api_ng_rails/api/data/concerns/hashable.rb +29 -0
- data/lib/betfair_api_ng_rails/api/data/constants.rb +11 -0
- data/lib/betfair_api_ng_rails/api/data/country_code_result.rb +19 -0
- data/lib/betfair_api_ng_rails/api/data/event.rb +20 -0
- data/lib/betfair_api_ng_rails/api/data/event_result.rb +19 -0
- data/lib/betfair_api_ng_rails/api/data/event_type.rb +20 -0
- data/lib/betfair_api_ng_rails/api/data/event_type_result.rb +19 -0
- data/lib/betfair_api_ng_rails/api/data/market_filter.rb +16 -0
- data/lib/betfair_api_ng_rails/api/data/market_type_result.rb +19 -0
- data/lib/betfair_api_ng_rails/api/data/time_range.rb +20 -0
- data/lib/betfair_api_ng_rails/api/data/time_range_result.rb +19 -0
- data/lib/betfair_api_ng_rails/api/data/venue_result.rb +19 -0
- data/lib/betfair_api_ng_rails/api/enums/bet_status.rb +15 -0
- data/lib/betfair_api_ng_rails/api/enums/concerns/enumable.rb +15 -0
- data/lib/betfair_api_ng_rails/api/enums/execution_report_error_code.rb +28 -0
- data/lib/betfair_api_ng_rails/api/enums/execution_report_status.rb +15 -0
- data/lib/betfair_api_ng_rails/api/enums/group_by.rb +17 -0
- data/lib/betfair_api_ng_rails/api/enums/instruction_report_error_code.rb +31 -0
- data/lib/betfair_api_ng_rails/api/enums/instruction_report_status.rb +14 -0
- data/lib/betfair_api_ng_rails/api/enums/market_betting_type.rb +17 -0
- data/lib/betfair_api_ng_rails/api/enums/market_projection.rb +18 -0
- data/lib/betfair_api_ng_rails/api/enums/market_sort.rb +17 -0
- data/lib/betfair_api_ng_rails/api/enums/market_status.rb +15 -0
- data/lib/betfair_api_ng_rails/api/enums/match_projection.rb +14 -0
- data/lib/betfair_api_ng_rails/api/enums/order_by.rb +14 -0
- data/lib/betfair_api_ng_rails/api/enums/order_projection.rb +14 -0
- data/lib/betfair_api_ng_rails/api/enums/order_status.rb +13 -0
- data/lib/betfair_api_ng_rails/api/enums/order_type.rb +14 -0
- data/lib/betfair_api_ng_rails/api/enums/persistence_type.rb +14 -0
- data/lib/betfair_api_ng_rails/api/enums/price_data.rb +16 -0
- data/lib/betfair_api_ng_rails/api/enums/rollup_model.rb +15 -0
- data/lib/betfair_api_ng_rails/api/enums/runner_status.rb +17 -0
- data/lib/betfair_api_ng_rails/api/enums/side.rb +13 -0
- data/lib/betfair_api_ng_rails/api/enums/sort_dir.rb +13 -0
- data/lib/betfair_api_ng_rails/api/enums/time_granularity.rb +14 -0
- data/lib/betfair_api_ng_rails/api/formatter_factory.rb +1 -1
- data/lib/betfair_api_ng_rails/api/formatters/js_tree_formatter.rb +38 -0
- data/lib/betfair_api_ng_rails/api/hashalator.rb +39 -0
- data/lib/betfair_api_ng_rails/api/helper.rb +29 -0
- data/lib/betfair_api_ng_rails/api/http/factory.rb +41 -0
- data/lib/betfair_api_ng_rails/api/http/helpers/information_response.rb +35 -0
- data/lib/betfair_api_ng_rails/api/http/helpers/keep_alive_response.rb +32 -0
- data/lib/betfair_api_ng_rails/api/http/helpers/session_response.rb +36 -0
- data/lib/betfair_api_ng_rails/api/http/requester.rb +75 -0
- data/lib/betfair_api_ng_rails/api/http/responser.rb +47 -0
- data/lib/betfair_api_ng_rails/api/parsers/base.rb +31 -0
- data/lib/betfair_api_ng_rails/api/parsers/list_competitions.rb +15 -0
- data/lib/betfair_api_ng_rails/api/parsers/list_countries.rb +15 -0
- data/lib/betfair_api_ng_rails/api/parsers/list_event_types.rb +15 -0
- data/lib/betfair_api_ng_rails/api/parsers/list_events.rb +15 -0
- data/lib/betfair_api_ng_rails/api/parsers/list_market_types.rb +15 -0
- data/lib/betfair_api_ng_rails/api/parsers/list_time_ranges.rb +15 -0
- data/lib/betfair_api_ng_rails/api/parsers/list_venues.rb +15 -0
- data/lib/betfair_api_ng_rails/api/provider.rb +38 -0
- data/lib/betfair_api_ng_rails/api/request_methods.rb +33 -0
- data/lib/betfair_api_ng_rails/api/session_manager.rb +54 -0
- data/lib/betfair_api_ng_rails/errors.rb +6 -0
- data/lib/betfair_api_ng_rails/railtie.rb +7 -0
- data/lib/betfair_api_ng_rails/version.rb +1 -1
- data/lib/generators/betfair_api_ng_rails/install/templates/betfair_api_ng_rails.rb +11 -9
- data/lib/generators/betfair_api_ng_rails/install/templates/betfair_api_ng_rails.yml +2 -0
- data/spec/betfair_api_ng_rails/api/connection_spec.rb +74 -0
- data/spec/betfair_api_ng_rails/api/data/concerns/hashable_spec.rb +81 -0
- data/spec/betfair_api_ng_rails/api/formatters/js_tree_formatter_spec.rb +70 -0
- data/spec/betfair_api_ng_rails/api/hashalator_spec.rb +146 -0
- data/spec/betfair_api_ng_rails/api/provider_spec.rb +91 -0
- data/spec/betfair_api_ng_rails/api/request_methods_spec.rb +60 -0
- data/spec/betfair_api_ng_rails/api/session_manager_spec.rb +59 -0
- data/spec/betfair_api_ng_rails/integration/list_competitions_spec.rb +18 -0
- data/spec/betfair_api_ng_rails/integration/list_countries_spec.rb +18 -0
- data/spec/betfair_api_ng_rails/integration/list_event_types_spec.rb +18 -0
- data/spec/betfair_api_ng_rails/integration/list_events_spec.rb +18 -0
- data/spec/betfair_api_ng_rails/integration/list_market_types_spec.rb +18 -0
- data/spec/betfair_api_ng_rails/integration/list_time_ranges_spec.rb +18 -0
- data/spec/betfair_api_ng_rails/integration/list_venues_spec.rb +18 -0
- data/spec/spec_helper.rb +16 -0
- data/spec/support/shared_examples/request_method.rb +18 -0
- data/spec/support/shared_examples/simple_list_filtering_request.rb +51 -0
- metadata +156 -66
- data/lib/betfair_api_ng_rails/api/base_provider.rb +0 -15
- data/lib/betfair_api_ng_rails/api/bf/concerns/errorable.rb +0 -21
- data/lib/betfair_api_ng_rails/api/bf/config.rb +0 -27
- data/lib/betfair_api_ng_rails/api/bf/constants.rb +0 -37
- data/lib/betfair_api_ng_rails/api/bf/data/attributes.rb +0 -52
- data/lib/betfair_api_ng_rails/api/bf/data/base.rb +0 -17
- data/lib/betfair_api_ng_rails/api/bf/data/competition.rb +0 -26
- data/lib/betfair_api_ng_rails/api/bf/data/competition_result.rb +0 -23
- data/lib/betfair_api_ng_rails/api/bf/data/concerns/hashable.rb +0 -40
- data/lib/betfair_api_ng_rails/api/bf/data/concerns/querable.rb +0 -46
- data/lib/betfair_api_ng_rails/api/bf/data/constants.rb +0 -13
- data/lib/betfair_api_ng_rails/api/bf/data/event.rb +0 -26
- data/lib/betfair_api_ng_rails/api/bf/data/event_result.rb +0 -21
- data/lib/betfair_api_ng_rails/api/bf/data/event_type.rb +0 -26
- data/lib/betfair_api_ng_rails/api/bf/data/event_type_result.rb +0 -21
- data/lib/betfair_api_ng_rails/api/bf/data/market_filter.rb +0 -19
- data/lib/betfair_api_ng_rails/api/bf/data/time_range.rb +0 -18
- data/lib/betfair_api_ng_rails/api/bf/data/time_range_result.rb +0 -21
- data/lib/betfair_api_ng_rails/api/bf/enums/bet_status.rb +0 -17
- data/lib/betfair_api_ng_rails/api/bf/enums/concerns/enumable.rb +0 -17
- data/lib/betfair_api_ng_rails/api/bf/enums/execution_report_error_code.rb +0 -30
- data/lib/betfair_api_ng_rails/api/bf/enums/execution_report_status.rb +0 -17
- data/lib/betfair_api_ng_rails/api/bf/enums/group_by.rb +0 -19
- data/lib/betfair_api_ng_rails/api/bf/enums/instruction_report_error_code.rb +0 -33
- data/lib/betfair_api_ng_rails/api/bf/enums/instruction_report_status.rb +0 -16
- data/lib/betfair_api_ng_rails/api/bf/enums/market_betting_type.rb +0 -19
- data/lib/betfair_api_ng_rails/api/bf/enums/market_projection.rb +0 -20
- data/lib/betfair_api_ng_rails/api/bf/enums/market_sort.rb +0 -19
- data/lib/betfair_api_ng_rails/api/bf/enums/market_status.rb +0 -17
- data/lib/betfair_api_ng_rails/api/bf/enums/match_projection.rb +0 -16
- data/lib/betfair_api_ng_rails/api/bf/enums/order_by.rb +0 -16
- data/lib/betfair_api_ng_rails/api/bf/enums/order_projection.rb +0 -16
- data/lib/betfair_api_ng_rails/api/bf/enums/order_status.rb +0 -15
- data/lib/betfair_api_ng_rails/api/bf/enums/order_type.rb +0 -16
- data/lib/betfair_api_ng_rails/api/bf/enums/persistence_type.rb +0 -16
- data/lib/betfair_api_ng_rails/api/bf/enums/price_data.rb +0 -18
- data/lib/betfair_api_ng_rails/api/bf/enums/rollup_model.rb +0 -17
- data/lib/betfair_api_ng_rails/api/bf/enums/runner_status.rb +0 -19
- data/lib/betfair_api_ng_rails/api/bf/enums/side.rb +0 -15
- data/lib/betfair_api_ng_rails/api/bf/enums/sort_dir.rb +0 -15
- data/lib/betfair_api_ng_rails/api/bf/enums/time_granularity.rb +0 -16
- data/lib/betfair_api_ng_rails/api/bf/formatters/js_tree_formatter.rb +0 -30
- data/lib/betfair_api_ng_rails/api/bf/helper.rb +0 -33
- data/lib/betfair_api_ng_rails/api/bf/http/factory.rb +0 -37
- data/lib/betfair_api_ng_rails/api/bf/http/requester.rb +0 -69
- data/lib/betfair_api_ng_rails/api/bf/http/responser.rb +0 -58
- data/lib/betfair_api_ng_rails/api/bf/orm/parsers/base.rb +0 -33
- data/lib/betfair_api_ng_rails/api/bf/orm/parsers/list_competitions.rb +0 -19
- data/lib/betfair_api_ng_rails/api/bf/orm/parsers/list_event_types.rb +0 -19
- data/lib/betfair_api_ng_rails/api/bf/orm/parsers/list_events.rb +0 -19
- data/lib/betfair_api_ng_rails/api/bf/orm/requester.rb +0 -52
- data/lib/betfair_api_ng_rails/api/bf/provider.rb +0 -38
- data/lib/betfair_api_ng_rails/api/bf/session_manager.rb +0 -46
@@ -0,0 +1,31 @@
|
|
1
|
+
module BetfairApiNgRails
|
2
|
+
module Api
|
3
|
+
module Enums
|
4
|
+
class InstructionReportErrorCode
|
5
|
+
extend Api::Enums::Concerns::Enumable
|
6
|
+
|
7
|
+
enumify "INVALID_BET_SIZE",
|
8
|
+
"INVALID_RUNNER",
|
9
|
+
"BET_TAKEN_OR_LAPSED",
|
10
|
+
"BET_IN_PROGRESS",
|
11
|
+
"RUNNER_REMOVED",
|
12
|
+
"MARKET_NOT_OPEN_FOR_BETTING",
|
13
|
+
"LOSS_LIMIT_EXCEEDED",
|
14
|
+
"MARKET_NOT_OPEN_FOR_BSP_BETTING",
|
15
|
+
"INVALID_PRICE_EDIT",
|
16
|
+
"INVALID_ODDS",
|
17
|
+
"INSUFFICIENT_FUNDS",
|
18
|
+
"INVALID_PERSISTENCE_TYPE",
|
19
|
+
"ERROR_IN_MATCHER",
|
20
|
+
"INVALID_BACK_LAY_COMBINATION",
|
21
|
+
"ERROR_IN_ORDER",
|
22
|
+
"INVALID_BID_TYPE",
|
23
|
+
"INVALID_BET_ID",
|
24
|
+
"CANCELLED_NOT_PLACED",
|
25
|
+
"RELATED_ACTION_FAILED",
|
26
|
+
"NO_ACTION_REQUIRED"
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module BetfairApiNgRails
|
2
|
+
module Api
|
3
|
+
module Enums
|
4
|
+
class MarketBettingType
|
5
|
+
extend Api::Enums::Concerns::Enumable
|
6
|
+
|
7
|
+
enumify "ODDS",
|
8
|
+
"LINE",
|
9
|
+
"RANGE",
|
10
|
+
"ASIAN_HANDICAP_DOUBLE_LINE",
|
11
|
+
"ASIAN_HANDICAP_SINGLE_LINE",
|
12
|
+
"FIXED_ODDS"
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module BetfairApiNgRails
|
2
|
+
module Api
|
3
|
+
module Enums
|
4
|
+
class MarketProjection
|
5
|
+
extend Api::Enums::Concerns::Enumable
|
6
|
+
|
7
|
+
enumify "COMPETITION",
|
8
|
+
"EVENT",
|
9
|
+
"EVENT_TYPE",
|
10
|
+
"MARKET_START_TIME",
|
11
|
+
"MARKET_DESCRIPTION",
|
12
|
+
"RUNNER_DESCRIPTION",
|
13
|
+
"RUNNER_METADATA"
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module BetfairApiNgRails
|
2
|
+
module Api
|
3
|
+
module Enums
|
4
|
+
class MarketSort
|
5
|
+
extend Api::Enums::Concerns::Enumable
|
6
|
+
|
7
|
+
enumify "MINIMUM_TRADED",
|
8
|
+
"MAXIMUM_TRADED",
|
9
|
+
"MINIMUM_AVAILABLE",
|
10
|
+
"MAXIMUM_AVAILABLE",
|
11
|
+
"FIRST_TO_START",
|
12
|
+
"LAST_TO_START"
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -12,7 +12,7 @@ module BetfairApiNgRails
|
|
12
12
|
private
|
13
13
|
|
14
14
|
def initialize_formatter_by(name: "")
|
15
|
-
"BetfairApiNgRails::Api::
|
15
|
+
"BetfairApiNgRails::Api::Formatters::#{name.to_s.camelize}Formatter".constantize.new
|
16
16
|
end
|
17
17
|
|
18
18
|
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'active_support/inflector'
|
3
|
+
|
4
|
+
module BetfairApiNgRails
|
5
|
+
module Api
|
6
|
+
module Formatters
|
7
|
+
class JsTreeFormatter
|
8
|
+
|
9
|
+
ALLOW_CHILDREN = [:event_types, :competitions]
|
10
|
+
|
11
|
+
def process(result, as: '')
|
12
|
+
result.map { |r| format_record(r, resource_from_method(as)) }
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def resource_from_method(method)
|
18
|
+
method.underscore.gsub(/^list_/, '').to_sym
|
19
|
+
end
|
20
|
+
|
21
|
+
def format_record(record, resource)
|
22
|
+
return {} unless record
|
23
|
+
obj = record.send resource.to_s.singularize
|
24
|
+
{
|
25
|
+
id: obj.id,
|
26
|
+
text: obj.name,
|
27
|
+
children: ALLOW_CHILDREN.include?(resource.to_sym),
|
28
|
+
data:{
|
29
|
+
type: resource.to_s.singularize,
|
30
|
+
fields: obj.to_hash
|
31
|
+
}
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module BetfairApiNgRails
|
2
|
+
module Api
|
3
|
+
class Hashalator
|
4
|
+
include Api::Data::Constants
|
5
|
+
|
6
|
+
attr_reader :hashable
|
7
|
+
|
8
|
+
def initialize(object)
|
9
|
+
@hashable = object
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_hash
|
13
|
+
hashable.inject({}) do |h, (k, v)|
|
14
|
+
h[hash_key(k)] = hash_value(v)
|
15
|
+
h
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def hash_value(val)
|
22
|
+
need_to_hash?(val) ? hashing_val(val) : val
|
23
|
+
end
|
24
|
+
|
25
|
+
def hashing_val(val)
|
26
|
+
val.is_a?(Array) ? val.map { |e| hash_value(e) } : val.to_hash
|
27
|
+
end
|
28
|
+
|
29
|
+
def need_to_hash?(val)
|
30
|
+
!ATTRS_AS_IS.include?(val.class)
|
31
|
+
end
|
32
|
+
|
33
|
+
def hash_key(key)
|
34
|
+
key.to_s.camelize(:lower)
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module BetfairApiNgRails
|
2
|
+
module Api
|
3
|
+
module Helper
|
4
|
+
|
5
|
+
def read_certificate_file(path)
|
6
|
+
OpenSSL::X509::Certificate.new read_file(path)
|
7
|
+
end
|
8
|
+
|
9
|
+
def read_rsa_file(path)
|
10
|
+
OpenSSL::PKey::RSA.new read_file(path)
|
11
|
+
end
|
12
|
+
|
13
|
+
def read_file(path)
|
14
|
+
File.read path
|
15
|
+
rescue
|
16
|
+
""
|
17
|
+
end
|
18
|
+
|
19
|
+
def prepare_api_req_json(method, params)
|
20
|
+
{
|
21
|
+
"jsonrpc" => "2.0",
|
22
|
+
"method" => "SportsAPING/v1.0/#{method}",
|
23
|
+
"params" => params
|
24
|
+
}.to_json
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module BetfairApiNgRails
|
2
|
+
module Api
|
3
|
+
module Http
|
4
|
+
class Factory
|
5
|
+
class << self
|
6
|
+
include Api::Constants
|
7
|
+
|
8
|
+
def provider_requester(ssoid = nil)
|
9
|
+
create_http_requester(Api::Config.api_url).tap do |req|
|
10
|
+
req.set_request_headers API_REQUEST_HEADERS
|
11
|
+
req.set_auth_headers Api::Config.application_key, ssoid
|
12
|
+
end
|
13
|
+
end
|
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
|
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
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def keep_alive_requester(ssoid)
|
25
|
+
create_http_requester(Api::Config.keep_alive_url).tap do |req|
|
26
|
+
req.set_accept_header 'application/json'
|
27
|
+
req.set_auth_headers Api::Config.application_key, ssoid
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def create_http_requester(url = "")
|
34
|
+
Api::Http::Requester.new url
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|