Commit a0e9dcf1 authored by sergio1990's avatar sergio1990

Merge branch 'go-requester'

parents 132490ac b1060dba
......@@ -114,9 +114,10 @@ module BetfairApiNgRails
module Http
autoload :Requester, 'betfair_api_ng_rails/api/http/requester'
autoload :Responser, 'betfair_api_ng_rails/api/http/responser'
autoload :Factory, 'betfair_api_ng_rails/api/http/factory'
autoload :Requester, 'betfair_api_ng_rails/api/http/requester'
autoload :Responser, 'betfair_api_ng_rails/api/http/responser'
autoload :Factory, 'betfair_api_ng_rails/api/http/factory'
autoload :GoRequester, 'betfair_api_ng_rails/api/http/go_requester'
end
......
......@@ -16,7 +16,11 @@ module BetfairApiNgRails
:keep_alive_session,
:keep_alive_url,
:use_cache,
:cache_expire
:cache_expire,
:go_url,
:go_enable,
:go_localuser,
:go_filename
def formatter=(value)
@formatter = BetfairApiNgRails::Api::FormatterFactory.initialize_formatter value
......
......@@ -52,7 +52,9 @@ module BetfairApiNgRails
:api_url,
:keep_alive_url,
:username,
:password
:password,
:go_localuser,
:go_filename
]
end
......
......@@ -13,7 +13,7 @@ module BetfairApiNgRails
end
def session_requester
create_http_requester(Api::Config.login_url).tap do |req|
create_http_requester(Api::Config.login_url, false).tap do |req|
req.set_ssl_files Api::Config.ssl_crt_filepath, Api::Config.ssl_key_filepath
req.set_request_headers SESSION_REQUEST_HEADERS
req.set_auth_headers Api::Config.application_key
......@@ -22,7 +22,7 @@ module BetfairApiNgRails
end
def keep_alive_requester(ssoid)
create_http_requester(Api::Config.keep_alive_url).tap do |req|
create_http_requester(Api::Config.keep_alive_url, false).tap do |req|
req.set_accept_header 'application/json'
req.set_auth_headers Api::Config.application_key, ssoid
end
......@@ -30,8 +30,12 @@ module BetfairApiNgRails
private
def create_http_requester(url = "")
Api::Http::Requester.new url
def create_http_requester(url = "", provider = true)
if !Api::Config.go_enable
Api::Http::Requester.new url
else
Api::Http::GoRequester.new url, provider
end
end
end
......
require "net/https"
require "uri"
require 'json'
require 'betfair_api_ng_rails/api/helper'
module BetfairApiNgRails
module Api
module Http
class GoRequester
include BetfairApiNgRails::Api::Helper
attr_reader :http, :request, :uri
attr_reader :app_key, :session_key, :username, :password, :body, :is_provider
def initialize(url, provider = true, use_ssl = true)
@is_provider = provider
end
def do_request
create_http
prepare_body
Api::Http::Responser.new http.request(request)
end
def set_auth_headers(app_key, session_key = nil)
@app_key = app_key
@session_key = session_key
end
def set_form_data(values)
@username = values["username"]
@password = values["password"]
end
def set_request_body(body)
@body = body
end
def set_api_req_body(method, params = {})
set_request_body prepare_api_req_json(method, params)
end
def set_crt_file(path); end
def set_key_file(path); end
def set_verify_mode(value); end
def set_ssl_files(crt_path, key_path, verify = OpenSSL::SSL::VERIFY_PEER); end
def set_accept_header(value); end
def set_request_headers(headers); end
def set_header(name, value); end
private
def create_http
@uri = URI.parse prepare_url
@http = Net::HTTP.new uri.host, uri.port
@request = Net::HTTP::Post.new uri.request_uri
end
def prepare_url
is_provider ? prepare_api_url : prepare_auth_url
end
def prepare_auth_url
"#{Api::Config.go_url}/auth/en/#{username}/#{password}/#{app_key}/#{Api::Config.go_localuser}/#{Api::Config.go_filename}"
end
def prepare_api_url
"#{Api::Config.go_url}/api"
end
def prepare_body
return if !is_provider
request.body = {
appKey: app_key,
sessionToken: session_key,
body: body
}.to_json
end
end
end
end
end
\ No newline at end of file
......@@ -13,4 +13,9 @@ BetfairApiNgRails.config do |config|
config.use_cache = false
config.cache_expire = 5 # in seconds
# Go layer settings
config.go_enable = false
# Uncomment next line if you will use go layer and go_enable is set to true
#config.go_url = "http://127.0.0.1/"
end
\ No newline at end of file
......@@ -5,6 +5,8 @@ development:
keep_alive_url: https://identitysso.betfair.com/api/keepAlive
username: YOUR_ACCOUNT_USERNAME
password: YOUR_ACCOUNT_PASSWORD
go_localuser: YOURUSERNAME
go_filename: betfair
production:
application_key: YOUR_APP_KEY
......@@ -12,4 +14,6 @@ production:
api_url: https://api-ng.betstores.com/betting/betfair/services/api.betfair.com/exchange/betting/json-rpc/v1
keep_alive_url: https://identitysso.betfair.com/api/keepAlive
username: YOUR_ACCOUNT_USERNAME
password: YOUR_ACCOUNT_PASSWORD
\ No newline at end of file
password: YOUR_ACCOUNT_PASSWORD
go_localuser: YOURUSERNAME
go_filename: betfair
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment