Commit 51598217 authored by sergio1990's avatar sergio1990

Raw version of GoRequester

parent 88303dd7
......@@ -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
request.body = 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
provider ? prepare_api_url : prepare_auth_url
end
def prepare_auth_url
"#{Api::Config.go_url}/en/#{username}/#{password}/#{app_key}/#{Api::Config.go_localuser}/#{Api::Config.go_filename}"
end
def prepare_api_url
"#{Api::Config.go_url}/api/#{app_key}/#{session_key}"
end
end
end
end
end
\ 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