betfair_api_ng_rails 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +60 -0
- data/Rakefile +1 -0
- data/betfair_api_ng_rails.gemspec +24 -0
- data/lib/betfair_api_ng_rails.rb +46 -0
- data/lib/betfair_api_ng_rails/api/base_parser.rb +21 -0
- data/lib/betfair_api_ng_rails/api/base_provider.rb +23 -0
- data/lib/betfair_api_ng_rails/api/base_requester.rb +25 -0
- data/lib/betfair_api_ng_rails/api/bf/concerns/errorable.rb +21 -0
- data/lib/betfair_api_ng_rails/api/bf/config.rb +21 -0
- data/lib/betfair_api_ng_rails/api/bf/constants.rb +20 -0
- data/lib/betfair_api_ng_rails/api/bf/http_requester.rb +73 -0
- data/lib/betfair_api_ng_rails/api/bf/http_responser.rb +44 -0
- data/lib/betfair_api_ng_rails/api/bf/parsers/soccer/competition_parser.rb +25 -0
- data/lib/betfair_api_ng_rails/api/bf/provider.rb +44 -0
- data/lib/betfair_api_ng_rails/api/bf/session_manager.rb +57 -0
- data/lib/betfair_api_ng_rails/api/soccer/competition_requester.rb +14 -0
- data/lib/betfair_api_ng_rails/api/soccer/requester.rb +20 -0
- data/lib/betfair_api_ng_rails/version.rb +3 -0
- data/lib/generators/betfair_api_ng_rails/install/install_generator.rb +18 -0
- data/lib/generators/betfair_api_ng_rails/install/templates/betfair_api_ng_rails.rb +14 -0
- data/lib/generators/betfair_api_ng_rails/install/templates/betfair_api_ng_rails.yml +13 -0
- metadata +110 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 175bc8d3f3f69e5a9e78d95ba91e207fb951c05f
|
4
|
+
data.tar.gz: e335dc1146bf08103dbf65e5e414c166ac4cec84
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 00506ec9d758ce164597a969ba211efb8418f1782edd8811adbd1aa09c84a3031c568c38e5065bd778cdd68708f7e978c25fed2644f412a814185b5c06ebf459
|
7
|
+
data.tar.gz: 8d2d2c44f10b3e010b1442441fe16f311cb6f7fde47c6c8723f171218c373b2861dc3e96d092ececcd5e29763c58a03c2735fd181500c63e7918dfadf11dd99c
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 sergio1990
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
# BetfairApiNgRails
|
2
|
+
|
3
|
+
API-NG is Betfair's next generation API for developers looking to create automated betting systems or custom interfaces for themselves or for Betfair customers. Using this gem you may do calls to API-NG for fetching some interesting information about competitions, events and markets.
|
4
|
+
|
5
|
+
## WARNING!!!
|
6
|
+
|
7
|
+
__Last version of gem supports only list* requests.__
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
gem 'betfair_api_ng_rails'
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install betfair_api_ng_rails
|
22
|
+
|
23
|
+
After this run next rake command:
|
24
|
+
|
25
|
+
$ bundle exec rake betfair_api_ng_rails:install
|
26
|
+
|
27
|
+
After installation will appear two files:
|
28
|
+
|
29
|
+
```
|
30
|
+
config/betfair_api_ng_rails.yml
|
31
|
+
config/initializers/betfair_api_ng_rails.rb
|
32
|
+
```
|
33
|
+
|
34
|
+
In this files you must specify credentials to API-NG. Also you should notice that this gem used non-interactive login and you must generate ssh keys for logining well. More information about this you may find [there](https://api.developer.betfair.com/services/webapps/docs/display/1smk3cen4v3lu3yomq5qye0ni/Non-Interactive+%28bot%29+login).
|
35
|
+
|
36
|
+
## Usage
|
37
|
+
|
38
|
+
Sample code for fetching competitions list:
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
requester = BetfairApiNgRails::Api::Soccer::CompetitionRequester.new provider: :bf
|
42
|
+
res = requester.load
|
43
|
+
```
|
44
|
+
|
45
|
+
For all available methods see [there](https://api.developer.betfair.com/services/webapps/docs/display/1smk3cen4v3lu3yomq5qye0ni/Betting+Operations).
|
46
|
+
|
47
|
+
Also you may passing filering params in _load_:
|
48
|
+
|
49
|
+
```ruby
|
50
|
+
requester = BetfairApiNgRails::Api::Soccer::CompetitionRequester.new provider: :bf
|
51
|
+
res = requester.load parameters: { event_ids: [1, 2] }
|
52
|
+
```
|
53
|
+
|
54
|
+
## Contributing
|
55
|
+
|
56
|
+
1. Fork it
|
57
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
58
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
59
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
60
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'betfair_api_ng_rails/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "betfair_api_ng_rails"
|
8
|
+
spec.version = BetfairApiNgRails::VERSION
|
9
|
+
spec.authors = ["sergio1990"]
|
10
|
+
spec.email = ["sergeg1990@gmail.com"]
|
11
|
+
spec.description = %q{Betfair API-NG for Rails}
|
12
|
+
spec.summary = %q{Provides accessing betfair.com api-ng using non-interactive login}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "activesupport", ">= 3.1.0"
|
24
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require "betfair_api_ng_rails/version"
|
2
|
+
|
3
|
+
module BetfairApiNgRails
|
4
|
+
|
5
|
+
module Api
|
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
|
+
|
11
|
+
module BF
|
12
|
+
|
13
|
+
autoload :Config, 'betfair_api_ng_rails/api/bf/config'
|
14
|
+
autoload :Constants, 'betfair_api_ng_rails/api/bf/constants'
|
15
|
+
autoload :HttpRequester, 'betfair_api_ng_rails/api/bf/http_requester'
|
16
|
+
autoload :HttpResponser, 'betfair_api_ng_rails/api/bf/http_responser'
|
17
|
+
autoload :Provider, 'betfair_api_ng_rails/api/bf/provider'
|
18
|
+
autoload :SessionManager, 'betfair_api_ng_rails/api/bf/session_manager'
|
19
|
+
|
20
|
+
module Parsers
|
21
|
+
|
22
|
+
module Soccer
|
23
|
+
|
24
|
+
autoload :CompetitionParser, 'betfair_api_ng_rails/api/bf/parsers/soccer/competition_parser'
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
module Soccer
|
33
|
+
|
34
|
+
autoload :Requester, 'betfair_api_ng_rails/api/soccer/requester'
|
35
|
+
autoload :CompetitionRequester, 'betfair_api_ng_rails/api/soccer/competition_requester'
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.config(&block)
|
42
|
+
@_config ||= BetfairApiNgRails::Api::BF::Config
|
43
|
+
block_given? ? yield(@_config) : @_config
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
@@ -0,0 +1,21 @@
|
|
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
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'active_support/inflector'
|
2
|
+
|
3
|
+
module BetfairApiNgRails
|
4
|
+
module Api
|
5
|
+
class BaseProvider
|
6
|
+
|
7
|
+
def fetch(data: "", parameters: {}, sport: "")
|
8
|
+
raise "Must be reimplemented!"
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def build_function(method)
|
14
|
+
"list#{method.to_s.pluralize.camelize}"
|
15
|
+
end
|
16
|
+
|
17
|
+
def build_parser(data, sport)
|
18
|
+
"BetfairApiNgRails::Api::BF::Parsers::#{sport.to_s.camelize}::#{data.to_s.camelize}Parser".constantize.new
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,25 @@
|
|
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(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
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'active_support/core_ext/object'
|
2
|
+
|
3
|
+
module BetfairApiNgRails
|
4
|
+
module Api
|
5
|
+
module BF
|
6
|
+
module Concerns
|
7
|
+
module Errorable
|
8
|
+
|
9
|
+
def has_errors?
|
10
|
+
!error_info.nil?
|
11
|
+
end
|
12
|
+
|
13
|
+
def error_info
|
14
|
+
@http_responser.try(:error_info?)
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module BetfairApiNgRails
|
2
|
+
module Api
|
3
|
+
module BF
|
4
|
+
class Config
|
5
|
+
|
6
|
+
class << self
|
7
|
+
|
8
|
+
attr_accessor :application_key,
|
9
|
+
:ssl_key_filepath,
|
10
|
+
:ssl_crt_filepath,
|
11
|
+
:login_url,
|
12
|
+
:api_url,
|
13
|
+
:username,
|
14
|
+
:password
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module BetfairApiNgRails
|
2
|
+
module Api
|
3
|
+
module BF
|
4
|
+
module Constants
|
5
|
+
|
6
|
+
SUCCESS_LOGIN = "SUCCESS"
|
7
|
+
|
8
|
+
SESSION_REQUEST_HEADERS = {
|
9
|
+
"Content-Type" => "application/x-www-form-urlencoded"
|
10
|
+
}
|
11
|
+
|
12
|
+
API_REQUEST_HEADERS = {
|
13
|
+
"Content-Type" => "application/json",
|
14
|
+
"Accept" => "application/json"
|
15
|
+
}
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,73 @@
|
|
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
|
@@ -0,0 +1,44 @@
|
|
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
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module BetfairApiNgRails
|
2
|
+
module Api
|
3
|
+
module BF
|
4
|
+
module Parsers
|
5
|
+
module Soccer
|
6
|
+
class CompetitionParser < Api::BaseParser
|
7
|
+
|
8
|
+
def parse(response: {})
|
9
|
+
response['result'].map { |r| process_competition(r) }
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def process_competition(h)
|
15
|
+
h.merge! h['competition']
|
16
|
+
h.except! 'competition'
|
17
|
+
h
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'betfair_api_ng_rails/api/bf/concerns/errorable'
|
2
|
+
|
3
|
+
module BetfairApiNgRails
|
4
|
+
module Api
|
5
|
+
module BF
|
6
|
+
class Provider < Api::BaseProvider
|
7
|
+
include Api::BF::Concerns::Errorable
|
8
|
+
include Api::BF::Constants
|
9
|
+
|
10
|
+
attr_reader :session_manager
|
11
|
+
|
12
|
+
def initialize
|
13
|
+
@session_manager = Api::BF::SessionManager.new
|
14
|
+
end
|
15
|
+
|
16
|
+
def fetch(data: "", parameters: {}, sport: "")
|
17
|
+
return [] unless session_manager.request_ssoid
|
18
|
+
setup_http_requester with_method: data
|
19
|
+
do_request data, parameters, sport
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def do_request(data, parameters, sport)
|
25
|
+
@http_responser = @http_requester.do_request
|
26
|
+
process_response @http_responser.result, build_parser(data, sport)
|
27
|
+
end
|
28
|
+
|
29
|
+
def process_response(response, parser)
|
30
|
+
parser.parse response: response
|
31
|
+
end
|
32
|
+
|
33
|
+
def setup_http_requester(with_method: "")
|
34
|
+
@http_requester = Api::BF::HttpRequester.new(Api::BF::Config.api_url).tap do |req|
|
35
|
+
req.set_request_headers API_REQUEST_HEADERS
|
36
|
+
req.set_auth_headers Api::BF::Config.application_key, session_manager.ssoid
|
37
|
+
req.set_api_req_body build_function(with_method)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require "net/https"
|
2
|
+
require "uri"
|
3
|
+
require 'json'
|
4
|
+
require 'betfair_api_ng_rails/api/bf/concerns/errorable'
|
5
|
+
|
6
|
+
module BetfairApiNgRails
|
7
|
+
module Api
|
8
|
+
module BF
|
9
|
+
class SessionManager
|
10
|
+
include Api::BF::Concerns::Errorable
|
11
|
+
include Api::BF::Constants
|
12
|
+
|
13
|
+
def initialize
|
14
|
+
setup_http_requester
|
15
|
+
end
|
16
|
+
|
17
|
+
def ssoid
|
18
|
+
@ssoid ||= fetch_ssoid
|
19
|
+
end
|
20
|
+
|
21
|
+
def request_ssoid
|
22
|
+
ssoid
|
23
|
+
!has_errors?
|
24
|
+
end
|
25
|
+
|
26
|
+
def expire_ssoid
|
27
|
+
@ssoid = nil
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def fetch_ssoid
|
33
|
+
process_response get_login_response
|
34
|
+
end
|
35
|
+
|
36
|
+
def process_response(response)
|
37
|
+
response['sessionToken']
|
38
|
+
end
|
39
|
+
|
40
|
+
def get_login_response
|
41
|
+
@http_responser = @http_requester.do_request
|
42
|
+
@http_responser.result
|
43
|
+
end
|
44
|
+
|
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
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module BetfairApiNgRails
|
2
|
+
class Api::Soccer::CompetitionRequester < BetfairApiNgRails::Api::Soccer::Requester
|
3
|
+
|
4
|
+
def initialize(provider: '')
|
5
|
+
@data = :competition
|
6
|
+
super provider
|
7
|
+
end
|
8
|
+
|
9
|
+
def load(parameters: {})
|
10
|
+
make_fetch parameters: parameters
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,20 @@
|
|
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
|
+
private
|
12
|
+
|
13
|
+
def make_fetch(parameters: {})
|
14
|
+
current_provider.fetch data: data, parameters: parameters, sport: sport
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rails/generators/base'
|
2
|
+
|
3
|
+
module BetfairApiNgRails
|
4
|
+
module Generators
|
5
|
+
class InstallGenerator < ::Rails::Generators::Base
|
6
|
+
source_root File.expand_path("../templates", __FILE__)
|
7
|
+
|
8
|
+
def create_configuration_file
|
9
|
+
copy_file 'betfair_api_ng_rails.yml', File.join('config', "betfair_api_ng_rails.yml")
|
10
|
+
end
|
11
|
+
|
12
|
+
def create_initializer_file
|
13
|
+
copy_file 'betfair_api_ng_rails.rb', File.join('config/initializers', "betfair_api_ng_rails.rb")
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
BetfairApiNgRails.config do |config|
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
load_config = YAML.load_file("#{Rails.root}/config/betfair_api_ng_rails.yml")[Rails.env]
|
5
|
+
|
6
|
+
config.application_key = load_config['application_key']
|
7
|
+
config.ssl_key_filepath = "#{Rails.root}/public/client-2048.key"
|
8
|
+
config.ssl_crt_filepath = "#{Rails.root}/public/client-2048.crt"
|
9
|
+
config.login_url = load_config['login_url']
|
10
|
+
config.api_url = load_config['api_url']
|
11
|
+
config.username = load_config['username']
|
12
|
+
config.password = load_config['password']
|
13
|
+
|
14
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
development:
|
2
|
+
application_key: YOUR_APP_KEY
|
3
|
+
login_url: https://identitysso.betfair.com/api/certlogin
|
4
|
+
api_url: https://api-ng.betstores.com/betting/betfair/services/api.betfair.com/exchange/betting/json-rpc/v1
|
5
|
+
username: YOUR_ACCOUNT_USERNAME
|
6
|
+
password: YOUR_ACCOUNT_PASSWORD
|
7
|
+
|
8
|
+
production:
|
9
|
+
application_key: YOUR_APP_KEY
|
10
|
+
login_url: https://identitysso.betfair.com/api/certlogin
|
11
|
+
api_url: https://api-ng.betstores.com/betting/betfair/services/api.betfair.com/exchange/betting/json-rpc/v1
|
12
|
+
username: YOUR_ACCOUNT_USERNAME
|
13
|
+
password: YOUR_ACCOUNT_PASSWORD
|
metadata
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: betfair_api_ng_rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- sergio1990
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-03-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: activesupport
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 3.1.0
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 3.1.0
|
55
|
+
description: Betfair API-NG for Rails
|
56
|
+
email:
|
57
|
+
- sergeg1990@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- .gitignore
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE.txt
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- betfair_api_ng_rails.gemspec
|
68
|
+
- lib/betfair_api_ng_rails.rb
|
69
|
+
- lib/betfair_api_ng_rails/api/base_parser.rb
|
70
|
+
- lib/betfair_api_ng_rails/api/base_provider.rb
|
71
|
+
- lib/betfair_api_ng_rails/api/base_requester.rb
|
72
|
+
- lib/betfair_api_ng_rails/api/bf/concerns/errorable.rb
|
73
|
+
- lib/betfair_api_ng_rails/api/bf/config.rb
|
74
|
+
- lib/betfair_api_ng_rails/api/bf/constants.rb
|
75
|
+
- lib/betfair_api_ng_rails/api/bf/http_requester.rb
|
76
|
+
- lib/betfair_api_ng_rails/api/bf/http_responser.rb
|
77
|
+
- lib/betfair_api_ng_rails/api/bf/parsers/soccer/competition_parser.rb
|
78
|
+
- lib/betfair_api_ng_rails/api/bf/provider.rb
|
79
|
+
- lib/betfair_api_ng_rails/api/bf/session_manager.rb
|
80
|
+
- lib/betfair_api_ng_rails/api/soccer/competition_requester.rb
|
81
|
+
- lib/betfair_api_ng_rails/api/soccer/requester.rb
|
82
|
+
- lib/betfair_api_ng_rails/version.rb
|
83
|
+
- lib/generators/betfair_api_ng_rails/install/install_generator.rb
|
84
|
+
- lib/generators/betfair_api_ng_rails/install/templates/betfair_api_ng_rails.rb
|
85
|
+
- lib/generators/betfair_api_ng_rails/install/templates/betfair_api_ng_rails.yml
|
86
|
+
homepage: ''
|
87
|
+
licenses:
|
88
|
+
- MIT
|
89
|
+
metadata: {}
|
90
|
+
post_install_message:
|
91
|
+
rdoc_options: []
|
92
|
+
require_paths:
|
93
|
+
- lib
|
94
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - '>='
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
requirements: []
|
105
|
+
rubyforge_project:
|
106
|
+
rubygems_version: 2.0.14
|
107
|
+
signing_key:
|
108
|
+
specification_version: 4
|
109
|
+
summary: Provides accessing betfair.com api-ng using non-interactive login
|
110
|
+
test_files: []
|