Commit 10bafb13 authored by Sergey Gernyak's avatar Sergey Gernyak

Move login url and keep alive url from yml to constants

parent f681288b
......@@ -5,14 +5,12 @@ module BetfairApiNgRails
attr_accessor :application_key,
:ssl_key_filepath,
:ssl_crt_filepath,
:login_url,
:api_url,
:username,
:password,
:locale,
:formatter,
:keep_alive_session,
:keep_alive_url,
:use_cache,
:cache_expire,
:proxy_url,
......
module BetfairApiNgRails
module Api
module Constants
SUCCESS_LOGIN = "SUCCESS"
PROVIDER_NAME = "BF"
SESSION_REQUEST_HEADERS = {
"Content-Type" => "application/x-www-form-urlencoded"
}
......@@ -49,15 +46,18 @@ module BetfairApiNgRails
LOADABLE_CONFIG_OPTIONS = [
:application_key,
:login_url,
:api_url,
:keep_alive_url,
:username,
:password,
:go_localuser,
:go_filename
]
# URLs
LOGIN_URL = "https://identitysso.betfair.com/api/certlogin"
KEEP_ALIVE_URL = "https://identitysso.betfair.com/api/keepAlive"
end
end
end
......@@ -13,7 +13,7 @@ module BetfairApiNgRails
end
def session_requester
create_http_requester(Api::Config.login_url, false).tap do |req|
create_http_requester(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, false).tap do |req|
create_http_requester(KEEP_ALIVE_URL, false).tap do |req|
req.set_accept_header 'application/json'
req.set_auth_headers Api::Config.application_key, ssoid
end
......
......@@ -26,6 +26,8 @@ module BetfairApiNgRails
run_request __method__, { market_id: market_id, instructions: instructions, customer_ref: customer_ref }
end
# Account API requests
private
def run_request(method, params, data = {})
......
BetfairApiNgRails.config do |config|
BetfairApiNgRails.config do |config|
config.load_for_environment "#{Rails.root}/config/betfair_api_ng_rails.yml", Rails.env
config.ssl_key_filepath = "#{Rails.root}/public/client-2048.key"
config.ssl_crt_filepath = "#{Rails.root}/public/client-2048.crt"
config.locale = :ru
config.formatter = nil
config.keep_alive_session = true
......
development:
application_key: YOUR_APP_KEY
login_url: https://identitysso.betfair.com/api/certlogin
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
go_localuser: YOURUSERNAME
......@@ -10,10 +8,8 @@ development:
production:
application_key: YOUR_APP_KEY
login_url: https://identitysso.betfair.com/api/certlogin
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
go_localuser: YOURUSERNAME
go_filename: betfair
\ No newline at end of file
go_filename: betfair
require 'spec_helper'
describe BetfairApiNgRails::Api::Config do
subject(:object) { described_class }
describe ".formatter=" do
let(:formatter) { double(:formatter) }
let(:value) { double(:value) }
......@@ -16,16 +14,14 @@ describe BetfairApiNgRails::Api::Config do
object.formatter = value
expect(object.instance_variable_get(:@formatter)).to eq formatter
end
end
describe ".load_for_environment" do
let(:path) { "path" }
let(:opts) { [:opt1] }
let(:config) { {'env' => { 'opt1' => :val1 }} }
before do
before do
stub_const("BetfairApiNgRails::Api::Constants::LOADABLE_CONFIG_OPTIONS", opts)
allow(YAML).to receive(:load_file).with(path).and_return config
end
......@@ -34,7 +30,5 @@ describe BetfairApiNgRails::Api::Config do
expect(object).to receive('opt1=').with(:val1)
object.load_for_environment path, 'env'
end
end
end
\ No newline at end of file
end
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